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
|
2016-06-10 07:12:33 +03:00
|
|
|
import hashlib
|
2015-12-23 23:30:14 +03:00
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import time
|
|
|
|
import weakref
|
|
|
|
|
|
|
|
from .i18n import _
|
|
|
|
from .node import (
|
|
|
|
hex,
|
|
|
|
nullid,
|
|
|
|
short,
|
|
|
|
wdirrev,
|
|
|
|
)
|
|
|
|
from . import (
|
|
|
|
bookmarks,
|
|
|
|
branchmap,
|
|
|
|
bundle2,
|
|
|
|
changegroup,
|
|
|
|
changelog,
|
2017-02-25 20:34:01 +03:00
|
|
|
color,
|
2015-12-23 23:30:14 +03:00
|
|
|
context,
|
|
|
|
dirstate,
|
2016-11-22 05:06:34 +03:00
|
|
|
dirstateguard,
|
2015-12-23 23:30:14 +03:00
|
|
|
encoding,
|
|
|
|
error,
|
|
|
|
exchange,
|
|
|
|
extensions,
|
|
|
|
filelog,
|
|
|
|
hook,
|
|
|
|
lock as lockmod,
|
|
|
|
manifest,
|
|
|
|
match as matchmod,
|
|
|
|
merge as mergemod,
|
2016-11-22 05:32:55 +03:00
|
|
|
mergeutil,
|
2015-12-23 23:30:14 +03:00
|
|
|
namespaces,
|
|
|
|
obsolete,
|
|
|
|
pathutil,
|
|
|
|
peer,
|
|
|
|
phases,
|
|
|
|
pushkey,
|
2017-03-19 08:08:59 +03:00
|
|
|
pycompat,
|
2015-12-23 23:30:14 +03:00
|
|
|
repoview,
|
|
|
|
revset,
|
2017-02-19 12:19:33 +03:00
|
|
|
revsetlang,
|
2015-12-23 23:30:14 +03:00
|
|
|
scmutil,
|
|
|
|
store,
|
|
|
|
subrepo,
|
|
|
|
tags as tagsmod,
|
|
|
|
transaction,
|
2017-02-20 19:21:00 +03:00
|
|
|
txnutil,
|
2015-12-23 23:30:14 +03:00
|
|
|
util,
|
2017-03-02 15:28:17 +03:00
|
|
|
vfs as vfsmod,
|
2015-12-23 23:30:14 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
release = lockmod.release
|
2016-04-07 02:22:12 +03:00
|
|
|
urlerr = util.urlerr
|
|
|
|
urlreq = util.urlreq
|
2009-04-22 04:01:22 +04:00
|
|
|
|
2016-05-06 18:31:29 +03:00
|
|
|
class repofilecache(scmutil.filecache):
|
2012-10-08 21:34:04 +04:00
|
|
|
"""All filecache usage on repo are done for logic that should be unfiltered
|
|
|
|
"""
|
|
|
|
|
2016-08-05 15:23:58 +03:00
|
|
|
def join(self, obj, fname):
|
2016-08-05 15:25:21 +03:00
|
|
|
return obj.vfs.join(fname)
|
2012-10-08 21:34:04 +04:00
|
|
|
def __get__(self, repo, type=None):
|
2016-06-17 22:06:09 +03:00
|
|
|
if repo is None:
|
|
|
|
return self
|
2012-10-08 21:34:04 +04:00
|
|
|
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)
|
|
|
|
|
2016-05-06 18:31:29 +03:00
|
|
|
class unfilteredpropertycache(util.propertycache):
|
2012-10-08 22:02:20 +04:00
|
|
|
"""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
|
|
|
|
2016-05-06 18:31:29 +03:00
|
|
|
class filteredpropertycache(util.propertycache):
|
2012-10-08 22:02:20 +04:00
|
|
|
"""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'''
|
|
|
|
|
2017-03-15 09:50:07 +03:00
|
|
|
def __init__(self, repo, caps=None):
|
|
|
|
if caps is None:
|
|
|
|
caps = moderncaps.copy()
|
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):
|
exchange: refactor APIs to obtain bundle data (API)
Currently, exchange.getbundle() returns either a cg1unpacker or a
util.chunkbuffer (in the case of bundle2). This is kinda OK, as
both expose a .read() to consumers. However, localpeer.getbundle()
has code inferring what the response type is based on arguments and
converts the util.chunkbuffer returned in the bundle2 case to a
bundle2.unbundle20 instance. This is a sign that the API for
exchange.getbundle() is not ideal because it doesn't consistently
return an "unbundler" instance.
In addition, unbundlers mask the fact that there is an underlying
generator of changegroup data. In both cg1 and bundle2, this generator
is being fed into a util.chunkbuffer so it can be re-exposed as a
file object.
util.chunkbuffer is a nice abstraction. However, it should only be
used "at the edges." This is because keeping data as a generator is
more efficient than converting it to a chunkbuffer, especially if we
convert that chunkbuffer back to a generator (as is the case in some
code paths currently).
This patch refactors exchange.getbundle() into
exchange.getbundlechunks(). The new API returns an iterator of chunks
instead of a file-like object.
Callers of exchange.getbundle() have been updated to use the new API.
There is a minor change of behavior in test-getbundle.t. This is
because `hg debuggetbundle` isn't defining bundlecaps. As a result,
a cg1 data stream and unpacker is being produced. This is getting fed
into a new bundle20 instance via bundle2.writebundle(), which uses
a backchannel mechanism between changegroup generation to add the
"nbchanges" part parameter. I never liked this backchannel mechanism
and I plan to remove it someday. `hg bundle` still produces the
"nbchanges" part parameter, so there should be no user-visible
change of behavior. I consider this "regression" a bug in
`hg debuggetbundle`. And that bug is captured by an existing
"TODO" in the code to use bundle2 capabilities.
2016-10-16 20:38:52 +03:00
|
|
|
chunks = exchange.getbundlechunks(self._repo, source, heads=heads,
|
|
|
|
common=common, bundlecaps=bundlecaps,
|
|
|
|
**kwargs)
|
|
|
|
cb = util.chunkbuffer(chunks)
|
|
|
|
|
2017-05-03 20:33:26 +03:00
|
|
|
if exchange.bundle2requested(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.
|
exchange: refactor APIs to obtain bundle data (API)
Currently, exchange.getbundle() returns either a cg1unpacker or a
util.chunkbuffer (in the case of bundle2). This is kinda OK, as
both expose a .read() to consumers. However, localpeer.getbundle()
has code inferring what the response type is based on arguments and
converts the util.chunkbuffer returned in the bundle2 case to a
bundle2.unbundle20 instance. This is a sign that the API for
exchange.getbundle() is not ideal because it doesn't consistently
return an "unbundler" instance.
In addition, unbundlers mask the fact that there is an underlying
generator of changegroup data. In both cg1 and bundle2, this generator
is being fed into a util.chunkbuffer so it can be re-exposed as a
file object.
util.chunkbuffer is a nice abstraction. However, it should only be
used "at the edges." This is because keeping data as a generator is
more efficient than converting it to a chunkbuffer, especially if we
convert that chunkbuffer back to a generator (as is the case in some
code paths currently).
This patch refactors exchange.getbundle() into
exchange.getbundlechunks(). The new API returns an iterator of chunks
instead of a file-like object.
Callers of exchange.getbundle() have been updated to use the new API.
There is a minor change of behavior in test-getbundle.t. This is
because `hg debuggetbundle` isn't defining bundlecaps. As a result,
a cg1 data stream and unpacker is being produced. This is getting fed
into a new bundle20 instance via bundle2.writebundle(), which uses
a backchannel mechanism between changegroup generation to add the
"nbchanges" part parameter. I never liked this backchannel mechanism
and I plan to remove it someday. `hg bundle` still produces the
"nbchanges" part parameter, so there should be no user-visible
change of behavior. I consider this "regression" a bug in
`hg debuggetbundle`. And that bug is captured by an existing
"TODO" in the code to use bundle2 capabilities.
2016-10-16 20:38:52 +03:00
|
|
|
return bundle2.getunbundler(self.ui, cb)
|
|
|
|
else:
|
|
|
|
return changegroup.getunbundler('01', cb, None)
|
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',
|
2017-02-13 16:05:24 +03:00
|
|
|
'relshared', '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()
|
|
|
|
|
2016-12-04 20:52:34 +03:00
|
|
|
def __init__(self, baseui, path, create=False):
|
2015-04-22 22:33:08 +03:00
|
|
|
self.requirements = set()
|
2017-03-21 16:50:42 +03:00
|
|
|
# wvfs: rooted at the repository root, used to access the working copy
|
2017-03-02 15:28:17 +03:00
|
|
|
self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
|
2017-03-21 16:50:42 +03:00
|
|
|
# vfs: rooted at .hg, used to access repo files outside of .hg/store
|
2016-08-05 14:49:05 +03:00
|
|
|
self.vfs = None
|
2017-03-21 16:50:42 +03:00
|
|
|
# svfs: usually rooted at .hg/store, used to access repository history
|
|
|
|
# If this is a shared repository, this vfs may point to another
|
|
|
|
# repository's .hg/store directory.
|
2016-08-05 14:49:05 +03:00
|
|
|
self.svfs = None
|
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)
|
2017-03-02 15:28:17 +03:00
|
|
|
self.vfs = vfsmod.vfs(self.path)
|
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:
|
2016-08-05 15:29:22 +03:00
|
|
|
self.ui.readconfig(self.vfs.join("hgrc"), self.root)
|
2017-02-16 06:41:14 +03:00
|
|
|
self._loadextensions()
|
2009-06-13 23:44:59 +04:00
|
|
|
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
|
2017-02-25 20:34:01 +03:00
|
|
|
color.setup(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
|
|
|
|
localrepo: experimental support for non-zlib revlog compression
The final part of integrating the compression manager APIs into
revlog storage is the plumbing for repositories to advertise they
are using non-zlib storage and for revlogs to instantiate a non-zlib
compression engine.
The main intent of the compression manager work was to zstd all
of the things. Adding zstd to revlogs has proved to be more involved
than other places because revlogs are... special. Very small inputs
and the use of delta chains (which are themselves a form of
compression) are a completely different use case from streaming
compression, which bundles and the wire protocol employ. I've
conducted numerous experiments with zstd in revlogs and have yet
to formalize compression settings and a storage architecture that
I'm confident I won't regret later. In other words, I'm not yet
ready to commit to a new mechanism for using zstd - or any other
compression format - in revlogs.
That being said, having some support for zstd (and other compression
formats) in revlogs in core is beneficial. It can allow others to
conduct experiments.
This patch introduces *highly experimental* support for non-zlib
compression formats in revlogs. Introduced is a config option to
control which compression engine to use. Also introduced is a namespace
of "exp-compression-*" requirements to denote support for non-zlib
compression in revlogs. I've prefixed the namespace with "exp-"
(short for "experimental") because I'm not confident of the
requirements "schema" and in no way want to give the illusion of
supporting these requirements in the future. I fully intend to drop
support for these requirements once we figure out what we're doing
with zstd in revlogs.
A good portion of the patch is teaching the requirements system
about registered compression engines and passing the requested
compression engine as an opener option so revlogs can instantiate
the proper compression engine for new operations.
That's a verbose way of saying "we can now use zstd in revlogs!"
On an `hg pull` conversion of the mozilla-unified repo with no extra
redelta settings (like aggressivemergedeltas), we can see the impact
of zstd vs zlib in revlogs:
$ hg perfrevlogchunks -c
! chunk
! wall 2.032052 comb 2.040000 user 1.990000 sys 0.050000 (best of 5)
! wall 1.866360 comb 1.860000 user 1.820000 sys 0.040000 (best of 6)
! chunk batch
! wall 1.877261 comb 1.870000 user 1.860000 sys 0.010000 (best of 6)
! wall 1.705410 comb 1.710000 user 1.690000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.721427 comb 2.720000 user 2.640000 sys 0.080000 (best of 4)
! wall 2.035076 comb 2.030000 user 1.950000 sys 0.080000 (best of 5)
! chunk batch
! wall 2.614561 comb 2.620000 user 2.580000 sys 0.040000 (best of 4)
! wall 1.910252 comb 1.910000 user 1.880000 sys 0.030000 (best of 6)
$ hg perfrevlog -c -d 1
! wall 4.812885 comb 4.820000 user 4.800000 sys 0.020000 (best of 3)
! wall 4.699621 comb 4.710000 user 4.700000 sys 0.010000 (best of 3)
$ hg perfrevlog -m -d 1000
! wall 34.252800 comb 34.250000 user 33.730000 sys 0.520000 (best of 3)
! wall 24.094999 comb 24.090000 user 23.320000 sys 0.770000 (best of 3)
Only modest wins for the changelog. But manifest reading is
significantly faster. What's going on?
One reason might be data volume. zstd decompresses faster. So given
more bytes, it will put more distance between it and zlib.
Another reason is size. In the current design, zstd revlogs are
*larger*:
debugcreatestreamclonebundle (size in bytes)
zlib: 1,638,852,492
zstd: 1,680,601,332
I haven't investigated this fully, but I reckon a significant cause of
larger revlogs is that the zstd frame/header has more bytes than
zlib's. For very small inputs or data that doesn't compress well, we'll
tend to store more uncompressed chunks than with zlib (because the
compressed size isn't smaller than original). This will make revlog
reading faster because it is doing less decompression.
Moving on to bundle performance:
$ hg bundle -a -t none-v2 (total CPU time)
zlib: 102.79s
zstd: 97.75s
So, marginal CPU decrease for reading all chunks in all revlogs
(this is somewhat disappointing).
$ hg bundle -a -t <engine>-v2 (total CPU time)
zlib: 191.59s
zstd: 115.36s
This last test effectively measures the difference between zlib->zlib
and zstd->zstd for revlogs to bundle. This is a rough approximation of
what a server does during `hg clone`.
There are some promising results for zstd. But not enough for me to
feel comfortable advertising it to users. We'll get there...
2017-01-14 07:16:56 +03:00
|
|
|
# Add compression engines.
|
|
|
|
for name in util.compengines:
|
|
|
|
engine = util.compengines[name]
|
|
|
|
if engine.revlogheader():
|
|
|
|
self.supported.add('exp-compression-%s' % name)
|
|
|
|
|
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:
|
2017-02-13 16:05:24 +03:00
|
|
|
sharedpath = self.vfs.read("sharedpath").rstrip('\n')
|
|
|
|
if 'relshared' in self.requirements:
|
|
|
|
sharedpath = self.vfs.join(sharedpath)
|
2017-03-02 15:28:17 +03:00
|
|
|
vfs = vfsmod.vfs(sharedpath, realpath=True)
|
2013-04-14 20:22:15 +04:00
|
|
|
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(
|
2017-03-02 15:28:17 +03:00
|
|
|
self.requirements, self.sharedpath, vfsmod.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()
|
|
|
|
|
2017-02-16 06:41:14 +03:00
|
|
|
def _loadextensions(self):
|
|
|
|
extensions.loadall(self.ui)
|
|
|
|
|
2015-02-25 05:43:31 +03:00
|
|
|
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))
|
2016-04-07 02:22:12 +03:00
|
|
|
caps.add('bundle2=' + urlreq.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
|
|
|
|
localrepo: experimental support for non-zlib revlog compression
The final part of integrating the compression manager APIs into
revlog storage is the plumbing for repositories to advertise they
are using non-zlib storage and for revlogs to instantiate a non-zlib
compression engine.
The main intent of the compression manager work was to zstd all
of the things. Adding zstd to revlogs has proved to be more involved
than other places because revlogs are... special. Very small inputs
and the use of delta chains (which are themselves a form of
compression) are a completely different use case from streaming
compression, which bundles and the wire protocol employ. I've
conducted numerous experiments with zstd in revlogs and have yet
to formalize compression settings and a storage architecture that
I'm confident I won't regret later. In other words, I'm not yet
ready to commit to a new mechanism for using zstd - or any other
compression format - in revlogs.
That being said, having some support for zstd (and other compression
formats) in revlogs in core is beneficial. It can allow others to
conduct experiments.
This patch introduces *highly experimental* support for non-zlib
compression formats in revlogs. Introduced is a config option to
control which compression engine to use. Also introduced is a namespace
of "exp-compression-*" requirements to denote support for non-zlib
compression in revlogs. I've prefixed the namespace with "exp-"
(short for "experimental") because I'm not confident of the
requirements "schema" and in no way want to give the illusion of
supporting these requirements in the future. I fully intend to drop
support for these requirements once we figure out what we're doing
with zstd in revlogs.
A good portion of the patch is teaching the requirements system
about registered compression engines and passing the requested
compression engine as an opener option so revlogs can instantiate
the proper compression engine for new operations.
That's a verbose way of saying "we can now use zstd in revlogs!"
On an `hg pull` conversion of the mozilla-unified repo with no extra
redelta settings (like aggressivemergedeltas), we can see the impact
of zstd vs zlib in revlogs:
$ hg perfrevlogchunks -c
! chunk
! wall 2.032052 comb 2.040000 user 1.990000 sys 0.050000 (best of 5)
! wall 1.866360 comb 1.860000 user 1.820000 sys 0.040000 (best of 6)
! chunk batch
! wall 1.877261 comb 1.870000 user 1.860000 sys 0.010000 (best of 6)
! wall 1.705410 comb 1.710000 user 1.690000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.721427 comb 2.720000 user 2.640000 sys 0.080000 (best of 4)
! wall 2.035076 comb 2.030000 user 1.950000 sys 0.080000 (best of 5)
! chunk batch
! wall 2.614561 comb 2.620000 user 2.580000 sys 0.040000 (best of 4)
! wall 1.910252 comb 1.910000 user 1.880000 sys 0.030000 (best of 6)
$ hg perfrevlog -c -d 1
! wall 4.812885 comb 4.820000 user 4.800000 sys 0.020000 (best of 3)
! wall 4.699621 comb 4.710000 user 4.700000 sys 0.010000 (best of 3)
$ hg perfrevlog -m -d 1000
! wall 34.252800 comb 34.250000 user 33.730000 sys 0.520000 (best of 3)
! wall 24.094999 comb 24.090000 user 23.320000 sys 0.770000 (best of 3)
Only modest wins for the changelog. But manifest reading is
significantly faster. What's going on?
One reason might be data volume. zstd decompresses faster. So given
more bytes, it will put more distance between it and zlib.
Another reason is size. In the current design, zstd revlogs are
*larger*:
debugcreatestreamclonebundle (size in bytes)
zlib: 1,638,852,492
zstd: 1,680,601,332
I haven't investigated this fully, but I reckon a significant cause of
larger revlogs is that the zstd frame/header has more bytes than
zlib's. For very small inputs or data that doesn't compress well, we'll
tend to store more uncompressed chunks than with zlib (because the
compressed size isn't smaller than original). This will make revlog
reading faster because it is doing less decompression.
Moving on to bundle performance:
$ hg bundle -a -t none-v2 (total CPU time)
zlib: 102.79s
zstd: 97.75s
So, marginal CPU decrease for reading all chunks in all revlogs
(this is somewhat disappointing).
$ hg bundle -a -t <engine>-v2 (total CPU time)
zlib: 191.59s
zstd: 115.36s
This last test effectively measures the difference between zlib->zlib
and zstd->zstd for revlogs to bundle. This is a rough approximation of
what a server does during `hg clone`.
There are some promising results for zstd. But not enough for me to
feel comfortable advertising it to users. We'll get there...
2017-01-14 07:16:56 +03:00
|
|
|
for r in self.requirements:
|
|
|
|
if r.startswith('exp-compression-'):
|
|
|
|
self.svfs.options['compengine'] = r[len('exp-compression-'):]
|
|
|
|
|
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)
|
2017-03-10 02:10:27 +03:00
|
|
|
class filteredrepo(repoview.repoview, self.unfiltered().__class__):
|
2012-12-20 18:32:42 +04:00
|
|
|
pass
|
2017-03-10 02:10:27 +03:00
|
|
|
return filteredrepo(self, name)
|
2012-12-20 18:32:42 +04:00
|
|
|
|
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)
|
2017-02-20 19:21:00 +03:00
|
|
|
if txnutil.mayhavepending(self.root):
|
|
|
|
c.readpending('00changelog.i.a')
|
2009-04-30 05:47:15 +04:00
|
|
|
return c
|
|
|
|
|
2016-10-19 03:32:51 +03:00
|
|
|
def _constructmanifest(self):
|
|
|
|
# This is a temporary function while we migrate from manifest to
|
|
|
|
# manifestlog. It allows bundlerepo and unionrepo to intercept the
|
|
|
|
# manifest creation.
|
2016-11-10 13:13:19 +03:00
|
|
|
return manifest.manifestrevlog(self.svfs)
|
2009-04-30 05:47:15 +04:00
|
|
|
|
2016-10-19 03:33:39 +03:00
|
|
|
@storecache('00manifest.i')
|
2016-08-17 23:25:13 +03:00
|
|
|
def manifestlog(self):
|
2016-08-17 23:25:13 +03:00
|
|
|
return manifest.manifestlog(self.svfs, self)
|
2016-08-17 23:25:13 +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
|
|
|
|
|
2017-03-13 22:40:14 +03:00
|
|
|
__bool__ = __nonzero__
|
|
|
|
|
2008-06-26 23:35:50 +04:00
|
|
|
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
|
2017-02-19 12:19:33 +03:00
|
|
|
%-formatting to escape certain types. See ``revsetlang.formatspec``.
|
2015-11-21 22:07:30 +03:00
|
|
|
|
2016-06-26 05:12:20 +03:00
|
|
|
Revset aliases from the configuration are not expanded. To expand
|
2017-02-19 14:00:18 +03:00
|
|
|
user aliases, consider calling ``scmutil.revrange()`` or
|
|
|
|
``repo.anyrevs([expr], user=True)``.
|
2016-06-26 05:12:20 +03:00
|
|
|
|
|
|
|
Returns a revset.abstractsmartset, which is a list-like interface
|
2015-11-21 22:07:30 +03:00
|
|
|
that contains integer revisions.
|
|
|
|
'''
|
2017-02-19 12:19:33 +03:00
|
|
|
expr = revsetlang.formatspec(expr, *args)
|
2011-11-02 22:37:34 +04:00
|
|
|
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.
|
2016-06-26 05:12:20 +03:00
|
|
|
|
|
|
|
Revset aliases from the configuration are not expanded. To expand
|
|
|
|
user aliases, consider calling ``scmutil.revrange()``.
|
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]
|
|
|
|
|
2017-02-19 14:00:18 +03:00
|
|
|
def anyrevs(self, specs, user=False):
|
|
|
|
'''Find revisions matching one of the given revsets.
|
|
|
|
|
|
|
|
Revset aliases from the configuration are not expanded by default. To
|
|
|
|
expand user aliases, specify ``user=True``.
|
|
|
|
'''
|
|
|
|
if user:
|
|
|
|
m = revset.matchany(self.ui, specs, repo=self)
|
|
|
|
else:
|
|
|
|
m = revset.matchany(None, specs)
|
|
|
|
return m(self)
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-03-28 08:41:23 +03:00
|
|
|
# map tag name to (node, hist)
|
|
|
|
alltags = tagsmod.findglobaltags(self.ui, self)
|
|
|
|
# map tag name to tag type
|
|
|
|
tagtypes = dict((tag, 'global') for tag in alltags)
|
2017-03-28 07:13:49 +03:00
|
|
|
|
2010-03-11 19:43:44 +03:00
|
|
|
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 wjoin(self, f, *insidef):
|
2015-01-02 15:30:38 +03:00
|
|
|
return self.vfs.reljoin(self.root, f, *insidef)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
|
|
|
def file(self, f):
|
2006-01-12 09:57:58 +03:00
|
|
|
if f[0] == '/':
|
|
|
|
f = f[1:]
|
2015-01-11 02:21:58 +03:00
|
|
|
return filelog.filelog(self.svfs, f)
|
2005-08-28 01:21:25 +04:00
|
|
|
|
2008-06-26 02:35:20 +04:00
|
|
|
def changectx(self, changeid):
|
2008-06-26 23:35:46 +04:00
|
|
|
return self[changeid]
|
2006-10-03 10:21:46 +04:00
|
|
|
|
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)
|
|
|
|
|
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):
|
2016-08-05 15:19:31 +03:00
|
|
|
if self.wvfs.islink(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')):
|
2016-08-05 14:44:17 +03:00
|
|
|
if self._currentlock(self._lockref) is None:
|
2016-12-06 20:06:39 +03:00
|
|
|
raise error.ProgrammingError('transaction requires locking')
|
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
|
|
|
|
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())
|
2017-03-21 05:06:57 +03:00
|
|
|
ha = hex(hashlib.sha1(idbase).digest())
|
2017-03-19 08:08:59 +03:00
|
|
|
txnid = 'TXN:' + ha
|
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)
|
2017-03-28 07:38:09 +03:00
|
|
|
# Code to track tag movement
|
|
|
|
#
|
|
|
|
# Since tags are all handled as file content, it is actually quite hard
|
|
|
|
# to track these movement from a code perspective. So we fallback to a
|
|
|
|
# tracking at the repository level. One could envision to track changes
|
|
|
|
# to the '.hgtags' file through changegroup apply but that fails to
|
|
|
|
# cope with case where transaction expose new heads without changegroup
|
|
|
|
# being involved (eg: phase movement).
|
|
|
|
#
|
|
|
|
# For now, We gate the feature behind a flag since this likely comes
|
|
|
|
# with performance impacts. The current code run more often than needed
|
|
|
|
# and do not use caches as much as it could. The current focus is on
|
|
|
|
# the behavior of the feature so we disable it by default. The flag
|
|
|
|
# will be removed when we are happy with the performance impact.
|
2017-03-28 11:15:02 +03:00
|
|
|
#
|
|
|
|
# Once this feature is no longer experimental move the following
|
|
|
|
# documentation to the appropriate help section:
|
|
|
|
#
|
|
|
|
# The ``HG_TAG_MOVED`` variable will be set if the transaction touched
|
|
|
|
# tags (new or changed or deleted tags). In addition the details of
|
|
|
|
# these changes are made available in a file at:
|
|
|
|
# ``REPOROOT/.hg/changes/tags.changes``.
|
|
|
|
# Make sure you check for HG_TAG_MOVED before reading that file as it
|
|
|
|
# might exist from a previous transaction even if no tag were touched
|
|
|
|
# in this one. Changes are recorded in a line base format::
|
|
|
|
#
|
|
|
|
# <action> <hex-node> <tag-name>\n
|
|
|
|
#
|
|
|
|
# Actions are defined as follow:
|
|
|
|
# "-R": tag is removed,
|
|
|
|
# "+A": tag is added,
|
|
|
|
# "-M": tag is moved (old value),
|
|
|
|
# "+M": tag is moved (new value),
|
2017-03-28 07:38:09 +03:00
|
|
|
tracktags = lambda x: None
|
|
|
|
# experimental config: experimental.hook-track-tags
|
|
|
|
shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags',
|
|
|
|
False)
|
|
|
|
if desc != 'strip' and shouldtracktags:
|
|
|
|
oldheads = self.changelog.headrevs()
|
|
|
|
def tracktags(tr2):
|
|
|
|
repo = reporef()
|
|
|
|
oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads)
|
|
|
|
newheads = repo.changelog.headrevs()
|
|
|
|
newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads)
|
|
|
|
# notes: we compare lists here.
|
|
|
|
# As we do it only once buiding set would not be cheaper
|
2017-03-28 11:14:55 +03:00
|
|
|
changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes)
|
|
|
|
if changes:
|
2017-03-28 07:38:09 +03:00
|
|
|
tr2.hookargs['tag_moved'] = '1'
|
2017-03-28 11:15:02 +03:00
|
|
|
with repo.vfs('changes/tags.changes', 'w',
|
|
|
|
atomictemp=True) as changesfile:
|
|
|
|
# note: we do not register the file to the transaction
|
|
|
|
# because we needs it to still exist on the transaction
|
|
|
|
# is close (for txnclose hooks)
|
|
|
|
tagsmod.writediff(changesfile, changes)
|
2017-03-28 07:38:09 +03:00
|
|
|
def validate(tr2):
|
2015-03-10 08:50:49 +03:00
|
|
|
"""will run pre-closing hooks"""
|
2017-03-28 07:38:09 +03:00
|
|
|
# XXX the transaction API is a bit lacking here so we take a hacky
|
|
|
|
# path for now
|
|
|
|
#
|
|
|
|
# We cannot add this as a "pending" hooks since the 'tr.hookargs'
|
|
|
|
# dict is copied before these run. In addition we needs the data
|
|
|
|
# available to in memory hooks too.
|
|
|
|
#
|
|
|
|
# Moreover, we also need to make sure this runs before txnclose
|
|
|
|
# hooks and there is no "pending" mechanism that would execute
|
|
|
|
# logic only if hooks are about to run.
|
|
|
|
#
|
|
|
|
# Fixing this limitation of the transaction is also needed to track
|
|
|
|
# other families of changes (bookmarks, phases, obsolescence).
|
|
|
|
#
|
|
|
|
# This will have to be fixed before we remove the experimental
|
|
|
|
# gating.
|
|
|
|
tracktags(tr2)
|
2015-10-16 19:15:34 +03:00
|
|
|
reporef().hook('pretxnclose', throw=True,
|
2017-03-19 08:10:02 +03:00
|
|
|
txnname=desc, **pycompat.strkwargs(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:
|
|
|
|
# discard all changes (including ones already written
|
|
|
|
# out) in this transaction
|
2016-05-13 23:30:08 +03:00
|
|
|
repo.dirstate.restorebackup(None, prefix='journal.')
|
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)
|
2017-05-02 19:45:51 +03:00
|
|
|
tr.changes['revs'] = set()
|
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,
|
2017-03-19 08:10:02 +03:00
|
|
|
**pycompat.strkwargs(hookargs))
|
2015-03-10 08:36:56 +03:00
|
|
|
reporef()._afterlock(hook)
|
|
|
|
tr.addfinalize('txnclose-hook', txnclosehook)
|
2017-05-02 22:39:43 +03:00
|
|
|
def warmscache(tr2):
|
|
|
|
repo = reporef()
|
|
|
|
repo.updatecaches(tr2)
|
|
|
|
tr.addpostclose('warms-cache', warmscache)
|
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):
|
2016-05-12 00:18:52 +03:00
|
|
|
self.dirstate.savebackup(None, prefix='journal.')
|
2015-01-11 01:02:52 +03:00
|
|
|
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"):
|
2016-11-22 05:06:34 +03:00
|
|
|
dsguard = dirstateguard.dirstateguard(self, 'rollback')
|
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
|
|
|
|
|
|
|
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'):
|
2016-06-12 23:11:56 +03:00
|
|
|
self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True)
|
2013-04-14 20:22:15 +04:00
|
|
|
if self.svfs.exists('undo.phaseroots'):
|
2016-06-12 23:11:56 +03:00
|
|
|
self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True)
|
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()
|
|
|
|
|
2016-05-13 23:30:08 +03:00
|
|
|
self.dirstate.restorebackup(None, prefix='undo.')
|
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())
|
|
|
|
|
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
|
|
|
|
|
2017-05-02 22:39:43 +03:00
|
|
|
@unfilteredmethod
|
2017-05-02 20:05:58 +03:00
|
|
|
def updatecaches(self, tr=None):
|
|
|
|
"""warm appropriate caches
|
|
|
|
|
|
|
|
If this function is called after a transaction closed. The transaction
|
|
|
|
will be available in the 'tr' argument. This can be used to selectively
|
|
|
|
update caches relevant to the changes in that transaction.
|
|
|
|
"""
|
|
|
|
if tr is not None and tr.hookargs.get('source') == 'strip':
|
2017-05-02 22:39:43 +03:00
|
|
|
# During strip, many caches are invalid but
|
|
|
|
# later call to `destroyed` will refresh them.
|
|
|
|
return
|
|
|
|
|
2017-05-02 20:05:58 +03:00
|
|
|
if tr is None or tr.changes['revs']:
|
|
|
|
# updating the unfiltered branchmap should refresh all the others,
|
2017-05-02 22:39:43 +03:00
|
|
|
branchmap.updatecache(self.filtered('served'))
|
|
|
|
|
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):
|
2016-09-11 21:06:28 +03:00
|
|
|
'''Invalidates both store and non-store parts other than dirstate
|
|
|
|
|
|
|
|
If a transaction is running, invalidation of store is omitted,
|
|
|
|
because discarding in-memory changes might cause inconsistency
|
|
|
|
(e.g. incomplete fncache causes unintentional failure, but
|
|
|
|
redundant one doesn't).
|
|
|
|
'''
|
2013-02-10 21:24:29 +04:00
|
|
|
unfiltered = self.unfiltered() # all file caches are stored unfiltered
|
2017-03-19 08:11:00 +03:00
|
|
|
for k in list(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()
|
2016-09-11 21:06:28 +03:00
|
|
|
if not self.currenttransaction():
|
|
|
|
# TODO: Changing contents of store outside transaction
|
|
|
|
# causes inconsistency. We should make in-memory store
|
|
|
|
# changes detectable, and abort if changed.
|
|
|
|
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()
|
|
|
|
|
2016-09-11 21:06:29 +03:00
|
|
|
@unfilteredmethod
|
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:
|
2016-12-17 23:04:41 +03:00
|
|
|
parentlock = encoding.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
|
2016-08-30 19:25:00 +03:00
|
|
|
# show more details for new-style locks
|
|
|
|
if ':' in inst.locker:
|
|
|
|
host, pid = inst.locker.split(":", 1)
|
|
|
|
self.ui.warn(
|
|
|
|
_("waiting for lock on %s held by process %r "
|
|
|
|
"on host %r\n") % (desc, pid, host))
|
|
|
|
else:
|
|
|
|
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.'''
|
2016-08-05 14:44:17 +03:00
|
|
|
l = self._currentlock(self._lockref)
|
|
|
|
if l is not None:
|
2009-04-22 04:01:22 +04:00
|
|
|
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')):
|
2016-08-05 14:44:17 +03:00
|
|
|
if self._currentlock(self._lockref) is not None:
|
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)
|
2016-05-20 00:35:22 +03:00
|
|
|
if manifest1.flags(fname) != fctx.flags():
|
|
|
|
changelist.append(fname)
|
2015-03-19 19:36:17 +03:00
|
|
|
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
|
|
|
|
2016-04-06 20:52:17 +03:00
|
|
|
def checkcommitpatterns(self, wctx, vdirs, match, status, fail):
|
2016-10-18 00:16:55 +03:00
|
|
|
"""check for commit arguments that aren't committable"""
|
2016-04-06 21:08:38 +03:00
|
|
|
if match.isexact() or match.prefix():
|
2016-04-06 20:52:17 +03:00
|
|
|
matched = set(status.modified + status.added + status.removed)
|
|
|
|
|
|
|
|
for f in match.files():
|
|
|
|
f = self.dirstate.normalize(f)
|
|
|
|
if f == '.' or f in matched or f in wctx.substate:
|
|
|
|
continue
|
|
|
|
if f in status.deleted:
|
|
|
|
fail(f, _('file not found!'))
|
|
|
|
if f in vdirs: # visited directory
|
|
|
|
d = f + '/'
|
|
|
|
for mf in matched:
|
|
|
|
if mf.startswith(d):
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
fail(f, _("no match under directory!"))
|
|
|
|
elif f not in self.dirstate:
|
|
|
|
fail(f, _("file not tracked!"))
|
|
|
|
|
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
|
2016-04-06 20:52:17 +03:00
|
|
|
if not force:
|
|
|
|
self.checkcommitpatterns(wctx, vdirs, match, status, fail)
|
2009-06-02 06:51:00 +04:00
|
|
|
|
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)
|
2016-11-22 05:32:55 +03:00
|
|
|
mergeutil.checkunresolved(ms)
|
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
|
|
|
|
2016-11-17 21:59:15 +03:00
|
|
|
if ctx.manifestnode():
|
|
|
|
# reuse an existing manifest revision
|
|
|
|
mn = ctx.manifestnode()
|
|
|
|
files = ctx.files()
|
|
|
|
elif ctx.files():
|
2016-11-08 19:03:43 +03:00
|
|
|
m1ctx = p1.manifestctx()
|
|
|
|
m2ctx = p2.manifestctx()
|
|
|
|
mctx = m1ctx.copy()
|
|
|
|
|
|
|
|
m = mctx.read()
|
|
|
|
m1 = m1ctx.read()
|
|
|
|
m2 = m2ctx.read()
|
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]
|
2016-11-08 19:03:43 +03:00
|
|
|
mn = mctx.write(trp, linkrev,
|
|
|
|
p1.manifestnode(), p2.manifestnode(),
|
|
|
|
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()
|
|
|
|
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
|
|
|
|
2017-05-02 20:05:58 +03:00
|
|
|
# refresh all repository caches
|
|
|
|
self.updatecaches()
|
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):
|
2017-02-02 13:56:38 +03:00
|
|
|
if start is None:
|
2017-02-13 13:26:18 +03:00
|
|
|
cl = self.changelog
|
2017-02-13 13:31:56 +03:00
|
|
|
headrevs = reversed(cl.headrevs())
|
2017-02-13 13:26:18 +03:00
|
|
|
return [cl.node(rev) for rev in headrevs]
|
2017-02-02 13:56:38 +03:00
|
|
|
|
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):
|
2016-04-13 02:09:11 +03:00
|
|
|
"""Return util.hooks consists of a pushop with repo, remote, outgoing
|
|
|
|
methods, which are called before pushing changesets.
|
2014-04-15 19:37:24 +04:00
|
|
|
"""
|
|
|
|
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:
|
2017-03-21 16:50:28 +03:00
|
|
|
# if src and dest refer to a same file, vfs.rename is a no-op,
|
|
|
|
# leaving both src and dest on disk. delete dest to make sure
|
|
|
|
# the rename couldn't be such a no-op.
|
|
|
|
vfs.tryunlink(dest)
|
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')
|
|
|
|
|
localrepo: experimental support for non-zlib revlog compression
The final part of integrating the compression manager APIs into
revlog storage is the plumbing for repositories to advertise they
are using non-zlib storage and for revlogs to instantiate a non-zlib
compression engine.
The main intent of the compression manager work was to zstd all
of the things. Adding zstd to revlogs has proved to be more involved
than other places because revlogs are... special. Very small inputs
and the use of delta chains (which are themselves a form of
compression) are a completely different use case from streaming
compression, which bundles and the wire protocol employ. I've
conducted numerous experiments with zstd in revlogs and have yet
to formalize compression settings and a storage architecture that
I'm confident I won't regret later. In other words, I'm not yet
ready to commit to a new mechanism for using zstd - or any other
compression format - in revlogs.
That being said, having some support for zstd (and other compression
formats) in revlogs in core is beneficial. It can allow others to
conduct experiments.
This patch introduces *highly experimental* support for non-zlib
compression formats in revlogs. Introduced is a config option to
control which compression engine to use. Also introduced is a namespace
of "exp-compression-*" requirements to denote support for non-zlib
compression in revlogs. I've prefixed the namespace with "exp-"
(short for "experimental") because I'm not confident of the
requirements "schema" and in no way want to give the illusion of
supporting these requirements in the future. I fully intend to drop
support for these requirements once we figure out what we're doing
with zstd in revlogs.
A good portion of the patch is teaching the requirements system
about registered compression engines and passing the requested
compression engine as an opener option so revlogs can instantiate
the proper compression engine for new operations.
That's a verbose way of saying "we can now use zstd in revlogs!"
On an `hg pull` conversion of the mozilla-unified repo with no extra
redelta settings (like aggressivemergedeltas), we can see the impact
of zstd vs zlib in revlogs:
$ hg perfrevlogchunks -c
! chunk
! wall 2.032052 comb 2.040000 user 1.990000 sys 0.050000 (best of 5)
! wall 1.866360 comb 1.860000 user 1.820000 sys 0.040000 (best of 6)
! chunk batch
! wall 1.877261 comb 1.870000 user 1.860000 sys 0.010000 (best of 6)
! wall 1.705410 comb 1.710000 user 1.690000 sys 0.020000 (best of 6)
$ hg perfrevlogchunks -m
! chunk
! wall 2.721427 comb 2.720000 user 2.640000 sys 0.080000 (best of 4)
! wall 2.035076 comb 2.030000 user 1.950000 sys 0.080000 (best of 5)
! chunk batch
! wall 2.614561 comb 2.620000 user 2.580000 sys 0.040000 (best of 4)
! wall 1.910252 comb 1.910000 user 1.880000 sys 0.030000 (best of 6)
$ hg perfrevlog -c -d 1
! wall 4.812885 comb 4.820000 user 4.800000 sys 0.020000 (best of 3)
! wall 4.699621 comb 4.710000 user 4.700000 sys 0.010000 (best of 3)
$ hg perfrevlog -m -d 1000
! wall 34.252800 comb 34.250000 user 33.730000 sys 0.520000 (best of 3)
! wall 24.094999 comb 24.090000 user 23.320000 sys 0.770000 (best of 3)
Only modest wins for the changelog. But manifest reading is
significantly faster. What's going on?
One reason might be data volume. zstd decompresses faster. So given
more bytes, it will put more distance between it and zlib.
Another reason is size. In the current design, zstd revlogs are
*larger*:
debugcreatestreamclonebundle (size in bytes)
zlib: 1,638,852,492
zstd: 1,680,601,332
I haven't investigated this fully, but I reckon a significant cause of
larger revlogs is that the zstd frame/header has more bytes than
zlib's. For very small inputs or data that doesn't compress well, we'll
tend to store more uncompressed chunks than with zlib (because the
compressed size isn't smaller than original). This will make revlog
reading faster because it is doing less decompression.
Moving on to bundle performance:
$ hg bundle -a -t none-v2 (total CPU time)
zlib: 102.79s
zstd: 97.75s
So, marginal CPU decrease for reading all chunks in all revlogs
(this is somewhat disappointing).
$ hg bundle -a -t <engine>-v2 (total CPU time)
zlib: 191.59s
zstd: 115.36s
This last test effectively measures the difference between zlib->zlib
and zstd->zstd for revlogs to bundle. This is a rough approximation of
what a server does during `hg clone`.
There are some promising results for zstd. But not enough for me to
feel comfortable advertising it to users. We'll get there...
2017-01-14 07:16:56 +03:00
|
|
|
compengine = ui.config('experimental', 'format.compression', 'zlib')
|
|
|
|
if compengine not in util.compengines:
|
|
|
|
raise error.Abort(_('compression engine %s defined by '
|
|
|
|
'experimental.format.compression not available') %
|
|
|
|
compengine,
|
|
|
|
hint=_('run "hg debuginstall" to list available '
|
|
|
|
'compression engines'))
|
|
|
|
|
|
|
|
# zlib is the historical default and doesn't need an explicit requirement.
|
|
|
|
if compengine != 'zlib':
|
|
|
|
requirements.add('exp-compression-%s' % compengine)
|
|
|
|
|
2016-02-16 00:20:20 +03:00
|
|
|
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
|