2005-08-28 01:21:25 +04:00
|
|
|
# localrepo.py - read/write repository class for mercurial
|
|
|
|
#
|
2007-06-19 10:51:34 +04:00
|
|
|
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
|
2005-08-28 01:21:25 +04:00
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2012-12-19 17:46:57 +04:00
|
|
|
from node import hex, nullid, short
|
2006-12-15 05:25:19 +03:00
|
|
|
from i18n import _
|
2014-04-17 09:49:20 +04:00
|
|
|
import urllib
|
2014-04-02 01:40:35 +04:00
|
|
|
import peer, changegroup, subrepo, pushkey, obsolete, repoview
|
2011-11-04 03:16:24 +04:00
|
|
|
import changelog, dirstate, filelog, manifest, context, bookmarks, phases
|
2013-11-12 11:23:52 +04:00
|
|
|
import lock as lockmod
|
2014-04-15 19:27:55 +04:00
|
|
|
import transaction, store, encoding, exchange, bundle2
|
2011-07-21 23:06:55 +04:00
|
|
|
import scmutil, util, extensions, hook, error, revset
|
2010-03-11 19:43:44 +03:00
|
|
|
import match as matchmod
|
|
|
|
import merge as mergemod
|
|
|
|
import tags as tagsmod
|
2009-04-22 04:01:22 +04:00
|
|
|
from lock import release
|
2010-06-07 22:03:32 +04:00
|
|
|
import weakref, errno, os, time, inspect
|
2013-11-07 03:19:04 +04:00
|
|
|
import branchmap, pathutil
|
2014-12-14 23:53:50 +03:00
|
|
|
import namespaces
|
2009-04-30 05:47:15 +04:00
|
|
|
propertycache = util.propertycache
|
2011-07-25 16:08:37 +04:00
|
|
|
filecache = scmutil.filecache
|
2009-04-22 04:01:22 +04:00
|
|
|
|
2012-10-08 21:34:04 +04:00
|
|
|
class repofilecache(filecache):
|
|
|
|
"""All filecache usage on repo are done for logic that should be unfiltered
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __get__(self, repo, type=None):
|
|
|
|
return super(repofilecache, self).__get__(repo.unfiltered(), type)
|
|
|
|
def __set__(self, repo, value):
|
|
|
|
return super(repofilecache, self).__set__(repo.unfiltered(), value)
|
|
|
|
def __delete__(self, repo):
|
|
|
|
return super(repofilecache, self).__delete__(repo.unfiltered())
|
|
|
|
|
|
|
|
class storecache(repofilecache):
|
2012-03-01 19:39:58 +04:00
|
|
|
"""filecache for files in the store"""
|
|
|
|
def join(self, obj, fname):
|
|
|
|
return obj.sjoin(fname)
|
|
|
|
|
2012-10-08 22:02:20 +04:00
|
|
|
class unfilteredpropertycache(propertycache):
|
|
|
|
"""propertycache that apply to unfiltered repo only"""
|
|
|
|
|
|
|
|
def __get__(self, repo, type=None):
|
2013-09-30 16:23:14 +04:00
|
|
|
unfi = repo.unfiltered()
|
|
|
|
if unfi is repo:
|
|
|
|
return super(unfilteredpropertycache, self).__get__(unfi)
|
|
|
|
return getattr(unfi, self.name)
|
2012-10-08 22:02:20 +04:00
|
|
|
|
|
|
|
class filteredpropertycache(propertycache):
|
|
|
|
"""propertycache that must take filtering in account"""
|
|
|
|
|
|
|
|
def cachevalue(self, obj, value):
|
|
|
|
object.__setattr__(obj, self.name, value)
|
|
|
|
|
|
|
|
|
|
|
|
def hasunfilteredcache(repo, name):
|
2013-02-10 21:24:29 +04:00
|
|
|
"""check if a repo has an unfilteredpropertycache value for <name>"""
|
2012-10-08 22:02:20 +04:00
|
|
|
return name in vars(repo.unfiltered())
|
|
|
|
|
2012-12-01 01:34:21 +04:00
|
|
|
def unfilteredmethod(orig):
|
2012-11-26 22:11:13 +04:00
|
|
|
"""decorate method that always need to be run on unfiltered version"""
|
|
|
|
def wrapper(repo, *args, **kwargs):
|
|
|
|
return orig(repo.unfiltered(), *args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
|
2014-04-02 10:41:32 +04:00
|
|
|
moderncaps = set(('lookup', 'branchmap', 'pushkey', 'known', 'getbundle',
|
2014-04-17 09:49:20 +04:00
|
|
|
'unbundle'))
|
2014-03-14 11:02:05 +04:00
|
|
|
legacycaps = moderncaps.union(set(['changegroupsubset']))
|
2012-07-13 23:47:06 +04:00
|
|
|
|
|
|
|
class localpeer(peer.peerrepository):
|
|
|
|
'''peer for a local repo; reflects only the most recent API'''
|
|
|
|
|
2014-03-14 11:02:05 +04:00
|
|
|
def __init__(self, repo, caps=moderncaps):
|
2012-07-13 23:47:06 +04:00
|
|
|
peer.peerrepository.__init__(self)
|
2013-01-13 11:39:16 +04:00
|
|
|
self._repo = repo.filtered('served')
|
2012-07-13 23:47:06 +04:00
|
|
|
self.ui = repo.ui
|
|
|
|
self._caps = repo._restrictcapabilities(caps)
|
|
|
|
self.requirements = repo.requirements
|
|
|
|
self.supportedformats = repo.supportedformats
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
self._repo.close()
|
|
|
|
|
|
|
|
def _capabilities(self):
|
|
|
|
return self._caps
|
|
|
|
|
|
|
|
def local(self):
|
|
|
|
return self._repo
|
|
|
|
|
2012-07-13 23:52:28 +04:00
|
|
|
def canpush(self):
|
|
|
|
return True
|
|
|
|
|
2012-07-13 23:47:06 +04:00
|
|
|
def url(self):
|
|
|
|
return self._repo.url()
|
|
|
|
|
|
|
|
def lookup(self, key):
|
|
|
|
return self._repo.lookup(key)
|
|
|
|
|
|
|
|
def branchmap(self):
|
2013-01-06 07:28:52 +04:00
|
|
|
return self._repo.branchmap()
|
2012-07-13 23:47:06 +04:00
|
|
|
|
|
|
|
def heads(self):
|
2013-01-06 07:28:52 +04:00
|
|
|
return self._repo.heads()
|
2012-07-13 23:47:06 +04:00
|
|
|
|
|
|
|
def known(self, nodes):
|
|
|
|
return self._repo.known(nodes)
|
|
|
|
|
2014-04-04 12:33:20 +04:00
|
|
|
def getbundle(self, source, heads=None, common=None, bundlecaps=None,
|
2014-04-18 01:25:50 +04:00
|
|
|
format='HG10', **kwargs):
|
2014-04-15 19:27:55 +04:00
|
|
|
cg = exchange.getbundle(self._repo, source, heads=heads,
|
2014-04-18 01:25:50 +04:00
|
|
|
common=common, bundlecaps=bundlecaps, **kwargs)
|
2014-10-02 08:40:23 +04:00
|
|
|
if bundlecaps is not None and 'HG2Y' in bundlecaps:
|
2014-04-15 19:27:55 +04:00
|
|
|
# When requesting a bundle2, getbundle returns a stream to make the
|
|
|
|
# wire level function happier. We need to build a proper object
|
|
|
|
# from it in local peer.
|
|
|
|
cg = bundle2.unbundle20(self.ui, cg)
|
|
|
|
return cg
|
2012-07-13 23:47:06 +04:00
|
|
|
|
|
|
|
# TODO We might want to move the next two calls into legacypeer and add
|
|
|
|
# unbundle instead.
|
|
|
|
|
2014-04-05 04:50:44 +04:00
|
|
|
def unbundle(self, cg, heads, url):
|
|
|
|
"""apply a bundle on a repo
|
|
|
|
|
|
|
|
This function handles the repo locking itself."""
|
|
|
|
try:
|
2014-04-16 00:42:52 +04:00
|
|
|
cg = exchange.readbundle(self.ui, cg, None)
|
2014-04-16 00:49:30 +04:00
|
|
|
ret = exchange.unbundle(self._repo, cg, heads, 'push', url)
|
|
|
|
if util.safehasattr(ret, 'getchunks'):
|
|
|
|
# This is a bundle20 object, turn it into an unbundler.
|
|
|
|
# This little dance should be dropped eventually when the API
|
|
|
|
# is finally improved.
|
|
|
|
stream = util.chunkbuffer(ret.getchunks())
|
|
|
|
ret = bundle2.unbundle20(self.ui, stream)
|
|
|
|
return ret
|
2014-04-22 05:59:09 +04:00
|
|
|
except error.PushRaced, exc:
|
2014-04-22 04:51:58 +04:00
|
|
|
raise error.ResponseError(_('push failed:'), str(exc))
|
2014-04-05 04:50:44 +04:00
|
|
|
|
2012-07-13 23:47:06 +04:00
|
|
|
def lock(self):
|
|
|
|
return self._repo.lock()
|
|
|
|
|
|
|
|
def addchangegroup(self, cg, source, url):
|
2014-04-02 02:27:53 +04:00
|
|
|
return changegroup.addchangegroup(self._repo, cg, source, url)
|
2012-07-13 23:47:06 +04:00
|
|
|
|
|
|
|
def pushkey(self, namespace, key, old, new):
|
|
|
|
return self._repo.pushkey(namespace, key, old, new)
|
|
|
|
|
|
|
|
def listkeys(self, namespace):
|
|
|
|
return self._repo.listkeys(namespace)
|
|
|
|
|
|
|
|
def debugwireargs(self, one, two, three=None, four=None, five=None):
|
|
|
|
'''used to test argument passing over the wire'''
|
|
|
|
return "%s %s %s %s %s" % (one, two, three, four, five)
|
|
|
|
|
|
|
|
class locallegacypeer(localpeer):
|
|
|
|
'''peer extension which implements legacy methods too; used for tests with
|
|
|
|
restricted capabilities'''
|
|
|
|
|
|
|
|
def __init__(self, repo):
|
2014-03-14 11:02:05 +04:00
|
|
|
localpeer.__init__(self, repo, caps=legacycaps)
|
2012-07-13 23:47:06 +04:00
|
|
|
|
|
|
|
def branches(self, nodes):
|
|
|
|
return self._repo.branches(nodes)
|
|
|
|
|
|
|
|
def between(self, pairs):
|
|
|
|
return self._repo.between(pairs)
|
|
|
|
|
|
|
|
def changegroup(self, basenodes, source):
|
2014-04-02 02:08:27 +04:00
|
|
|
return changegroup.changegroup(self._repo, basenodes, source)
|
2012-07-13 23:47:06 +04:00
|
|
|
|
|
|
|
def changegroupsubset(self, bases, heads, source):
|
2014-04-02 01:25:03 +04:00
|
|
|
return changegroup.changegroupsubset(self._repo, bases, heads, source)
|
2012-07-13 23:47:06 +04:00
|
|
|
|
|
|
|
class localrepository(object):
|
|
|
|
|
2011-05-08 23:32:33 +04:00
|
|
|
supportedformats = set(('revlogv1', 'generaldelta'))
|
localrepo: make supported features manageable in each repositories individually
Before this patch, all localrepositories support same features,
because supported features are managed by the class variable
"supported" of "localrepository".
For example, "largefiles" feature provided by largefiles extension is
recognized as supported, by adding the feature name to "supported" of
"localrepository".
So, commands handling multiple repositories at a time like below
misunderstand that such features are supported also in repositories
not enabling corresponded extensions:
- clone/pull from or push to localhost
- recursive execution in subrepo tree
"reposetup()" can't be used to fix this problem, because it is invoked
after checking whether supported features satisfy ones required in the
target repository.
So, this patch adds the set object named as "featuresetupfuncs" to
"localrepository" to manage hook functions to setup supported features
of each repositories.
If any functions are added to "featuresetupfuncs", they are invoked,
and information about supported features is managed in each
repositories individually.
This patch also adds checking below:
- pull from localhost: whether features supported in the local(= dst)
repository satisfies ones required in the remote(= src)
- push to localhost: whether features supported in the remote(= dst)
repository satisfies ones required in the local(= src)
Managing supported features by the class variable means that there is
no difference of supported features between each instances of
"localrepository" in the same Python process, so such checking is not
needed before this patch.
Even with this patch, if intermediate bundlefile is used as pulling
source, pulling indirectly from the remote repository, which requires
features more than ones supported in the local, can't be prevented,
because bundlefile has no information about "required features" in it.
2013-09-21 16:33:29 +04:00
|
|
|
_basesupported = supportedformats | set(('store', 'fncache', 'shared',
|
|
|
|
'dotencode'))
|
2012-07-12 02:36:00 +04:00
|
|
|
openerreqs = set(('revlogv1', 'generaldelta'))
|
|
|
|
requirements = ['revlogv1']
|
2012-12-24 06:05:02 +04:00
|
|
|
filtername = None
|
2012-07-12 02:36:00 +04:00
|
|
|
|
2013-10-17 16:45:17 +04:00
|
|
|
# a list of (ui, featureset) functions.
|
|
|
|
# only functions defined in module of enabled extensions are invoked
|
localrepo: make supported features manageable in each repositories individually
Before this patch, all localrepositories support same features,
because supported features are managed by the class variable
"supported" of "localrepository".
For example, "largefiles" feature provided by largefiles extension is
recognized as supported, by adding the feature name to "supported" of
"localrepository".
So, commands handling multiple repositories at a time like below
misunderstand that such features are supported also in repositories
not enabling corresponded extensions:
- clone/pull from or push to localhost
- recursive execution in subrepo tree
"reposetup()" can't be used to fix this problem, because it is invoked
after checking whether supported features satisfy ones required in the
target repository.
So, this patch adds the set object named as "featuresetupfuncs" to
"localrepository" to manage hook functions to setup supported features
of each repositories.
If any functions are added to "featuresetupfuncs", they are invoked,
and information about supported features is managed in each
repositories individually.
This patch also adds checking below:
- pull from localhost: whether features supported in the local(= dst)
repository satisfies ones required in the remote(= src)
- push to localhost: whether features supported in the remote(= dst)
repository satisfies ones required in the local(= src)
Managing supported features by the class variable means that there is
no difference of supported features between each instances of
"localrepository" in the same Python process, so such checking is not
needed before this patch.
Even with this patch, if intermediate bundlefile is used as pulling
source, pulling indirectly from the remote repository, which requires
features more than ones supported in the local, can't be prevented,
because bundlefile has no information about "required features" in it.
2013-09-21 16:33:29 +04:00
|
|
|
featuresetupfuncs = set()
|
|
|
|
|
2012-07-12 02:36:00 +04:00
|
|
|
def _baserequirements(self, create):
|
|
|
|
return self.requirements[:]
|
2006-06-16 03:37:23 +04:00
|
|
|
|
2011-05-18 21:30:17 +04:00
|
|
|
def __init__(self, baseui, path=None, create=False):
|
2013-04-14 20:22:15 +04:00
|
|
|
self.wvfs = scmutil.vfs(path, expandpath=True, realpath=True)
|
2012-08-30 21:06:29 +04:00
|
|
|
self.wopener = self.wvfs
|
2012-07-06 13:45:27 +04:00
|
|
|
self.root = self.wvfs.base
|
2012-07-06 13:45:27 +04:00
|
|
|
self.path = self.wvfs.join(".hg")
|
2006-12-10 02:06:45 +03:00
|
|
|
self.origroot = path
|
2013-11-07 03:19:04 +04:00
|
|
|
self.auditor = pathutil.pathauditor(self.root, self._checknested)
|
2012-08-30 21:06:29 +04:00
|
|
|
self.vfs = scmutil.vfs(self.path)
|
|
|
|
self.opener = self.vfs
|
2009-06-13 23:44:59 +04:00
|
|
|
self.baseui = baseui
|
|
|
|
self.ui = baseui.copy()
|
2013-11-12 01:59:26 +04:00
|
|
|
self.ui.copy = baseui.copy # prevent copying repo configuration
|
2012-01-18 20:23:54 +04:00
|
|
|
# A list of callback to shape the phase if no data were found.
|
|
|
|
# Callback are in the form: func(repo, roots) --> processed root.
|
|
|
|
# This list it to be filled by extension during repo setup
|
|
|
|
self._phasedefaults = []
|
2009-06-13 23:44:59 +04:00
|
|
|
try:
|
|
|
|
self.ui.readconfig(self.join("hgrc"), self.root)
|
|
|
|
extensions.loadall(self.ui)
|
|
|
|
except IOError:
|
|
|
|
pass
|
2005-08-28 03:28:53 +04:00
|
|
|
|
localrepo: make supported features manageable in each repositories individually
Before this patch, all localrepositories support same features,
because supported features are managed by the class variable
"supported" of "localrepository".
For example, "largefiles" feature provided by largefiles extension is
recognized as supported, by adding the feature name to "supported" of
"localrepository".
So, commands handling multiple repositories at a time like below
misunderstand that such features are supported also in repositories
not enabling corresponded extensions:
- clone/pull from or push to localhost
- recursive execution in subrepo tree
"reposetup()" can't be used to fix this problem, because it is invoked
after checking whether supported features satisfy ones required in the
target repository.
So, this patch adds the set object named as "featuresetupfuncs" to
"localrepository" to manage hook functions to setup supported features
of each repositories.
If any functions are added to "featuresetupfuncs", they are invoked,
and information about supported features is managed in each
repositories individually.
This patch also adds checking below:
- pull from localhost: whether features supported in the local(= dst)
repository satisfies ones required in the remote(= src)
- push to localhost: whether features supported in the remote(= dst)
repository satisfies ones required in the local(= src)
Managing supported features by the class variable means that there is
no difference of supported features between each instances of
"localrepository" in the same Python process, so such checking is not
needed before this patch.
Even with this patch, if intermediate bundlefile is used as pulling
source, pulling indirectly from the remote repository, which requires
features more than ones supported in the local, can't be prevented,
because bundlefile has no information about "required features" in it.
2013-09-21 16:33:29 +04:00
|
|
|
if self.featuresetupfuncs:
|
|
|
|
self.supported = set(self._basesupported) # use private copy
|
2013-10-17 16:45:17 +04:00
|
|
|
extmods = set(m.__name__ for n, m
|
|
|
|
in extensions.extensions(self.ui))
|
localrepo: make supported features manageable in each repositories individually
Before this patch, all localrepositories support same features,
because supported features are managed by the class variable
"supported" of "localrepository".
For example, "largefiles" feature provided by largefiles extension is
recognized as supported, by adding the feature name to "supported" of
"localrepository".
So, commands handling multiple repositories at a time like below
misunderstand that such features are supported also in repositories
not enabling corresponded extensions:
- clone/pull from or push to localhost
- recursive execution in subrepo tree
"reposetup()" can't be used to fix this problem, because it is invoked
after checking whether supported features satisfy ones required in the
target repository.
So, this patch adds the set object named as "featuresetupfuncs" to
"localrepository" to manage hook functions to setup supported features
of each repositories.
If any functions are added to "featuresetupfuncs", they are invoked,
and information about supported features is managed in each
repositories individually.
This patch also adds checking below:
- pull from localhost: whether features supported in the local(= dst)
repository satisfies ones required in the remote(= src)
- push to localhost: whether features supported in the remote(= dst)
repository satisfies ones required in the local(= src)
Managing supported features by the class variable means that there is
no difference of supported features between each instances of
"localrepository" in the same Python process, so such checking is not
needed before this patch.
Even with this patch, if intermediate bundlefile is used as pulling
source, pulling indirectly from the remote repository, which requires
features more than ones supported in the local, can't be prevented,
because bundlefile has no information about "required features" in it.
2013-09-21 16:33:29 +04:00
|
|
|
for setupfunc in self.featuresetupfuncs:
|
2013-10-17 16:45:17 +04:00
|
|
|
if setupfunc.__module__ in extmods:
|
|
|
|
setupfunc(self.ui, self.supported)
|
localrepo: make supported features manageable in each repositories individually
Before this patch, all localrepositories support same features,
because supported features are managed by the class variable
"supported" of "localrepository".
For example, "largefiles" feature provided by largefiles extension is
recognized as supported, by adding the feature name to "supported" of
"localrepository".
So, commands handling multiple repositories at a time like below
misunderstand that such features are supported also in repositories
not enabling corresponded extensions:
- clone/pull from or push to localhost
- recursive execution in subrepo tree
"reposetup()" can't be used to fix this problem, because it is invoked
after checking whether supported features satisfy ones required in the
target repository.
So, this patch adds the set object named as "featuresetupfuncs" to
"localrepository" to manage hook functions to setup supported features
of each repositories.
If any functions are added to "featuresetupfuncs", they are invoked,
and information about supported features is managed in each
repositories individually.
This patch also adds checking below:
- pull from localhost: whether features supported in the local(= dst)
repository satisfies ones required in the remote(= src)
- push to localhost: whether features supported in the remote(= dst)
repository satisfies ones required in the local(= src)
Managing supported features by the class variable means that there is
no difference of supported features between each instances of
"localrepository" in the same Python process, so such checking is not
needed before this patch.
Even with this patch, if intermediate bundlefile is used as pulling
source, pulling indirectly from the remote repository, which requires
features more than ones supported in the local, can't be prevented,
because bundlefile has no information about "required features" in it.
2013-09-21 16:33:29 +04:00
|
|
|
else:
|
|
|
|
self.supported = self._basesupported
|
|
|
|
|
2012-07-06 13:45:27 +04:00
|
|
|
if not self.vfs.isdir():
|
2006-09-03 01:06:47 +04:00
|
|
|
if create:
|
2012-07-06 13:45:27 +04:00
|
|
|
if not self.wvfs.exists():
|
|
|
|
self.wvfs.makedirs()
|
|
|
|
self.vfs.makedir(notindexed=True)
|
2012-07-12 02:36:00 +04:00
|
|
|
requirements = self._baserequirements(create)
|
2009-06-13 23:44:59 +04:00
|
|
|
if self.ui.configbool('format', 'usestore', True):
|
2012-07-06 13:45:27 +04:00
|
|
|
self.vfs.mkdir("store")
|
2007-03-09 02:08:24 +03:00
|
|
|
requirements.append("store")
|
2009-06-13 23:44:59 +04:00
|
|
|
if self.ui.configbool('format', 'usefncache', True):
|
2008-10-24 12:31:51 +04:00
|
|
|
requirements.append("fncache")
|
2010-10-09 23:54:50 +04:00
|
|
|
if self.ui.configbool('format', 'dotencode', True):
|
|
|
|
requirements.append('dotencode')
|
2007-03-09 02:08:24 +03:00
|
|
|
# create an invalid changelog
|
2012-07-06 13:45:27 +04:00
|
|
|
self.vfs.append(
|
2011-05-02 12:11:18 +04:00
|
|
|
"00changelog.i",
|
2007-03-09 02:08:24 +03:00
|
|
|
'\0\0\0\2' # represents revlogv2
|
|
|
|
' dummy changelog to prevent using the old repo layout'
|
|
|
|
)
|
2011-05-08 23:32:33 +04:00
|
|
|
if self.ui.configbool('format', 'generaldelta', False):
|
|
|
|
requirements.append("generaldelta")
|
2011-07-21 02:23:06 +04:00
|
|
|
requirements = set(requirements)
|
2006-09-03 01:06:47 +04:00
|
|
|
else:
|
2009-01-12 19:42:31 +03:00
|
|
|
raise error.RepoError(_("repository %s not found") % path)
|
2006-09-03 01:06:47 +04:00
|
|
|
elif create:
|
2009-01-12 19:42:31 +03:00
|
|
|
raise error.RepoError(_("repository %s already exists") % path)
|
2006-12-10 02:06:59 +03:00
|
|
|
else:
|
|
|
|
try:
|
2012-07-06 13:45:27 +04:00
|
|
|
requirements = scmutil.readrequires(self.vfs, self.supported)
|
2006-12-10 02:06:59 +03:00
|
|
|
except IOError, inst:
|
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
2011-05-31 21:16:18 +04:00
|
|
|
requirements = set()
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2009-06-14 03:01:46 +04:00
|
|
|
self.sharedpath = self.path
|
|
|
|
try:
|
2013-04-14 20:22:15 +04:00
|
|
|
vfs = scmutil.vfs(self.vfs.read("sharedpath").rstrip('\n'),
|
|
|
|
realpath=True)
|
|
|
|
s = vfs.base
|
|
|
|
if not vfs.exists():
|
2009-06-14 03:01:46 +04:00
|
|
|
raise error.RepoError(
|
2009-06-19 10:28:29 +04:00
|
|
|
_('.hg/sharedpath points to nonexistent directory %s') % s)
|
2009-06-14 03:01:46 +04:00
|
|
|
self.sharedpath = s
|
|
|
|
except IOError, inst:
|
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
|
2012-08-30 21:06:29 +04:00
|
|
|
self.store = store.store(requirements, self.sharedpath, scmutil.vfs)
|
2008-07-24 18:32:52 +04:00
|
|
|
self.spath = self.store.path
|
2012-08-30 21:06:29 +04:00
|
|
|
self.svfs = self.store.vfs
|
|
|
|
self.sopener = self.svfs
|
2008-07-24 18:32:52 +04:00
|
|
|
self.sjoin = self.store.join
|
2012-08-30 21:06:29 +04:00
|
|
|
self.vfs.createmode = self.store.createmode
|
2010-09-15 12:44:10 +04:00
|
|
|
self._applyrequirements(requirements)
|
|
|
|
if create:
|
|
|
|
self._writerequirements()
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2009-07-16 18:39:41 +04:00
|
|
|
|
2012-12-24 06:21:15 +04:00
|
|
|
self._branchcaches = {}
|
2006-12-30 05:04:31 +03:00
|
|
|
self.filterpats = {}
|
2008-01-28 23:39:47 +03:00
|
|
|
self._datafilters = {}
|
2007-07-22 01:02:10 +04:00
|
|
|
self._transref = self._lockref = self._wlockref = None
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2011-07-25 16:08:37 +04:00
|
|
|
# A cache for various files under .hg/ that tracks file changes,
|
|
|
|
# (used by the filecache decorator)
|
|
|
|
#
|
|
|
|
# Maps a property name to its util.filecacheentry
|
|
|
|
self._filecache = {}
|
|
|
|
|
2012-12-20 20:14:07 +04:00
|
|
|
# hold sets of revision to be filtered
|
|
|
|
# should be cleared when something might have changed the filter value:
|
|
|
|
# - new changesets,
|
|
|
|
# - phase change,
|
|
|
|
# - new obsolescence marker,
|
|
|
|
# - working directory parent change,
|
|
|
|
# - bookmark changes
|
|
|
|
self.filteredrevcache = {}
|
|
|
|
|
2014-12-14 23:53:50 +03:00
|
|
|
# generic mapping between names and nodes
|
2014-12-15 06:11:44 +03:00
|
|
|
self.names = namespaces.namespaces()
|
2014-12-14 23:53:50 +03:00
|
|
|
|
2012-07-13 23:47:06 +04:00
|
|
|
def close(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _restrictcapabilities(self, caps):
|
2014-04-02 10:41:32 +04:00
|
|
|
# bundle2 is not ready for prime time, drop it unless explicitly
|
|
|
|
# required by the tests (or some brave tester)
|
2014-04-18 00:01:58 +04:00
|
|
|
if self.ui.configbool('experimental', 'bundle2-exp', False):
|
2014-04-02 10:41:32 +04:00
|
|
|
caps = set(caps)
|
2014-08-25 21:21:47 +04:00
|
|
|
capsblob = bundle2.encodecaps(bundle2.getrepocaps(self))
|
2014-04-17 23:33:17 +04:00
|
|
|
caps.add('bundle2-exp=' + urllib.quote(capsblob))
|
2012-07-13 23:47:06 +04:00
|
|
|
return caps
|
|
|
|
|
2010-09-15 12:44:10 +04:00
|
|
|
def _applyrequirements(self, requirements):
|
|
|
|
self.requirements = requirements
|
2015-01-11 02:21:58 +03:00
|
|
|
self.svfs.options = dict((r, 1) for r in requirements
|
2012-07-12 02:36:00 +04:00
|
|
|
if r in self.openerreqs)
|
revlog: allow tuning of the chunk cache size (via format.chunkcachesize)
Running perfmoonwalk on the Mercurial repo (with almost 20,000 changesets) on
Mac OS X with an SSD, before this change:
$ hg --config format.chunkcachesize=1024 perfmoonwalk
! wall 2.022021 comb 2.030000 user 1.970000 sys 0.060000 (best of 5)
(16,154 cache hits, 3,840 misses.)
$ hg --config format.chunkcachesize=4096 perfmoonwalk
! wall 1.901006 comb 1.900000 user 1.880000 sys 0.020000 (best of 6)
(19,003 hits, 991 misses.)
$ hg --config format.chunkcachesize=16384 perfmoonwalk
! wall 1.802775 comb 1.800000 user 1.800000 sys 0.000000 (best of 6)
(19,746 hits, 248 misses.)
$ hg --config format.chunkcachesize=32768 perfmoonwalk
! wall 1.818545 comb 1.810000 user 1.810000 sys 0.000000 (best of 6)
(19,870 hits, 124 misses.)
$ hg --config format.chunkcachesize=65536 perfmoonwalk
! wall 1.801350 comb 1.810000 user 1.800000 sys 0.010000 (best of 6)
(19,932 hits, 62 misses.)
$ hg --config format.chunkcachesize=131072 perfmoonwalk
! wall 1.805879 comb 1.820000 user 1.810000 sys 0.010000 (best of 6)
(19,963 hits, 31 misses.)
We may want to change the default size in the future based on testing and
user feedback.
2013-11-18 03:04:29 +04:00
|
|
|
chunkcachesize = self.ui.configint('format', 'chunkcachesize')
|
|
|
|
if chunkcachesize is not None:
|
2015-01-11 02:21:58 +03:00
|
|
|
self.svfs.options['chunkcachesize'] = chunkcachesize
|
2014-11-11 18:35:06 +03:00
|
|
|
maxchainlen = self.ui.configint('format', 'maxchainlen')
|
2014-11-07 01:20:05 +03:00
|
|
|
if maxchainlen is not None:
|
2015-01-11 02:21:58 +03:00
|
|
|
self.svfs.options['maxchainlen'] = maxchainlen
|
2015-01-24 04:06:03 +03:00
|
|
|
manifestcachesize = self.ui.configint('format', 'manifestcachesize')
|
|
|
|
if manifestcachesize is not None:
|
|
|
|
self.svfs.options['manifestcachesize'] = manifestcachesize
|
2010-09-15 12:44:10 +04:00
|
|
|
|
|
|
|
def _writerequirements(self):
|
2015-01-11 01:02:52 +03:00
|
|
|
reqfile = self.vfs("requires", "w")
|
2012-12-12 05:38:14 +04:00
|
|
|
for r in sorted(self.requirements):
|
2010-09-15 12:44:10 +04:00
|
|
|
reqfile.write("%s\n" % r)
|
|
|
|
reqfile.close()
|
|
|
|
|
2010-09-03 14:58:51 +04:00
|
|
|
def _checknested(self, path):
|
|
|
|
"""Determine if path is a legal nested repository."""
|
|
|
|
if not path.startswith(self.root):
|
|
|
|
return False
|
|
|
|
subpath = path[len(self.root) + 1:]
|
2011-12-24 14:05:25 +04:00
|
|
|
normsubpath = util.pconvert(subpath)
|
2010-09-03 14:58:51 +04:00
|
|
|
|
|
|
|
# XXX: Checking against the current working copy is wrong in
|
|
|
|
# the sense that it can reject things like
|
|
|
|
#
|
|
|
|
# $ hg cat -r 10 sub/x.txt
|
|
|
|
#
|
|
|
|
# if sub/ is no longer a subrepository in the working copy
|
|
|
|
# parent revision.
|
|
|
|
#
|
|
|
|
# However, it can of course also allow things that would have
|
|
|
|
# been rejected before, such as the above cat command if sub/
|
|
|
|
# is a subrepository now, but was a normal directory before.
|
|
|
|
# The old path auditor would have rejected by mistake since it
|
|
|
|
# panics when it sees sub/.hg/.
|
|
|
|
#
|
2010-09-07 17:31:56 +04:00
|
|
|
# All in all, checking against the working copy seems sensible
|
|
|
|
# since we want to prevent access to nested repositories on
|
|
|
|
# the filesystem *now*.
|
|
|
|
ctx = self[None]
|
2010-09-03 14:58:51 +04:00
|
|
|
parts = util.splitpath(subpath)
|
|
|
|
while parts:
|
2011-12-24 14:05:25 +04:00
|
|
|
prefix = '/'.join(parts)
|
2010-09-03 14:58:51 +04:00
|
|
|
if prefix in ctx.substate:
|
2011-12-24 14:05:25 +04:00
|
|
|
if prefix == normsubpath:
|
2010-09-03 14:58:51 +04:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
sub = ctx.sub(prefix)
|
|
|
|
return sub.checknested(subpath[len(prefix) + 1:])
|
|
|
|
else:
|
|
|
|
parts.pop()
|
|
|
|
return False
|
|
|
|
|
2012-07-13 23:47:06 +04:00
|
|
|
def peer(self):
|
|
|
|
return localpeer(self) # not cached to avoid reference cycle
|
|
|
|
|
2012-11-21 03:36:29 +04:00
|
|
|
def unfiltered(self):
|
|
|
|
"""Return unfiltered version of the repository
|
|
|
|
|
2013-02-10 21:24:29 +04:00
|
|
|
Intended to be overwritten by filtered repo."""
|
2012-11-21 03:36:29 +04:00
|
|
|
return self
|
|
|
|
|
2012-12-20 18:32:42 +04:00
|
|
|
def filtered(self, name):
|
|
|
|
"""Return a filtered version of a repository"""
|
|
|
|
# build a new class with the mixin and the current class
|
2013-02-10 21:24:29 +04:00
|
|
|
# (possibly subclass of the repo)
|
2012-12-20 18:32:42 +04:00
|
|
|
class proxycls(repoview.repoview, self.unfiltered().__class__):
|
|
|
|
pass
|
|
|
|
return proxycls(self, name)
|
|
|
|
|
2012-10-08 21:34:04 +04:00
|
|
|
@repofilecache('bookmarks')
|
2011-02-10 22:46:27 +03:00
|
|
|
def _bookmarks(self):
|
2012-11-08 02:21:39 +04:00
|
|
|
return bookmarks.bmstore(self)
|
2011-02-10 22:46:27 +03:00
|
|
|
|
2012-10-08 21:34:04 +04:00
|
|
|
@repofilecache('bookmarks.current')
|
2011-02-10 22:46:27 +03:00
|
|
|
def _bookmarkcurrent(self):
|
|
|
|
return bookmarks.readcurrent(self)
|
2010-09-03 14:58:51 +04:00
|
|
|
|
2012-05-13 13:54:58 +04:00
|
|
|
def bookmarkheads(self, bookmark):
|
|
|
|
name = bookmark.split('@', 1)[0]
|
|
|
|
heads = []
|
|
|
|
for mark, n in self._bookmarks.iteritems():
|
|
|
|
if mark.split('@', 1)[0] == name:
|
|
|
|
heads.append(n)
|
|
|
|
return heads
|
|
|
|
|
2012-03-01 19:39:58 +04:00
|
|
|
@storecache('phaseroots')
|
2012-05-12 02:24:07 +04:00
|
|
|
def _phasecache(self):
|
|
|
|
return phases.phasecache(self, self._phasedefaults)
|
2011-11-04 03:20:20 +04:00
|
|
|
|
2012-06-07 21:07:39 +04:00
|
|
|
@storecache('obsstore')
|
|
|
|
def obsstore(self):
|
2014-09-17 04:52:40 +04:00
|
|
|
# read default format for new obsstore.
|
|
|
|
defaultformat = self.ui.configint('format', 'obsstore-version', None)
|
|
|
|
# rely on obsstore class default when possible.
|
|
|
|
kwargs = {}
|
|
|
|
if defaultformat is not None:
|
2014-10-15 23:52:10 +04:00
|
|
|
kwargs['defaultformat'] = defaultformat
|
2014-10-15 00:23:52 +04:00
|
|
|
readonly = not obsolete.isenabled(self, obsolete.createmarkersopt)
|
2015-01-11 02:21:58 +03:00
|
|
|
store = obsolete.obsstore(self.svfs, readonly=readonly,
|
2014-10-15 00:20:31 +04:00
|
|
|
**kwargs)
|
2014-10-15 00:23:52 +04:00
|
|
|
if store and readonly:
|
2012-07-31 17:57:50 +04:00
|
|
|
# message is rare enough to not be translated
|
2012-07-28 15:05:25 +04:00
|
|
|
msg = 'obsolete feature not enabled but %i markers found!\n'
|
|
|
|
self.ui.warn(msg % len(list(store)))
|
2012-06-07 21:07:39 +04:00
|
|
|
return store
|
|
|
|
|
2012-03-01 19:39:58 +04:00
|
|
|
@storecache('00changelog.i')
|
2009-04-30 05:47:15 +04:00
|
|
|
def changelog(self):
|
2015-01-11 02:21:58 +03:00
|
|
|
c = changelog.changelog(self.svfs)
|
2009-04-30 05:47:15 +04:00
|
|
|
if 'HG_PENDING' in os.environ:
|
|
|
|
p = os.environ['HG_PENDING']
|
|
|
|
if p.startswith(self.root):
|
|
|
|
c.readpending('00changelog.i.a')
|
|
|
|
return c
|
|
|
|
|
2012-03-01 19:39:58 +04:00
|
|
|
@storecache('00manifest.i')
|
2009-04-30 05:47:15 +04:00
|
|
|
def manifest(self):
|
2015-01-11 02:21:58 +03:00
|
|
|
return manifest.manifest(self.svfs)
|
2009-04-30 05:47:15 +04:00
|
|
|
|
2012-10-08 21:34:04 +04:00
|
|
|
@repofilecache('dirstate')
|
2009-04-30 05:47:15 +04:00
|
|
|
def dirstate(self):
|
2010-11-22 21:43:31 +03:00
|
|
|
warned = [0]
|
|
|
|
def validate(node):
|
|
|
|
try:
|
2011-04-30 15:59:14 +04:00
|
|
|
self.changelog.rev(node)
|
2010-11-22 21:43:31 +03:00
|
|
|
return node
|
|
|
|
except error.LookupError:
|
|
|
|
if not warned[0]:
|
|
|
|
warned[0] = True
|
|
|
|
self.ui.warn(_("warning: ignoring unknown"
|
2010-11-24 15:25:12 +03:00
|
|
|
" working parent %s!\n") % short(node))
|
2010-11-22 21:43:31 +03:00
|
|
|
return nullid
|
|
|
|
|
2015-01-11 01:02:52 +03:00
|
|
|
return dirstate.dirstate(self.vfs, self.ui, self.root, validate)
|
2006-04-29 02:50:22 +04:00
|
|
|
|
2008-06-26 23:35:46 +04:00
|
|
|
def __getitem__(self, changeid):
|
2009-05-20 02:52:46 +04:00
|
|
|
if changeid is None:
|
2008-06-26 23:35:46 +04:00
|
|
|
return context.workingctx(self)
|
2014-12-18 22:30:10 +03:00
|
|
|
if isinstance(changeid, slice):
|
|
|
|
return [context.changectx(self, i)
|
|
|
|
for i in xrange(*changeid.indices(len(self)))
|
|
|
|
if i not in self.changelog.filteredrevs]
|
2008-06-26 23:35:46 +04:00
|
|
|
return context.changectx(self, changeid)
|
|
|
|
|
2009-11-24 15:32:19 +03:00
|
|
|
def __contains__(self, changeid):
|
|
|
|
try:
|
|
|
|
return bool(self.lookup(changeid))
|
|
|
|
except error.RepoLookupError:
|
|
|
|
return False
|
|
|
|
|
2008-06-26 23:35:50 +04:00
|
|
|
def __nonzero__(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return len(self.changelog)
|
|
|
|
|
|
|
|
def __iter__(self):
|
2012-09-20 21:01:53 +04:00
|
|
|
return iter(self.changelog)
|
2008-06-26 23:35:50 +04:00
|
|
|
|
2011-11-02 22:37:34 +04:00
|
|
|
def revs(self, expr, *args):
|
|
|
|
'''Return a list of revisions matching the given revset'''
|
|
|
|
expr = revset.formatspec(expr, *args)
|
|
|
|
m = revset.match(None, expr)
|
2014-03-06 05:42:05 +04:00
|
|
|
return m(self, revset.spanset(self))
|
2011-11-02 22:37:34 +04:00
|
|
|
|
2011-07-21 23:06:55 +04:00
|
|
|
def set(self, expr, *args):
|
|
|
|
'''
|
|
|
|
Yield a context for each matching revision, after doing arg
|
2011-07-23 01:46:22 +04:00
|
|
|
replacement via revset.formatspec
|
2011-07-21 23:06:55 +04:00
|
|
|
'''
|
2011-11-02 22:37:34 +04:00
|
|
|
for r in self.revs(expr, *args):
|
2011-07-21 23:06:55 +04:00
|
|
|
yield self[r]
|
|
|
|
|
2006-07-26 00:50:32 +04:00
|
|
|
def url(self):
|
|
|
|
return 'file:' + self.root
|
|
|
|
|
2006-02-15 02:28:06 +03:00
|
|
|
def hook(self, name, throw=False, **args):
|
2014-07-12 21:52:58 +04:00
|
|
|
"""Call a hook, passing this repo instance.
|
|
|
|
|
|
|
|
This a convenience method to aid invoking hooks. Extensions likely
|
|
|
|
won't call this unless they have registered a custom hook or are
|
|
|
|
replacing code that is expected to call a hook.
|
|
|
|
"""
|
2007-06-18 22:24:34 +04:00
|
|
|
return hook.hook(self.ui, self, name, throw, **args)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2014-05-05 16:26:40 +04:00
|
|
|
def _tag(self, names, node, message, local, user, date, extra={},
|
|
|
|
editor=False):
|
2008-03-15 01:38:56 +03:00
|
|
|
if isinstance(names, str):
|
|
|
|
names = (names,)
|
2007-02-27 23:58:40 +03:00
|
|
|
|
2010-04-19 12:41:12 +04:00
|
|
|
branches = self.branchmap()
|
2008-03-15 01:38:56 +03:00
|
|
|
for name in names:
|
|
|
|
self.hook('pretag', throw=True, node=hex(node), tag=name,
|
|
|
|
local=local)
|
2010-04-19 12:41:12 +04:00
|
|
|
if name in branches:
|
|
|
|
self.ui.warn(_("warning: tag %s conflicts with existing"
|
|
|
|
" branch name\n") % name)
|
2007-02-27 23:58:40 +03:00
|
|
|
|
2008-03-15 01:38:56 +03:00
|
|
|
def writetags(fp, names, munge, prevtags):
|
2008-02-04 02:03:46 +03:00
|
|
|
fp.seek(0, 2)
|
2007-07-17 07:15:03 +04:00
|
|
|
if prevtags and prevtags[-1] != '\n':
|
|
|
|
fp.write('\n')
|
2008-03-15 01:38:56 +03:00
|
|
|
for name in names:
|
2008-06-14 02:29:10 +04:00
|
|
|
m = munge and munge(name) or name
|
2012-05-12 17:54:54 +04:00
|
|
|
if (self._tagscache.tagtypes and
|
|
|
|
name in self._tagscache.tagtypes):
|
2011-07-25 16:08:57 +04:00
|
|
|
old = self.tags().get(name, nullid)
|
2008-06-14 02:29:10 +04:00
|
|
|
fp.write('%s %s\n' % (hex(old), m))
|
|
|
|
fp.write('%s %s\n' % (hex(node), m))
|
2007-07-17 07:15:03 +04:00
|
|
|
fp.close()
|
2007-07-22 01:02:09 +04:00
|
|
|
|
2007-07-17 07:15:03 +04:00
|
|
|
prevtags = ''
|
2007-02-27 23:58:40 +03:00
|
|
|
if local:
|
2007-07-17 07:15:03 +04:00
|
|
|
try:
|
2015-01-11 01:02:52 +03:00
|
|
|
fp = self.vfs('localtags', 'r+')
|
2009-03-23 15:13:06 +03:00
|
|
|
except IOError:
|
2015-01-11 01:02:52 +03:00
|
|
|
fp = self.vfs('localtags', 'a')
|
2007-07-17 07:15:03 +04:00
|
|
|
else:
|
|
|
|
prevtags = fp.read()
|
|
|
|
|
2007-02-27 23:58:40 +03:00
|
|
|
# local tags are stored in the current charset
|
2008-03-15 01:38:56 +03:00
|
|
|
writetags(fp, names, None, prevtags)
|
|
|
|
for name in names:
|
|
|
|
self.hook('tag', node=hex(node), tag=name, local=local)
|
2007-02-27 23:58:40 +03:00
|
|
|
return
|
|
|
|
|
2009-05-14 22:20:40 +04:00
|
|
|
try:
|
|
|
|
fp = self.wfile('.hgtags', 'rb+')
|
2011-06-16 00:15:04 +04:00
|
|
|
except IOError, e:
|
|
|
|
if e.errno != errno.ENOENT:
|
|
|
|
raise
|
2009-05-14 22:20:40 +04:00
|
|
|
fp = self.wfile('.hgtags', 'ab')
|
2007-02-27 23:58:40 +03:00
|
|
|
else:
|
2009-05-14 22:20:40 +04:00
|
|
|
prevtags = fp.read()
|
2007-07-17 07:15:03 +04:00
|
|
|
|
|
|
|
# committed tags are stored in UTF-8
|
2009-04-03 23:51:48 +04:00
|
|
|
writetags(fp, names, encoding.fromlocal, prevtags)
|
2007-07-17 07:15:03 +04:00
|
|
|
|
2010-12-24 17:23:01 +03:00
|
|
|
fp.close()
|
|
|
|
|
2012-01-19 05:14:06 +04:00
|
|
|
self.invalidatecaches()
|
|
|
|
|
2009-05-14 22:20:40 +04:00
|
|
|
if '.hgtags' not in self.dirstate:
|
2010-06-07 22:03:32 +04:00
|
|
|
self[None].add(['.hgtags'])
|
2007-02-27 23:58:40 +03:00
|
|
|
|
2010-03-11 19:43:44 +03:00
|
|
|
m = matchmod.exact(self.root, '', ['.hgtags'])
|
2014-05-05 16:26:40 +04:00
|
|
|
tagnode = self.commit(message, user, date, extra=extra, match=m,
|
|
|
|
editor=editor)
|
2007-02-27 23:58:40 +03:00
|
|
|
|
2008-03-15 01:38:56 +03:00
|
|
|
for name in names:
|
|
|
|
self.hook('tag', node=hex(node), tag=name, local=local)
|
2007-02-27 23:58:40 +03:00
|
|
|
|
|
|
|
return tagnode
|
|
|
|
|
2014-05-05 16:26:40 +04:00
|
|
|
def tag(self, names, node, message, local, user, date, editor=False):
|
2008-03-15 01:38:56 +03:00
|
|
|
'''tag a revision with one or more symbolic names.
|
2006-07-12 19:59:20 +04:00
|
|
|
|
2008-03-15 01:38:56 +03:00
|
|
|
names is a list of strings or, when adding a single tag, names may be a
|
|
|
|
string.
|
2008-03-21 02:39:39 +03:00
|
|
|
|
2008-03-15 01:38:56 +03:00
|
|
|
if local is True, the tags are stored in a per-repository file.
|
|
|
|
otherwise, they are stored in the .hgtags file, and a new
|
2006-07-12 19:59:20 +04:00
|
|
|
changeset is committed with the change.
|
|
|
|
|
|
|
|
keyword arguments:
|
|
|
|
|
2008-03-15 01:38:56 +03:00
|
|
|
local: whether to store tags in non-version-controlled file
|
2006-07-12 19:59:20 +04:00
|
|
|
(default False)
|
|
|
|
|
|
|
|
message: commit message to use if committing
|
|
|
|
|
|
|
|
user: name of user to use if committing
|
|
|
|
|
|
|
|
date: date tuple to use if committing'''
|
|
|
|
|
2010-12-14 06:20:30 +03:00
|
|
|
if not local:
|
2014-10-03 03:38:10 +04:00
|
|
|
m = matchmod.exact(self.root, '', ['.hgtags'])
|
|
|
|
if util.any(self.status(match=m, unknown=True, ignored=True)):
|
2014-10-03 03:39:57 +04:00
|
|
|
raise util.Abort(_('working copy of .hgtags is changed'),
|
|
|
|
hint=_('please commit .hgtags manually'))
|
2006-07-12 19:59:20 +04:00
|
|
|
|
2009-03-03 04:19:09 +03:00
|
|
|
self.tags() # instantiate the cache
|
2014-05-05 16:26:40 +04:00
|
|
|
self._tag(names, node, message, local, user, date, editor=editor)
|
2006-07-12 19:59:20 +04:00
|
|
|
|
2012-10-08 22:02:20 +04:00
|
|
|
@filteredpropertycache
|
2011-07-25 16:08:57 +04:00
|
|
|
def _tagscache(self):
|
2012-05-12 17:54:54 +04:00
|
|
|
'''Returns a tagscache object that contains various tags related
|
|
|
|
caches.'''
|
2011-07-25 16:08:57 +04:00
|
|
|
|
|
|
|
# This simplifies its cache management by having one decorated
|
|
|
|
# function (this one) and the rest simply fetch things from it.
|
|
|
|
class tagscache(object):
|
|
|
|
def __init__(self):
|
|
|
|
# These two define the set of tags for this repository. tags
|
|
|
|
# maps tag name to node; tagtypes maps tag name to 'global' or
|
|
|
|
# 'local'. (Global tags are defined by .hgtags across all
|
|
|
|
# heads, and local tags are defined in .hg/localtags.)
|
|
|
|
# They constitute the in-memory cache of tags.
|
|
|
|
self.tags = self.tagtypes = None
|
|
|
|
|
|
|
|
self.nodetagscache = self.tagslist = None
|
|
|
|
|
|
|
|
cache = tagscache()
|
|
|
|
cache.tags, cache.tagtypes = self._findtags()
|
|
|
|
|
|
|
|
return cache
|
|
|
|
|
2005-08-28 01:21:25 +04:00
|
|
|
def tags(self):
|
|
|
|
'''return a mapping of tag to node'''
|
2012-04-07 00:16:30 +04:00
|
|
|
t = {}
|
2012-09-03 16:35:05 +04:00
|
|
|
if self.changelog.filteredrevs:
|
|
|
|
tags, tt = self._findtags()
|
|
|
|
else:
|
|
|
|
tags = self._tagscache.tags
|
|
|
|
for k, v in tags.iteritems():
|
2012-04-07 00:16:30 +04:00
|
|
|
try:
|
|
|
|
# ignore tags to unknown nodes
|
|
|
|
self.changelog.rev(v)
|
|
|
|
t[k] = v
|
2012-05-12 22:25:33 +04:00
|
|
|
except (error.LookupError, ValueError):
|
2012-04-07 00:16:30 +04:00
|
|
|
pass
|
|
|
|
return t
|
2009-07-16 18:39:41 +04:00
|
|
|
|
|
|
|
def _findtags(self):
|
|
|
|
'''Do the hard work of finding tags. Return a pair of dicts
|
|
|
|
(tags, tagtypes) where tags maps tag name to node, and tagtypes
|
|
|
|
maps tag name to a string like \'global\' or \'local\'.
|
|
|
|
Subclasses or extensions are free to add their own tags, but
|
|
|
|
should be aware that the returned dicts will be retained for the
|
|
|
|
duration of the localrepo object.'''
|
|
|
|
|
|
|
|
# XXX what tagtype should subclasses/extensions use? Currently
|
|
|
|
# mq and bookmarks add tags, but do not set the tagtype at all.
|
|
|
|
# Should each extension invent its own tag type? Should there
|
|
|
|
# be one tagtype for all such "virtual" tags? Or is the status
|
|
|
|
# quo fine?
|
2006-03-22 07:30:47 +03:00
|
|
|
|
2009-07-16 18:39:41 +04:00
|
|
|
alltags = {} # map tag name to (node, hist)
|
|
|
|
tagtypes = {}
|
|
|
|
|
2010-03-11 19:43:44 +03:00
|
|
|
tagsmod.findglobaltags(self.ui, self, alltags, tagtypes)
|
|
|
|
tagsmod.readlocaltags(self.ui, self, alltags, tagtypes)
|
2007-03-15 00:40:47 +03:00
|
|
|
|
2009-07-16 18:41:19 +04:00
|
|
|
# Build the return dicts. Have to re-encode tag names because
|
|
|
|
# the tags module always uses UTF-8 (in order not to lose info
|
|
|
|
# writing to the cache), but the rest of Mercurial wants them in
|
|
|
|
# local encoding.
|
2009-07-16 18:39:41 +04:00
|
|
|
tags = {}
|
2009-07-16 18:39:41 +04:00
|
|
|
for (name, (node, hist)) in alltags.iteritems():
|
|
|
|
if node != nullid:
|
2012-04-07 00:16:30 +04:00
|
|
|
tags[encoding.tolocal(name)] = node
|
2009-07-16 18:39:41 +04:00
|
|
|
tags['tip'] = self.changelog.tip()
|
2009-07-16 18:41:19 +04:00
|
|
|
tagtypes = dict([(encoding.tolocal(name), value)
|
|
|
|
for (name, value) in tagtypes.iteritems()])
|
2009-07-16 18:39:41 +04:00
|
|
|
return (tags, tagtypes)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2007-12-09 10:32:05 +03:00
|
|
|
def tagtype(self, tagname):
|
|
|
|
'''
|
|
|
|
return the type of the given tag. result can be:
|
|
|
|
|
|
|
|
'local' : a local tag
|
|
|
|
'global' : a global tag
|
|
|
|
None : tag does not exist
|
|
|
|
'''
|
|
|
|
|
2011-07-25 16:08:57 +04:00
|
|
|
return self._tagscache.tagtypes.get(tagname)
|
2007-12-09 10:32:05 +03:00
|
|
|
|
2005-08-28 01:21:25 +04:00
|
|
|
def tagslist(self):
|
|
|
|
'''return a list of tags ordered by revision'''
|
2011-07-25 16:08:57 +04:00
|
|
|
if not self._tagscache.tagslist:
|
|
|
|
l = []
|
|
|
|
for t, n in self.tags().iteritems():
|
2014-08-15 06:37:46 +04:00
|
|
|
l.append((self.changelog.rev(n), t, n))
|
2011-07-25 16:08:57 +04:00
|
|
|
self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)]
|
|
|
|
|
|
|
|
return self._tagscache.tagslist
|
2005-08-28 01:21:25 +04:00
|
|
|
|
|
|
|
def nodetags(self, node):
|
|
|
|
'''return the tags associated with a node'''
|
2011-07-25 16:08:57 +04:00
|
|
|
if not self._tagscache.nodetagscache:
|
|
|
|
nodetagscache = {}
|
2012-04-07 00:16:30 +04:00
|
|
|
for t, n in self._tagscache.tags.iteritems():
|
2011-07-25 16:08:57 +04:00
|
|
|
nodetagscache.setdefault(n, []).append(t)
|
|
|
|
for tags in nodetagscache.itervalues():
|
2010-04-26 23:58:36 +04:00
|
|
|
tags.sort()
|
2011-07-25 16:08:57 +04:00
|
|
|
self._tagscache.nodetagscache = nodetagscache
|
|
|
|
return self._tagscache.nodetagscache.get(node, [])
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2011-02-11 21:36:15 +03:00
|
|
|
def nodebookmarks(self, node):
|
|
|
|
marks = []
|
|
|
|
for bookmark, n in self._bookmarks.iteritems():
|
|
|
|
if n == node:
|
|
|
|
marks.append(bookmark)
|
|
|
|
return sorted(marks)
|
|
|
|
|
2010-08-29 01:57:39 +04:00
|
|
|
def branchmap(self):
|
2013-11-22 00:17:18 +04:00
|
|
|
'''returns a dictionary {branch: [branchheads]} with branchheads
|
|
|
|
ordered by increasing revision number'''
|
2012-12-24 06:21:15 +04:00
|
|
|
branchmap.updatecache(self)
|
|
|
|
return self._branchcaches[self.filtername]
|
2012-09-03 16:34:19 +04:00
|
|
|
|
2014-10-17 08:49:28 +04:00
|
|
|
def branchtip(self, branch, ignoremissing=False):
|
|
|
|
'''return the tip node for a given branch
|
|
|
|
|
|
|
|
If ignoremissing is True, then this method will not raise an error.
|
|
|
|
This is helpful for callers that only expect None for a missing branch
|
|
|
|
(e.g. namespace).
|
|
|
|
|
|
|
|
'''
|
2013-09-16 12:08:29 +04:00
|
|
|
try:
|
|
|
|
return self.branchmap().branchtip(branch)
|
|
|
|
except KeyError:
|
2014-10-17 08:49:28 +04:00
|
|
|
if not ignoremissing:
|
|
|
|
raise error.RepoLookupError(_("unknown branch '%s'") % branch)
|
|
|
|
else:
|
|
|
|
pass
|
2012-05-13 16:04:04 +04:00
|
|
|
|
2005-08-28 01:21:25 +04:00
|
|
|
def lookup(self, key):
|
2012-04-08 21:38:10 +04:00
|
|
|
return self[key].node()
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2010-04-13 03:33:25 +04:00
|
|
|
def lookupbranch(self, key, remote=None):
|
|
|
|
repo = remote or self
|
|
|
|
if key in repo.branchmap():
|
|
|
|
return key
|
|
|
|
|
|
|
|
repo = (remote and remote.local()) and remote or self
|
|
|
|
return repo[key].branch()
|
|
|
|
|
2011-03-22 11:22:21 +03:00
|
|
|
def known(self, nodes):
|
|
|
|
nm = self.changelog.nodemap
|
2012-05-12 02:24:07 +04:00
|
|
|
pc = self._phasecache
|
2012-01-12 04:25:57 +04:00
|
|
|
result = []
|
|
|
|
for n in nodes:
|
|
|
|
r = nm.get(n)
|
2012-05-12 02:24:07 +04:00
|
|
|
resp = not (r is None or pc.phase(self, r) >= phases.secret)
|
2012-01-12 04:25:57 +04:00
|
|
|
result.append(resp)
|
|
|
|
return result
|
2011-03-22 11:22:21 +03:00
|
|
|
|
2005-08-28 01:21:25 +04:00
|
|
|
def local(self):
|
2011-06-13 21:51:38 +04:00
|
|
|
return self
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2012-07-13 23:47:06 +04:00
|
|
|
def cancopy(self):
|
2014-01-30 23:52:38 +04:00
|
|
|
# so statichttprepo's override of local() works
|
|
|
|
if not self.local():
|
|
|
|
return False
|
|
|
|
if not self.ui.configbool('phases', 'publish', True):
|
|
|
|
return True
|
|
|
|
# if publishing we can't copy if there is filtered content
|
|
|
|
return not self.filtered('visible').changelog.filteredrevs
|
2012-07-13 23:47:06 +04:00
|
|
|
|
2014-12-21 02:19:10 +03:00
|
|
|
def shared(self):
|
|
|
|
'''the type of shared repository (None if not shared)'''
|
|
|
|
if self.sharedpath != self.path:
|
|
|
|
return 'store'
|
|
|
|
return None
|
|
|
|
|
2014-08-28 19:23:05 +04:00
|
|
|
def join(self, f, *insidef):
|
2014-12-23 21:48:38 +03:00
|
|
|
return self.vfs.join(os.path.join(f, *insidef))
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2014-08-28 19:23:05 +04:00
|
|
|
def wjoin(self, f, *insidef):
|
2015-01-02 15:30:38 +03:00
|
|
|
return self.vfs.reljoin(self.root, f, *insidef)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
|
|
|
def file(self, f):
|
2006-01-12 09:57:58 +03:00
|
|
|
if f[0] == '/':
|
|
|
|
f = f[1:]
|
2015-01-11 02:21:58 +03:00
|
|
|
return filelog.filelog(self.svfs, f)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2008-06-26 02:35:20 +04:00
|
|
|
def changectx(self, changeid):
|
2008-06-26 23:35:46 +04:00
|
|
|
return self[changeid]
|
2006-10-03 10:21:46 +04:00
|
|
|
|
2006-09-30 00:48:16 +04:00
|
|
|
def parents(self, changeid=None):
|
2008-06-26 22:46:33 +04:00
|
|
|
'''get list of changectxs for parents of changeid'''
|
2008-06-26 23:35:46 +04:00
|
|
|
return self[changeid].parents()
|
2006-09-30 00:48:16 +04:00
|
|
|
|
2012-04-30 00:25:55 +04:00
|
|
|
def setparents(self, p1, p2=nullid):
|
2014-09-05 22:36:20 +04:00
|
|
|
self.dirstate.beginparentchange()
|
2012-04-30 00:25:55 +04:00
|
|
|
copies = self.dirstate.setparents(p1, p2)
|
2013-03-01 07:29:31 +04:00
|
|
|
pctx = self[p1]
|
2012-04-30 00:25:55 +04:00
|
|
|
if copies:
|
|
|
|
# Adjust copy records, the dirstate cannot do it, it
|
|
|
|
# requires access to parents manifests. Preserve them
|
|
|
|
# only for entries added to first parent.
|
|
|
|
for f in copies:
|
|
|
|
if f not in pctx and copies[f] in pctx:
|
|
|
|
self.dirstate.copy(copies[f], f)
|
2013-03-01 07:29:31 +04:00
|
|
|
if p2 == nullid:
|
|
|
|
for f, s in sorted(self.dirstate.copies().items()):
|
|
|
|
if f not in pctx and s not in pctx:
|
|
|
|
self.dirstate.copy(None, f)
|
2014-09-05 22:36:20 +04:00
|
|
|
self.dirstate.endparentchange()
|
2012-04-30 00:25:55 +04:00
|
|
|
|
2006-06-29 02:08:10 +04:00
|
|
|
def filectx(self, path, changeid=None, fileid=None):
|
|
|
|
"""changeid can be a changeset revision, node, or tag.
|
|
|
|
fileid can be a file revision or node."""
|
|
|
|
return context.filectx(self, path, changeid, fileid)
|
|
|
|
|
2005-08-28 01:21:25 +04:00
|
|
|
def getcwd(self):
|
|
|
|
return self.dirstate.getcwd()
|
|
|
|
|
2007-06-09 06:49:12 +04:00
|
|
|
def pathto(self, f, cwd=None):
|
|
|
|
return self.dirstate.pathto(f, cwd)
|
|
|
|
|
2005-08-28 01:21:25 +04:00
|
|
|
def wfile(self, f, mode='r'):
|
2015-01-11 03:32:36 +03:00
|
|
|
return self.wvfs(f, mode)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2007-03-24 05:40:25 +03:00
|
|
|
def _link(self, f):
|
2013-04-14 20:22:15 +04:00
|
|
|
return self.wvfs.islink(f)
|
2007-03-24 05:40:25 +03:00
|
|
|
|
2010-07-23 19:28:20 +04:00
|
|
|
def _loadfilter(self, filter):
|
2006-12-30 05:04:31 +03:00
|
|
|
if filter not in self.filterpats:
|
2005-09-15 11:59:16 +04:00
|
|
|
l = []
|
2006-12-30 05:04:31 +03:00
|
|
|
for pat, cmd in self.ui.configitems(filter):
|
2008-10-14 23:28:49 +04:00
|
|
|
if cmd == '!':
|
|
|
|
continue
|
2010-03-11 19:43:44 +03:00
|
|
|
mf = matchmod.match(self.root, '', [pat])
|
2008-01-28 23:39:47 +03:00
|
|
|
fn = None
|
2008-02-09 20:27:58 +03:00
|
|
|
params = cmd
|
2008-01-28 23:39:47 +03:00
|
|
|
for name, filterfn in self._datafilters.iteritems():
|
2008-03-07 02:24:36 +03:00
|
|
|
if cmd.startswith(name):
|
2008-01-28 23:39:47 +03:00
|
|
|
fn = filterfn
|
2008-02-09 20:27:58 +03:00
|
|
|
params = cmd[len(name):].lstrip()
|
2008-01-28 23:39:47 +03:00
|
|
|
break
|
|
|
|
if not fn:
|
2007-12-22 07:21:17 +03:00
|
|
|
fn = lambda s, c, **kwargs: util.filter(s, c)
|
|
|
|
# Wrap old filters not supporting keyword arguments
|
|
|
|
if not inspect.getargspec(fn)[2]:
|
|
|
|
oldfn = fn
|
|
|
|
fn = lambda s, c, **kwargs: oldfn(s, c)
|
2008-02-09 20:27:58 +03:00
|
|
|
l.append((mf, fn, params))
|
2006-12-30 05:04:31 +03:00
|
|
|
self.filterpats[filter] = l
|
2010-10-10 21:07:58 +04:00
|
|
|
return self.filterpats[filter]
|
2005-09-15 11:59:16 +04:00
|
|
|
|
2010-10-10 21:10:16 +04:00
|
|
|
def _filter(self, filterpats, filename, data):
|
|
|
|
for mf, fn, cmd in filterpats:
|
2005-09-15 11:59:16 +04:00
|
|
|
if mf(filename):
|
2009-09-19 03:15:38 +04:00
|
|
|
self.ui.debug("filtering %s through %s\n" % (filename, cmd))
|
2007-12-22 07:21:17 +03:00
|
|
|
data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
|
2005-09-15 11:59:16 +04:00
|
|
|
break
|
|
|
|
|
|
|
|
return data
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2012-10-08 22:02:20 +04:00
|
|
|
@unfilteredpropertycache
|
2010-10-10 20:58:45 +04:00
|
|
|
def _encodefilterpats(self):
|
|
|
|
return self._loadfilter('encode')
|
|
|
|
|
2012-10-08 22:02:20 +04:00
|
|
|
@unfilteredpropertycache
|
2010-10-10 20:58:45 +04:00
|
|
|
def _decodefilterpats(self):
|
|
|
|
return self._loadfilter('decode')
|
|
|
|
|
2008-01-28 23:39:47 +03:00
|
|
|
def adddatafilter(self, name, filter):
|
|
|
|
self._datafilters[name] = filter
|
|
|
|
|
2006-12-30 05:04:31 +03:00
|
|
|
def wread(self, filename):
|
|
|
|
if self._link(filename):
|
2013-04-14 20:22:15 +04:00
|
|
|
data = self.wvfs.readlink(filename)
|
2006-12-30 05:04:31 +03:00
|
|
|
else:
|
2015-01-11 03:32:36 +03:00
|
|
|
data = self.wvfs.read(filename)
|
2010-10-10 20:58:45 +04:00
|
|
|
return self._filter(self._encodefilterpats, filename, data)
|
2005-09-15 11:59:16 +04:00
|
|
|
|
2006-12-30 05:04:31 +03:00
|
|
|
def wwrite(self, filename, data, flags):
|
2010-10-10 20:58:45 +04:00
|
|
|
data = self._filter(self._decodefilterpats, filename, data)
|
2008-08-11 06:55:06 +04:00
|
|
|
if 'l' in flags:
|
2015-01-11 03:32:36 +03:00
|
|
|
self.wvfs.symlink(data, filename)
|
2008-08-11 06:55:06 +04:00
|
|
|
else:
|
2015-01-11 03:32:36 +03:00
|
|
|
self.wvfs.write(filename, data)
|
2008-08-11 06:55:06 +04:00
|
|
|
if 'x' in flags:
|
2013-04-14 20:22:15 +04:00
|
|
|
self.wvfs.setflags(filename, False, True)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2006-12-30 05:04:31 +03:00
|
|
|
def wwritedata(self, filename, data):
|
2010-10-10 20:58:45 +04:00
|
|
|
return self._filter(self._decodefilterpats, filename, data)
|
2006-12-30 05:04:31 +03:00
|
|
|
|
2014-11-13 14:12:47 +03:00
|
|
|
def currenttransaction(self):
|
|
|
|
"""return the current transaction or None if non exists"""
|
2009-04-15 21:54:22 +04:00
|
|
|
tr = self._transref and self._transref() or None
|
|
|
|
if tr and tr.running():
|
2014-11-13 14:12:47 +03:00
|
|
|
return tr
|
|
|
|
return None
|
|
|
|
|
|
|
|
def transaction(self, desc, report=None):
|
|
|
|
tr = self.currenttransaction()
|
|
|
|
if tr is not None:
|
2009-04-15 21:54:22 +04:00
|
|
|
return tr.nest()
|
2006-02-28 21:24:54 +03:00
|
|
|
|
2008-01-16 20:32:25 +03:00
|
|
|
# abort here if the journal already exists
|
2013-04-14 20:22:15 +04:00
|
|
|
if self.svfs.exists("journal"):
|
2010-01-25 09:05:27 +03:00
|
|
|
raise error.RepoError(
|
2014-05-08 18:58:25 +04:00
|
|
|
_("abandoned transaction found"),
|
|
|
|
hint=_("run 'hg recover' to clean up transaction"))
|
2008-01-16 20:32:25 +03:00
|
|
|
|
2012-03-06 20:42:52 +04:00
|
|
|
self._writejournal(desc)
|
2013-04-14 20:22:15 +04:00
|
|
|
renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
|
2013-10-01 14:20:29 +04:00
|
|
|
rp = report and report or self.ui.warn
|
2015-01-11 01:02:52 +03:00
|
|
|
vfsmap = {'plain': self.vfs} # root of .hg/
|
2015-01-11 02:21:58 +03:00
|
|
|
tr = transaction.transaction(rp, self.svfs, vfsmap,
|
2013-11-12 11:23:52 +04:00
|
|
|
"journal",
|
2015-01-17 06:35:04 +03:00
|
|
|
"undo",
|
2011-05-01 15:07:00 +04:00
|
|
|
aftertrans(renames),
|
2014-12-05 00:49:45 +03:00
|
|
|
self.store.createmode)
|
2014-12-05 03:35:03 +03:00
|
|
|
# note: writing the fncache only during finalize mean that the file is
|
|
|
|
# outdated when running hooks. As fncache is used for streaming clone,
|
|
|
|
# this is not expected to break anything that happen during the hooks.
|
|
|
|
tr.addfinalize('flush-fncache', self.store.write)
|
2011-05-01 15:07:00 +04:00
|
|
|
self._transref = weakref.ref(tr)
|
|
|
|
return tr
|
|
|
|
|
2012-03-06 20:42:52 +04:00
|
|
|
def _journalfiles(self):
|
2013-04-14 20:22:15 +04:00
|
|
|
return ((self.svfs, 'journal'),
|
|
|
|
(self.vfs, 'journal.dirstate'),
|
|
|
|
(self.vfs, 'journal.branch'),
|
|
|
|
(self.vfs, 'journal.desc'),
|
|
|
|
(self.vfs, 'journal.bookmarks'),
|
|
|
|
(self.svfs, 'journal.phaseroots'))
|
2012-03-06 20:42:52 +04:00
|
|
|
|
|
|
|
def undofiles(self):
|
2014-03-08 20:03:28 +04:00
|
|
|
return [(vfs, undoname(x)) for vfs, x in self._journalfiles()]
|
2012-03-06 20:42:52 +04:00
|
|
|
|
2011-05-01 15:07:00 +04:00
|
|
|
def _writejournal(self, desc):
|
2015-01-11 01:02:52 +03:00
|
|
|
self.vfs.write("journal.dirstate",
|
|
|
|
self.vfs.tryread("dirstate"))
|
|
|
|
self.vfs.write("journal.branch",
|
2011-05-02 12:11:18 +04:00
|
|
|
encoding.fromlocal(self.dirstate.branch()))
|
2015-01-11 01:02:52 +03:00
|
|
|
self.vfs.write("journal.desc",
|
2011-05-02 12:11:18 +04:00
|
|
|
"%d\n%s\n" % (len(self), desc))
|
2015-01-11 01:02:52 +03:00
|
|
|
self.vfs.write("journal.bookmarks",
|
|
|
|
self.vfs.tryread("bookmarks"))
|
2015-01-11 02:21:58 +03:00
|
|
|
self.svfs.write("journal.phaseroots",
|
|
|
|
self.svfs.tryread("phaseroots"))
|
2011-05-01 15:07:00 +04:00
|
|
|
|
2005-08-28 01:21:25 +04:00
|
|
|
def recover(self):
|
2009-04-22 04:01:22 +04:00
|
|
|
lock = self.lock()
|
2007-07-22 01:02:10 +04:00
|
|
|
try:
|
2013-04-14 20:22:15 +04:00
|
|
|
if self.svfs.exists("journal"):
|
2007-07-22 01:02:10 +04:00
|
|
|
self.ui.status(_("rolling back interrupted transaction\n"))
|
2015-01-11 02:21:58 +03:00
|
|
|
vfsmap = {'': self.svfs,
|
2015-01-11 01:02:52 +03:00
|
|
|
'plain': self.vfs,}
|
2015-01-11 02:21:58 +03:00
|
|
|
transaction.rollback(self.svfs, vfsmap, "journal",
|
2010-01-25 09:05:27 +03:00
|
|
|
self.ui.warn)
|
2007-07-22 01:02:10 +04:00
|
|
|
self.invalidate()
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
self.ui.warn(_("no interrupted transaction available\n"))
|
|
|
|
return False
|
|
|
|
finally:
|
2009-04-22 04:01:22 +04:00
|
|
|
lock.release()
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2011-10-01 05:58:54 +04:00
|
|
|
def rollback(self, dryrun=False, force=False):
|
2007-07-22 01:02:10 +04:00
|
|
|
wlock = lock = None
|
2007-07-22 01:02:10 +04:00
|
|
|
try:
|
2007-07-22 01:02:10 +04:00
|
|
|
wlock = self.wlock()
|
|
|
|
lock = self.lock()
|
2013-04-14 20:22:15 +04:00
|
|
|
if self.svfs.exists("undo"):
|
2011-10-01 05:58:54 +04:00
|
|
|
return self._rollback(dryrun, force)
|
2007-07-22 01:02:10 +04:00
|
|
|
else:
|
|
|
|
self.ui.warn(_("no rollback information available\n"))
|
2010-05-16 02:48:49 +04:00
|
|
|
return 1
|
2007-07-22 01:02:10 +04:00
|
|
|
finally:
|
2009-04-22 04:01:22 +04:00
|
|
|
release(lock, wlock)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2012-12-01 01:34:21 +04:00
|
|
|
@unfilteredmethod # Until we get smarter cache management
|
2011-10-01 05:58:54 +04:00
|
|
|
def _rollback(self, dryrun, force):
|
2011-09-17 05:38:06 +04:00
|
|
|
ui = self.ui
|
2011-09-12 05:21:58 +04:00
|
|
|
try:
|
2015-01-11 01:02:52 +03:00
|
|
|
args = self.vfs.read('undo.desc').splitlines()
|
2011-09-17 05:38:06 +04:00
|
|
|
(oldlen, desc, detail) = (int(args[0]), args[1], None)
|
|
|
|
if len(args) >= 3:
|
|
|
|
detail = args[2]
|
|
|
|
oldtip = oldlen - 1
|
|
|
|
|
|
|
|
if detail and ui.verbose:
|
|
|
|
msg = (_('repository tip rolled back to revision %s'
|
|
|
|
' (undo %s: %s)\n')
|
|
|
|
% (oldtip, desc, detail))
|
|
|
|
else:
|
|
|
|
msg = (_('repository tip rolled back to revision %s'
|
|
|
|
' (undo %s)\n')
|
|
|
|
% (oldtip, desc))
|
2011-09-12 05:21:58 +04:00
|
|
|
except IOError:
|
2011-09-17 05:38:06 +04:00
|
|
|
msg = _('rolling back unknown transaction\n')
|
2011-10-01 05:58:54 +04:00
|
|
|
desc = None
|
|
|
|
|
|
|
|
if not force and self['.'] != self['tip'] and desc == 'commit':
|
|
|
|
raise util.Abort(
|
|
|
|
_('rollback of last commit while not checked out '
|
2011-10-02 01:18:51 +04:00
|
|
|
'may lose data'), hint=_('use -f to force'))
|
2011-10-01 05:58:54 +04:00
|
|
|
|
2011-09-17 05:38:06 +04:00
|
|
|
ui.status(msg)
|
2011-09-12 05:21:58 +04:00
|
|
|
if dryrun:
|
|
|
|
return 0
|
2011-09-19 03:59:33 +04:00
|
|
|
|
|
|
|
parents = self.dirstate.parents()
|
2012-12-15 22:08:13 +04:00
|
|
|
self.destroying()
|
2015-01-17 06:29:16 +03:00
|
|
|
vfsmap = {'plain': self.vfs, '': self.svfs}
|
2015-01-11 02:21:58 +03:00
|
|
|
transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn)
|
2013-04-14 20:22:15 +04:00
|
|
|
if self.vfs.exists('undo.bookmarks'):
|
2013-04-14 20:22:15 +04:00
|
|
|
self.vfs.rename('undo.bookmarks', 'bookmarks')
|
2013-04-14 20:22:15 +04:00
|
|
|
if self.svfs.exists('undo.phaseroots'):
|
2013-04-14 20:22:15 +04:00
|
|
|
self.svfs.rename('undo.phaseroots', 'phaseroots')
|
2011-09-12 05:21:58 +04:00
|
|
|
self.invalidate()
|
2011-09-19 03:59:33 +04:00
|
|
|
|
|
|
|
parentgone = (parents[0] not in self.changelog.nodemap or
|
|
|
|
parents[1] not in self.changelog.nodemap)
|
|
|
|
if parentgone:
|
2013-04-14 20:22:15 +04:00
|
|
|
self.vfs.rename('undo.dirstate', 'dirstate')
|
2011-09-19 03:59:33 +04:00
|
|
|
try:
|
2015-01-11 01:02:52 +03:00
|
|
|
branch = self.vfs.read('undo.branch')
|
2012-08-15 14:04:50 +04:00
|
|
|
self.dirstate.setbranch(encoding.tolocal(branch))
|
2011-09-19 03:59:33 +04:00
|
|
|
except IOError:
|
|
|
|
ui.warn(_('named branch could not be reset: '
|
|
|
|
'current branch is still \'%s\'\n')
|
|
|
|
% self.dirstate.branch())
|
|
|
|
|
|
|
|
self.dirstate.invalidate()
|
|
|
|
parents = tuple([p.rev() for p in self.parents()])
|
|
|
|
if len(parents) > 1:
|
|
|
|
ui.status(_('working directory now based on '
|
|
|
|
'revisions %d and %d\n') % parents)
|
|
|
|
else:
|
|
|
|
ui.status(_('working directory now based on '
|
|
|
|
'revision %d\n') % parents)
|
2012-05-18 23:45:47 +04:00
|
|
|
# TODO: if we know which new heads may result from this rollback, pass
|
|
|
|
# them to destroy(), which will prevent the branchhead cache from being
|
|
|
|
# invalidated.
|
2011-12-02 02:39:30 +04:00
|
|
|
self.destroyed()
|
2011-09-12 05:21:58 +04:00
|
|
|
return 0
|
|
|
|
|
2010-02-21 22:59:27 +03:00
|
|
|
def invalidatecaches(self):
|
2012-01-26 02:21:54 +04:00
|
|
|
|
2012-10-08 22:02:20 +04:00
|
|
|
if '_tagscache' in vars(self):
|
|
|
|
# can't use delattr on proxy
|
|
|
|
del self.__dict__['_tagscache']
|
2011-07-25 16:08:57 +04:00
|
|
|
|
2012-12-24 06:21:15 +04:00
|
|
|
self.unfiltered()._branchcaches.clear()
|
2012-12-18 05:04:37 +04:00
|
|
|
self.invalidatevolatilesets()
|
|
|
|
|
|
|
|
def invalidatevolatilesets(self):
|
2012-12-20 20:14:07 +04:00
|
|
|
self.filteredrevcache.clear()
|
2012-12-18 05:04:37 +04:00
|
|
|
obsolete.clearobscaches(self)
|
2006-02-22 09:26:29 +03:00
|
|
|
|
2011-07-25 16:08:37 +04:00
|
|
|
def invalidatedirstate(self):
|
|
|
|
'''Invalidates the dirstate, causing the next call to dirstate
|
|
|
|
to check if it was modified since the last time it was read,
|
|
|
|
rereading it if it has.
|
|
|
|
|
|
|
|
This is different to dirstate.invalidate() that it doesn't always
|
|
|
|
rereads the dirstate. Use dirstate.invalidate() if you want to
|
|
|
|
explicitly read the dirstate again (i.e. restoring it to a previous
|
|
|
|
known good state).'''
|
2012-10-08 22:02:20 +04:00
|
|
|
if hasunfilteredcache(self, 'dirstate'):
|
2012-03-01 19:39:58 +04:00
|
|
|
for k in self.dirstate._filecache:
|
|
|
|
try:
|
|
|
|
delattr(self.dirstate, k)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2012-11-26 22:22:12 +04:00
|
|
|
delattr(self.unfiltered(), 'dirstate')
|
2011-07-25 16:08:37 +04:00
|
|
|
|
2010-02-21 22:59:27 +03:00
|
|
|
def invalidate(self):
|
2013-02-10 21:24:29 +04:00
|
|
|
unfiltered = self.unfiltered() # all file caches are stored unfiltered
|
2011-07-25 16:08:37 +04:00
|
|
|
for k in self._filecache:
|
|
|
|
# dirstate is invalidated separately in invalidatedirstate()
|
|
|
|
if k == 'dirstate':
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
2012-11-26 22:22:12 +04:00
|
|
|
delattr(unfiltered, k)
|
2011-07-25 16:08:37 +04:00
|
|
|
except AttributeError:
|
|
|
|
pass
|
2010-02-21 22:59:27 +03:00
|
|
|
self.invalidatecaches()
|
2014-03-25 02:35:07 +04:00
|
|
|
self.store.invalidatecaches()
|
2010-02-21 22:59:27 +03:00
|
|
|
|
2014-03-03 14:41:23 +04:00
|
|
|
def invalidateall(self):
|
|
|
|
'''Fully invalidates both store and non-store parts, causing the
|
|
|
|
subsequent operation to reread any outside changes.'''
|
|
|
|
# extension should hook this to invalidate its caches
|
|
|
|
self.invalidate()
|
|
|
|
self.invalidatedirstate()
|
|
|
|
|
2013-11-12 11:23:52 +04:00
|
|
|
def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc):
|
2005-08-28 01:21:25 +04:00
|
|
|
try:
|
2013-11-12 11:23:52 +04:00
|
|
|
l = lockmod.lock(vfs, lockname, 0, releasefn, desc=desc)
|
2009-01-12 20:09:14 +03:00
|
|
|
except error.LockHeld, inst:
|
2005-11-12 02:34:13 +03:00
|
|
|
if not wait:
|
2006-03-28 21:01:07 +04:00
|
|
|
raise
|
2006-11-20 21:55:59 +03:00
|
|
|
self.ui.warn(_("waiting for lock on %s held by %r\n") %
|
|
|
|
(desc, inst.locker))
|
2006-03-28 21:01:07 +04:00
|
|
|
# default to 600 seconds timeout
|
2013-11-12 11:23:52 +04:00
|
|
|
l = lockmod.lock(vfs, lockname,
|
2013-11-12 11:23:52 +04:00
|
|
|
int(self.ui.config("ui", "timeout", "600")),
|
|
|
|
releasefn, desc=desc)
|
2014-02-06 04:55:09 +04:00
|
|
|
self.ui.warn(_("got lock after %s seconds\n") % l.delay)
|
2006-02-20 00:39:09 +03:00
|
|
|
if acquirefn:
|
|
|
|
acquirefn()
|
|
|
|
return l
|
|
|
|
|
2011-12-01 01:36:55 +04:00
|
|
|
def _afterlock(self, callback):
|
2011-11-28 18:05:26 +04:00
|
|
|
"""add a callback to the current repository lock.
|
|
|
|
|
|
|
|
The callback will be executed on lock release."""
|
|
|
|
l = self._lockref and self._lockref()
|
2011-12-01 02:20:07 +04:00
|
|
|
if l:
|
2011-12-01 02:53:44 +04:00
|
|
|
l.postrelease.append(callback)
|
2012-05-12 22:06:02 +04:00
|
|
|
else:
|
|
|
|
callback()
|
2011-11-28 18:05:26 +04:00
|
|
|
|
2007-07-22 01:02:09 +04:00
|
|
|
def lock(self, wait=True):
|
2009-08-05 16:42:57 +04:00
|
|
|
'''Lock the repository store (.hg/store) and return a weak reference
|
|
|
|
to the lock. Use this before modifying the store (e.g. committing or
|
|
|
|
stripping). If you are opening a transaction, get a lock as well.)'''
|
2009-04-22 04:01:22 +04:00
|
|
|
l = self._lockref and self._lockref()
|
|
|
|
if l is not None and l.held:
|
|
|
|
l.lock()
|
|
|
|
return l
|
2007-07-22 01:02:10 +04:00
|
|
|
|
2011-07-25 16:08:37 +04:00
|
|
|
def unlock():
|
|
|
|
for k, ce in self._filecache.items():
|
2012-12-17 01:13:02 +04:00
|
|
|
if k == 'dirstate' or k not in self.__dict__:
|
2011-07-25 16:08:37 +04:00
|
|
|
continue
|
|
|
|
ce.refresh()
|
|
|
|
|
2013-11-12 11:23:52 +04:00
|
|
|
l = self._lock(self.svfs, "lock", wait, unlock,
|
2011-01-28 15:38:34 +03:00
|
|
|
self.invalidate, _('repository %s') % self.origroot)
|
2007-07-22 01:02:10 +04:00
|
|
|
self._lockref = weakref.ref(l)
|
|
|
|
return l
|
2006-02-20 00:39:09 +03:00
|
|
|
|
2007-07-22 01:02:09 +04:00
|
|
|
def wlock(self, wait=True):
|
2009-08-05 16:42:57 +04:00
|
|
|
'''Lock the non-store parts of the repository (everything under
|
|
|
|
.hg except .hg/store) and return a weak reference to the lock.
|
|
|
|
Use this before modifying files in .hg.'''
|
2009-04-22 04:01:22 +04:00
|
|
|
l = self._wlockref and self._wlockref()
|
|
|
|
if l is not None and l.held:
|
|
|
|
l.lock()
|
|
|
|
return l
|
2007-07-22 01:02:10 +04:00
|
|
|
|
2011-07-25 16:08:37 +04:00
|
|
|
def unlock():
|
2014-09-05 22:34:29 +04:00
|
|
|
if self.dirstate.pendingparentchange():
|
|
|
|
self.dirstate.invalidate()
|
|
|
|
else:
|
|
|
|
self.dirstate.write()
|
|
|
|
|
2013-01-11 01:57:03 +04:00
|
|
|
self._filecache['dirstate'].refresh()
|
2011-07-25 16:08:37 +04:00
|
|
|
|
2013-11-12 11:23:52 +04:00
|
|
|
l = self._lock(self.vfs, "wlock", wait, unlock,
|
2011-07-25 16:08:37 +04:00
|
|
|
self.invalidatedirstate, _('working directory of %s') %
|
2007-07-22 01:02:10 +04:00
|
|
|
self.origroot)
|
|
|
|
self._wlockref = weakref.ref(l)
|
|
|
|
return l
|
2005-11-12 02:34:13 +03:00
|
|
|
|
2009-05-14 22:20:40 +04:00
|
|
|
def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
|
2006-10-09 04:57:45 +04:00
|
|
|
"""
|
2006-10-09 23:02:01 +04:00
|
|
|
commit an individual file as part of a larger transaction
|
2006-10-09 04:57:45 +04:00
|
|
|
"""
|
2006-10-09 23:02:01 +04:00
|
|
|
|
2009-04-28 20:14:49 +04:00
|
|
|
fname = fctx.path()
|
|
|
|
text = fctx.data()
|
|
|
|
flog = self.file(fname)
|
|
|
|
fparent1 = manifest1.get(fname, nullid)
|
2014-09-21 19:07:06 +04:00
|
|
|
fparent2 = manifest2.get(fname, nullid)
|
2006-02-18 02:23:53 +03:00
|
|
|
|
2006-10-09 04:57:45 +04:00
|
|
|
meta = {}
|
2009-04-28 20:14:49 +04:00
|
|
|
copy = fctx.renamed()
|
|
|
|
if copy and copy[0] != fname:
|
2007-01-31 00:09:08 +03:00
|
|
|
# Mark the new revision of this file as a copy of another
|
2007-06-06 22:22:52 +04:00
|
|
|
# file. This copy data will effectively act as a parent
|
|
|
|
# of this new revision. If this is a merge, the first
|
2007-01-31 00:09:08 +03:00
|
|
|
# parent will be the nullid (meaning "look up the copy data")
|
|
|
|
# and the second one will be the other parent. For example:
|
|
|
|
#
|
|
|
|
# 0 --- 1 --- 3 rev1 changes file foo
|
|
|
|
# \ / rev2 renames foo to bar and changes it
|
|
|
|
# \- 2 -/ rev3 should have bar with all changes and
|
|
|
|
# should record that bar descends from
|
|
|
|
# bar in rev2 and foo in rev1
|
|
|
|
#
|
|
|
|
# this allows this merge to succeed:
|
|
|
|
#
|
|
|
|
# 0 --- 1 --- 3 rev4 reverts the content change from rev2
|
|
|
|
# \ / merging rev3 and rev4 should use bar@rev2
|
|
|
|
# \- 2 --- 4 as the merge base
|
|
|
|
#
|
2008-08-11 03:01:03 +04:00
|
|
|
|
2009-04-28 20:14:49 +04:00
|
|
|
cfname = copy[0]
|
|
|
|
crev = manifest1.get(cfname)
|
|
|
|
newfparent = fparent2
|
2008-08-11 03:01:03 +04:00
|
|
|
|
|
|
|
if manifest2: # branch merge
|
2009-04-28 20:14:49 +04:00
|
|
|
if fparent2 == nullid or crev is None: # copied on remote side
|
|
|
|
if cfname in manifest2:
|
|
|
|
crev = manifest2[cfname]
|
|
|
|
newfparent = fparent1
|
2008-08-11 03:01:03 +04:00
|
|
|
|
2015-01-21 02:05:44 +03:00
|
|
|
# Here, we used to search backwards through history to try to find
|
|
|
|
# where the file copy came from if the source of a copy was not in
|
|
|
|
# the parent diretory. However, this doesn't actually make sense to
|
|
|
|
# do (what does a copy from something not in your working copy even
|
|
|
|
# mean?) and it causes bugs (eg, issue4476). Instead, we will warn
|
|
|
|
# the user that copy information was dropped, so if they didn't
|
|
|
|
# expect this outcome it can be fixed, but this is the correct
|
|
|
|
# behavior in this circumstance.
|
2008-08-11 03:01:03 +04:00
|
|
|
|
2010-11-16 02:04:55 +03:00
|
|
|
if crev:
|
|
|
|
self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev)))
|
|
|
|
meta["copy"] = cfname
|
|
|
|
meta["copyrev"] = hex(crev)
|
|
|
|
fparent1, fparent2 = nullid, newfparent
|
|
|
|
else:
|
|
|
|
self.ui.warn(_("warning: can't find ancestor for '%s' "
|
|
|
|
"copied from '%s'!\n") % (fname, cfname))
|
|
|
|
|
2014-02-25 01:42:14 +04:00
|
|
|
elif fparent1 == nullid:
|
|
|
|
fparent1, fparent2 = fparent2, nullid
|
2009-04-28 20:14:49 +04:00
|
|
|
elif fparent2 != nullid:
|
2006-02-18 02:23:53 +03:00
|
|
|
# is one parent an ancestor of the other?
|
2014-04-17 22:01:39 +04:00
|
|
|
fparentancestors = flog.commonancestorsheads(fparent1, fparent2)
|
2014-04-08 01:17:51 +04:00
|
|
|
if fparent1 in fparentancestors:
|
2009-04-28 20:14:49 +04:00
|
|
|
fparent1, fparent2 = fparent2, nullid
|
2014-04-08 01:17:51 +04:00
|
|
|
elif fparent2 in fparentancestors:
|
2009-04-28 20:14:49 +04:00
|
|
|
fparent2 = nullid
|
2006-02-18 02:23:53 +03:00
|
|
|
|
2009-05-14 22:20:40 +04:00
|
|
|
# is the file changed?
|
|
|
|
if fparent2 != nullid or flog.cmp(fparent1, text) or meta:
|
|
|
|
changelist.append(fname)
|
|
|
|
return flog.add(text, meta, tr, linkrev, fparent1, fparent2)
|
|
|
|
# are just the flags changed during merge?
|
2014-09-21 19:07:06 +04:00
|
|
|
elif fname in manifest1 and manifest1.flags(fname) != fctx.flags():
|
2009-05-14 22:20:40 +04:00
|
|
|
changelist.append(fname)
|
|
|
|
|
|
|
|
return fparent1
|
2005-11-12 02:34:13 +03:00
|
|
|
|
2012-12-01 01:34:21 +04:00
|
|
|
@unfilteredmethod
|
2009-06-01 23:11:32 +04:00
|
|
|
def commit(self, text="", user=None, date=None, match=None, force=False,
|
|
|
|
editor=False, extra={}):
|
2009-05-19 13:39:12 +04:00
|
|
|
"""Add a new revision to current repository.
|
|
|
|
|
2009-06-01 23:11:32 +04:00
|
|
|
Revision information is gathered from the working directory,
|
|
|
|
match can be used to filter the committed files. If editor is
|
|
|
|
supplied, it is called to get a commit message.
|
2009-05-19 13:39:12 +04:00
|
|
|
"""
|
2009-06-02 06:51:00 +04:00
|
|
|
|
2009-06-05 01:21:03 +04:00
|
|
|
def fail(f, msg):
|
|
|
|
raise util.Abort('%s: %s' % (f, msg))
|
|
|
|
|
|
|
|
if not match:
|
2010-03-11 19:43:44 +03:00
|
|
|
match = matchmod.always(self.root, '')
|
2009-06-05 01:21:03 +04:00
|
|
|
|
|
|
|
if not force:
|
|
|
|
vdirs = []
|
2013-04-29 08:27:21 +04:00
|
|
|
match.explicitdir = vdirs.append
|
2009-06-05 01:21:03 +04:00
|
|
|
match.bad = fail
|
|
|
|
|
2009-05-14 22:20:40 +04:00
|
|
|
wlock = self.wlock()
|
|
|
|
try:
|
2009-06-15 11:45:38 +04:00
|
|
|
wctx = self[None]
|
2010-04-21 03:34:12 +04:00
|
|
|
merge = len(wctx.parents()) > 1
|
2009-05-14 22:20:40 +04:00
|
|
|
|
2010-04-21 03:34:12 +04:00
|
|
|
if (not force and merge and match and
|
2009-05-19 02:36:24 +04:00
|
|
|
(match.files() or match.anypats())):
|
2009-05-14 22:20:40 +04:00
|
|
|
raise util.Abort(_('cannot partially commit a merge '
|
|
|
|
'(do not specify files or patterns)'))
|
|
|
|
|
2014-10-04 00:22:31 +04:00
|
|
|
status = self.status(match=match, clean=force)
|
2009-06-01 23:11:32 +04:00
|
|
|
if force:
|
2014-10-04 00:22:31 +04:00
|
|
|
status.modified.extend(status.clean) # mq may commit clean files
|
2008-06-19 00:52:25 +04:00
|
|
|
|
2009-06-15 11:45:38 +04:00
|
|
|
# check subrepos
|
|
|
|
subs = []
|
2012-02-07 01:10:01 +04:00
|
|
|
commitsubs = set()
|
|
|
|
newstate = wctx.substate.copy()
|
|
|
|
# only manage subrepos and .hgsubstate if .hgsub is present
|
2011-06-07 00:17:40 +04:00
|
|
|
if '.hgsub' in wctx:
|
2012-02-07 01:10:01 +04:00
|
|
|
# we'll decide whether to track this ourselves, thanks
|
2014-10-04 00:22:31 +04:00
|
|
|
for c in status.modified, status.added, status.removed:
|
localrepo: omit ".hgsubstate" also from "added" files
Before this patch, "localrepository.commit()" omits ".hgsubstate" from
"modified" (changes[0]) and "removed" (changes[2]) file list before
checking subrepositories, but leaves one in "added" (changes[1]) as it
is.
Then, "localrepository.commit()" adds ".hgsubstate" into "modified" or
"removed" list forcibly, according to subrepository statuses.
If "added" contains ".hgsubstate", the committed context will contain
two ".hgsubstate" in its "files": one from "added" (not omitted one),
and another from "modified" or "removed" (newly added one).
How many times ".hgsubstate" appears in "files" changes node hash,
even though revision content is same, because node hash calculation
uses the specified "files" directly (without duplication check or so).
This means that node hash of committed revision changes according to
existence of ".hgsubstate" in "added" at "localrepository.commit()".
".hgsubstate" is treated as "added", not only in accidental cases, but
also in the case of "qpush" for the patch adding ".hgsubstate".
This patch omits ".hgsubstate" also from "added" files before checking
subrepositories. This patch also omits ".hgsubstate" exclusion in
"qnew"/"qrefresh" introduced by changeset bbb8109a634f, because this
patch makes them meaningless.
"hg parents --template '{files}\n'" newly added to "test-mq-subrepo.t"
enhances checking unexpected multiple appearances of ".hgsubstate" in
"files" of created/refreshed MQ revisions.
2014-03-22 18:39:51 +04:00
|
|
|
if '.hgsubstate' in c:
|
|
|
|
c.remove('.hgsubstate')
|
2012-02-07 01:10:01 +04:00
|
|
|
|
|
|
|
# compare current state to last committed state
|
|
|
|
# build new substate based on last committed state
|
|
|
|
oldstate = wctx.p1().substate
|
|
|
|
for s in sorted(newstate.keys()):
|
|
|
|
if not match(s):
|
|
|
|
# ignore working copy, use old state if present
|
|
|
|
if s in oldstate:
|
|
|
|
newstate[s] = oldstate[s]
|
|
|
|
continue
|
|
|
|
if not force:
|
|
|
|
raise util.Abort(
|
|
|
|
_("commit with new subrepo %s excluded") % s)
|
|
|
|
if wctx.sub(s).dirty(True):
|
|
|
|
if not self.ui.configbool('ui', 'commitsubrepos'):
|
|
|
|
raise util.Abort(
|
|
|
|
_("uncommitted changes in subrepo %s") % s,
|
|
|
|
hint=_("use --subrepos for recursive commit"))
|
2011-06-07 00:17:40 +04:00
|
|
|
subs.append(s)
|
2012-02-07 01:10:01 +04:00
|
|
|
commitsubs.add(s)
|
|
|
|
else:
|
|
|
|
bs = wctx.sub(s).basestate()
|
|
|
|
newstate[s] = (newstate[s][0], bs, newstate[s][2])
|
|
|
|
if oldstate.get(s, (None, None, None))[1] != bs:
|
|
|
|
subs.append(s)
|
|
|
|
|
|
|
|
# check for removed subrepos
|
|
|
|
for p in wctx.parents():
|
|
|
|
r = [s for s in p.substate if s not in newstate]
|
|
|
|
subs += [s for s in r if match(s)]
|
|
|
|
if subs:
|
2011-06-07 00:17:40 +04:00
|
|
|
if (not match('.hgsub') and
|
|
|
|
'.hgsub' in (wctx.modified() + wctx.added())):
|
|
|
|
raise util.Abort(
|
|
|
|
_("can't commit subrepos without .hgsub"))
|
2014-10-04 00:22:31 +04:00
|
|
|
status.modified.insert(0, '.hgsubstate')
|
2012-02-07 01:10:01 +04:00
|
|
|
|
2014-10-04 00:22:31 +04:00
|
|
|
elif '.hgsub' in status.removed:
|
2011-06-07 00:17:40 +04:00
|
|
|
# clean up .hgsubstate when .hgsub is removed
|
|
|
|
if ('.hgsubstate' in wctx and
|
2014-10-04 00:22:31 +04:00
|
|
|
'.hgsubstate' not in (status.modified + status.added +
|
|
|
|
status.removed)):
|
|
|
|
status.removed.insert(0, '.hgsubstate')
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2009-06-02 06:51:00 +04:00
|
|
|
# make sure all explicit patterns are matched
|
|
|
|
if not force and match.files():
|
2014-10-04 00:22:31 +04:00
|
|
|
matched = set(status.modified + status.added + status.removed)
|
2009-06-02 06:51:00 +04:00
|
|
|
|
|
|
|
for f in match.files():
|
2012-08-17 23:37:59 +04:00
|
|
|
f = self.dirstate.normalize(f)
|
2009-06-15 11:45:38 +04:00
|
|
|
if f == '.' or f in matched or f in wctx.substate:
|
2009-06-02 06:51:00 +04:00
|
|
|
continue
|
2014-10-04 00:22:31 +04:00
|
|
|
if f in status.deleted:
|
2009-06-02 06:51:00 +04:00
|
|
|
fail(f, _('file not found!'))
|
|
|
|
if f in vdirs: # visited directory
|
|
|
|
d = f + '/'
|
2009-06-02 07:13:08 +04:00
|
|
|
for mf in matched:
|
|
|
|
if mf.startswith(d):
|
|
|
|
break
|
|
|
|
else:
|
2009-06-02 06:51:00 +04:00
|
|
|
fail(f, _("no match under directory!"))
|
|
|
|
elif f not in self.dirstate:
|
|
|
|
fail(f, _("file not tracked!"))
|
|
|
|
|
2014-12-31 11:55:43 +03:00
|
|
|
cctx = context.workingcommitctx(self, status,
|
|
|
|
text, user, date, extra)
|
2013-02-08 17:36:07 +04:00
|
|
|
|
2010-04-21 03:34:12 +04:00
|
|
|
if (not force and not extra.get("close") and not merge
|
2013-02-08 17:36:08 +04:00
|
|
|
and not cctx.files()
|
2010-04-21 03:34:12 +04:00
|
|
|
and wctx.branch() == wctx.p1().branch()):
|
2009-05-14 22:20:40 +04:00
|
|
|
return None
|
|
|
|
|
2013-02-08 17:36:08 +04:00
|
|
|
if merge and cctx.deleted():
|
commit: abort on merge with missing files
Here is a script illustrating the previous behaviour:
The merge brings a new file 'b' from remote
$ hg merge 1 --debug
searching for copies back to rev 1
unmatched files in other:
b
resolving manifests
overwrite: False, partial: False
ancestor: 07f494440405, local: 540395c44225+, remote: 102a90ea7b4a
b: remote created -> g
updating: b 1/1 files (100.00%)
getting b
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
Delete but do not remove b
$ rm b
$ hg st
! b
The commit succeeds
$ hg commit -m merge
$ hg parents --template "{rev} {desc|firstline} files: {files}\n"
3 merge files:
$ hg st
! b
b changes were ignored, but even b existence was ignored
$ hg manifest
a
This happens because localrepo.commitctx() checks the input ctx.files(), which
is empty for workingctx.files() only returns added, modified or removed
entries, and bypass files/manifest updates completely. So the committed
revision manifest is the same as its first parent one, not containing the 'b'
file.
This patch forces the commit to abort in presence of a merge and missing files.
test-merge4.t is modified accordingly as it was introduced to check hg was not
just terminating with a traceback (5cc0d3ba11f9).
2012-04-28 17:01:57 +04:00
|
|
|
raise util.Abort(_("cannot commit merge with missing files"))
|
|
|
|
|
2010-03-11 19:43:44 +03:00
|
|
|
ms = mergemod.mergestate(self)
|
2014-10-04 00:22:31 +04:00
|
|
|
for f in status.modified:
|
2008-08-14 05:18:40 +04:00
|
|
|
if f in ms and ms[f] == 'u':
|
2015-01-18 03:01:14 +03:00
|
|
|
raise util.Abort(_('unresolved merge conflicts '
|
|
|
|
'(see "hg help resolve")'))
|
2009-05-19 02:36:24 +04:00
|
|
|
|
|
|
|
if editor:
|
2009-07-01 10:05:24 +04:00
|
|
|
cctx._text = editor(self, cctx, subs)
|
2009-11-25 05:08:40 +03:00
|
|
|
edited = (text != cctx._text)
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2014-03-18 20:07:41 +04:00
|
|
|
# Save commit message in case this transaction gets rolled back
|
|
|
|
# (e.g. by a pretxncommit hook). Leave the content alone on
|
|
|
|
# the assumption that the user will use the same editor again.
|
|
|
|
msgfn = self.savecommitmessage(cctx._text)
|
|
|
|
|
2012-02-07 01:10:01 +04:00
|
|
|
# commit subs and write new state
|
|
|
|
if subs:
|
|
|
|
for s in sorted(commitsubs):
|
2010-05-02 01:05:22 +04:00
|
|
|
sub = wctx.sub(s)
|
|
|
|
self.ui.status(_('committing subrepository %s\n') %
|
2010-10-19 05:55:28 +04:00
|
|
|
subrepo.subrelpath(sub))
|
2010-05-02 01:05:22 +04:00
|
|
|
sr = sub.commit(cctx._text, user, date)
|
2012-02-07 01:10:01 +04:00
|
|
|
newstate[s] = (newstate[s][0], sr)
|
|
|
|
subrepo.writestate(self, newstate)
|
2009-06-15 11:45:38 +04:00
|
|
|
|
2010-04-21 03:34:12 +04:00
|
|
|
p1, p2 = self.dirstate.parents()
|
|
|
|
hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
|
2009-11-25 05:08:40 +03:00
|
|
|
try:
|
2012-05-12 17:54:54 +04:00
|
|
|
self.hook("precommit", throw=True, parent1=hookp1,
|
|
|
|
parent2=hookp2)
|
2009-11-25 05:08:40 +03:00
|
|
|
ret = self.commitctx(cctx, True)
|
2012-05-13 15:18:06 +04:00
|
|
|
except: # re-raises
|
2009-11-25 05:08:40 +03:00
|
|
|
if edited:
|
|
|
|
self.ui.write(
|
|
|
|
_('note: commit message saved in %s\n') % msgfn)
|
|
|
|
raise
|
2009-05-14 22:24:39 +04:00
|
|
|
|
2011-02-10 22:46:27 +03:00
|
|
|
# update bookmarks, dirstate and mergestate
|
2012-05-12 23:28:10 +04:00
|
|
|
bookmarks.update(self, [p1, p2], ret)
|
2013-02-08 17:36:08 +04:00
|
|
|
cctx.markcommitted(ret)
|
2009-05-19 02:36:24 +04:00
|
|
|
ms.reset()
|
2008-06-19 00:52:26 +04:00
|
|
|
finally:
|
2009-05-14 22:20:40 +04:00
|
|
|
wlock.release()
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2012-05-12 22:06:02 +04:00
|
|
|
def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2):
|
2014-11-02 02:17:50 +03:00
|
|
|
# hack for command that use a temporary commit (eg: histedit)
|
|
|
|
# temporary commit got stripped before hook release
|
|
|
|
if node in self:
|
|
|
|
self.hook("commit", node=node, parent1=parent1,
|
|
|
|
parent2=parent2)
|
2012-05-12 22:06:02 +04:00
|
|
|
self._afterlock(commithook)
|
2010-02-17 17:43:21 +03:00
|
|
|
return ret
|
|
|
|
|
2012-12-01 01:34:21 +04:00
|
|
|
@unfilteredmethod
|
2009-05-19 02:36:24 +04:00
|
|
|
def commitctx(self, ctx, error=False):
|
2008-10-11 15:07:29 +04:00
|
|
|
"""Add a new revision to current repository.
|
2009-05-14 22:21:20 +04:00
|
|
|
Revision information is passed via the context argument.
|
2008-10-11 15:07:29 +04:00
|
|
|
"""
|
2008-06-19 02:14:23 +04:00
|
|
|
|
2014-10-14 01:34:53 +04:00
|
|
|
tr = None
|
2009-05-14 22:24:26 +04:00
|
|
|
p1, p2 = ctx.p1(), ctx.p2()
|
2009-05-14 22:21:20 +04:00
|
|
|
user = ctx.user()
|
2009-05-14 22:21:20 +04:00
|
|
|
|
|
|
|
lock = self.lock()
|
|
|
|
try:
|
2010-04-10 02:23:35 +04:00
|
|
|
tr = self.transaction("commit")
|
2007-07-22 23:53:57 +04:00
|
|
|
trp = weakref.proxy(tr)
|
2007-07-22 01:02:10 +04:00
|
|
|
|
2011-05-02 21:20:29 +04:00
|
|
|
if ctx.files():
|
2014-10-14 01:11:47 +04:00
|
|
|
m1 = p1.manifest()
|
2011-05-02 21:20:29 +04:00
|
|
|
m2 = p2.manifest()
|
2014-10-14 01:11:47 +04:00
|
|
|
m = m1.copy()
|
2011-05-02 21:20:29 +04:00
|
|
|
|
|
|
|
# check in files
|
2014-10-14 01:18:47 +04:00
|
|
|
added = []
|
2011-05-02 21:20:29 +04:00
|
|
|
changed = []
|
2014-10-14 03:43:37 +04:00
|
|
|
removed = list(ctx.removed())
|
2011-05-02 21:20:29 +04:00
|
|
|
linkrev = len(self)
|
2014-04-18 15:33:20 +04:00
|
|
|
self.ui.note(_("committing files:\n"))
|
2011-05-02 21:20:29 +04:00
|
|
|
for f in sorted(ctx.modified() + ctx.added()):
|
|
|
|
self.ui.note(f + "\n")
|
|
|
|
try:
|
|
|
|
fctx = ctx[f]
|
2014-08-27 00:03:32 +04:00
|
|
|
if fctx is None:
|
|
|
|
removed.append(f)
|
|
|
|
else:
|
2014-10-14 01:18:47 +04:00
|
|
|
added.append(f)
|
|
|
|
m[f] = self._filecommit(fctx, m1, m2, linkrev,
|
|
|
|
trp, changed)
|
2014-10-10 22:09:37 +04:00
|
|
|
m.setflag(f, fctx.flags())
|
2011-05-02 21:20:29 +04:00
|
|
|
except OSError, inst:
|
2007-07-22 01:02:10 +04:00
|
|
|
self.ui.warn(_("trouble committing %s!\n") % f)
|
|
|
|
raise
|
2011-05-02 21:20:29 +04:00
|
|
|
except IOError, inst:
|
|
|
|
errcode = getattr(inst, 'errno', errno.ENOENT)
|
|
|
|
if error or errcode and errcode != errno.ENOENT:
|
|
|
|
self.ui.warn(_("trouble committing %s!\n") % f)
|
2014-08-27 00:03:32 +04:00
|
|
|
raise
|
2011-05-02 21:20:29 +04:00
|
|
|
|
|
|
|
# update manifest
|
2014-04-18 15:33:20 +04:00
|
|
|
self.ui.note(_("committing manifest\n"))
|
2011-05-02 21:20:29 +04:00
|
|
|
removed = [f for f in sorted(removed) if f in m1 or f in m2]
|
2014-10-14 01:11:47 +04:00
|
|
|
drop = [f for f in removed if f in m]
|
2011-05-02 21:20:29 +04:00
|
|
|
for f in drop:
|
2014-10-14 01:11:47 +04:00
|
|
|
del m[f]
|
|
|
|
mn = self.manifest.add(m, trp, linkrev,
|
|
|
|
p1.manifestnode(), p2.manifestnode(),
|
2014-10-14 01:18:47 +04:00
|
|
|
added, drop)
|
2011-05-02 21:20:29 +04:00
|
|
|
files = changed + removed
|
|
|
|
else:
|
|
|
|
mn = p1.manifestnode()
|
|
|
|
files = []
|
2007-07-22 01:02:10 +04:00
|
|
|
|
2009-05-19 02:36:24 +04:00
|
|
|
# update changelog
|
2014-04-18 15:33:20 +04:00
|
|
|
self.ui.note(_("committing changelog\n"))
|
2014-10-18 08:55:31 +04:00
|
|
|
self.changelog.delayupdate(tr)
|
2011-05-02 21:20:29 +04:00
|
|
|
n = self.changelog.add(mn, files, ctx.description(),
|
2009-05-19 02:36:24 +04:00
|
|
|
trp, p1.node(), p2.node(),
|
2009-05-14 22:21:20 +04:00
|
|
|
user, ctx.date(), ctx.extra().copy())
|
2014-10-18 08:55:31 +04:00
|
|
|
p = lambda: tr.writepending() and self.root or ""
|
2010-02-17 17:43:21 +03:00
|
|
|
xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
|
2007-07-22 01:02:10 +04:00
|
|
|
self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
|
2009-02-17 04:35:07 +03:00
|
|
|
parent2=xp2, pending=p)
|
2011-12-20 04:31:25 +04:00
|
|
|
# set the new commit is proper phase
|
2013-11-13 10:55:30 +04:00
|
|
|
targetphase = subrepo.newcommitphase(self.ui, ctx)
|
2011-12-20 04:31:25 +04:00
|
|
|
if targetphase:
|
|
|
|
# retract boundary do not alter parent changeset.
|
|
|
|
# if a parent have higher the resulting phase will
|
|
|
|
# be compliant anyway
|
|
|
|
#
|
|
|
|
# if minimal phase was 0 we don't need to retract anything
|
2014-08-06 10:52:21 +04:00
|
|
|
phases.retractboundary(self, tr, targetphase, [n])
|
2007-07-22 01:02:10 +04:00
|
|
|
tr.close()
|
2013-01-16 03:08:08 +04:00
|
|
|
branchmap.updatecache(self.filtered('served'))
|
2007-07-22 01:02:10 +04:00
|
|
|
return n
|
|
|
|
finally:
|
2010-05-27 19:47:40 +04:00
|
|
|
if tr:
|
|
|
|
tr.release()
|
2009-05-14 22:20:40 +04:00
|
|
|
lock.release()
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2012-12-15 22:08:13 +04:00
|
|
|
@unfilteredmethod
|
|
|
|
def destroying(self):
|
|
|
|
'''Inform the repository that nodes are about to be destroyed.
|
|
|
|
Intended for use by strip and rollback, so there's a common
|
|
|
|
place for anything that has to be done before destroying history.
|
|
|
|
|
|
|
|
This is mostly useful for saving state that is in memory and waiting
|
|
|
|
to be flushed when the current lock is released. Because a call to
|
|
|
|
destroyed is imminent, the repo will be invalidated causing those
|
|
|
|
changes to stay in memory (waiting for the next unlock), or vanish
|
|
|
|
completely.
|
|
|
|
'''
|
2013-01-11 02:05:52 +04:00
|
|
|
# When using the same lock to commit and strip, the phasecache is left
|
|
|
|
# dirty after committing. Then when we strip, the repo is invalidated,
|
|
|
|
# causing those changes to disappear.
|
|
|
|
if '_phasecache' in vars(self):
|
|
|
|
self._phasecache.write()
|
|
|
|
|
2012-12-01 01:34:21 +04:00
|
|
|
@unfilteredmethod
|
2013-01-16 03:09:26 +04:00
|
|
|
def destroyed(self):
|
2009-07-16 18:39:41 +04:00
|
|
|
'''Inform the repository that nodes have been destroyed.
|
|
|
|
Intended for use by strip and rollback, so there's a common
|
2012-05-18 23:45:47 +04:00
|
|
|
place for anything that has to be done after destroying history.
|
|
|
|
'''
|
2012-12-21 20:19:52 +04:00
|
|
|
# When one tries to:
|
|
|
|
# 1) destroy nodes thus calling this method (e.g. strip)
|
|
|
|
# 2) use phasecache somewhere (e.g. commit)
|
|
|
|
#
|
|
|
|
# then 2) will fail because the phasecache contains nodes that were
|
|
|
|
# removed. We can either remove phasecache from the filecache,
|
|
|
|
# causing it to reload next time it is accessed, or simply filter
|
|
|
|
# the removed nodes now and write the updated cache.
|
2013-03-23 15:34:50 +04:00
|
|
|
self._phasecache.filterunknown(self)
|
|
|
|
self._phasecache.write()
|
2012-12-21 20:19:52 +04:00
|
|
|
|
2013-01-16 02:33:07 +04:00
|
|
|
# update the 'served' branch cache to help read only server process
|
2013-02-10 21:24:29 +04:00
|
|
|
# Thanks to branchcache collaboration this is done from the nearest
|
2013-01-16 02:33:07 +04:00
|
|
|
# filtered subset and it is expected to be fast.
|
|
|
|
branchmap.updatecache(self.filtered('served'))
|
2013-01-04 22:05:20 +04:00
|
|
|
|
2009-07-16 18:39:42 +04:00
|
|
|
# Ensure the persistent tag cache is updated. Doing it now
|
|
|
|
# means that the tag cache only has to worry about destroyed
|
|
|
|
# heads immediately after a strip/rollback. That in turn
|
|
|
|
# guarantees that "cachetip == currenttip" (comparing both rev
|
|
|
|
# and node) always means no nodes have been added or destroyed.
|
|
|
|
|
|
|
|
# XXX this is suboptimal when qrefresh'ing: we strip the current
|
|
|
|
# head, refresh the tag cache, then immediately add a new head.
|
|
|
|
# But I think doing it this way is necessary for the "instant
|
|
|
|
# tag cache retrieval" case to work.
|
2013-01-09 22:37:44 +04:00
|
|
|
self.invalidate()
|
2012-07-28 23:40:30 +04:00
|
|
|
|
2008-05-12 20:37:08 +04:00
|
|
|
def walk(self, match, node=None):
|
2006-10-27 20:24:10 +04:00
|
|
|
'''
|
|
|
|
walk recursively through the directory tree or a given
|
|
|
|
changeset, finding all files matched by the match
|
|
|
|
function
|
|
|
|
'''
|
2008-06-28 04:25:48 +04:00
|
|
|
return self[node].walk(match)
|
2006-10-27 20:24:10 +04:00
|
|
|
|
2008-07-12 03:46:02 +04:00
|
|
|
def status(self, node1='.', node2=None, match=None,
|
2010-09-03 14:58:51 +04:00
|
|
|
ignored=False, clean=False, unknown=False,
|
|
|
|
listsubrepos=False):
|
2014-04-26 00:44:55 +04:00
|
|
|
'''a convenience method that calls node1.status(node2)'''
|
|
|
|
return self[node1].status(node2, match, ignored, clean, unknown,
|
|
|
|
listsubrepos)
|
2006-07-21 03:21:07 +04:00
|
|
|
|
2009-06-11 03:11:49 +04:00
|
|
|
def heads(self, start=None):
|
2005-11-16 14:08:25 +03:00
|
|
|
heads = self.changelog.heads(start)
|
|
|
|
# sort the output in rev descending order
|
2010-12-03 13:30:45 +03:00
|
|
|
return sorted(heads, key=self.changelog.rev, reverse=True)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2009-06-03 15:42:55 +04:00
|
|
|
def branchheads(self, branch=None, start=None, closed=False):
|
2009-09-23 17:51:36 +04:00
|
|
|
'''return a (possibly filtered) list of heads for the given branch
|
|
|
|
|
|
|
|
Heads are returned in topological order, from newest to oldest.
|
|
|
|
If branch is None, use the dirstate branch.
|
|
|
|
If start is not None, return only heads reachable from start.
|
|
|
|
If closed is True, return heads that are marked as closed as well.
|
|
|
|
'''
|
2008-06-26 23:35:46 +04:00
|
|
|
if branch is None:
|
|
|
|
branch = self[None].branch()
|
2009-10-31 02:31:08 +03:00
|
|
|
branches = self.branchmap()
|
2007-06-19 19:37:43 +04:00
|
|
|
if branch not in branches:
|
|
|
|
return []
|
2009-01-15 05:47:38 +03:00
|
|
|
# the cache returns heads ordered lowest to highest
|
2013-09-16 12:08:29 +04:00
|
|
|
bheads = list(reversed(branches.branchheads(branch, closed=closed)))
|
2007-06-19 19:37:43 +04:00
|
|
|
if start is not None:
|
2009-01-15 05:47:38 +03:00
|
|
|
# filter out the heads that cannot be reached from startrev
|
2009-09-23 17:51:36 +04:00
|
|
|
fbheads = set(self.changelog.nodesbetween([start], bheads)[2])
|
|
|
|
bheads = [h for h in bheads if h in fbheads]
|
2009-01-15 05:47:38 +03:00
|
|
|
return bheads
|
2007-06-19 19:37:43 +04:00
|
|
|
|
2005-08-28 01:21:25 +04:00
|
|
|
def branches(self, nodes):
|
2006-01-12 09:57:58 +03:00
|
|
|
if not nodes:
|
|
|
|
nodes = [self.changelog.tip()]
|
2005-08-28 01:21:25 +04:00
|
|
|
b = []
|
|
|
|
for n in nodes:
|
|
|
|
t = n
|
2011-06-01 14:38:46 +04:00
|
|
|
while True:
|
2005-08-28 01:21:25 +04:00
|
|
|
p = self.changelog.parents(n)
|
|
|
|
if p[1] != nullid or p[0] == nullid:
|
|
|
|
b.append((t, n, p[0], p[1]))
|
|
|
|
break
|
|
|
|
n = p[0]
|
|
|
|
return b
|
|
|
|
|
|
|
|
def between(self, pairs):
|
|
|
|
r = []
|
|
|
|
|
|
|
|
for top, bottom in pairs:
|
|
|
|
n, l, i = top, [], 0
|
|
|
|
f = 1
|
|
|
|
|
2009-01-25 19:16:45 +03:00
|
|
|
while n != bottom and n != nullid:
|
2005-08-28 01:21:25 +04:00
|
|
|
p = self.changelog.parents(n)[0]
|
|
|
|
if i == f:
|
|
|
|
l.append(n)
|
|
|
|
f = f * 2
|
|
|
|
n = p
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
r.append(l)
|
|
|
|
|
|
|
|
return r
|
|
|
|
|
2014-04-02 00:45:48 +04:00
|
|
|
def checkpush(self, pushop):
|
2011-02-01 00:16:33 +03:00
|
|
|
"""Extensions can override this function if additional checks have
|
|
|
|
to be performed before pushing, or call it if they override push
|
|
|
|
command.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2014-04-15 19:37:24 +04:00
|
|
|
@unfilteredpropertycache
|
|
|
|
def prepushoutgoinghooks(self):
|
|
|
|
"""Return util.hooks consists of "(repo, remote, outgoing)"
|
|
|
|
functions, which are called before pushing changesets.
|
|
|
|
"""
|
|
|
|
return util.hooks()
|
|
|
|
|
clone: only use stream when we understand the revlog format
This patch fixes issues with stream cloning in the presense of parentdelta,
lwcopy and similar additions that change the interpretation of the revlog
format, or the format itself.
Currently, the stream capability is sent like this:
stream=<version of changelog>
But the client doesn't actually check the version number; also, it only checks
the changelog and it doesn't capture the interpretation-changes and
flag-changes in parentdelta and lwcopy.
This patch removes the 'stream' capability whenever we use a non-basic revlog
format, to prevent old clients from receiving incorrect data. In those cases,
a new capability called 'streamreqs' is added instead. Instead of a revlog
version, it comes with a list of revlog-format relevant requirements, which
are a subset of the repository requirements, excluding things that are not
relevant for stream.
New clients use this to determine whether or not they can stream. Old clients
only look for the 'stream' capability, as always. New servers will still send
this when serving old repositories.
2010-09-15 13:06:22 +04:00
|
|
|
def stream_in(self, remote, requirements):
|
2011-01-28 15:34:07 +03:00
|
|
|
lock = self.lock()
|
2006-10-27 20:17:12 +04:00
|
|
|
try:
|
2012-10-04 00:19:53 +04:00
|
|
|
# Save remote branchmap. We will use it later
|
|
|
|
# to speed up branchcache creation
|
|
|
|
rbranchmap = None
|
|
|
|
if remote.capable("branchmap"):
|
|
|
|
rbranchmap = remote.branchmap()
|
|
|
|
|
2011-01-28 15:34:07 +03:00
|
|
|
fp = remote.stream_out()
|
|
|
|
l = fp.readline()
|
|
|
|
try:
|
|
|
|
resp = int(l)
|
|
|
|
except ValueError:
|
|
|
|
raise error.ResponseError(
|
2012-06-12 16:18:18 +04:00
|
|
|
_('unexpected response from remote server:'), l)
|
2011-01-28 15:34:07 +03:00
|
|
|
if resp == 1:
|
|
|
|
raise util.Abort(_('operation forbidden by server'))
|
|
|
|
elif resp == 2:
|
|
|
|
raise util.Abort(_('locking the remote repository failed'))
|
|
|
|
elif resp != 0:
|
|
|
|
raise util.Abort(_('the server sent an unknown error code'))
|
|
|
|
self.ui.status(_('streaming all changes\n'))
|
2006-10-27 20:17:12 +04:00
|
|
|
l = fp.readline()
|
|
|
|
try:
|
2011-01-28 15:34:07 +03:00
|
|
|
total_files, total_bytes = map(int, l.split(' ', 1))
|
2008-10-04 01:13:03 +04:00
|
|
|
except (ValueError, TypeError):
|
2009-01-12 20:28:28 +03:00
|
|
|
raise error.ResponseError(
|
2012-06-12 16:18:18 +04:00
|
|
|
_('unexpected response from remote server:'), l)
|
2011-01-28 15:34:07 +03:00
|
|
|
self.ui.status(_('%d files to transfer, %s of data\n') %
|
|
|
|
(total_files, util.bytecount(total_bytes)))
|
2012-05-21 23:25:46 +04:00
|
|
|
handled_bytes = 0
|
|
|
|
self.ui.progress(_('clone'), 0, total=total_bytes)
|
2011-01-28 15:34:07 +03:00
|
|
|
start = time.time()
|
2014-03-25 02:38:20 +04:00
|
|
|
|
|
|
|
tr = self.transaction(_('clone'))
|
|
|
|
try:
|
|
|
|
for i in xrange(total_files):
|
|
|
|
# XXX doesn't support '\n' or '\r' in filenames
|
|
|
|
l = fp.readline()
|
|
|
|
try:
|
|
|
|
name, size = l.split('\0', 1)
|
|
|
|
size = int(size)
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
raise error.ResponseError(
|
|
|
|
_('unexpected response from remote server:'), l)
|
|
|
|
if self.ui.debugflag:
|
|
|
|
self.ui.debug('adding %s (%s)\n' %
|
|
|
|
(name, util.bytecount(size)))
|
|
|
|
# for backwards compat, name was partially encoded
|
2015-01-11 02:21:58 +03:00
|
|
|
ofp = self.svfs(store.decodedir(name), 'w')
|
2014-03-25 02:38:20 +04:00
|
|
|
for chunk in util.filechunkiter(fp, limit=size):
|
|
|
|
handled_bytes += len(chunk)
|
|
|
|
self.ui.progress(_('clone'), handled_bytes,
|
|
|
|
total=total_bytes)
|
|
|
|
ofp.write(chunk)
|
|
|
|
ofp.close()
|
|
|
|
tr.close()
|
|
|
|
finally:
|
|
|
|
tr.release()
|
|
|
|
|
|
|
|
# Writing straight to files circumvented the inmemory caches
|
|
|
|
self.invalidate()
|
|
|
|
|
2011-01-28 15:34:07 +03:00
|
|
|
elapsed = time.time() - start
|
|
|
|
if elapsed <= 0:
|
|
|
|
elapsed = 0.001
|
2012-05-21 23:25:46 +04:00
|
|
|
self.ui.progress(_('clone'), None)
|
2011-01-28 15:34:07 +03:00
|
|
|
self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %
|
|
|
|
(util.bytecount(total_bytes), elapsed,
|
|
|
|
util.bytecount(total_bytes / elapsed)))
|
|
|
|
|
2012-05-12 17:54:54 +04:00
|
|
|
# new requirements = old non-format requirements +
|
|
|
|
# new format-related
|
2011-01-28 15:34:07 +03:00
|
|
|
# requirements from the streamed-in repository
|
|
|
|
requirements.update(set(self.requirements) - self.supportedformats)
|
|
|
|
self._applyrequirements(requirements)
|
|
|
|
self._writerequirements()
|
clone: only use stream when we understand the revlog format
This patch fixes issues with stream cloning in the presense of parentdelta,
lwcopy and similar additions that change the interpretation of the revlog
format, or the format itself.
Currently, the stream capability is sent like this:
stream=<version of changelog>
But the client doesn't actually check the version number; also, it only checks
the changelog and it doesn't capture the interpretation-changes and
flag-changes in parentdelta and lwcopy.
This patch removes the 'stream' capability whenever we use a non-basic revlog
format, to prevent old clients from receiving incorrect data. In those cases,
a new capability called 'streamreqs' is added instead. Instead of a revlog
version, it comes with a list of revlog-format relevant requirements, which
are a subset of the repository requirements, excluding things that are not
relevant for stream.
New clients use this to determine whether or not they can stream. Old clients
only look for the 'stream' capability, as always. New servers will still send
this when serving old repositories.
2010-09-15 13:06:22 +04:00
|
|
|
|
2012-10-04 00:19:53 +04:00
|
|
|
if rbranchmap:
|
|
|
|
rbheads = []
|
2014-11-02 01:30:57 +03:00
|
|
|
closed = []
|
2012-10-04 00:19:53 +04:00
|
|
|
for bheads in rbranchmap.itervalues():
|
|
|
|
rbheads.extend(bheads)
|
2014-11-02 01:30:57 +03:00
|
|
|
for h in bheads:
|
|
|
|
r = self.changelog.rev(h)
|
|
|
|
b, c = self.changelog.branchinfo(r)
|
|
|
|
if c:
|
|
|
|
closed.append(h)
|
2012-10-04 00:19:53 +04:00
|
|
|
|
|
|
|
if rbheads:
|
|
|
|
rtiprev = max((int(self.changelog.rev(node))
|
|
|
|
for node in rbheads))
|
2012-12-22 04:59:05 +04:00
|
|
|
cache = branchmap.branchcache(rbranchmap,
|
2012-12-22 05:06:26 +04:00
|
|
|
self[rtiprev].node(),
|
2014-11-02 01:30:57 +03:00
|
|
|
rtiprev,
|
|
|
|
closednodes=closed)
|
2013-01-16 03:12:01 +04:00
|
|
|
# Try to stick it as low as possible
|
|
|
|
# filter above served are unlikely to be fetch from a clone
|
|
|
|
for candidate in ('base', 'immutable', 'served'):
|
|
|
|
rview = self.filtered(candidate)
|
|
|
|
if cache.validfor(rview):
|
|
|
|
self._branchcaches[candidate] = cache
|
|
|
|
cache.write(rview)
|
|
|
|
break
|
2011-01-28 15:34:07 +03:00
|
|
|
self.invalidate()
|
|
|
|
return len(self.heads()) + 1
|
|
|
|
finally:
|
|
|
|
lock.release()
|
2006-08-08 01:27:09 +04:00
|
|
|
|
2014-12-13 01:06:36 +03:00
|
|
|
def clone(self, remote, heads=[], stream=None):
|
2006-07-14 22:17:22 +04:00
|
|
|
'''clone remote repository.
|
|
|
|
|
|
|
|
keyword arguments:
|
|
|
|
heads: list of revs to clone (forces use of pull)
|
2006-07-16 03:06:35 +04:00
|
|
|
stream: use streaming clone if possible'''
|
2006-07-14 22:17:22 +04:00
|
|
|
|
2006-07-16 03:06:35 +04:00
|
|
|
# now, all clients that can request uncompressed clones can
|
|
|
|
# read repo formats supported by all servers that can serve
|
|
|
|
# them.
|
2006-07-14 22:17:22 +04:00
|
|
|
|
|
|
|
# if revlog format changes, client will have to check version
|
2006-07-16 03:06:35 +04:00
|
|
|
# and format flags on "stream" capability, and use
|
|
|
|
# uncompressed only if compatible.
|
2006-07-14 22:17:22 +04:00
|
|
|
|
2014-12-13 01:06:36 +03:00
|
|
|
if stream is None:
|
2012-08-21 04:41:20 +04:00
|
|
|
# if the server explicitly prefers to stream (for fast LANs)
|
2012-04-04 02:00:47 +04:00
|
|
|
stream = remote.capable('stream-preferred')
|
|
|
|
|
clone: only use stream when we understand the revlog format
This patch fixes issues with stream cloning in the presense of parentdelta,
lwcopy and similar additions that change the interpretation of the revlog
format, or the format itself.
Currently, the stream capability is sent like this:
stream=<version of changelog>
But the client doesn't actually check the version number; also, it only checks
the changelog and it doesn't capture the interpretation-changes and
flag-changes in parentdelta and lwcopy.
This patch removes the 'stream' capability whenever we use a non-basic revlog
format, to prevent old clients from receiving incorrect data. In those cases,
a new capability called 'streamreqs' is added instead. Instead of a revlog
version, it comes with a list of revlog-format relevant requirements, which
are a subset of the repository requirements, excluding things that are not
relevant for stream.
New clients use this to determine whether or not they can stream. Old clients
only look for the 'stream' capability, as always. New servers will still send
this when serving old repositories.
2010-09-15 13:06:22 +04:00
|
|
|
if stream and not heads:
|
|
|
|
# 'stream' means remote revlog format is revlogv1 only
|
|
|
|
if remote.capable('stream'):
|
2014-10-31 22:56:25 +03:00
|
|
|
self.stream_in(remote, set(('revlogv1',)))
|
|
|
|
else:
|
|
|
|
# otherwise, 'streamreqs' contains the remote revlog format
|
|
|
|
streamreqs = remote.capable('streamreqs')
|
|
|
|
if streamreqs:
|
|
|
|
streamreqs = set(streamreqs.split(','))
|
|
|
|
# if we support it, stream in and adjust our requirements
|
|
|
|
if not streamreqs - self.supportedformats:
|
|
|
|
self.stream_in(remote, streamreqs)
|
2014-09-27 04:44:00 +04:00
|
|
|
|
|
|
|
quiet = self.ui.backupconfig('ui', 'quietbookmarkmove')
|
|
|
|
try:
|
|
|
|
self.ui.setconfig('ui', 'quietbookmarkmove', True, 'clone')
|
2014-10-03 20:15:33 +04:00
|
|
|
ret = exchange.pull(self, remote, heads).cgresult
|
2014-09-27 04:44:00 +04:00
|
|
|
finally:
|
|
|
|
self.ui.restoreconfig(quiet)
|
|
|
|
return ret
|
2006-07-14 22:17:22 +04:00
|
|
|
|
2010-06-17 01:04:46 +04:00
|
|
|
def pushkey(self, namespace, key, old, new):
|
2014-11-30 06:17:47 +03:00
|
|
|
try:
|
|
|
|
self.hook('prepushkey', throw=True, namespace=namespace, key=key,
|
|
|
|
old=old, new=new)
|
|
|
|
except error.HookAbort, exc:
|
|
|
|
self.ui.write_err(_("pushkey-abort: %s\n") % exc)
|
|
|
|
if exc.hint:
|
|
|
|
self.ui.write_err(_("(%s)\n") % exc.hint)
|
|
|
|
return False
|
2012-07-28 14:28:35 +04:00
|
|
|
self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key))
|
2011-05-01 13:12:36 +04:00
|
|
|
ret = pushkey.push(self, namespace, key, old, new)
|
2014-12-23 02:48:39 +03:00
|
|
|
def runhook():
|
|
|
|
self.hook('pushkey', namespace=namespace, key=key, old=old, new=new,
|
|
|
|
ret=ret)
|
|
|
|
self._afterlock(runhook)
|
2011-05-01 13:12:36 +04:00
|
|
|
return ret
|
2010-06-17 01:04:46 +04:00
|
|
|
|
|
|
|
def listkeys(self, namespace):
|
2011-05-01 13:12:36 +04:00
|
|
|
self.hook('prelistkeys', throw=True, namespace=namespace)
|
2012-07-28 14:28:35 +04:00
|
|
|
self.ui.debug('listing keys for "%s"\n' % namespace)
|
2011-05-01 13:12:36 +04:00
|
|
|
values = pushkey.list(self, namespace)
|
|
|
|
self.hook('listkeys', namespace=namespace, values=values)
|
|
|
|
return values
|
2010-06-17 01:04:46 +04:00
|
|
|
|
2011-04-29 16:54:01 +04:00
|
|
|
def debugwireargs(self, one, two, three=None, four=None, five=None):
|
2011-03-22 09:38:32 +03:00
|
|
|
'''used to test argument passing over the wire'''
|
2011-04-29 16:54:01 +04:00
|
|
|
return "%s %s %s %s %s" % (one, two, three, four, five)
|
2011-03-22 09:38:32 +03:00
|
|
|
|
2011-06-04 17:56:48 +04:00
|
|
|
def savecommitmessage(self, text):
|
2015-01-11 01:02:52 +03:00
|
|
|
fp = self.vfs('last-message.txt', 'wb')
|
2011-06-04 17:56:48 +04:00
|
|
|
try:
|
|
|
|
fp.write(text)
|
|
|
|
finally:
|
|
|
|
fp.close()
|
2012-12-10 02:33:16 +04:00
|
|
|
return self.pathto(fp.name[len(self.root) + 1:])
|
2011-06-04 17:56:48 +04:00
|
|
|
|
2006-02-28 21:24:54 +03:00
|
|
|
# used to avoid circular references so destructors work
|
2006-12-05 13:28:21 +03:00
|
|
|
def aftertrans(files):
|
|
|
|
renamefiles = [tuple(t) for t in files]
|
2006-02-28 21:24:54 +03:00
|
|
|
def a():
|
2013-04-14 20:22:15 +04:00
|
|
|
for vfs, src, dest in renamefiles:
|
2012-04-16 12:56:37 +04:00
|
|
|
try:
|
2013-04-14 20:22:15 +04:00
|
|
|
vfs.rename(src, dest)
|
2012-04-16 12:56:37 +04:00
|
|
|
except OSError: # journal file does not yet exist
|
|
|
|
pass
|
2006-02-28 21:24:54 +03:00
|
|
|
return a
|
|
|
|
|
2011-05-01 15:07:00 +04:00
|
|
|
def undoname(fn):
|
|
|
|
base, name = os.path.split(fn)
|
|
|
|
assert name.startswith('journal')
|
|
|
|
return os.path.join(base, name.replace('journal', 'undo', 1))
|
|
|
|
|
2006-07-31 18:11:12 +04:00
|
|
|
def instance(ui, path, create):
|
2011-07-01 19:37:09 +04:00
|
|
|
return localrepository(ui, util.urllocalpath(path), create)
|
2006-10-01 21:26:33 +04:00
|
|
|
|
2006-07-31 18:11:12 +04:00
|
|
|
def islocal(path):
|
|
|
|
return True
|