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.
|
2015-12-23 23:30:14 +03:00
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import errno
|
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import time
|
2014-04-17 09:49:20 +04:00
|
|
|
import urllib
|
2015-12-23 23:30:14 +03:00
|
|
|
import weakref
|
|
|
|
|
|
|
|
from .i18n import _
|
|
|
|
from .node import (
|
|
|
|
hex,
|
|
|
|
nullid,
|
|
|
|
short,
|
|
|
|
wdirrev,
|
|
|
|
)
|
|
|
|
from . import (
|
|
|
|
bookmarks,
|
|
|
|
branchmap,
|
|
|
|
bundle2,
|
|
|
|
changegroup,
|
|
|
|
changelog,
|
|
|
|
cmdutil,
|
|
|
|
context,
|
|
|
|
dirstate,
|
|
|
|
encoding,
|
|
|
|
error,
|
|
|
|
exchange,
|
|
|
|
extensions,
|
|
|
|
filelog,
|
|
|
|
hook,
|
|
|
|
lock as lockmod,
|
|
|
|
manifest,
|
|
|
|
match as matchmod,
|
|
|
|
merge as mergemod,
|
|
|
|
namespaces,
|
|
|
|
obsolete,
|
|
|
|
pathutil,
|
|
|
|
peer,
|
|
|
|
phases,
|
|
|
|
pushkey,
|
|
|
|
repoview,
|
|
|
|
revset,
|
|
|
|
scmutil,
|
|
|
|
store,
|
|
|
|
subrepo,
|
|
|
|
tags as tagsmod,
|
|
|
|
transaction,
|
|
|
|
util,
|
|
|
|
)
|
|
|
|
|
|
|
|
release = lockmod.release
|
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,
|
2015-04-07 18:45:52 +03:00
|
|
|
**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)
|
2015-04-09 23:25:48 +03:00
|
|
|
if bundlecaps is not None and 'HG20' 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.
|
2015-04-07 02:04:33 +03:00
|
|
|
cg = bundle2.getunbundler(self.ui, cg)
|
2014-04-15 19:27:55 +04:00
|
|
|
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:
|
2015-04-16 12:09:37 +03:00
|
|
|
try:
|
|
|
|
cg = exchange.readbundle(self.ui, cg, None)
|
|
|
|
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.getunbundler(self.ui, stream)
|
|
|
|
return ret
|
2015-06-24 08:20:08 +03:00
|
|
|
except Exception as exc:
|
2015-04-16 11:01:51 +03:00
|
|
|
# If the exception contains output salvaged from a bundle2
|
|
|
|
# reply, we need to make sure it is printed before continuing
|
|
|
|
# to fail. So we build a bundle2 with such output and consume
|
|
|
|
# it directly.
|
|
|
|
#
|
|
|
|
# This is not very elegant but allows a "simple" solution for
|
|
|
|
# issue4594
|
|
|
|
output = getattr(exc, '_bundle2salvagedoutput', ())
|
|
|
|
if output:
|
|
|
|
bundler = bundle2.bundle20(self._repo.ui)
|
|
|
|
for out in output:
|
|
|
|
bundler.addpart(out)
|
|
|
|
stream = util.chunkbuffer(bundler.getchunks())
|
|
|
|
b = bundle2.getunbundler(self.ui, stream)
|
|
|
|
bundle2.processbundle(self._repo, b)
|
2015-04-16 12:09:37 +03:00
|
|
|
raise
|
2015-06-24 08:20:08 +03:00
|
|
|
except error.PushRaced as 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):
|
2015-10-14 00:14:07 +03:00
|
|
|
return cg.apply(self._repo, 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):
|
|
|
|
|
2015-05-05 18:40:59 +03:00
|
|
|
supportedformats = set(('revlogv1', 'generaldelta', 'treemanifest',
|
|
|
|
'manifestv2'))
|
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'))
|
2015-05-05 18:40:59 +03:00
|
|
|
openerreqs = set(('revlogv1', 'generaldelta', 'treemanifest', 'manifestv2'))
|
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()
|
|
|
|
|
2011-05-18 21:30:17 +04:00
|
|
|
def __init__(self, baseui, path=None, create=False):
|
2015-04-22 22:33:08 +03:00
|
|
|
self.requirements = set()
|
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)
|
2015-12-04 00:22:36 +03:00
|
|
|
self.nofsauditor = pathutil.pathauditor(self.root, self._checknested,
|
|
|
|
realfs=False)
|
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:
|
2016-02-16 00:20:20 +03:00
|
|
|
self.requirements = newreporequirements(self)
|
2016-02-16 00:19:07 +03:00
|
|
|
|
|
|
|
if not self.wvfs.exists():
|
|
|
|
self.wvfs.makedirs()
|
|
|
|
self.vfs.makedir(notindexed=True)
|
|
|
|
|
2016-02-16 00:20:20 +03:00
|
|
|
if 'store' in self.requirements:
|
2016-02-16 00:19:07 +03:00
|
|
|
self.vfs.mkdir("store")
|
|
|
|
|
|
|
|
# create an invalid changelog
|
|
|
|
self.vfs.append(
|
|
|
|
"00changelog.i",
|
|
|
|
'\0\0\0\2' # represents revlogv2
|
|
|
|
' dummy changelog to prevent using the old repo layout'
|
|
|
|
)
|
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:
|
2015-04-22 22:33:08 +03:00
|
|
|
self.requirements = scmutil.readrequires(
|
|
|
|
self.vfs, self.supported)
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as inst:
|
2006-12-10 02:06:59 +03:00
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
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
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as inst:
|
2009-06-14 03:01:46 +04:00
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
|
2015-04-22 22:33:08 +03:00
|
|
|
self.store = store.store(
|
|
|
|
self.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
|
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
|
2015-04-22 22:06:44 +03:00
|
|
|
self._applyopenerreqs()
|
2010-09-15 12:44:10 +04:00
|
|
|
if create:
|
|
|
|
self._writerequirements()
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2015-09-03 08:05:23 +03:00
|
|
|
self._dirstatevalidatewarned = False
|
2009-07-16 18:39:41 +04:00
|
|
|
|
2012-12-24 06:21:15 +04:00
|
|
|
self._branchcaches = {}
|
2015-02-11 06:53:48 +03:00
|
|
|
self._revbranchcache = None
|
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):
|
2015-02-25 05:43:31 +03:00
|
|
|
self._writecaches()
|
|
|
|
|
|
|
|
def _writecaches(self):
|
|
|
|
if self._revbranchcache:
|
|
|
|
self._revbranchcache.write()
|
2012-07-13 23:47:06 +04:00
|
|
|
|
|
|
|
def _restrictcapabilities(self, caps):
|
2015-04-10 22:41:33 +03:00
|
|
|
if self.ui.configbool('experimental', 'bundle2-advertise', True):
|
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))
|
2015-04-09 23:25:48 +03:00
|
|
|
caps.add('bundle2=' + urllib.quote(capsblob))
|
2012-07-13 23:47:06 +04:00
|
|
|
return caps
|
|
|
|
|
2015-04-22 22:06:44 +03:00
|
|
|
def _applyopenerreqs(self):
|
|
|
|
self.svfs.options = dict((r, 1) for r in self.requirements
|
2012-07-12 02:36:00 +04:00
|
|
|
if r in self.openerreqs)
|
2015-06-26 01:50:27 +03:00
|
|
|
# experimental config: format.chunkcachesize
|
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
|
2015-06-26 01:50:27 +03:00
|
|
|
# experimental config: format.maxchainlen
|
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-06-26 01:50:27 +03:00
|
|
|
# experimental config: format.manifestcachesize
|
2015-01-24 04:06:03 +03:00
|
|
|
manifestcachesize = self.ui.configint('format', 'manifestcachesize')
|
|
|
|
if manifestcachesize is not None:
|
|
|
|
self.svfs.options['manifestcachesize'] = manifestcachesize
|
2015-08-31 00:03:32 +03:00
|
|
|
# experimental config: format.aggressivemergedeltas
|
|
|
|
aggressivemergedeltas = self.ui.configbool('format',
|
|
|
|
'aggressivemergedeltas', False)
|
|
|
|
self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas
|
2015-11-02 18:59:12 +03:00
|
|
|
self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui)
|
2010-09-15 12:44:10 +04:00
|
|
|
|
|
|
|
def _writerequirements(self):
|
2015-04-14 01:11:47 +03:00
|
|
|
scmutil.writerequires(self.vfs, self.requirements)
|
2010-09-15 12:44:10 +04:00
|
|
|
|
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)
|
|
|
|
|
2015-11-12 05:18:02 +03:00
|
|
|
@repofilecache('bookmarks', 'bookmarks.current')
|
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
|
|
|
|
2015-11-12 05:18:02 +03:00
|
|
|
@property
|
2015-04-14 23:17:33 +03:00
|
|
|
def _activebookmark(self):
|
2015-11-12 05:18:02 +03:00
|
|
|
return self._bookmarks.active
|
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
|
|
|
|
|
2015-09-29 15:57:08 +03:00
|
|
|
# _phaserevs and _phasesets depend on changelog. what we need is to
|
2015-09-29 15:57:08 +03:00
|
|
|
# call _phasecache.invalidate() if '00changelog.i' was changed, but it
|
|
|
|
# can't be easily expressed in filecache mechanism.
|
|
|
|
@storecache('phaseroots', '00changelog.i')
|
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.
|
2015-06-26 01:50:27 +03:00
|
|
|
# developer config: format.obsstore-version
|
2014-09-17 04:52:40 +04:00
|
|
|
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:
|
2015-03-21 00:39:07 +03:00
|
|
|
self.ui.warn(
|
|
|
|
_('obsolete feature not enabled but %i markers found!\n')
|
|
|
|
% 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
|
|
|
|
2015-04-13 09:51:06 +03:00
|
|
|
def dirlog(self, dir):
|
2015-04-11 09:12:33 +03:00
|
|
|
return self.manifest.dirlog(dir)
|
2015-04-13 09:51:06 +03:00
|
|
|
|
2012-10-08 21:34:04 +04:00
|
|
|
@repofilecache('dirstate')
|
2009-04-30 05:47:15 +04:00
|
|
|
def dirstate(self):
|
2015-09-03 08:05:23 +03:00
|
|
|
return dirstate.dirstate(self.vfs, self.ui, self.root,
|
|
|
|
self._dirstatevalidate)
|
|
|
|
|
|
|
|
def _dirstatevalidate(self, node):
|
|
|
|
try:
|
|
|
|
self.changelog.rev(node)
|
|
|
|
return node
|
|
|
|
except error.LookupError:
|
|
|
|
if not self._dirstatevalidatewarned:
|
|
|
|
self._dirstatevalidatewarned = True
|
|
|
|
self.ui.warn(_("warning: ignoring unknown"
|
|
|
|
" working parent %s!\n") % short(node))
|
|
|
|
return nullid
|
2006-04-29 02:50:22 +04:00
|
|
|
|
2008-06-26 23:35:46 +04:00
|
|
|
def __getitem__(self, changeid):
|
2014-08-16 08:25:45 +04:00
|
|
|
if changeid is None or changeid == wdirrev:
|
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:
|
2014-08-17 06:35:31 +04:00
|
|
|
self[changeid]
|
|
|
|
return True
|
2009-11-24 15:32:19 +03:00
|
|
|
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):
|
2015-11-21 22:07:30 +03:00
|
|
|
'''Find revisions matching a revset.
|
|
|
|
|
|
|
|
The revset is specified as a string ``expr`` that may contain
|
|
|
|
%-formatting to escape certain types. See ``revset.formatspec``.
|
|
|
|
|
|
|
|
Return a revset.abstractsmartset, which is a list-like interface
|
|
|
|
that contains integer revisions.
|
|
|
|
'''
|
2011-11-02 22:37:34 +04:00
|
|
|
expr = revset.formatspec(expr, *args)
|
|
|
|
m = revset.match(None, expr)
|
2015-02-02 16:21:07 +03:00
|
|
|
return m(self)
|
2011-11-02 22:37:34 +04:00
|
|
|
|
2011-07-21 23:06:55 +04:00
|
|
|
def set(self, expr, *args):
|
2015-11-21 22:07:30 +03:00
|
|
|
'''Find revisions matching a revset and emit changectx instances.
|
|
|
|
|
|
|
|
This is a convenience wrapper around ``revs()`` that iterates the
|
|
|
|
result and is a generator of changectx instances.
|
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
|
|
|
|
2015-03-06 01:42:25 +03:00
|
|
|
@unfilteredmethod
|
2015-09-24 10:56:30 +03:00
|
|
|
def _tag(self, names, node, message, local, user, date, extra=None,
|
2014-05-05 16:26:40 +04:00
|
|
|
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:
|
2015-03-14 00:00:06 +03:00
|
|
|
if munge:
|
|
|
|
m = munge(name)
|
|
|
|
else:
|
|
|
|
m = 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+')
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as e:
|
2011-06-16 00:15:04 +04:00
|
|
|
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'])
|
2015-05-16 21:30:07 +03:00
|
|
|
if any(self.status(match=m, unknown=True, ignored=True)):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('working copy of .hgtags is changed'),
|
2014-10-03 03:39:57 +04:00
|
|
|
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):
|
2015-11-12 04:02:05 +03:00
|
|
|
"""return the list of bookmarks pointing to the specified node"""
|
2011-02-11 21:36:15 +03:00
|
|
|
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
|
|
|
|
2015-02-11 06:53:48 +03:00
|
|
|
@unfilteredmethod
|
|
|
|
def revbranchcache(self):
|
|
|
|
if not self._revbranchcache:
|
|
|
|
self._revbranchcache = branchmap.revbranchcache(self.unfiltered())
|
|
|
|
return self._revbranchcache
|
|
|
|
|
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):
|
2015-12-03 03:12:15 +03:00
|
|
|
cl = self.changelog
|
|
|
|
nm = cl.nodemap
|
|
|
|
filtered = cl.filteredrevs
|
2012-01-12 04:25:57 +04:00
|
|
|
result = []
|
|
|
|
for n in nodes:
|
|
|
|
r = nm.get(n)
|
2015-12-03 03:12:15 +03:00
|
|
|
resp = not (r is None or r in filtered)
|
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
|
|
|
|
2015-06-18 23:33:24 +03:00
|
|
|
def publishing(self):
|
2015-06-18 23:39:52 +03:00
|
|
|
# it's safe (and desirable) to trust the publish flag unconditionally
|
|
|
|
# so that we don't finalize changes shared between users via ssh or nfs
|
|
|
|
return self.ui.configbool('phases', 'publish', True, untrusted=True)
|
2015-06-18 23:33:24 +03: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
|
2015-06-18 23:34:22 +03:00
|
|
|
if not self.publishing():
|
2014-01-30 23:52:38 +04:00
|
|
|
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
|
|
|
|
2015-12-06 10:14:49 +03:00
|
|
|
def parents(self, changeid=None):
|
|
|
|
'''get list of changectxs for parents of changeid'''
|
|
|
|
msg = 'repo.parents() is deprecated, use repo[%r].parents()' % changeid
|
|
|
|
self.ui.deprecwarn(msg, '3.7')
|
|
|
|
return self[changeid].parents()
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2016-02-21 02:25:27 +03:00
|
|
|
def wwrite(self, filename, data, flags, backgroundclose=False):
|
2015-04-24 17:52:41 +03:00
|
|
|
"""write ``data`` into ``filename`` in the working directory
|
|
|
|
|
|
|
|
This returns length of written (maybe decoded) data.
|
|
|
|
"""
|
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:
|
2016-02-21 02:25:27 +03:00
|
|
|
self.wvfs.write(filename, data, backgroundclose=backgroundclose)
|
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)
|
2015-04-24 17:52:41 +03:00
|
|
|
return len(data)
|
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"""
|
2015-03-14 00:00:06 +03:00
|
|
|
if self._transref:
|
|
|
|
tr = self._transref()
|
|
|
|
else:
|
|
|
|
tr = None
|
|
|
|
|
2009-04-15 21:54:22 +04:00
|
|
|
if tr and tr.running():
|
2014-11-13 14:12:47 +03:00
|
|
|
return tr
|
|
|
|
return None
|
|
|
|
|
|
|
|
def transaction(self, desc, report=None):
|
2015-05-27 00:14:36 +03:00
|
|
|
if (self.ui.configbool('devel', 'all-warnings')
|
2015-03-11 07:03:45 +03:00
|
|
|
or self.ui.configbool('devel', 'check-locks')):
|
|
|
|
l = self._lockref and self._lockref()
|
|
|
|
if l is None or not l.held:
|
2015-06-19 21:19:45 +03:00
|
|
|
self.ui.develwarn('transaction with no lock')
|
2014-11-13 14:12:47 +03:00
|
|
|
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
|
|
|
|
localrepo: make journal.dirstate contain in-memory changes before transaction
Before this patch, in-memory dirstate changes aren't written out at
opening transaction, even though 'journal.dirstate' is created
directly from '.hg/dirstate'.
Therefore, subsequent 'hg rollback' uses incomplete 'undo.dirstate' to
restore dirstate, if dirstate is changed and isn't written out before
opening transaction.
In cases below, the condition "dirstate is changed and isn't written
out before opening transaction" isn't satisfied and this problem
doesn't appear:
- "wlock scope" and "transaction scope" are almost equivalent
e.g. 'commit --amend', 'import' and so on
- dirstate changes are written out before opening transaction
e.g. 'rebase' (via 'dirstateguard') and 'commit -A' (by separated
wlock scopes)
On the other hand, 'backout' may satisfy the condition above.
To make 'journal.dirstate' contain in-memory changes before opening
transaction, this patch explicitly invokes 'dirstate.write()' in
'localrepository.transaction()'.
'dirstate.write()' is placed before not "writing journal files out"
but "invoking pretxnopen hooks" for visibility of dirstate changes to
external hook processes.
BTW, in the test script, 'touch -t 200001010000' and 'hg status' are
invoked to make file 'c' surely clean in dirstate, because "clean but
unsure" files indirectly cause 'dirstate.write()' at 'repo.status()'
in 'repo.commit()' (see e1d123a2ee1f for detail) and prevents from
certainly reproducing the issue.
2015-07-30 00:16:12 +03:00
|
|
|
# make journal.dirstate contain in-memory changes at this point
|
2015-10-16 19:15:34 +03:00
|
|
|
self.dirstate.write(None)
|
localrepo: make journal.dirstate contain in-memory changes before transaction
Before this patch, in-memory dirstate changes aren't written out at
opening transaction, even though 'journal.dirstate' is created
directly from '.hg/dirstate'.
Therefore, subsequent 'hg rollback' uses incomplete 'undo.dirstate' to
restore dirstate, if dirstate is changed and isn't written out before
opening transaction.
In cases below, the condition "dirstate is changed and isn't written
out before opening transaction" isn't satisfied and this problem
doesn't appear:
- "wlock scope" and "transaction scope" are almost equivalent
e.g. 'commit --amend', 'import' and so on
- dirstate changes are written out before opening transaction
e.g. 'rebase' (via 'dirstateguard') and 'commit -A' (by separated
wlock scopes)
On the other hand, 'backout' may satisfy the condition above.
To make 'journal.dirstate' contain in-memory changes before opening
transaction, this patch explicitly invokes 'dirstate.write()' in
'localrepository.transaction()'.
'dirstate.write()' is placed before not "writing journal files out"
but "invoking pretxnopen hooks" for visibility of dirstate changes to
external hook processes.
BTW, in the test script, 'touch -t 200001010000' and 'hg status' are
invoked to make file 'c' surely clean in dirstate, because "clean but
unsure" files indirectly cause 'dirstate.write()' at 'repo.status()'
in 'repo.commit()' (see e1d123a2ee1f for detail) and prevents from
certainly reproducing the issue.
2015-07-30 00:16:12 +03:00
|
|
|
|
transaction: separate calculating TXNID from creating transaction object
Before this patch, transaction ID (TXNID) is calculated from
`transaction` object itself by `id()`, but this prevents TXNID from
being passed to `pretxnopen` hooks, which should be executed before
starting transaction processing (also any preparations for it, like
writing journal files out).
As a preparation for passing TXNID to `pretxnopen` hooks, this patch
separates calculation of TXNID from creation of `transaction` object.
This patch uses "random" library for reasonable unique ID. "uuid"
library can't be used, because it was introduced since Python 2.5 and
isn't suitable for Mercurial 3.4.x stable line.
`%f` formatting for `random.random()` is used with explicit precision
number 40, because default precision for `%f` is 6. 40 should be long
enough, even if 10**9 transactions are executed in a short time (a
second or less).
On the other hand, `time.time()` is used to ensures uniqueness of
TXNID in a long time, for safety.
BTW, platform not providing `/dev/urandom` or so may cause failure of
`import random` itself with some Python versions (see Python
issue15340 for detail http://bugs.python.org/issue15340).
But this patch uses "random" without any workaround, because:
- "random" is already used directly in some code paths,
- such platforms are very rare (e.g. Tru64 and HPUX), and
http://bugs.python.org/issue15340#msg170000
- updating Python runtime can avoid this issue
2015-05-24 19:26:19 +03:00
|
|
|
idbase = "%.40f#%f" % (random.random(), time.time())
|
|
|
|
txnid = 'TXN:' + util.sha1(idbase).hexdigest()
|
2015-05-24 19:26:23 +03:00
|
|
|
self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid)
|
2014-12-11 05:19:49 +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()]
|
2015-03-14 00:00:06 +03:00
|
|
|
if report:
|
|
|
|
rp = report
|
|
|
|
else:
|
|
|
|
rp = self.ui.warn
|
2015-01-11 01:02:52 +03:00
|
|
|
vfsmap = {'plain': self.vfs} # root of .hg/
|
2015-03-10 08:50:49 +03:00
|
|
|
# we must avoid cyclic reference between repo and transaction.
|
|
|
|
reporef = weakref.ref(self)
|
|
|
|
def validate(tr):
|
|
|
|
"""will run pre-closing hooks"""
|
2015-10-16 19:15:34 +03:00
|
|
|
reporef().hook('pretxnclose', throw=True,
|
2015-05-19 22:34:27 +03:00
|
|
|
txnname=desc, **tr.hookargs)
|
2015-10-08 21:53:46 +03:00
|
|
|
def releasefn(tr, success):
|
|
|
|
repo = reporef()
|
|
|
|
if success:
|
2015-10-13 20:49:17 +03:00
|
|
|
# this should be explicitly invoked here, because
|
|
|
|
# in-memory changes aren't written out at closing
|
|
|
|
# transaction, if tr.addfilegenerator (via
|
|
|
|
# dirstate.write or so) isn't invoked while
|
|
|
|
# transaction running
|
2015-10-16 19:15:34 +03:00
|
|
|
repo.dirstate.write(None)
|
2015-10-08 21:53:46 +03:00
|
|
|
else:
|
|
|
|
# prevent in-memory changes from being written out at
|
|
|
|
# the end of outer wlock scope or so
|
|
|
|
repo.dirstate.invalidate()
|
|
|
|
|
|
|
|
# discard all changes (including ones already written
|
|
|
|
# out) in this transaction
|
|
|
|
repo.vfs.rename('journal.dirstate', 'dirstate')
|
2015-03-10 08:50:49 +03:00
|
|
|
|
localrepo: discard objects in _filecache at transaction failure (issue4876)
'repo.invalidate()' deletes 'filecache'-ed properties by
'filecache.__delete__()' below via 'delattr(unfiltered, k)'. But
cached objects are still kept in 'repo._filecache'.
def __delete__(self, obj):
try:
del obj.__dict__[self.name]
except KeyError:
raise AttributeError(self.name)
If 'repo' object is reused even after failure of command execution,
referring 'filecache'-ed property may reuse one kept in
'repo._filecache', even if reloading from a file is expected.
Executing command sequence on command server is a typical case of this
situation (e0a0f9ad3e4c also tried to fix this issue). For example:
1. start a command execution
2. 'changelog.delayupdate()' is invoked in a transaction scope
This replaces own 'opener' by '_divertopener()' for additional
accessing to '00changelog.i.a' (aka "pending file").
3. transaction is aborted, and command (1) execution is ended
After 'repo.invalidate()' at releasing store lock, changelog
object above (= 'opener' of it is still replaced) is deleted from
'repo.__dict__', but still kept in 'repo._filecache'.
4. start next command execution with same 'repo'
5. referring 'repo.changelog' may reuse changelog object kept in
'repo._filecache' according to timestamp of '00changelog.i'
'00changelog.i' is truncated at transaction failure (even though
this truncation is unintentional one, as described later), and
'st_mtime' of it is changed. But 'st_mtime' doesn't have enough
resolution to always detect this truncation, and invalid
changelog object kept in 'repo._filecache' is reused
occasionally.
Then, "No such file or directory" error occurs for
'00changelog.i.a', which is already removed at (3).
This patch discards objects in '_filecache' other than dirstate at
transaction failure.
Changes in 'invalidate()' can't be simplified by 'self._filecache =
{}', because 'invalidate()' should keep dirstate in 'self._filecache'
'repo.invalidate()' at "hg qpush" failure is removed in this patch,
because now it is redundant.
This patch doesn't make 'repo.invalidate()' always discard objects in
'_filecache', because 'repo.invalidate()' is invoked also at unlocking
store lock.
- "always discard objects in filecache at unlocking" may cause
serious performance problem for subsequent procedures at normal
execution
- but it is impossible to "discard objects in filecache at unlocking
only at failure", because 'releasefn' of lock can't know whether a
lock scope is terminated normally or not
BTW, using "with" statement described in PEP343 for lock may
resolve this ?
After this patch, truncation of '00changelog.i' still occurs at
transaction failure, even though newly added revisions exist only in
'00changelog.i.a' and size of '00changelog.i' isn't changed by this
truncation.
Updating 'st_mtime' of '00changelog.i' implied by this redundant
truncation also affects cache behavior as described above.
This will be fixed by dropping '00changelog.i' at aborting from the
list of files to be truncated in transaction.
2015-10-24 12:58:57 +03:00
|
|
|
repo.invalidate(clearfilecache=True)
|
|
|
|
|
2015-06-26 08:17:52 +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),
|
2015-03-10 08:50:49 +03:00
|
|
|
self.store.createmode,
|
2015-10-08 21:53:46 +03:00
|
|
|
validator=validate,
|
|
|
|
releasefn=releasefn)
|
2015-04-15 18:11:54 +03:00
|
|
|
|
transaction: separate calculating TXNID from creating transaction object
Before this patch, transaction ID (TXNID) is calculated from
`transaction` object itself by `id()`, but this prevents TXNID from
being passed to `pretxnopen` hooks, which should be executed before
starting transaction processing (also any preparations for it, like
writing journal files out).
As a preparation for passing TXNID to `pretxnopen` hooks, this patch
separates calculation of TXNID from creation of `transaction` object.
This patch uses "random" library for reasonable unique ID. "uuid"
library can't be used, because it was introduced since Python 2.5 and
isn't suitable for Mercurial 3.4.x stable line.
`%f` formatting for `random.random()` is used with explicit precision
number 40, because default precision for `%f` is 6. 40 should be long
enough, even if 10**9 transactions are executed in a short time (a
second or less).
On the other hand, `time.time()` is used to ensures uniqueness of
TXNID in a long time, for safety.
BTW, platform not providing `/dev/urandom` or so may cause failure of
`import random` itself with some Python versions (see Python
issue15340 for detail http://bugs.python.org/issue15340).
But this patch uses "random" without any workaround, because:
- "random" is already used directly in some code paths,
- such platforms are very rare (e.g. Tru64 and HPUX), and
http://bugs.python.org/issue15340#msg170000
- updating Python runtime can avoid this issue
2015-05-24 19:26:19 +03:00
|
|
|
tr.hookargs['txnid'] = txnid
|
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)
|
2015-03-10 08:36:56 +03:00
|
|
|
def txnclosehook(tr2):
|
|
|
|
"""To be run if transaction is successful, will schedule a hook run
|
|
|
|
"""
|
2016-01-18 01:14:15 +03:00
|
|
|
# Don't reference tr2 in hook() so we don't hold a reference.
|
|
|
|
# This reduces memory consumption when there are multiple
|
|
|
|
# transactions per lock. This can likely go away if issue5045
|
|
|
|
# fixes the function accumulation.
|
|
|
|
hookargs = tr2.hookargs
|
|
|
|
|
2015-03-10 08:36:56 +03:00
|
|
|
def hook():
|
|
|
|
reporef().hook('txnclose', throw=False, txnname=desc,
|
2016-01-18 01:14:15 +03:00
|
|
|
**hookargs)
|
2015-03-10 08:36:56 +03:00
|
|
|
reporef()._afterlock(hook)
|
|
|
|
tr.addfinalize('txnclose-hook', txnclosehook)
|
2015-04-16 12:36:49 +03:00
|
|
|
def txnaborthook(tr2):
|
|
|
|
"""To be run if transaction is aborted
|
|
|
|
"""
|
|
|
|
reporef().hook('txnabort', throw=False, txnname=desc,
|
|
|
|
**tr2.hookargs)
|
|
|
|
tr.addabort('txnabort-hook', txnaborthook)
|
2015-09-14 18:32:39 +03:00
|
|
|
# avoid eager cache invalidation. in-memory data should be identical
|
|
|
|
# to stored data if transaction has no error.
|
|
|
|
tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats)
|
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):
|
2016-01-16 00:14:50 +03:00
|
|
|
with self.lock():
|
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
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2011-10-01 05:58:54 +04:00
|
|
|
def rollback(self, dryrun=False, force=False):
|
localrepo: restore dirstate to one before rollbacking if not parent-gone
'localrepository.rollback()' explicilty restores dirstate, only if at
least one of current parents of the working directory is removed at
rollbacking (a.k.a "parent-gone").
After DirstateTransactionPlan, 'dirstate.write()' will cause marking
'.hg/dirstate' as a file to be restored at rollbacking.
https://mercurial.selenic.com/wiki/DirstateTransactionPlan
Then, 'transaction.rollback()' restores '.hg/dirstate' regardless of
parents of the working directory at that time, and this causes
unexpected dirstate changes if not "parent-gone" (e.g. "hg update" to
another branch after "hg commit" or so, then "hg rollback").
To avoid such situation, this patch restores dirstate to one before
rollbacking if not "parent-gone".
before:
b1. restore dirstate explicitly, if "parent-gone"
after:
a1. save dirstate before actual rollbacking via dirstateguard
a2. restore dirstate via 'transaction.rollback()'
a3. if "parent-gone"
- discard backup (a1)
- restore dirstate from 'undo.dirstate'
a4. otherwise, restore dirstate from backup (a1)
Even though restoring dirstate at (a3) after (a2) seems redundant,
this patch keeps this existing code path, because:
- it isn't ensured that 'dirstate.write()' was invoked at least once
while transaction running
If not, '.hg/dirstate' isn't restored at (a2).
In addition to it, rude 3rd party extension invoking
'dirstate.write()' without 'repo' while transaction running (see
subsequent patches for detail) may break consistency of a file
backup-ed by transaction.
- this patch mainly focuses on changes for DirstateTransactionPlan
Restoring dirstate at (a3) itself should be cheaper enough than
rollbacking itself. Redundancy will be removed in next step.
Newly added test is almost meaningless at this point. It will be used
to detect regression while implementing delayed dirstate write out.
2015-10-13 22:25:43 +03:00
|
|
|
wlock = lock = dsguard = 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"):
|
localrepo: restore dirstate to one before rollbacking if not parent-gone
'localrepository.rollback()' explicilty restores dirstate, only if at
least one of current parents of the working directory is removed at
rollbacking (a.k.a "parent-gone").
After DirstateTransactionPlan, 'dirstate.write()' will cause marking
'.hg/dirstate' as a file to be restored at rollbacking.
https://mercurial.selenic.com/wiki/DirstateTransactionPlan
Then, 'transaction.rollback()' restores '.hg/dirstate' regardless of
parents of the working directory at that time, and this causes
unexpected dirstate changes if not "parent-gone" (e.g. "hg update" to
another branch after "hg commit" or so, then "hg rollback").
To avoid such situation, this patch restores dirstate to one before
rollbacking if not "parent-gone".
before:
b1. restore dirstate explicitly, if "parent-gone"
after:
a1. save dirstate before actual rollbacking via dirstateguard
a2. restore dirstate via 'transaction.rollback()'
a3. if "parent-gone"
- discard backup (a1)
- restore dirstate from 'undo.dirstate'
a4. otherwise, restore dirstate from backup (a1)
Even though restoring dirstate at (a3) after (a2) seems redundant,
this patch keeps this existing code path, because:
- it isn't ensured that 'dirstate.write()' was invoked at least once
while transaction running
If not, '.hg/dirstate' isn't restored at (a2).
In addition to it, rude 3rd party extension invoking
'dirstate.write()' without 'repo' while transaction running (see
subsequent patches for detail) may break consistency of a file
backup-ed by transaction.
- this patch mainly focuses on changes for DirstateTransactionPlan
Restoring dirstate at (a3) itself should be cheaper enough than
rollbacking itself. Redundancy will be removed in next step.
Newly added test is almost meaningless at this point. It will be used
to detect regression while implementing delayed dirstate write out.
2015-10-13 22:25:43 +03:00
|
|
|
dsguard = cmdutil.dirstateguard(self, 'rollback')
|
|
|
|
|
|
|
|
return self._rollback(dryrun, force, dsguard)
|
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:
|
localrepo: restore dirstate to one before rollbacking if not parent-gone
'localrepository.rollback()' explicilty restores dirstate, only if at
least one of current parents of the working directory is removed at
rollbacking (a.k.a "parent-gone").
After DirstateTransactionPlan, 'dirstate.write()' will cause marking
'.hg/dirstate' as a file to be restored at rollbacking.
https://mercurial.selenic.com/wiki/DirstateTransactionPlan
Then, 'transaction.rollback()' restores '.hg/dirstate' regardless of
parents of the working directory at that time, and this causes
unexpected dirstate changes if not "parent-gone" (e.g. "hg update" to
another branch after "hg commit" or so, then "hg rollback").
To avoid such situation, this patch restores dirstate to one before
rollbacking if not "parent-gone".
before:
b1. restore dirstate explicitly, if "parent-gone"
after:
a1. save dirstate before actual rollbacking via dirstateguard
a2. restore dirstate via 'transaction.rollback()'
a3. if "parent-gone"
- discard backup (a1)
- restore dirstate from 'undo.dirstate'
a4. otherwise, restore dirstate from backup (a1)
Even though restoring dirstate at (a3) after (a2) seems redundant,
this patch keeps this existing code path, because:
- it isn't ensured that 'dirstate.write()' was invoked at least once
while transaction running
If not, '.hg/dirstate' isn't restored at (a2).
In addition to it, rude 3rd party extension invoking
'dirstate.write()' without 'repo' while transaction running (see
subsequent patches for detail) may break consistency of a file
backup-ed by transaction.
- this patch mainly focuses on changes for DirstateTransactionPlan
Restoring dirstate at (a3) itself should be cheaper enough than
rollbacking itself. Redundancy will be removed in next step.
Newly added test is almost meaningless at this point. It will be used
to detect regression while implementing delayed dirstate write out.
2015-10-13 22:25:43 +03:00
|
|
|
release(dsguard, 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
|
localrepo: restore dirstate to one before rollbacking if not parent-gone
'localrepository.rollback()' explicilty restores dirstate, only if at
least one of current parents of the working directory is removed at
rollbacking (a.k.a "parent-gone").
After DirstateTransactionPlan, 'dirstate.write()' will cause marking
'.hg/dirstate' as a file to be restored at rollbacking.
https://mercurial.selenic.com/wiki/DirstateTransactionPlan
Then, 'transaction.rollback()' restores '.hg/dirstate' regardless of
parents of the working directory at that time, and this causes
unexpected dirstate changes if not "parent-gone" (e.g. "hg update" to
another branch after "hg commit" or so, then "hg rollback").
To avoid such situation, this patch restores dirstate to one before
rollbacking if not "parent-gone".
before:
b1. restore dirstate explicitly, if "parent-gone"
after:
a1. save dirstate before actual rollbacking via dirstateguard
a2. restore dirstate via 'transaction.rollback()'
a3. if "parent-gone"
- discard backup (a1)
- restore dirstate from 'undo.dirstate'
a4. otherwise, restore dirstate from backup (a1)
Even though restoring dirstate at (a3) after (a2) seems redundant,
this patch keeps this existing code path, because:
- it isn't ensured that 'dirstate.write()' was invoked at least once
while transaction running
If not, '.hg/dirstate' isn't restored at (a2).
In addition to it, rude 3rd party extension invoking
'dirstate.write()' without 'repo' while transaction running (see
subsequent patches for detail) may break consistency of a file
backup-ed by transaction.
- this patch mainly focuses on changes for DirstateTransactionPlan
Restoring dirstate at (a3) itself should be cheaper enough than
rollbacking itself. Redundancy will be removed in next step.
Newly added test is almost meaningless at this point. It will be used
to detect regression while implementing delayed dirstate write out.
2015-10-13 22:25:43 +03:00
|
|
|
def _rollback(self, dryrun, force, dsguard):
|
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':
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(
|
2011-10-01 05:58:54 +04:00
|
|
|
_('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:
|
localrepo: restore dirstate to one before rollbacking if not parent-gone
'localrepository.rollback()' explicilty restores dirstate, only if at
least one of current parents of the working directory is removed at
rollbacking (a.k.a "parent-gone").
After DirstateTransactionPlan, 'dirstate.write()' will cause marking
'.hg/dirstate' as a file to be restored at rollbacking.
https://mercurial.selenic.com/wiki/DirstateTransactionPlan
Then, 'transaction.rollback()' restores '.hg/dirstate' regardless of
parents of the working directory at that time, and this causes
unexpected dirstate changes if not "parent-gone" (e.g. "hg update" to
another branch after "hg commit" or so, then "hg rollback").
To avoid such situation, this patch restores dirstate to one before
rollbacking if not "parent-gone".
before:
b1. restore dirstate explicitly, if "parent-gone"
after:
a1. save dirstate before actual rollbacking via dirstateguard
a2. restore dirstate via 'transaction.rollback()'
a3. if "parent-gone"
- discard backup (a1)
- restore dirstate from 'undo.dirstate'
a4. otherwise, restore dirstate from backup (a1)
Even though restoring dirstate at (a3) after (a2) seems redundant,
this patch keeps this existing code path, because:
- it isn't ensured that 'dirstate.write()' was invoked at least once
while transaction running
If not, '.hg/dirstate' isn't restored at (a2).
In addition to it, rude 3rd party extension invoking
'dirstate.write()' without 'repo' while transaction running (see
subsequent patches for detail) may break consistency of a file
backup-ed by transaction.
- this patch mainly focuses on changes for DirstateTransactionPlan
Restoring dirstate at (a3) itself should be cheaper enough than
rollbacking itself. Redundancy will be removed in next step.
Newly added test is almost meaningless at this point. It will be used
to detect regression while implementing delayed dirstate write out.
2015-10-13 22:25:43 +03:00
|
|
|
# prevent dirstateguard from overwriting already restored one
|
|
|
|
dsguard.close()
|
|
|
|
|
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()
|
2015-11-12 04:07:15 +03:00
|
|
|
parents = tuple([p.rev() for p in self[None].parents()])
|
2011-09-19 03:59:33 +04:00
|
|
|
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)
|
2015-11-18 04:04:32 +03:00
|
|
|
mergemod.mergestate.clean(self, self['.'].node())
|
2015-04-17 02:48:20 +03:00
|
|
|
|
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
|
|
|
|
localrepo: discard objects in _filecache at transaction failure (issue4876)
'repo.invalidate()' deletes 'filecache'-ed properties by
'filecache.__delete__()' below via 'delattr(unfiltered, k)'. But
cached objects are still kept in 'repo._filecache'.
def __delete__(self, obj):
try:
del obj.__dict__[self.name]
except KeyError:
raise AttributeError(self.name)
If 'repo' object is reused even after failure of command execution,
referring 'filecache'-ed property may reuse one kept in
'repo._filecache', even if reloading from a file is expected.
Executing command sequence on command server is a typical case of this
situation (e0a0f9ad3e4c also tried to fix this issue). For example:
1. start a command execution
2. 'changelog.delayupdate()' is invoked in a transaction scope
This replaces own 'opener' by '_divertopener()' for additional
accessing to '00changelog.i.a' (aka "pending file").
3. transaction is aborted, and command (1) execution is ended
After 'repo.invalidate()' at releasing store lock, changelog
object above (= 'opener' of it is still replaced) is deleted from
'repo.__dict__', but still kept in 'repo._filecache'.
4. start next command execution with same 'repo'
5. referring 'repo.changelog' may reuse changelog object kept in
'repo._filecache' according to timestamp of '00changelog.i'
'00changelog.i' is truncated at transaction failure (even though
this truncation is unintentional one, as described later), and
'st_mtime' of it is changed. But 'st_mtime' doesn't have enough
resolution to always detect this truncation, and invalid
changelog object kept in 'repo._filecache' is reused
occasionally.
Then, "No such file or directory" error occurs for
'00changelog.i.a', which is already removed at (3).
This patch discards objects in '_filecache' other than dirstate at
transaction failure.
Changes in 'invalidate()' can't be simplified by 'self._filecache =
{}', because 'invalidate()' should keep dirstate in 'self._filecache'
'repo.invalidate()' at "hg qpush" failure is removed in this patch,
because now it is redundant.
This patch doesn't make 'repo.invalidate()' always discard objects in
'_filecache', because 'repo.invalidate()' is invoked also at unlocking
store lock.
- "always discard objects in filecache at unlocking" may cause
serious performance problem for subsequent procedures at normal
execution
- but it is impossible to "discard objects in filecache at unlocking
only at failure", because 'releasefn' of lock can't know whether a
lock scope is terminated normally or not
BTW, using "with" statement described in PEP343 for lock may
resolve this ?
After this patch, truncation of '00changelog.i' still occurs at
transaction failure, even though newly added revisions exist only in
'00changelog.i.a' and size of '00changelog.i' isn't changed by this
truncation.
Updating 'st_mtime' of '00changelog.i' implied by this redundant
truncation also affects cache behavior as described above.
This will be fixed by dropping '00changelog.i' at aborting from the
list of files to be truncated in transaction.
2015-10-24 12:58:57 +03:00
|
|
|
def invalidate(self, clearfilecache=False):
|
2013-02-10 21:24:29 +04:00
|
|
|
unfiltered = self.unfiltered() # all file caches are stored unfiltered
|
localrepo: discard objects in _filecache at transaction failure (issue4876)
'repo.invalidate()' deletes 'filecache'-ed properties by
'filecache.__delete__()' below via 'delattr(unfiltered, k)'. But
cached objects are still kept in 'repo._filecache'.
def __delete__(self, obj):
try:
del obj.__dict__[self.name]
except KeyError:
raise AttributeError(self.name)
If 'repo' object is reused even after failure of command execution,
referring 'filecache'-ed property may reuse one kept in
'repo._filecache', even if reloading from a file is expected.
Executing command sequence on command server is a typical case of this
situation (e0a0f9ad3e4c also tried to fix this issue). For example:
1. start a command execution
2. 'changelog.delayupdate()' is invoked in a transaction scope
This replaces own 'opener' by '_divertopener()' for additional
accessing to '00changelog.i.a' (aka "pending file").
3. transaction is aborted, and command (1) execution is ended
After 'repo.invalidate()' at releasing store lock, changelog
object above (= 'opener' of it is still replaced) is deleted from
'repo.__dict__', but still kept in 'repo._filecache'.
4. start next command execution with same 'repo'
5. referring 'repo.changelog' may reuse changelog object kept in
'repo._filecache' according to timestamp of '00changelog.i'
'00changelog.i' is truncated at transaction failure (even though
this truncation is unintentional one, as described later), and
'st_mtime' of it is changed. But 'st_mtime' doesn't have enough
resolution to always detect this truncation, and invalid
changelog object kept in 'repo._filecache' is reused
occasionally.
Then, "No such file or directory" error occurs for
'00changelog.i.a', which is already removed at (3).
This patch discards objects in '_filecache' other than dirstate at
transaction failure.
Changes in 'invalidate()' can't be simplified by 'self._filecache =
{}', because 'invalidate()' should keep dirstate in 'self._filecache'
'repo.invalidate()' at "hg qpush" failure is removed in this patch,
because now it is redundant.
This patch doesn't make 'repo.invalidate()' always discard objects in
'_filecache', because 'repo.invalidate()' is invoked also at unlocking
store lock.
- "always discard objects in filecache at unlocking" may cause
serious performance problem for subsequent procedures at normal
execution
- but it is impossible to "discard objects in filecache at unlocking
only at failure", because 'releasefn' of lock can't know whether a
lock scope is terminated normally or not
BTW, using "with" statement described in PEP343 for lock may
resolve this ?
After this patch, truncation of '00changelog.i' still occurs at
transaction failure, even though newly added revisions exist only in
'00changelog.i.a' and size of '00changelog.i' isn't changed by this
truncation.
Updating 'st_mtime' of '00changelog.i' implied by this redundant
truncation also affects cache behavior as described above.
This will be fixed by dropping '00changelog.i' at aborting from the
list of files to be truncated in transaction.
2015-10-24 12:58:57 +03:00
|
|
|
for k in self._filecache.keys():
|
2011-07-25 16:08:37 +04:00
|
|
|
# dirstate is invalidated separately in invalidatedirstate()
|
|
|
|
if k == 'dirstate':
|
|
|
|
continue
|
|
|
|
|
localrepo: discard objects in _filecache at transaction failure (issue4876)
'repo.invalidate()' deletes 'filecache'-ed properties by
'filecache.__delete__()' below via 'delattr(unfiltered, k)'. But
cached objects are still kept in 'repo._filecache'.
def __delete__(self, obj):
try:
del obj.__dict__[self.name]
except KeyError:
raise AttributeError(self.name)
If 'repo' object is reused even after failure of command execution,
referring 'filecache'-ed property may reuse one kept in
'repo._filecache', even if reloading from a file is expected.
Executing command sequence on command server is a typical case of this
situation (e0a0f9ad3e4c also tried to fix this issue). For example:
1. start a command execution
2. 'changelog.delayupdate()' is invoked in a transaction scope
This replaces own 'opener' by '_divertopener()' for additional
accessing to '00changelog.i.a' (aka "pending file").
3. transaction is aborted, and command (1) execution is ended
After 'repo.invalidate()' at releasing store lock, changelog
object above (= 'opener' of it is still replaced) is deleted from
'repo.__dict__', but still kept in 'repo._filecache'.
4. start next command execution with same 'repo'
5. referring 'repo.changelog' may reuse changelog object kept in
'repo._filecache' according to timestamp of '00changelog.i'
'00changelog.i' is truncated at transaction failure (even though
this truncation is unintentional one, as described later), and
'st_mtime' of it is changed. But 'st_mtime' doesn't have enough
resolution to always detect this truncation, and invalid
changelog object kept in 'repo._filecache' is reused
occasionally.
Then, "No such file or directory" error occurs for
'00changelog.i.a', which is already removed at (3).
This patch discards objects in '_filecache' other than dirstate at
transaction failure.
Changes in 'invalidate()' can't be simplified by 'self._filecache =
{}', because 'invalidate()' should keep dirstate in 'self._filecache'
'repo.invalidate()' at "hg qpush" failure is removed in this patch,
because now it is redundant.
This patch doesn't make 'repo.invalidate()' always discard objects in
'_filecache', because 'repo.invalidate()' is invoked also at unlocking
store lock.
- "always discard objects in filecache at unlocking" may cause
serious performance problem for subsequent procedures at normal
execution
- but it is impossible to "discard objects in filecache at unlocking
only at failure", because 'releasefn' of lock can't know whether a
lock scope is terminated normally or not
BTW, using "with" statement described in PEP343 for lock may
resolve this ?
After this patch, truncation of '00changelog.i' still occurs at
transaction failure, even though newly added revisions exist only in
'00changelog.i.a' and size of '00changelog.i' isn't changed by this
truncation.
Updating 'st_mtime' of '00changelog.i' implied by this redundant
truncation also affects cache behavior as described above.
This will be fixed by dropping '00changelog.i' at aborting from the
list of files to be truncated in transaction.
2015-10-24 12:58:57 +03:00
|
|
|
if clearfilecache:
|
|
|
|
del self._filecache[k]
|
2011-07-25 16:08:37 +04:00
|
|
|
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()
|
|
|
|
|
2015-09-14 18:32:39 +03:00
|
|
|
def _refreshfilecachestats(self, tr):
|
2015-09-15 15:00:28 +03:00
|
|
|
"""Reload stats of cached files so that they are flagged as valid"""
|
|
|
|
for k, ce in self._filecache.items():
|
|
|
|
if k == 'dirstate' or k not in self.__dict__:
|
|
|
|
continue
|
|
|
|
ce.refresh()
|
|
|
|
|
2015-09-25 22:28:12 +03:00
|
|
|
def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc,
|
2015-10-06 23:19:05 +03:00
|
|
|
inheritchecker=None, parentenvvar=None):
|
2015-09-25 22:28:12 +03:00
|
|
|
parentlock = None
|
2015-10-05 05:28:43 +03:00
|
|
|
# the contents of parentenvvar are used by the underlying lock to
|
|
|
|
# determine whether it can be inherited
|
2015-09-25 22:28:12 +03:00
|
|
|
if parentenvvar is not None:
|
|
|
|
parentlock = os.environ.get(parentenvvar)
|
2005-08-28 01:21:25 +04:00
|
|
|
try:
|
2015-09-23 00:09:42 +03:00
|
|
|
l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn,
|
2015-09-25 22:28:12 +03:00
|
|
|
acquirefn=acquirefn, desc=desc,
|
2015-10-06 23:19:05 +03:00
|
|
|
inheritchecker=inheritchecker,
|
2015-09-25 22:28:12 +03:00
|
|
|
parentlock=parentlock)
|
2015-06-24 08:20:08 +03:00
|
|
|
except error.LockHeld as 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")),
|
2015-09-23 00:09:42 +03:00
|
|
|
releasefn=releasefn, acquirefn=acquirefn,
|
|
|
|
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
|
|
|
return l
|
|
|
|
|
2011-12-01 01:36:55 +04:00
|
|
|
def _afterlock(self, callback):
|
2015-04-20 16:27:55 +03:00
|
|
|
"""add a callback to be run when the repository is fully unlocked
|
|
|
|
|
|
|
|
The callback will be executed when the outermost lock is released
|
|
|
|
(with wlock being higher level than 'lock')."""
|
|
|
|
for ref in (self._wlockref, self._lockref):
|
|
|
|
l = ref and ref()
|
|
|
|
if l and l.held:
|
|
|
|
l.postrelease.append(callback)
|
|
|
|
break
|
|
|
|
else: # no lock have been found.
|
2012-05-12 22:06:02 +04:00
|
|
|
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
|
2015-04-15 08:20:48 +03:00
|
|
|
stripping). If you are opening a transaction, get a lock as well.)
|
|
|
|
|
|
|
|
If both 'lock' and 'wlock' must be acquired, ensure you always acquires
|
|
|
|
'wlock' first to avoid a dead-lock hazard.'''
|
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
|
|
|
|
2015-09-14 18:32:39 +03:00
|
|
|
l = self._lock(self.svfs, "lock", wait, None,
|
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
|
|
|
|
2015-10-06 23:19:05 +03:00
|
|
|
def _wlockchecktransaction(self):
|
|
|
|
if self.currenttransaction() is not None:
|
|
|
|
raise error.LockInheritanceContractViolation(
|
|
|
|
'wlock cannot be inherited in the middle of a transaction')
|
|
|
|
|
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.
|
2015-04-15 08:20:48 +03:00
|
|
|
|
|
|
|
Use this before modifying files in .hg.
|
|
|
|
|
|
|
|
If both 'lock' and 'wlock' must be acquired, ensure you always acquires
|
|
|
|
'wlock' first to avoid a dead-lock hazard.'''
|
2015-04-12 17:01:48 +03:00
|
|
|
l = self._wlockref and self._wlockref()
|
|
|
|
if l is not None and l.held:
|
|
|
|
l.lock()
|
|
|
|
return l
|
|
|
|
|
2015-10-17 01:58:46 +03:00
|
|
|
# We do not need to check for non-waiting lock acquisition. Such
|
2015-04-12 22:37:59 +03:00
|
|
|
# acquisition would not cause dead-lock as they would just fail.
|
2015-05-27 00:14:36 +03:00
|
|
|
if wait and (self.ui.configbool('devel', 'all-warnings')
|
2015-04-12 22:37:59 +03:00
|
|
|
or self.ui.configbool('devel', 'check-locks')):
|
2015-01-16 13:51:10 +03:00
|
|
|
l = self._lockref and self._lockref()
|
|
|
|
if l is not None and l.held:
|
2015-06-19 21:19:45 +03:00
|
|
|
self.ui.develwarn('"wlock" acquired after "lock"')
|
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:
|
2015-10-16 19:15:34 +03:00
|
|
|
self.dirstate.write(None)
|
2014-09-05 22:34:29 +04:00
|
|
|
|
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') %
|
2015-10-06 23:19:05 +03:00
|
|
|
self.origroot,
|
|
|
|
inheritchecker=self._wlockchecktransaction,
|
|
|
|
parentenvvar='HG_WLOCK_LOCKER')
|
2007-07-22 01:02:10 +04:00
|
|
|
self._wlockref = weakref.ref(l)
|
|
|
|
return l
|
2005-11-12 02:34:13 +03:00
|
|
|
|
2015-10-06 00:26:53 +03:00
|
|
|
def _currentlock(self, lockref):
|
|
|
|
"""Returns the lock if it's held, or None if it's not."""
|
|
|
|
if lockref is None:
|
|
|
|
return None
|
|
|
|
l = lockref()
|
|
|
|
if l is None or not l.held:
|
|
|
|
return None
|
|
|
|
return l
|
|
|
|
|
2015-10-06 00:27:37 +03:00
|
|
|
def currentwlock(self):
|
|
|
|
"""Returns the wlock if it's held, or None if it's not."""
|
|
|
|
return self._currentlock(self._wlockref)
|
|
|
|
|
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()
|
|
|
|
fparent1 = manifest1.get(fname, nullid)
|
2014-09-21 19:07:06 +04:00
|
|
|
fparent2 = manifest2.get(fname, nullid)
|
2015-03-19 19:36:17 +03:00
|
|
|
if isinstance(fctx, context.filectx):
|
|
|
|
node = fctx.filenode()
|
|
|
|
if node in [fparent1, fparent2]:
|
|
|
|
self.ui.debug('reusing %s filelog entry\n' % fname)
|
|
|
|
return node
|
2006-02-18 02:23:53 +03:00
|
|
|
|
2015-03-19 19:36:17 +03:00
|
|
|
flog = self.file(fname)
|
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
|
2015-01-18 04:38:57 +03:00
|
|
|
# the parent directory. However, this doesn't actually make sense to
|
2015-01-21 02:05:44 +03:00
|
|
|
# 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?
|
2015-03-19 19:36:17 +03:00
|
|
|
text = fctx.data()
|
2009-05-14 22:20:40 +04:00
|
|
|
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,
|
2015-09-24 10:56:18 +03:00
|
|
|
editor=False, extra=None):
|
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
|
|
|
"""
|
2015-09-24 10:56:18 +03:00
|
|
|
if extra is None:
|
|
|
|
extra = {}
|
2009-06-02 06:51:00 +04:00
|
|
|
|
2009-06-05 01:21:03 +04:00
|
|
|
def fail(f, msg):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort('%s: %s' % (f, msg))
|
2009-06-05 01:21:03 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-11-18 12:36:58 +03:00
|
|
|
wlock = lock = tr = None
|
2009-05-14 22:20:40 +04:00
|
|
|
try:
|
2015-11-18 12:36:58 +03:00
|
|
|
wlock = self.wlock()
|
2015-12-09 02:28:53 +03:00
|
|
|
lock = self.lock() # for recent changelog (see issue4368)
|
|
|
|
|
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
|
|
|
|
2015-05-16 01:43:26 +03:00
|
|
|
if not force and merge and match.ispartial():
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot partially commit a merge '
|
2009-05-14 22:20:40 +04:00
|
|
|
'(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:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(
|
2012-02-07 01:10:01 +04:00
|
|
|
_("commit with new subrepo %s excluded") % s)
|
2015-03-25 07:55:32 +03:00
|
|
|
dirtyreason = wctx.sub(s).dirtyreason(True)
|
|
|
|
if dirtyreason:
|
2012-02-07 01:10:01 +04:00
|
|
|
if not self.ui.configbool('ui', 'commitsubrepos'):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(dirtyreason,
|
2012-02-07 01:10:01 +04:00
|
|
|
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())):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(
|
2011-06-07 00:17:40 +04:00
|
|
|
_("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
|
2015-05-19 21:36:05 +03:00
|
|
|
if not force and (match.isexact() or match.prefix()):
|
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
|
|
|
|
2015-06-26 01:51:02 +03:00
|
|
|
# internal config: ui.allowemptycommit
|
2015-05-12 21:44:14 +03:00
|
|
|
allowemptycommit = (wctx.branch() != wctx.p1().branch()
|
2015-05-12 02:18:28 +03:00
|
|
|
or extra.get('close') or merge or cctx.files()
|
|
|
|
or self.ui.configbool('ui', 'allowemptycommit'))
|
2015-05-12 02:16:22 +03:00
|
|
|
if not allowemptycommit:
|
2009-05-14 22:20:40 +04:00
|
|
|
return None
|
|
|
|
|
2013-02-08 17:36:08 +04:00
|
|
|
if merge and cctx.deleted():
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("cannot commit merge with missing files"))
|
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
|
|
|
|
2015-11-18 00:58:50 +03:00
|
|
|
ms = mergemod.mergestate.read(self)
|
2015-12-01 03:31:28 +03:00
|
|
|
|
|
|
|
if list(ms.unresolved()):
|
2015-10-15 02:04:43 +03:00
|
|
|
raise error.Abort(_('unresolved merge conflicts '
|
|
|
|
'(see "hg help resolve")'))
|
2015-12-01 03:31:28 +03:00
|
|
|
if ms.mdstate() != 's' or list(ms.driverresolved()):
|
2015-10-15 02:04:43 +03:00
|
|
|
raise error.Abort(_('driver-resolved merge conflicts'),
|
|
|
|
hint=_('run "hg resolve --all" to 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)
|
2015-11-18 12:36:58 +03:00
|
|
|
tr = self.transaction('commit')
|
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
|
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()
|
2015-11-18 12:36:58 +03:00
|
|
|
tr.close()
|
|
|
|
|
2008-06-19 00:52:26 +04:00
|
|
|
finally:
|
2015-11-18 12:36:58 +03:00
|
|
|
lockmod.release(tr, lock, wlock)
|
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
|
localrepo: use changelog.hasnode instead of self.__contains__
Before this patch, releasing the store lock implies the actions below, when
the transaction is aborted:
1. "commithook()" scheduled in "localrepository.commit()" is invoked
2. "changectx.__init__()" is invoked via "self.__contains__()"
3. specified ID is examined against "repo.dirstate.p1()"
4. validation function is invoked in "dirstate.p1()"
In subsequent patches, "dirstate.invalidate()" invocations for
discarding changes are replaced with "dirstateguard", but discarding
changes by "dirstateguard" is executed after releasing the store lock:
resources are acquired in "wlock => dirstateguard => store lock" order,
and are released in reverse order.
This may cause that "dirstate.p1()" still refers to the changeset to be
rolled-back at (4) above: pushing multiple patches by "hg qpush" is
a typical case.
When releasing the store lock, such changesets are:
- not contained in "repo.changelog", if it is reloaded from
".hg/00changelog.i", as that file was already truncated by
"transaction.abort()"
- still contained in it, otherwise
(this "dirty read" problem is discussed in "Transaction Plan"
http://mercurial.selenic.com/wiki/TransactionPlan)
Validation function shows "unknown working parent" warning in the
former case, but reloading "repo.changelog" depends on the timestamp
of ".hg/00changelog.i". This causes occasional test failures.
In the case of scheduled "commithook()", it just wants to examine
whether "node ID" of committed changeset is still valid or not. Other
examinations implied in "changectx.__init__()" are meaningless.
To avoid showing the "unknown working parent" warning irregularly, this
patch uses "changelog.hasnode()" instead of "node in self" to examine
existence of committed changeset.
2015-05-07 06:07:10 +03:00
|
|
|
if self.changelog.hasnode(ret):
|
2014-11-02 02:17:50 +03:00
|
|
|
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())
|
2015-06-24 08:20:08 +03:00
|
|
|
except OSError as inst:
|
2007-07-22 01:02:10 +04:00
|
|
|
self.ui.warn(_("trouble committing %s!\n") % f)
|
|
|
|
raise
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as inst:
|
2011-05-02 21:20:29 +04:00
|
|
|
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())
|
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,
|
2015-10-16 19:15:34 +03:00
|
|
|
parent2=xp2)
|
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()
|
|
|
|
|
2010-06-17 01:04:46 +04:00
|
|
|
def pushkey(self, namespace, key, old, new):
|
2014-11-30 06:17:47 +03:00
|
|
|
try:
|
2015-04-20 18:15:50 +03:00
|
|
|
tr = self.currenttransaction()
|
|
|
|
hookargs = {}
|
|
|
|
if tr is not None:
|
|
|
|
hookargs.update(tr.hookargs)
|
|
|
|
hookargs['namespace'] = namespace
|
|
|
|
hookargs['key'] = key
|
|
|
|
hookargs['old'] = old
|
|
|
|
hookargs['new'] = new
|
|
|
|
self.hook('prepushkey', throw=True, **hookargs)
|
2015-06-24 08:20:08 +03:00
|
|
|
except error.HookAbort as exc:
|
2014-11-30 06:17:47 +03:00
|
|
|
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
|
2016-02-16 00:20:20 +03:00
|
|
|
|
|
|
|
def newreporequirements(repo):
|
|
|
|
"""Determine the set of requirements for a new local repository.
|
|
|
|
|
|
|
|
Extensions can wrap this function to specify custom requirements for
|
|
|
|
new repositories.
|
|
|
|
"""
|
|
|
|
ui = repo.ui
|
|
|
|
requirements = set(['revlogv1'])
|
|
|
|
if ui.configbool('format', 'usestore', True):
|
|
|
|
requirements.add('store')
|
|
|
|
if ui.configbool('format', 'usefncache', True):
|
|
|
|
requirements.add('fncache')
|
|
|
|
if ui.configbool('format', 'dotencode', True):
|
|
|
|
requirements.add('dotencode')
|
|
|
|
|
|
|
|
if scmutil.gdinitconfig(ui):
|
|
|
|
requirements.add('generaldelta')
|
|
|
|
if ui.configbool('experimental', 'treemanifest', False):
|
|
|
|
requirements.add('treemanifest')
|
|
|
|
if ui.configbool('experimental', 'manifestv2', False):
|
|
|
|
requirements.add('manifestv2')
|
|
|
|
|
|
|
|
return requirements
|