2006-06-29 02:07:46 +04:00
|
|
|
# context.py - changeset and file context objects for mercurial
|
|
|
|
#
|
2007-06-19 10:51:34 +04:00
|
|
|
# Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
|
2006-06-29 02:07:46 +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.
|
2006-06-29 02:07:46 +04:00
|
|
|
|
2015-12-22 08:51:31 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import errno
|
|
|
|
import os
|
2015-10-09 02:19:37 +03:00
|
|
|
import re
|
2015-12-22 08:51:31 +03:00
|
|
|
import stat
|
2015-10-09 02:19:37 +03:00
|
|
|
|
2015-12-22 08:51:31 +03:00
|
|
|
from .i18n import _
|
|
|
|
from .node import (
|
2016-11-10 13:19:16 +03:00
|
|
|
addednodeid,
|
2015-12-22 08:51:31 +03:00
|
|
|
bin,
|
|
|
|
hex,
|
2016-11-10 13:19:16 +03:00
|
|
|
modifiednodeid,
|
2016-11-10 13:17:22 +03:00
|
|
|
newnodeid,
|
2015-12-22 08:51:31 +03:00
|
|
|
nullid,
|
|
|
|
nullrev,
|
|
|
|
short,
|
|
|
|
wdirid,
|
|
|
|
)
|
|
|
|
from . import (
|
|
|
|
encoding,
|
|
|
|
error,
|
|
|
|
fileset,
|
|
|
|
match as matchmod,
|
|
|
|
mdiff,
|
|
|
|
obsolete as obsmod,
|
|
|
|
patch,
|
|
|
|
phases,
|
|
|
|
repoview,
|
|
|
|
revlog,
|
|
|
|
scmutil,
|
|
|
|
subrepo,
|
|
|
|
util,
|
|
|
|
)
|
2006-09-18 07:20:44 +04:00
|
|
|
|
2009-04-27 01:50:44 +04:00
|
|
|
propertycache = util.propertycache
|
2008-11-14 14:44:26 +03:00
|
|
|
|
2015-10-09 02:19:37 +03:00
|
|
|
nonascii = re.compile(r'[^\x21-\x7f]').search
|
|
|
|
|
2013-07-14 04:59:21 +04:00
|
|
|
class basectx(object):
|
|
|
|
"""A basectx object represents the common logic for its children:
|
|
|
|
changectx: read-only context that is already present in the repo,
|
|
|
|
workingctx: a context that represents the working directory and can
|
|
|
|
be committed,
|
|
|
|
memctx: a context that represents changes in-memory and can also
|
|
|
|
be committed."""
|
|
|
|
def __new__(cls, repo, changeid='', *args, **kwargs):
|
2013-08-07 00:50:28 +04:00
|
|
|
if isinstance(changeid, basectx):
|
|
|
|
return changeid
|
|
|
|
|
|
|
|
o = super(basectx, cls).__new__(cls)
|
|
|
|
|
|
|
|
o._repo = repo
|
|
|
|
o._rev = nullrev
|
|
|
|
o._node = nullid
|
|
|
|
|
|
|
|
return o
|
2013-07-14 04:59:21 +04:00
|
|
|
|
2013-08-03 01:46:23 +04:00
|
|
|
def __str__(self):
|
|
|
|
return short(self.node())
|
|
|
|
|
2013-08-03 01:52:13 +04:00
|
|
|
def __int__(self):
|
|
|
|
return self.rev()
|
|
|
|
|
2013-08-03 03:24:08 +04:00
|
|
|
def __repr__(self):
|
|
|
|
return "<%s %s>" % (type(self).__name__, str(self))
|
|
|
|
|
2013-08-06 02:00:09 +04:00
|
|
|
def __eq__(self, other):
|
|
|
|
try:
|
|
|
|
return type(self) == type(other) and self._rev == other._rev
|
|
|
|
except AttributeError:
|
|
|
|
return False
|
|
|
|
|
2013-08-06 02:00:32 +04:00
|
|
|
def __ne__(self, other):
|
|
|
|
return not (self == other)
|
|
|
|
|
2013-08-06 02:21:38 +04:00
|
|
|
def __contains__(self, key):
|
|
|
|
return key in self._manifest
|
|
|
|
|
2013-08-06 02:22:05 +04:00
|
|
|
def __getitem__(self, key):
|
|
|
|
return self.filectx(key)
|
|
|
|
|
2013-08-06 02:22:18 +04:00
|
|
|
def __iter__(self):
|
2014-11-17 08:00:25 +03:00
|
|
|
return iter(self._manifest)
|
2013-08-06 02:22:18 +04:00
|
|
|
|
2014-04-24 05:52:10 +04:00
|
|
|
def _manifestmatches(self, match, s):
|
|
|
|
"""generate a new manifest filtered by the match argument
|
|
|
|
|
|
|
|
This method is for internal use only and mainly exists to provide an
|
|
|
|
object oriented way for other contexts to customize the manifest
|
|
|
|
generation.
|
|
|
|
"""
|
2014-10-23 08:38:30 +04:00
|
|
|
return self.manifest().matches(match)
|
2014-04-24 05:52:10 +04:00
|
|
|
|
2014-10-12 10:18:53 +04:00
|
|
|
def _matchstatus(self, other, match):
|
2014-04-24 00:39:30 +04:00
|
|
|
"""return match.always if match is none
|
|
|
|
|
|
|
|
This internal method provides a way for child objects to override the
|
|
|
|
match operator.
|
|
|
|
"""
|
|
|
|
return match or matchmod.always(self._repo.root, self._repo.getcwd())
|
|
|
|
|
2014-04-22 06:35:36 +04:00
|
|
|
def _buildstatus(self, other, s, match, listignored, listclean,
|
2014-05-30 01:09:16 +04:00
|
|
|
listunknown):
|
2014-04-22 06:35:36 +04:00
|
|
|
"""build a status with respect to another context"""
|
2014-11-11 21:16:54 +03:00
|
|
|
# Load earliest manifest first for caching reasons. More specifically,
|
|
|
|
# if you have revisions 1000 and 1001, 1001 is probably stored as a
|
|
|
|
# delta against 1000. Thus, if you read 1000 first, we'll reconstruct
|
|
|
|
# 1000 and cache it so that when you read 1001, we just need to apply a
|
|
|
|
# delta to what's in the cache. So that's one full reconstruction + one
|
|
|
|
# delta application.
|
2014-10-12 11:00:13 +04:00
|
|
|
if self.rev() is not None and self.rev() < other.rev():
|
|
|
|
self.manifest()
|
2014-04-22 06:35:36 +04:00
|
|
|
mf1 = other._manifestmatches(match, s)
|
|
|
|
mf2 = self._manifestmatches(match, s)
|
|
|
|
|
2014-12-15 23:33:55 +03:00
|
|
|
modified, added = [], []
|
|
|
|
removed = []
|
2014-12-16 00:06:04 +03:00
|
|
|
clean = []
|
2014-11-13 09:20:36 +03:00
|
|
|
deleted, unknown, ignored = s.deleted, s.unknown, s.ignored
|
2014-10-25 01:24:28 +04:00
|
|
|
deletedset = set(deleted)
|
2014-12-16 00:06:04 +03:00
|
|
|
d = mf1.diff(mf2, clean=listclean)
|
|
|
|
for fn, value in d.iteritems():
|
2015-01-06 04:12:04 +03:00
|
|
|
if fn in deletedset:
|
|
|
|
continue
|
2014-12-16 00:06:04 +03:00
|
|
|
if value is None:
|
|
|
|
clean.append(fn)
|
|
|
|
continue
|
|
|
|
(node1, flag1), (node2, flag2) = value
|
2014-12-15 23:33:55 +03:00
|
|
|
if node1 is None:
|
2014-04-22 06:35:36 +04:00
|
|
|
added.append(fn)
|
2014-12-15 23:33:55 +03:00
|
|
|
elif node2 is None:
|
|
|
|
removed.append(fn)
|
2016-01-13 00:10:31 +03:00
|
|
|
elif flag1 != flag2:
|
|
|
|
modified.append(fn)
|
2016-11-10 13:17:22 +03:00
|
|
|
elif node2 != newnodeid:
|
2016-01-13 00:09:54 +03:00
|
|
|
# When comparing files between two commits, we save time by
|
|
|
|
# not comparing the file contents when the nodeids differ.
|
|
|
|
# Note that this means we incorrectly report a reverted change
|
|
|
|
# to a file as a modification.
|
2016-01-12 23:43:36 +03:00
|
|
|
modified.append(fn)
|
2014-12-15 23:33:55 +03:00
|
|
|
elif self[fn].cmp(other[fn]):
|
|
|
|
modified.append(fn)
|
|
|
|
else:
|
2014-12-16 00:06:04 +03:00
|
|
|
clean.append(fn)
|
2014-12-15 23:33:55 +03:00
|
|
|
|
2014-08-02 00:13:24 +04:00
|
|
|
if removed:
|
|
|
|
# need to filter files if they are already reported as removed
|
|
|
|
unknown = [fn for fn in unknown if fn not in mf1]
|
|
|
|
ignored = [fn for fn in ignored if fn not in mf1]
|
2015-01-06 03:52:12 +03:00
|
|
|
# if they're deleted, don't report them as removed
|
|
|
|
removed = [fn for fn in removed if fn not in deletedset]
|
2014-04-22 06:35:36 +04:00
|
|
|
|
2014-11-13 03:51:11 +03:00
|
|
|
return scmutil.status(modified, added, removed, deleted, unknown,
|
|
|
|
ignored, clean)
|
2014-04-22 06:35:36 +04:00
|
|
|
|
2013-08-06 02:21:23 +04:00
|
|
|
@propertycache
|
|
|
|
def substate(self):
|
|
|
|
return subrepo.state(self, self._repo.ui)
|
|
|
|
|
2013-09-21 06:55:42 +04:00
|
|
|
def subrev(self, subpath):
|
|
|
|
return self.substate[subpath][1]
|
|
|
|
|
2013-08-03 04:09:06 +04:00
|
|
|
def rev(self):
|
|
|
|
return self._rev
|
2013-08-03 01:48:19 +04:00
|
|
|
def node(self):
|
|
|
|
return self._node
|
2013-08-03 01:49:01 +04:00
|
|
|
def hex(self):
|
2013-08-03 01:50:13 +04:00
|
|
|
return hex(self.node())
|
2013-08-06 02:22:49 +04:00
|
|
|
def manifest(self):
|
|
|
|
return self._manifest
|
2016-11-08 19:03:43 +03:00
|
|
|
def manifestctx(self):
|
|
|
|
return self._manifestctx
|
2015-03-13 05:54:53 +03:00
|
|
|
def repo(self):
|
|
|
|
return self._repo
|
2013-08-06 03:19:04 +04:00
|
|
|
def phasestr(self):
|
|
|
|
return phases.phasenames[self.phase()]
|
2013-08-06 03:19:19 +04:00
|
|
|
def mutable(self):
|
|
|
|
return self.phase() > phases.public
|
2013-08-03 04:09:06 +04:00
|
|
|
|
2014-02-05 00:27:49 +04:00
|
|
|
def getfileset(self, expr):
|
|
|
|
return fileset.getfileset(self, expr)
|
|
|
|
|
2013-09-18 08:34:57 +04:00
|
|
|
def obsolete(self):
|
|
|
|
"""True if the changeset is obsolete"""
|
|
|
|
return self.rev() in obsmod.getrevs(self._repo, 'obsolete')
|
|
|
|
|
|
|
|
def extinct(self):
|
|
|
|
"""True if the changeset is extinct"""
|
|
|
|
return self.rev() in obsmod.getrevs(self._repo, 'extinct')
|
|
|
|
|
|
|
|
def unstable(self):
|
|
|
|
"""True if the changeset is not obsolete but it's ancestor are"""
|
|
|
|
return self.rev() in obsmod.getrevs(self._repo, 'unstable')
|
|
|
|
|
|
|
|
def bumped(self):
|
|
|
|
"""True if the changeset try to be a successor of a public changeset
|
|
|
|
|
|
|
|
Only non-public and non-obsolete changesets may be bumped.
|
|
|
|
"""
|
|
|
|
return self.rev() in obsmod.getrevs(self._repo, 'bumped')
|
|
|
|
|
|
|
|
def divergent(self):
|
|
|
|
"""Is a successors of a changeset with multiple possible successors set
|
|
|
|
|
|
|
|
Only non-public and non-obsolete changesets may be divergent.
|
|
|
|
"""
|
|
|
|
return self.rev() in obsmod.getrevs(self._repo, 'divergent')
|
|
|
|
|
|
|
|
def troubled(self):
|
|
|
|
"""True if the changeset is either unstable, bumped or divergent"""
|
|
|
|
return self.unstable() or self.bumped() or self.divergent()
|
|
|
|
|
|
|
|
def troubles(self):
|
|
|
|
"""return the list of troubles affecting this changesets.
|
|
|
|
|
|
|
|
Troubles are returned as strings. possible values are:
|
|
|
|
- unstable,
|
|
|
|
- bumped,
|
|
|
|
- divergent.
|
|
|
|
"""
|
|
|
|
troubles = []
|
|
|
|
if self.unstable():
|
|
|
|
troubles.append('unstable')
|
|
|
|
if self.bumped():
|
|
|
|
troubles.append('bumped')
|
|
|
|
if self.divergent():
|
|
|
|
troubles.append('divergent')
|
|
|
|
return troubles
|
|
|
|
|
2013-08-06 03:19:38 +04:00
|
|
|
def parents(self):
|
|
|
|
"""return contexts for each parent changeset"""
|
|
|
|
return self._parents
|
|
|
|
|
2013-08-06 03:26:15 +04:00
|
|
|
def p1(self):
|
|
|
|
return self._parents[0]
|
|
|
|
|
2013-08-06 03:26:54 +04:00
|
|
|
def p2(self):
|
2015-11-22 06:21:01 +03:00
|
|
|
parents = self._parents
|
|
|
|
if len(parents) == 2:
|
|
|
|
return parents[1]
|
|
|
|
return changectx(self._repo, nullrev)
|
2013-08-06 03:26:54 +04:00
|
|
|
|
2013-08-06 03:28:23 +04:00
|
|
|
def _fileinfo(self, path):
|
|
|
|
if '_manifest' in self.__dict__:
|
|
|
|
try:
|
|
|
|
return self._manifest[path], self._manifest.flags(path)
|
|
|
|
except KeyError:
|
|
|
|
raise error.ManifestLookupError(self._node, path,
|
|
|
|
_('not found in manifest'))
|
|
|
|
if '_manifestdelta' in self.__dict__ or path in self.files():
|
|
|
|
if path in self._manifestdelta:
|
|
|
|
return (self._manifestdelta[path],
|
|
|
|
self._manifestdelta.flags(path))
|
2016-11-08 19:03:43 +03:00
|
|
|
mfl = self._repo.manifestlog
|
|
|
|
try:
|
|
|
|
node, flag = mfl[self._changeset.manifest].find(path)
|
|
|
|
except KeyError:
|
2013-08-06 03:28:23 +04:00
|
|
|
raise error.ManifestLookupError(self._node, path,
|
|
|
|
_('not found in manifest'))
|
|
|
|
|
|
|
|
return node, flag
|
|
|
|
|
2013-08-06 03:28:40 +04:00
|
|
|
def filenode(self, path):
|
|
|
|
return self._fileinfo(path)[0]
|
|
|
|
|
2013-08-06 03:28:54 +04:00
|
|
|
def flags(self, path):
|
|
|
|
try:
|
|
|
|
return self._fileinfo(path)[1]
|
|
|
|
except error.LookupError:
|
|
|
|
return ''
|
|
|
|
|
verify: don't init subrepo when missing one is referenced (issue5128) (API)
Initializing a subrepo when one doesn't exist is the right thing to do when the
parent is being updated, but in few other cases. Unfortunately, there isn't
enough context in the subrepo module to distinguish this case. This same issue
can be caused with other subrepo aware commands, so there is a general issue
here beyond the scope of this fix.
A simpler attempt I tried was to add an '_updating' boolean to localrepo, and
set/clear it around the call to mergemod.update() in hg.updaterepo(). That
mostly worked, but doesn't handle the case where archive will clone the subrepo
if it is missing. (I vaguely recall that there may be other commands that will
clone if needed like this, but certainly not all do. It seems both handy, and a
bit surprising for what should be a read only operation. It might be nice if
all commands did this consistently, but we probably need Angel's subrepo caching
first, to not make a mess of the working directory.)
I originally handled 'Exception' in order to pick up the Aborts raised in
subrepo.state(), but this turns out to be unnecessary because that is called
once and cached by ctx.sub() when iterating the subrepos.
It was suggested in the bug discussion to skip looking at the subrepo links
unless -S is specified. I don't really like that idea because missing a subrepo
or (less likely, but worse) a corrupt .hgsubstate is a problem of the parent
repo when checking out a revision. The -S option seems like a better fit for
functionality that would recurse into each subrepo and do a full verification.
Ultimately, the default value for 'allowcreate' should probably be flipped, but
since the default behavior was to allow creation, this is less risky for now.
2016-04-28 05:45:52 +03:00
|
|
|
def sub(self, path, allowcreate=True):
|
2015-06-17 06:03:36 +03:00
|
|
|
'''return a subrepo for the stored revision of path, never wdir()'''
|
verify: don't init subrepo when missing one is referenced (issue5128) (API)
Initializing a subrepo when one doesn't exist is the right thing to do when the
parent is being updated, but in few other cases. Unfortunately, there isn't
enough context in the subrepo module to distinguish this case. This same issue
can be caused with other subrepo aware commands, so there is a general issue
here beyond the scope of this fix.
A simpler attempt I tried was to add an '_updating' boolean to localrepo, and
set/clear it around the call to mergemod.update() in hg.updaterepo(). That
mostly worked, but doesn't handle the case where archive will clone the subrepo
if it is missing. (I vaguely recall that there may be other commands that will
clone if needed like this, but certainly not all do. It seems both handy, and a
bit surprising for what should be a read only operation. It might be nice if
all commands did this consistently, but we probably need Angel's subrepo caching
first, to not make a mess of the working directory.)
I originally handled 'Exception' in order to pick up the Aborts raised in
subrepo.state(), but this turns out to be unnecessary because that is called
once and cached by ctx.sub() when iterating the subrepos.
It was suggested in the bug discussion to skip looking at the subrepo links
unless -S is specified. I don't really like that idea because missing a subrepo
or (less likely, but worse) a corrupt .hgsubstate is a problem of the parent
repo when checking out a revision. The -S option seems like a better fit for
functionality that would recurse into each subrepo and do a full verification.
Ultimately, the default value for 'allowcreate' should probably be flipped, but
since the default behavior was to allow creation, this is less risky for now.
2016-04-28 05:45:52 +03:00
|
|
|
return subrepo.subrepo(self, path, allowcreate=allowcreate)
|
2013-08-06 03:40:36 +04:00
|
|
|
|
2015-06-03 20:51:27 +03:00
|
|
|
def nullsub(self, path, pctx):
|
|
|
|
return subrepo.nullsubrepo(self, path, pctx)
|
|
|
|
|
2015-06-17 06:03:36 +03:00
|
|
|
def workingsub(self, path):
|
|
|
|
'''return a subrepo for the stored revision, or wdir if this is a wdir
|
|
|
|
context.
|
|
|
|
'''
|
|
|
|
return subrepo.subrepo(self, path, allowwdir=True)
|
|
|
|
|
2015-05-16 07:36:35 +03:00
|
|
|
def match(self, pats=[], include=None, exclude=None, default='glob',
|
2015-06-06 02:01:04 +03:00
|
|
|
listsubrepos=False, badfn=None):
|
2013-08-06 03:41:00 +04:00
|
|
|
r = self._repo
|
|
|
|
return matchmod.match(r.root, r.getcwd(), pats,
|
|
|
|
include, exclude, default,
|
2015-12-04 00:23:46 +03:00
|
|
|
auditor=r.nofsauditor, ctx=self,
|
2015-06-06 02:01:04 +03:00
|
|
|
listsubrepos=listsubrepos, badfn=badfn)
|
2013-08-06 03:41:00 +04:00
|
|
|
|
2013-08-06 03:41:12 +04:00
|
|
|
def diff(self, ctx2=None, match=None, **opts):
|
|
|
|
"""Returns a diff generator for the given contexts and matcher"""
|
|
|
|
if ctx2 is None:
|
|
|
|
ctx2 = self.p1()
|
2013-08-07 00:11:31 +04:00
|
|
|
if ctx2 is not None:
|
2013-08-06 03:41:12 +04:00
|
|
|
ctx2 = self._repo[ctx2]
|
|
|
|
diffopts = patch.diffopts(self._repo.ui, opts)
|
2014-04-30 01:43:59 +04:00
|
|
|
return patch.diff(self._repo, ctx2, self, match=match, opts=diffopts)
|
2013-08-06 03:41:12 +04:00
|
|
|
|
2013-08-06 03:41:56 +04:00
|
|
|
def dirs(self):
|
2015-03-14 01:23:02 +03:00
|
|
|
return self._manifest.dirs()
|
|
|
|
|
2015-03-14 01:32:45 +03:00
|
|
|
def hasdir(self, dir):
|
|
|
|
return self._manifest.hasdir(dir)
|
2013-08-06 03:41:56 +04:00
|
|
|
|
2014-06-18 07:26:51 +04:00
|
|
|
def dirty(self, missing=False, merge=True, branch=True):
|
2013-08-06 03:42:41 +04:00
|
|
|
return False
|
|
|
|
|
2014-04-25 03:07:42 +04:00
|
|
|
def status(self, other=None, match=None, listignored=False,
|
|
|
|
listclean=False, listunknown=False, listsubrepos=False):
|
|
|
|
"""return status of files between two nodes or node and working
|
|
|
|
directory.
|
|
|
|
|
|
|
|
If other is None, compare this node with working directory.
|
2014-06-01 04:26:15 +04:00
|
|
|
|
|
|
|
returns (modified, added, removed, deleted, unknown, ignored, clean)
|
2014-04-25 03:07:42 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
ctx1 = self
|
|
|
|
ctx2 = self._repo[other]
|
|
|
|
|
|
|
|
# This next code block is, admittedly, fragile logic that tests for
|
|
|
|
# reversing the contexts and wouldn't need to exist if it weren't for
|
|
|
|
# the fast (and common) code path of comparing the working directory
|
|
|
|
# with its first parent.
|
|
|
|
#
|
|
|
|
# What we're aiming for here is the ability to call:
|
|
|
|
#
|
|
|
|
# workingctx.status(parentctx)
|
|
|
|
#
|
|
|
|
# If we always built the manifest for each context and compared those,
|
|
|
|
# then we'd be done. But the special case of the above call means we
|
|
|
|
# just copy the manifest of the parent.
|
|
|
|
reversed = False
|
|
|
|
if (not isinstance(ctx1, changectx)
|
|
|
|
and isinstance(ctx2, changectx)):
|
|
|
|
reversed = True
|
|
|
|
ctx1, ctx2 = ctx2, ctx1
|
|
|
|
|
2014-10-12 10:18:53 +04:00
|
|
|
match = ctx2._matchstatus(ctx1, match)
|
2014-11-13 09:20:36 +03:00
|
|
|
r = scmutil.status([], [], [], [], [], [], [])
|
2014-04-25 03:07:42 +04:00
|
|
|
r = ctx2._buildstatus(ctx1, r, match, listignored, listclean,
|
2014-05-30 01:09:16 +04:00
|
|
|
listunknown)
|
2014-04-25 03:07:42 +04:00
|
|
|
|
|
|
|
if reversed:
|
2014-11-13 08:19:07 +03:00
|
|
|
# Reverse added and removed. Clear deleted, unknown and ignored as
|
|
|
|
# these make no sense to reverse.
|
|
|
|
r = scmutil.status(r.modified, r.removed, r.added, [], [], [],
|
|
|
|
r.clean)
|
2014-04-25 03:07:42 +04:00
|
|
|
|
|
|
|
if listsubrepos:
|
|
|
|
for subpath, sub in scmutil.itersubrepos(ctx1, ctx2):
|
|
|
|
try:
|
2015-11-18 01:42:52 +03:00
|
|
|
rev2 = ctx2.subrev(subpath)
|
|
|
|
except KeyError:
|
|
|
|
# A subrepo that existed in node1 was deleted between
|
|
|
|
# node1 and node2 (inclusive). Thus, ctx2's substate
|
|
|
|
# won't contain that subpath. The best we can do ignore it.
|
|
|
|
rev2 = None
|
2016-02-06 08:09:32 +03:00
|
|
|
submatch = matchmod.subdirmatcher(subpath, match)
|
2015-11-18 01:42:52 +03:00
|
|
|
s = sub.status(rev2, match=submatch, ignored=listignored,
|
|
|
|
clean=listclean, unknown=listunknown,
|
|
|
|
listsubrepos=True)
|
|
|
|
for rfiles, sfiles in zip(r, s):
|
|
|
|
rfiles.extend("%s/%s" % (subpath, f) for f in sfiles)
|
2014-04-25 03:07:42 +04:00
|
|
|
|
|
|
|
for l in r:
|
|
|
|
l.sort()
|
2014-05-28 02:04:48 +04:00
|
|
|
|
2014-11-13 08:19:07 +03:00
|
|
|
return r
|
2014-04-25 03:07:42 +04:00
|
|
|
|
|
|
|
|
2013-11-07 07:09:15 +04:00
|
|
|
def makememctx(repo, parents, text, user, date, branch, files, store,
|
2015-05-22 23:06:45 +03:00
|
|
|
editor=None, extra=None):
|
2013-11-07 07:09:15 +04:00
|
|
|
def getfilectx(repo, memctx, path):
|
2014-08-27 00:03:32 +04:00
|
|
|
data, mode, copied = store.getfile(path)
|
|
|
|
if data is None:
|
|
|
|
return None
|
|
|
|
islink, isexec = mode
|
2013-08-16 01:49:27 +04:00
|
|
|
return memfilectx(repo, path, data, islink=islink, isexec=isexec,
|
|
|
|
copied=copied, memctx=memctx)
|
2015-05-22 23:06:45 +03:00
|
|
|
if extra is None:
|
|
|
|
extra = {}
|
2013-11-07 07:09:15 +04:00
|
|
|
if branch:
|
|
|
|
extra['branch'] = encoding.fromlocal(branch)
|
2015-12-31 11:16:59 +03:00
|
|
|
ctx = memctx(repo, parents, text, files, getfilectx, user,
|
|
|
|
date, extra, editor)
|
2013-11-07 07:09:15 +04:00
|
|
|
return ctx
|
|
|
|
|
2013-07-14 04:59:21 +04:00
|
|
|
class changectx(basectx):
|
2006-06-29 02:07:46 +04:00
|
|
|
"""A changecontext object makes access to data related to a particular
|
2013-10-23 21:49:56 +04:00
|
|
|
changeset convenient. It represents a read-only context already present in
|
2013-07-14 04:59:21 +04:00
|
|
|
the repo."""
|
2008-06-26 22:46:31 +04:00
|
|
|
def __init__(self, repo, changeid=''):
|
2006-06-29 02:07:46 +04:00
|
|
|
"""changeid is a revision number, node, or tag"""
|
2013-08-07 01:42:41 +04:00
|
|
|
|
|
|
|
# since basectx.__new__ already took care of copying the object, we
|
|
|
|
# don't need to do anything in __init__, so we just exit here
|
|
|
|
if isinstance(changeid, basectx):
|
|
|
|
return
|
|
|
|
|
2008-06-26 22:46:31 +04:00
|
|
|
if changeid == '':
|
|
|
|
changeid = '.'
|
2006-06-29 02:07:46 +04:00
|
|
|
self._repo = repo
|
2012-04-08 21:38:07 +04:00
|
|
|
|
2014-10-16 03:05:24 +04:00
|
|
|
try:
|
|
|
|
if isinstance(changeid, int):
|
2014-10-16 03:14:50 +04:00
|
|
|
self._node = repo.changelog.node(changeid)
|
2014-10-16 03:05:24 +04:00
|
|
|
self._rev = changeid
|
|
|
|
return
|
|
|
|
if isinstance(changeid, long):
|
|
|
|
changeid = str(changeid)
|
|
|
|
if changeid == 'null':
|
|
|
|
self._node = nullid
|
|
|
|
self._rev = nullrev
|
|
|
|
return
|
|
|
|
if changeid == 'tip':
|
|
|
|
self._node = repo.changelog.tip()
|
|
|
|
self._rev = repo.changelog.rev(self._node)
|
|
|
|
return
|
2014-11-20 23:15:12 +03:00
|
|
|
if changeid == '.' or changeid == repo.dirstate.p1():
|
|
|
|
# this is a hack to delay/avoid loading obsmarkers
|
|
|
|
# when we know that '.' won't be hidden
|
|
|
|
self._node = repo.dirstate.p1()
|
|
|
|
self._rev = repo.unfiltered().changelog.rev(self._node)
|
|
|
|
return
|
2014-10-16 03:05:24 +04:00
|
|
|
if len(changeid) == 20:
|
|
|
|
try:
|
|
|
|
self._node = changeid
|
|
|
|
self._rev = repo.changelog.rev(changeid)
|
|
|
|
return
|
2014-10-16 07:37:44 +04:00
|
|
|
except error.FilteredRepoLookupError:
|
|
|
|
raise
|
2014-10-16 03:05:24 +04:00
|
|
|
except LookupError:
|
|
|
|
pass
|
|
|
|
|
2012-04-08 21:38:07 +04:00
|
|
|
try:
|
2014-10-16 03:05:24 +04:00
|
|
|
r = int(changeid)
|
|
|
|
if str(r) != changeid:
|
|
|
|
raise ValueError
|
|
|
|
l = len(repo.changelog)
|
|
|
|
if r < 0:
|
|
|
|
r += l
|
|
|
|
if r < 0 or r >= l:
|
|
|
|
raise ValueError
|
|
|
|
self._rev = r
|
|
|
|
self._node = repo.changelog.node(r)
|
2012-04-08 21:38:07 +04:00
|
|
|
return
|
2014-10-16 07:37:44 +04:00
|
|
|
except error.FilteredIndexError:
|
|
|
|
raise
|
2014-10-16 03:05:24 +04:00
|
|
|
except (ValueError, OverflowError, IndexError):
|
2012-04-08 21:38:07 +04:00
|
|
|
pass
|
|
|
|
|
2014-10-16 03:05:24 +04:00
|
|
|
if len(changeid) == 40:
|
|
|
|
try:
|
|
|
|
self._node = bin(changeid)
|
|
|
|
self._rev = repo.changelog.rev(self._node)
|
|
|
|
return
|
2014-10-16 07:37:44 +04:00
|
|
|
except error.FilteredLookupError:
|
|
|
|
raise
|
2014-10-16 03:05:24 +04:00
|
|
|
except (TypeError, LookupError):
|
|
|
|
pass
|
|
|
|
|
2014-10-17 10:27:54 +04:00
|
|
|
# lookup bookmarks through the name interface
|
|
|
|
try:
|
2014-12-15 06:11:44 +03:00
|
|
|
self._node = repo.names.singlenode(repo, changeid)
|
2014-10-16 03:05:24 +04:00
|
|
|
self._rev = repo.changelog.rev(self._node)
|
|
|
|
return
|
2014-10-17 10:27:54 +04:00
|
|
|
except KeyError:
|
|
|
|
pass
|
2014-10-16 07:37:44 +04:00
|
|
|
except error.FilteredRepoLookupError:
|
|
|
|
raise
|
2014-10-16 03:05:24 +04:00
|
|
|
except error.RepoLookupError:
|
2012-04-08 21:38:07 +04:00
|
|
|
pass
|
|
|
|
|
2014-10-16 07:37:44 +04:00
|
|
|
self._node = repo.unfiltered().changelog._partialmatch(changeid)
|
2014-10-16 03:05:24 +04:00
|
|
|
if self._node is not None:
|
|
|
|
self._rev = repo.changelog.rev(self._node)
|
|
|
|
return
|
2012-04-08 21:38:07 +04:00
|
|
|
|
2014-10-16 03:05:24 +04:00
|
|
|
# lookup failed
|
|
|
|
# check if it might have come from damaged dirstate
|
|
|
|
#
|
|
|
|
# XXX we could avoid the unfiltered if we had a recognizable
|
|
|
|
# exception for filtered changeset access
|
|
|
|
if changeid in repo.unfiltered().dirstate.parents():
|
|
|
|
msg = _("working directory has unknown parent '%s'!")
|
|
|
|
raise error.Abort(msg % short(changeid))
|
|
|
|
try:
|
2015-10-09 02:19:37 +03:00
|
|
|
if len(changeid) == 20 and nonascii(changeid):
|
2014-10-16 03:05:24 +04:00
|
|
|
changeid = hex(changeid)
|
|
|
|
except TypeError:
|
|
|
|
pass
|
2014-10-16 07:37:44 +04:00
|
|
|
except (error.FilteredIndexError, error.FilteredLookupError,
|
|
|
|
error.FilteredRepoLookupError):
|
2015-05-04 20:38:45 +03:00
|
|
|
if repo.filtername.startswith('visible'):
|
2014-10-18 02:25:32 +04:00
|
|
|
msg = _("hidden revision '%s'") % changeid
|
|
|
|
hint = _('use --hidden to access hidden revisions')
|
|
|
|
raise error.FilteredRepoLookupError(msg, hint=hint)
|
2014-10-18 02:54:43 +04:00
|
|
|
msg = _("filtered revision '%s' (not in '%s' subset)")
|
|
|
|
msg %= (changeid, repo.filtername)
|
|
|
|
raise error.FilteredRepoLookupError(msg)
|
2014-10-16 03:14:50 +04:00
|
|
|
except IndexError:
|
|
|
|
pass
|
2012-04-08 21:38:07 +04:00
|
|
|
raise error.RepoLookupError(
|
|
|
|
_("unknown revision '%s'") % changeid)
|
2006-06-29 02:07:46 +04:00
|
|
|
|
2008-04-05 00:41:17 +04:00
|
|
|
def __hash__(self):
|
|
|
|
try:
|
|
|
|
return hash(self._rev)
|
|
|
|
except AttributeError:
|
|
|
|
return id(self)
|
|
|
|
|
2006-09-30 02:47:51 +04:00
|
|
|
def __nonzero__(self):
|
2006-10-29 12:53:51 +03:00
|
|
|
return self._rev != nullrev
|
2006-09-30 02:47:51 +04:00
|
|
|
|
2009-04-24 20:47:15 +04:00
|
|
|
@propertycache
|
2008-11-14 14:44:26 +03:00
|
|
|
def _changeset(self):
|
2016-03-07 00:26:37 +03:00
|
|
|
return self._repo.changelog.changelogrevision(self.rev())
|
2008-11-14 14:44:26 +03:00
|
|
|
|
2009-04-24 20:47:15 +04:00
|
|
|
@propertycache
|
2008-11-14 14:44:26 +03:00
|
|
|
def _manifest(self):
|
2016-11-08 19:03:43 +03:00
|
|
|
return self._manifestctx.read()
|
|
|
|
|
|
|
|
@propertycache
|
|
|
|
def _manifestctx(self):
|
|
|
|
return self._repo.manifestlog[self._changeset.manifest]
|
2008-11-14 14:44:26 +03:00
|
|
|
|
2009-04-24 20:47:15 +04:00
|
|
|
@propertycache
|
2008-11-14 14:44:26 +03:00
|
|
|
def _manifestdelta(self):
|
2016-11-08 19:03:43 +03:00
|
|
|
return self._manifestctx.readdelta()
|
2008-11-14 14:44:26 +03:00
|
|
|
|
2009-04-24 20:47:15 +04:00
|
|
|
@propertycache
|
2008-11-14 14:44:26 +03:00
|
|
|
def _parents(self):
|
2015-11-22 06:04:12 +03:00
|
|
|
repo = self._repo
|
|
|
|
p1, p2 = repo.changelog.parentrevs(self._rev)
|
|
|
|
if p2 == nullrev:
|
|
|
|
return [changectx(repo, p1)]
|
|
|
|
return [changectx(repo, p1), changectx(repo, p2)]
|
2006-10-03 00:17:59 +04:00
|
|
|
|
2010-01-25 09:05:27 +03:00
|
|
|
def changeset(self):
|
2016-03-07 00:26:37 +03:00
|
|
|
c = self._changeset
|
|
|
|
return (
|
|
|
|
c.manifest,
|
|
|
|
c.user,
|
|
|
|
c.date,
|
|
|
|
c.files,
|
|
|
|
c.description,
|
|
|
|
c.extra,
|
|
|
|
)
|
2010-01-25 09:05:27 +03:00
|
|
|
def manifestnode(self):
|
2016-03-07 00:26:37 +03:00
|
|
|
return self._changeset.manifest
|
2010-01-25 09:05:27 +03:00
|
|
|
|
|
|
|
def user(self):
|
2016-03-07 00:26:37 +03:00
|
|
|
return self._changeset.user
|
2010-01-25 09:05:27 +03:00
|
|
|
def date(self):
|
2016-03-07 00:26:37 +03:00
|
|
|
return self._changeset.date
|
2010-01-25 09:05:27 +03:00
|
|
|
def files(self):
|
2016-03-07 00:26:37 +03:00
|
|
|
return self._changeset.files
|
2010-01-25 09:05:27 +03:00
|
|
|
def description(self):
|
2016-03-07 00:26:37 +03:00
|
|
|
return self._changeset.description
|
2010-01-25 09:05:27 +03:00
|
|
|
def branch(self):
|
2016-03-07 00:26:37 +03:00
|
|
|
return encoding.tolocal(self._changeset.extra.get("branch"))
|
2012-05-13 16:04:06 +04:00
|
|
|
def closesbranch(self):
|
2016-03-07 00:26:37 +03:00
|
|
|
return 'close' in self._changeset.extra
|
2010-01-25 09:05:27 +03:00
|
|
|
def extra(self):
|
2016-03-07 00:26:37 +03:00
|
|
|
return self._changeset.extra
|
2010-01-25 09:05:27 +03:00
|
|
|
def tags(self):
|
|
|
|
return self._repo.nodetags(self._node)
|
2011-02-11 21:36:15 +03:00
|
|
|
def bookmarks(self):
|
|
|
|
return self._repo.nodebookmarks(self._node)
|
2011-10-18 20:25:53 +04:00
|
|
|
def phase(self):
|
2012-05-12 02:24:07 +04:00
|
|
|
return self._repo._phasecache.phase(self._repo, self._rev)
|
2011-06-16 03:57:59 +04:00
|
|
|
def hidden(self):
|
2013-01-13 11:39:16 +04:00
|
|
|
return self._rev in repoview.filterrevs(self._repo, 'visible')
|
2006-06-29 02:07:46 +04:00
|
|
|
|
|
|
|
def children(self):
|
|
|
|
"""return contexts for each child changeset"""
|
2006-07-16 18:39:02 +04:00
|
|
|
c = self._repo.changelog.children(self._node)
|
2006-11-17 10:06:54 +03:00
|
|
|
return [changectx(self._repo, x) for x in c]
|
2006-06-29 02:07:46 +04:00
|
|
|
|
2008-08-11 03:38:43 +04:00
|
|
|
def ancestors(self):
|
2012-06-01 23:37:18 +04:00
|
|
|
for a in self._repo.changelog.ancestors([self._rev]):
|
2008-08-11 03:38:43 +04:00
|
|
|
yield changectx(self._repo, a)
|
|
|
|
|
|
|
|
def descendants(self):
|
2012-06-01 23:45:16 +04:00
|
|
|
for d in self._repo.changelog.descendants([self._rev]):
|
2008-08-11 03:38:43 +04:00
|
|
|
yield changectx(self._repo, d)
|
|
|
|
|
2006-12-25 20:57:55 +03:00
|
|
|
def filectx(self, path, fileid=None, filelog=None):
|
2006-06-29 02:07:46 +04:00
|
|
|
"""get a file context from this changeset"""
|
2006-07-16 18:39:03 +04:00
|
|
|
if fileid is None:
|
|
|
|
fileid = self.filenode(path)
|
2006-12-25 20:57:55 +03:00
|
|
|
return filectx(self._repo, path, fileid=fileid,
|
|
|
|
changectx=self, filelog=filelog)
|
2006-06-29 02:07:46 +04:00
|
|
|
|
2014-04-30 23:19:01 +04:00
|
|
|
def ancestor(self, c2, warn=False):
|
2014-08-19 03:13:10 +04:00
|
|
|
"""return the "best" ancestor context of self and c2
|
|
|
|
|
|
|
|
If there are multiple candidates, it will show a message and check
|
|
|
|
merge.preferancestor configuration before falling back to the
|
|
|
|
revlog ancestor."""
|
2009-11-12 21:03:39 +03:00
|
|
|
# deal with workingctxs
|
|
|
|
n2 = c2._node
|
2010-11-22 20:15:58 +03:00
|
|
|
if n2 is None:
|
2009-11-12 21:03:39 +03:00
|
|
|
n2 = c2._parents[0]._node
|
2014-04-17 19:32:04 +04:00
|
|
|
cahs = self._repo.changelog.commonancestorsheads(self._node, n2)
|
|
|
|
if not cahs:
|
|
|
|
anc = nullid
|
|
|
|
elif len(cahs) == 1:
|
|
|
|
anc = cahs[0]
|
|
|
|
else:
|
2015-06-26 01:54:55 +03:00
|
|
|
# experimental config: merge.preferancestor
|
|
|
|
for r in self._repo.ui.configlist('merge', 'preferancestor', ['*']):
|
2014-10-01 05:40:51 +04:00
|
|
|
try:
|
|
|
|
ctx = changectx(self._repo, r)
|
|
|
|
except error.RepoLookupError:
|
2014-08-15 04:46:44 +04:00
|
|
|
continue
|
2014-02-25 01:42:14 +04:00
|
|
|
anc = ctx.node()
|
|
|
|
if anc in cahs:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
anc = self._repo.changelog.ancestor(self._node, n2)
|
2014-04-30 23:19:01 +04:00
|
|
|
if warn:
|
|
|
|
self._repo.ui.status(
|
|
|
|
(_("note: using %s as ancestor of %s and %s\n") %
|
|
|
|
(short(anc), short(self._node), short(n2))) +
|
|
|
|
''.join(_(" alternatively, use --config "
|
|
|
|
"merge.preferancestor=%s\n") %
|
|
|
|
short(n) for n in sorted(cahs) if n != anc))
|
2014-04-17 19:32:04 +04:00
|
|
|
return changectx(self._repo, anc)
|
2006-09-18 07:59:33 +04:00
|
|
|
|
2012-09-18 16:39:12 +04:00
|
|
|
def descendant(self, other):
|
|
|
|
"""True if other is descendant of this changeset"""
|
|
|
|
return self._repo.changelog.descendant(self._rev, other._rev)
|
|
|
|
|
2008-06-28 04:25:48 +04:00
|
|
|
def walk(self, match):
|
2015-04-08 01:18:52 +03:00
|
|
|
'''Generates matching file names.'''
|
|
|
|
|
2015-06-05 04:37:59 +03:00
|
|
|
# Wrap match.bad method to have message with nodeid
|
2015-04-08 01:18:52 +03:00
|
|
|
def bad(fn, msg):
|
2015-05-17 08:06:10 +03:00
|
|
|
# The manifest doesn't know about subrepos, so don't complain about
|
|
|
|
# paths into valid subrepos.
|
2015-05-19 15:17:57 +03:00
|
|
|
if any(fn == s or fn.startswith(s + '/')
|
|
|
|
for s in self.substate):
|
2015-05-17 08:06:10 +03:00
|
|
|
return
|
2015-06-05 04:37:59 +03:00
|
|
|
match.bad(fn, _('no such file in rev %s') % self)
|
2015-04-08 01:18:52 +03:00
|
|
|
|
2015-06-05 04:37:59 +03:00
|
|
|
m = matchmod.badmatch(match, bad)
|
|
|
|
return self._manifest.walk(m)
|
2008-06-28 04:25:48 +04:00
|
|
|
|
2014-08-02 09:07:29 +04:00
|
|
|
def matches(self, match):
|
|
|
|
return self.walk(match)
|
|
|
|
|
2013-08-11 00:10:26 +04:00
|
|
|
class basefilectx(object):
|
|
|
|
"""A filecontext object represents the common logic for its children:
|
|
|
|
filectx: read-only access to a filerevision that is already present
|
|
|
|
in the repo,
|
|
|
|
workingfilectx: a filecontext that represents files from the working
|
|
|
|
directory,
|
|
|
|
memfilectx: a filecontext that represents files in-memory."""
|
|
|
|
def __new__(cls, repo, path, *args, **kwargs):
|
|
|
|
return super(basefilectx, cls).__new__(cls)
|
|
|
|
|
2013-08-12 07:40:59 +04:00
|
|
|
@propertycache
|
|
|
|
def _filelog(self):
|
|
|
|
return self._repo.file(self._path)
|
|
|
|
|
2013-08-12 07:44:06 +04:00
|
|
|
@propertycache
|
|
|
|
def _changeid(self):
|
|
|
|
if '_changeid' in self.__dict__:
|
|
|
|
return self._changeid
|
|
|
|
elif '_changectx' in self.__dict__:
|
|
|
|
return self._changectx.rev()
|
2015-02-02 01:26:35 +03:00
|
|
|
elif '_descendantrev' in self.__dict__:
|
|
|
|
# this file context was created from a revision with a known
|
|
|
|
# descendant, we can (lazily) correct for linkrev aliases
|
2016-11-01 11:22:50 +03:00
|
|
|
return self._adjustlinkrev(self._descendantrev)
|
2013-08-12 07:44:06 +04:00
|
|
|
else:
|
|
|
|
return self._filelog.linkrev(self._filerev)
|
|
|
|
|
2013-08-12 07:44:19 +04:00
|
|
|
@propertycache
|
|
|
|
def _filenode(self):
|
|
|
|
if '_fileid' in self.__dict__:
|
|
|
|
return self._filelog.lookup(self._fileid)
|
|
|
|
else:
|
|
|
|
return self._changectx.filenode(self._path)
|
|
|
|
|
2013-08-12 07:44:36 +04:00
|
|
|
@propertycache
|
|
|
|
def _filerev(self):
|
|
|
|
return self._filelog.rev(self._filenode)
|
|
|
|
|
2013-08-12 07:44:51 +04:00
|
|
|
@propertycache
|
|
|
|
def _repopath(self):
|
|
|
|
return self._path
|
|
|
|
|
2013-08-12 07:45:13 +04:00
|
|
|
def __nonzero__(self):
|
|
|
|
try:
|
|
|
|
self._filenode
|
|
|
|
return True
|
|
|
|
except error.LookupError:
|
|
|
|
# file is missing
|
|
|
|
return False
|
|
|
|
|
2013-08-12 07:45:30 +04:00
|
|
|
def __str__(self):
|
2015-03-20 00:22:50 +03:00
|
|
|
try:
|
|
|
|
return "%s@%s" % (self.path(), self._changectx)
|
|
|
|
except error.LookupError:
|
|
|
|
return "%s@???" % self.path()
|
2013-08-12 07:45:30 +04:00
|
|
|
|
2013-08-12 07:46:54 +04:00
|
|
|
def __repr__(self):
|
|
|
|
return "<%s %s>" % (type(self).__name__, str(self))
|
|
|
|
|
2013-08-12 07:47:39 +04:00
|
|
|
def __hash__(self):
|
|
|
|
try:
|
|
|
|
return hash((self._path, self._filenode))
|
|
|
|
except AttributeError:
|
|
|
|
return id(self)
|
|
|
|
|
2013-08-12 07:49:03 +04:00
|
|
|
def __eq__(self, other):
|
|
|
|
try:
|
|
|
|
return (type(self) == type(other) and self._path == other._path
|
|
|
|
and self._filenode == other._filenode)
|
|
|
|
except AttributeError:
|
|
|
|
return False
|
|
|
|
|
2013-08-12 07:49:40 +04:00
|
|
|
def __ne__(self, other):
|
|
|
|
return not (self == other)
|
|
|
|
|
2013-08-12 07:50:15 +04:00
|
|
|
def filerev(self):
|
|
|
|
return self._filerev
|
2013-08-12 07:50:37 +04:00
|
|
|
def filenode(self):
|
|
|
|
return self._filenode
|
2013-08-12 07:51:04 +04:00
|
|
|
def flags(self):
|
|
|
|
return self._changectx.flags(self._path)
|
2013-08-12 07:51:18 +04:00
|
|
|
def filelog(self):
|
|
|
|
return self._filelog
|
2013-08-12 07:51:30 +04:00
|
|
|
def rev(self):
|
|
|
|
return self._changeid
|
2013-08-12 07:51:41 +04:00
|
|
|
def linkrev(self):
|
|
|
|
return self._filelog.linkrev(self._filerev)
|
2013-08-12 07:51:53 +04:00
|
|
|
def node(self):
|
|
|
|
return self._changectx.node()
|
2013-08-12 07:53:23 +04:00
|
|
|
def hex(self):
|
|
|
|
return self._changectx.hex()
|
2013-08-12 07:53:47 +04:00
|
|
|
def user(self):
|
|
|
|
return self._changectx.user()
|
2013-08-12 07:53:56 +04:00
|
|
|
def date(self):
|
|
|
|
return self._changectx.date()
|
2013-08-12 07:54:12 +04:00
|
|
|
def files(self):
|
|
|
|
return self._changectx.files()
|
2013-08-12 07:54:22 +04:00
|
|
|
def description(self):
|
|
|
|
return self._changectx.description()
|
2013-08-12 07:54:31 +04:00
|
|
|
def branch(self):
|
|
|
|
return self._changectx.branch()
|
2013-08-12 07:54:39 +04:00
|
|
|
def extra(self):
|
|
|
|
return self._changectx.extra()
|
2013-08-12 07:54:48 +04:00
|
|
|
def phase(self):
|
|
|
|
return self._changectx.phase()
|
2013-08-12 07:54:58 +04:00
|
|
|
def phasestr(self):
|
|
|
|
return self._changectx.phasestr()
|
2013-08-12 07:55:09 +04:00
|
|
|
def manifest(self):
|
|
|
|
return self._changectx.manifest()
|
2013-08-12 07:56:02 +04:00
|
|
|
def changectx(self):
|
|
|
|
return self._changectx
|
2015-03-14 03:34:52 +03:00
|
|
|
def repo(self):
|
|
|
|
return self._repo
|
2013-08-12 07:50:15 +04:00
|
|
|
|
2013-08-12 07:56:18 +04:00
|
|
|
def path(self):
|
|
|
|
return self._path
|
|
|
|
|
2013-08-12 07:56:30 +04:00
|
|
|
def isbinary(self):
|
|
|
|
try:
|
|
|
|
return util.binary(self.data())
|
|
|
|
except IOError:
|
|
|
|
return False
|
2014-07-26 05:11:47 +04:00
|
|
|
def isexec(self):
|
|
|
|
return 'x' in self.flags()
|
|
|
|
def islink(self):
|
|
|
|
return 'l' in self.flags()
|
2013-08-12 07:56:30 +04:00
|
|
|
|
2015-11-16 22:27:27 +03:00
|
|
|
def isabsent(self):
|
|
|
|
"""whether this filectx represents a file not in self._changectx
|
|
|
|
|
|
|
|
This is mainly for merge code to detect change/delete conflicts. This is
|
|
|
|
expected to be True for all subclasses of basectx."""
|
|
|
|
return False
|
|
|
|
|
2015-11-14 09:37:51 +03:00
|
|
|
_customcmp = False
|
2013-08-12 07:56:53 +04:00
|
|
|
def cmp(self, fctx):
|
|
|
|
"""compare with other file context
|
|
|
|
|
|
|
|
returns True if different than fctx.
|
|
|
|
"""
|
2015-11-14 09:37:51 +03:00
|
|
|
if fctx._customcmp:
|
|
|
|
return fctx.cmp(self)
|
|
|
|
|
2016-02-09 01:17:11 +03:00
|
|
|
if (fctx._filenode is None
|
2013-08-12 07:56:53 +04:00
|
|
|
and (self._repo._encodefilterpats
|
|
|
|
# if file data starts with '\1\n', empty metadata block is
|
|
|
|
# prepended, which adds 4 bytes to filelog.size().
|
|
|
|
or self.size() - 4 == fctx.size())
|
|
|
|
or self.size() == fctx.size()):
|
|
|
|
return self._filelog.cmp(self._filenode, fctx.data())
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2016-11-01 11:22:50 +03:00
|
|
|
def _adjustlinkrev(self, srcrev, inclusive=False):
|
2015-01-18 04:38:57 +03:00
|
|
|
"""return the first ancestor of <srcrev> introducing <fnode>
|
2015-01-30 17:39:03 +03:00
|
|
|
|
|
|
|
If the linkrev of the file revision does not point to an ancestor of
|
|
|
|
srcrev, we'll walk down the ancestors until we find one introducing
|
|
|
|
this file revision.
|
|
|
|
|
|
|
|
:srcrev: the changeset revision we search ancestors from
|
|
|
|
:inclusive: if true, the src revision will also be checked
|
|
|
|
"""
|
|
|
|
repo = self._repo
|
|
|
|
cl = repo.unfiltered().changelog
|
2016-09-14 02:26:30 +03:00
|
|
|
mfl = repo.manifestlog
|
2015-01-30 17:39:03 +03:00
|
|
|
# fetch the linkrev
|
2016-11-01 11:22:50 +03:00
|
|
|
lkr = self.linkrev()
|
2015-01-30 19:02:28 +03:00
|
|
|
# hack to reuse ancestor computation when searching for renames
|
|
|
|
memberanc = getattr(self, '_ancestrycontext', None)
|
|
|
|
iteranc = None
|
2015-03-20 09:57:34 +03:00
|
|
|
if srcrev is None:
|
|
|
|
# wctx case, used by workingfilectx during mergecopy
|
|
|
|
revs = [p.rev() for p in self._repo[None].parents()]
|
|
|
|
inclusive = True # we skipped the real (revless) source
|
|
|
|
else:
|
|
|
|
revs = [srcrev]
|
2015-01-30 19:02:28 +03:00
|
|
|
if memberanc is None:
|
2015-03-20 09:57:34 +03:00
|
|
|
memberanc = iteranc = cl.ancestors(revs, lkr,
|
2015-01-30 19:02:28 +03:00
|
|
|
inclusive=inclusive)
|
2015-01-30 17:39:03 +03:00
|
|
|
# check if this linkrev is an ancestor of srcrev
|
2015-01-30 19:02:28 +03:00
|
|
|
if lkr not in memberanc:
|
|
|
|
if iteranc is None:
|
2015-03-20 09:52:26 +03:00
|
|
|
iteranc = cl.ancestors(revs, lkr, inclusive=inclusive)
|
2016-11-01 11:22:50 +03:00
|
|
|
fnode = self._filenode
|
|
|
|
path = self._path
|
2015-01-30 19:02:28 +03:00
|
|
|
for a in iteranc:
|
2015-01-30 17:39:03 +03:00
|
|
|
ac = cl.read(a) # get changeset data (we avoid object creation)
|
|
|
|
if path in ac[3]: # checking the 'files' field.
|
|
|
|
# The file has been touched, check if the content is
|
|
|
|
# similar to the one we search for.
|
2016-09-14 02:26:30 +03:00
|
|
|
if fnode == mfl[ac[0]].readfast().get(path):
|
2015-01-30 17:39:03 +03:00
|
|
|
return a
|
|
|
|
# In theory, we should never get out of that loop without a result.
|
|
|
|
# But if manifest uses a buggy file revision (not children of the
|
|
|
|
# one it replaces) we could. Such a buggy situation will likely
|
|
|
|
# result is crash somewhere else at to some point.
|
|
|
|
return lkr
|
|
|
|
|
linkrev: introduce an 'introrev' method on filectx
The previous changeset properly fixed the ancestors computation, but we need to
ensure that the initial filectx is also using the right changeset.
When asking for log or annotation from a certain point, the first step is to
define the changeset that introduced the current file version. We cannot just
pick the "starting point" changesets as it may just "use" the file revision,
unchanged.
Currently, we were using 'linkrev' for this purpose, but this exposes us to
unexpected branch-jumping when the revision introducing the starting point
version is itself linkrev-shadowed. So we need to take the topology into
account again. Therefore, we introduce an 'introrev' function, returning the
changeset which introduced the file change in the current changeset.
This function will be used to fix linkrev-related issues when bootstrapping 'hg
log --follow' and 'hg annotate'.
It reuses the '_adjustlinkrev' function, extending it to allow introspection of
the initial changeset too. In the previous usage of the '_adjustlinkrev' the
starting rev was always using a children file revisions, so it could be safely
ignored in the search. In this case, the starting point is using the revision
of the file we are looking, and may be the changeset we are looking for.
2014-12-24 03:14:39 +03:00
|
|
|
def introrev(self):
|
|
|
|
"""return the rev of the changeset which introduced this file revision
|
|
|
|
|
|
|
|
This method is different from linkrev because it take into account the
|
|
|
|
changeset the filectx was created from. It ensures the returned
|
|
|
|
revision is one of its ancestors. This prevents bugs from
|
|
|
|
'linkrev-shadowing' when a file revision is used by multiple
|
|
|
|
changesets.
|
|
|
|
"""
|
|
|
|
lkr = self.linkrev()
|
|
|
|
attrs = vars(self)
|
|
|
|
noctx = not ('_changeid' in attrs or '_changectx' in attrs)
|
|
|
|
if noctx or self.rev() == lkr:
|
|
|
|
return self.linkrev()
|
2016-11-01 11:22:50 +03:00
|
|
|
return self._adjustlinkrev(self.rev(), inclusive=True)
|
linkrev: introduce an 'introrev' method on filectx
The previous changeset properly fixed the ancestors computation, but we need to
ensure that the initial filectx is also using the right changeset.
When asking for log or annotation from a certain point, the first step is to
define the changeset that introduced the current file version. We cannot just
pick the "starting point" changesets as it may just "use" the file revision,
unchanged.
Currently, we were using 'linkrev' for this purpose, but this exposes us to
unexpected branch-jumping when the revision introducing the starting point
version is itself linkrev-shadowed. So we need to take the topology into
account again. Therefore, we introduce an 'introrev' function, returning the
changeset which introduced the file change in the current changeset.
This function will be used to fix linkrev-related issues when bootstrapping 'hg
log --follow' and 'hg annotate'.
It reuses the '_adjustlinkrev' function, extending it to allow introspection of
the initial changeset too. In the previous usage of the '_adjustlinkrev' the
starting rev was always using a children file revisions, so it could be safely
ignored in the search. In this case, the starting point is using the revision
of the file we are looking, and may be the changeset we are looking for.
2014-12-24 03:14:39 +03:00
|
|
|
|
2015-04-18 08:03:41 +03:00
|
|
|
def _parentfilectx(self, path, fileid, filelog):
|
|
|
|
"""create parent filectx keeping ancestry info for _adjustlinkrev()"""
|
|
|
|
fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog)
|
|
|
|
if '_changeid' in vars(self) or '_changectx' in vars(self):
|
|
|
|
# If self is associated with a changeset (probably explicitly
|
|
|
|
# fed), ensure the created filectx is associated with a
|
|
|
|
# changeset that is an ancestor of self.changectx.
|
|
|
|
# This lets us later use _adjustlinkrev to get a correct link.
|
|
|
|
fctx._descendantrev = self.rev()
|
|
|
|
fctx._ancestrycontext = getattr(self, '_ancestrycontext', None)
|
|
|
|
elif '_descendantrev' in vars(self):
|
|
|
|
# Otherwise propagate _descendantrev if we have one associated.
|
|
|
|
fctx._descendantrev = self._descendantrev
|
|
|
|
fctx._ancestrycontext = getattr(self, '_ancestrycontext', None)
|
|
|
|
return fctx
|
|
|
|
|
2013-08-12 07:57:21 +04:00
|
|
|
def parents(self):
|
2014-08-15 06:37:46 +04:00
|
|
|
_path = self._path
|
2013-08-12 07:57:21 +04:00
|
|
|
fl = self._filelog
|
2014-12-24 05:29:03 +03:00
|
|
|
parents = self._filelog.parents(self._filenode)
|
|
|
|
pl = [(_path, node, fl) for node in parents if node != nullid]
|
2013-08-12 07:57:21 +04:00
|
|
|
|
filectx.parents: enforce changeid of parent to be in own changectx ancestors
Because of the way filenodes are computed, you can have multiple changesets
"introducing" the same file revision. For example, in the changeset graph
below, changeset 2 and 3 both change a file -to- and -from- the same content.
o 3: content = new
|
| o 2: content = new
|/
o 1: content = old
In such cases, the file revision is create once, when 2 is added, and just reused
for 3. So the file change in '3' (from "old" to "new)" has no linkrev pointing
to it). We'll call this situation "linkrev-shadowing". As the linkrev is used for
optimization purposes when walking a file history, the linkrev-shadowing
results in an unexpected jump to another branch during such a walk.. This leads to
multiple bugs with log, annotate and rename detection.
One element to fix such bugs is to ensure that walking the file history sticks on
the same topology as the changeset's history. For this purpose, we extend the
logic in 'basefilectx.parents' so that it always defines the proper changeset
to associate the parent file revision with. This "proper" changeset has to be an
ancestor of the changeset associated with the child file revision.
This logic is performed in the '_adjustlinkrev' function. This function is
given the starting changeset and all the information regarding the parent file
revision. If the linkrev for the file revision is an ancestor of the starting
changeset, the linkrev is valid and will be used. If it is not, we detected a
topological jump caused by linkrev shadowing, we are going to walk the
ancestors of the starting changeset until we find one setting the file to the
revision we are trying to create.
The performance impact appears acceptable:
- We are walking the changelog once for each filelog traversal (as there should
be no overlap between searches),
- changelog traversal itself is fairly cheap, compared to what is likely going
to be perform on the result on the filelog traversal,
- We only touch the manifest for ancestors touching the file, And such
changesets are likely to be the one introducing the file. (except in
pathological cases involving merge),
- We use manifest diff instead of full manifest unpacking to check manifest
content, so it does not involve applying multiple diffs in most case.
- linkrev shadowing is not the common case.
Tests for fixed issues in log, annotate and rename detection have been
added.
But this changeset does not solve all problems. It fixes -ancestry-
computation, but if the linkrev-shadowed changesets is the starting one, we'll
still get things wrong. We'll have to fix the bootstrapping of such operations
in a later changeset. Also, the usage of `hg log FILE` without --follow still
has issues with linkrev pointing to hidden changesets, because it relies on the
`filelog` revset which implement its own traversal logic that is still to be
fixed.
Thanks goes to:
- Matt Mackall: for nudging me in the right direction
- Julien Cristau and Rémi Cardona: for keep telling me linkrev bug were an
evolution show stopper for 3 years.
- Durham Goode: for finding a new linkrev issue every few weeks
- Mads Kiilerich: for that last rename bug who raise this topic over my
anoyance limit.
2014-12-24 02:30:38 +03:00
|
|
|
r = fl.renamed(self._filenode)
|
2013-08-12 07:57:21 +04:00
|
|
|
if r:
|
2014-12-24 05:29:03 +03:00
|
|
|
# - In the simple rename case, both parent are nullid, pl is empty.
|
|
|
|
# - In case of merge, only one of the parent is null id and should
|
|
|
|
# be replaced with the rename information. This parent is -always-
|
|
|
|
# the first one.
|
|
|
|
#
|
2015-01-18 04:38:57 +03:00
|
|
|
# As null id have always been filtered out in the previous list
|
2014-12-24 05:29:03 +03:00
|
|
|
# comprehension, inserting to 0 will always result in "replacing
|
|
|
|
# first nullid parent with rename information.
|
2014-12-24 05:30:46 +03:00
|
|
|
pl.insert(0, (r[0], r[1], self._repo.file(r[0])))
|
2013-08-12 07:57:21 +04:00
|
|
|
|
2015-04-18 08:03:41 +03:00
|
|
|
return [self._parentfilectx(path, fnode, l) for path, fnode, l in pl]
|
2013-08-12 07:57:21 +04:00
|
|
|
|
2013-08-12 07:59:10 +04:00
|
|
|
def p1(self):
|
|
|
|
return self.parents()[0]
|
|
|
|
|
2013-08-12 08:00:11 +04:00
|
|
|
def p2(self):
|
|
|
|
p = self.parents()
|
|
|
|
if len(p) == 2:
|
|
|
|
return p[1]
|
|
|
|
return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
|
|
|
|
|
2016-07-11 15:44:19 +03:00
|
|
|
def annotate(self, follow=False, linenumber=False, diffopts=None):
|
|
|
|
'''returns a list of tuples of ((ctx, number), line) for each line
|
2006-09-27 20:10:21 +04:00
|
|
|
in the file, where ctx is the filectx of the node where
|
2016-07-11 15:44:19 +03:00
|
|
|
that line was last changed; if linenumber parameter is true, number is
|
|
|
|
the line number at the first appearance in the managed file, otherwise,
|
|
|
|
number has a fixed value of False.
|
|
|
|
'''
|
2007-07-08 21:46:04 +04:00
|
|
|
|
2016-05-19 00:37:32 +03:00
|
|
|
def lines(text):
|
|
|
|
if text.endswith("\n"):
|
|
|
|
return text.count("\n")
|
2016-10-01 16:18:58 +03:00
|
|
|
return text.count("\n") + int(bool(text))
|
2016-05-19 00:37:32 +03:00
|
|
|
|
2016-07-11 15:44:19 +03:00
|
|
|
if linenumber:
|
2014-08-15 09:33:19 +04:00
|
|
|
def decorate(text, rev):
|
2016-05-19 00:37:32 +03:00
|
|
|
return ([(rev, i) for i in xrange(1, lines(text) + 1)], text)
|
2014-08-15 09:29:30 +04:00
|
|
|
else:
|
2014-08-15 09:33:19 +04:00
|
|
|
def decorate(text, rev):
|
2016-05-19 00:37:32 +03:00
|
|
|
return ([(rev, False)] * lines(text), text)
|
2007-07-08 21:46:04 +04:00
|
|
|
|
2006-09-27 20:10:21 +04:00
|
|
|
def pair(parent, child):
|
2016-09-27 15:46:34 +03:00
|
|
|
blocks = mdiff.allblocks(parent[1], child[1], opts=diffopts)
|
2011-11-18 15:04:31 +04:00
|
|
|
for (a1, a2, b1, b2), t in blocks:
|
|
|
|
# Changed blocks ('!') or blocks made only of blank lines ('~')
|
|
|
|
# belong to the child.
|
|
|
|
if t == '=':
|
|
|
|
child[0][b1:b2] = parent[0][a1:a2]
|
2006-09-27 20:10:21 +04:00
|
|
|
return child
|
|
|
|
|
2009-07-10 02:10:07 +04:00
|
|
|
getlog = util.lrucachefunc(lambda x: self._repo.file(x))
|
2006-09-27 20:10:21 +04:00
|
|
|
|
|
|
|
def parents(f):
|
2015-04-25 09:38:06 +03:00
|
|
|
# Cut _descendantrev here to mitigate the penalty of lazy linkrev
|
|
|
|
# adjustment. Otherwise, p._adjustlinkrev() would walk changelog
|
|
|
|
# from the topmost introrev (= srcrev) down to p.linkrev() if it
|
|
|
|
# isn't an ancestor of the srcrev.
|
|
|
|
f._changeid
|
2013-05-31 06:29:03 +04:00
|
|
|
pl = f.parents()
|
|
|
|
|
|
|
|
# Don't return renamed parents if we aren't following.
|
|
|
|
if not follow:
|
|
|
|
pl = [p for p in pl if p.path() == f.path()]
|
|
|
|
|
|
|
|
# renamed filectx won't have a filelog yet, so set it
|
|
|
|
# from the cache to save time
|
|
|
|
for p in pl:
|
|
|
|
if not '_filelog' in p.__dict__:
|
|
|
|
p._filelog = getlog(p.path())
|
|
|
|
|
|
|
|
return pl
|
2006-10-01 21:26:33 +04:00
|
|
|
|
2006-10-16 05:43:46 +04:00
|
|
|
# use linkrev to find the first changeset where self appeared
|
2014-12-24 14:26:48 +03:00
|
|
|
base = self
|
|
|
|
introrev = self.introrev()
|
|
|
|
if self.rev() != introrev:
|
2015-01-09 22:21:29 +03:00
|
|
|
base = self.filectx(self.filenode(), changeid=introrev)
|
2015-04-18 09:27:03 +03:00
|
|
|
if getattr(base, '_ancestrycontext', None) is None:
|
|
|
|
cl = self._repo.changelog
|
|
|
|
if introrev is None:
|
|
|
|
# wctx is not inclusive, but works because _ancestrycontext
|
|
|
|
# is used to test filelog revisions
|
|
|
|
ac = cl.ancestors([p.rev() for p in base.parents()],
|
|
|
|
inclusive=True)
|
|
|
|
else:
|
|
|
|
ac = cl.ancestors([introrev], inclusive=True)
|
2015-03-20 05:52:23 +03:00
|
|
|
base._ancestrycontext = ac
|
2006-10-16 05:43:46 +04:00
|
|
|
|
2011-03-08 00:44:43 +03:00
|
|
|
# This algorithm would prefer to be recursive, but Python is a
|
|
|
|
# bit recursion-hostile. Instead we do an iterative
|
|
|
|
# depth-first search.
|
|
|
|
|
annotate: pre-calculate the "needed" dictionary (issue5360)
The "needed" dict is used as a reference counter to free items in the giant
"hist" dict. However, currently it is not very accurate and can lead to
dropping "hist" items unnecessarily, for example, with the following DAG,
-3-
/ \
0--1--2--4--
The current algorithm will visit and calculate rev 1 twice, undesired. And
it tries to be smart by clearing rev 1's parents: "pcache[1] = []" at the
time hist[1] being accessed (note: hist[1] needs to be used twice, by rev 2
and rev 3). It can result in incorrect results if p1 of rev 4 deletes chunks
belonging to rev 0.
However, simply removing "needed" is not okay, because it will consume 10x
memory:
# without any change
% HGRCPATH= lrun ./hg annotate mercurial/commands.py -r d130a38 3>&2 [1]
MEMORY 49074176
CPUTIME 9.213
REALTIME 9.270
# with "needed" removed
MEMORY 637673472
CPUTIME 8.164
REALTIME 8.249
This patch moves "needed" (and "pcache") calculation to a separate DFS to
address the issue. It improves perf and fixes issue5360 by correctly reusing
hist, while maintaining low memory usage. Some additional attempt has been
made to further reduce memory usage, like changing "pcache[f] = []" to "del
pcache[f]". Therefore the result can be both faster and lower memory usage:
# with this patch applied
MEMORY 47575040
CPUTIME 7.870
REALTIME 7.926
[1]: lrun is a lightweight sandbox built on Linux cgroup and namespace. It's
used to measure CPU and memory usage here. Source code is available at
github.com/quark-zju/lrun.
2016-09-02 17:20:59 +03:00
|
|
|
# 1st DFS pre-calculates pcache and needed
|
2006-10-16 05:43:46 +04:00
|
|
|
visit = [base]
|
2011-03-08 00:44:43 +03:00
|
|
|
pcache = {}
|
|
|
|
needed = {base: 1}
|
annotate: pre-calculate the "needed" dictionary (issue5360)
The "needed" dict is used as a reference counter to free items in the giant
"hist" dict. However, currently it is not very accurate and can lead to
dropping "hist" items unnecessarily, for example, with the following DAG,
-3-
/ \
0--1--2--4--
The current algorithm will visit and calculate rev 1 twice, undesired. And
it tries to be smart by clearing rev 1's parents: "pcache[1] = []" at the
time hist[1] being accessed (note: hist[1] needs to be used twice, by rev 2
and rev 3). It can result in incorrect results if p1 of rev 4 deletes chunks
belonging to rev 0.
However, simply removing "needed" is not okay, because it will consume 10x
memory:
# without any change
% HGRCPATH= lrun ./hg annotate mercurial/commands.py -r d130a38 3>&2 [1]
MEMORY 49074176
CPUTIME 9.213
REALTIME 9.270
# with "needed" removed
MEMORY 637673472
CPUTIME 8.164
REALTIME 8.249
This patch moves "needed" (and "pcache") calculation to a separate DFS to
address the issue. It improves perf and fixes issue5360 by correctly reusing
hist, while maintaining low memory usage. Some additional attempt has been
made to further reduce memory usage, like changing "pcache[f] = []" to "del
pcache[f]". Therefore the result can be both faster and lower memory usage:
# with this patch applied
MEMORY 47575040
CPUTIME 7.870
REALTIME 7.926
[1]: lrun is a lightweight sandbox built on Linux cgroup and namespace. It's
used to measure CPU and memory usage here. Source code is available at
github.com/quark-zju/lrun.
2016-09-02 17:20:59 +03:00
|
|
|
while visit:
|
|
|
|
f = visit.pop()
|
|
|
|
if f in pcache:
|
|
|
|
continue
|
|
|
|
pl = parents(f)
|
|
|
|
pcache[f] = pl
|
|
|
|
for p in pl:
|
|
|
|
needed[p] = needed.get(p, 0) + 1
|
|
|
|
if p not in pcache:
|
|
|
|
visit.append(p)
|
|
|
|
|
|
|
|
# 2nd DFS does the actual annotate
|
|
|
|
visit[:] = [base]
|
|
|
|
hist = {}
|
2006-09-27 20:10:21 +04:00
|
|
|
while visit:
|
2011-03-08 00:44:43 +03:00
|
|
|
f = visit[-1]
|
annotate: pre-calculate the "needed" dictionary (issue5360)
The "needed" dict is used as a reference counter to free items in the giant
"hist" dict. However, currently it is not very accurate and can lead to
dropping "hist" items unnecessarily, for example, with the following DAG,
-3-
/ \
0--1--2--4--
The current algorithm will visit and calculate rev 1 twice, undesired. And
it tries to be smart by clearing rev 1's parents: "pcache[1] = []" at the
time hist[1] being accessed (note: hist[1] needs to be used twice, by rev 2
and rev 3). It can result in incorrect results if p1 of rev 4 deletes chunks
belonging to rev 0.
However, simply removing "needed" is not okay, because it will consume 10x
memory:
# without any change
% HGRCPATH= lrun ./hg annotate mercurial/commands.py -r d130a38 3>&2 [1]
MEMORY 49074176
CPUTIME 9.213
REALTIME 9.270
# with "needed" removed
MEMORY 637673472
CPUTIME 8.164
REALTIME 8.249
This patch moves "needed" (and "pcache") calculation to a separate DFS to
address the issue. It improves perf and fixes issue5360 by correctly reusing
hist, while maintaining low memory usage. Some additional attempt has been
made to further reduce memory usage, like changing "pcache[f] = []" to "del
pcache[f]". Therefore the result can be both faster and lower memory usage:
# with this patch applied
MEMORY 47575040
CPUTIME 7.870
REALTIME 7.926
[1]: lrun is a lightweight sandbox built on Linux cgroup and namespace. It's
used to measure CPU and memory usage here. Source code is available at
github.com/quark-zju/lrun.
2016-09-02 17:20:59 +03:00
|
|
|
if f in hist:
|
|
|
|
visit.pop()
|
|
|
|
continue
|
2011-03-08 00:44:43 +03:00
|
|
|
|
|
|
|
ready = True
|
|
|
|
pl = pcache[f]
|
|
|
|
for p in pl:
|
|
|
|
if p not in hist:
|
|
|
|
ready = False
|
2006-09-27 20:10:21 +04:00
|
|
|
visit.append(p)
|
2011-03-08 00:44:43 +03:00
|
|
|
if ready:
|
|
|
|
visit.pop()
|
annotate: pre-calculate the "needed" dictionary (issue5360)
The "needed" dict is used as a reference counter to free items in the giant
"hist" dict. However, currently it is not very accurate and can lead to
dropping "hist" items unnecessarily, for example, with the following DAG,
-3-
/ \
0--1--2--4--
The current algorithm will visit and calculate rev 1 twice, undesired. And
it tries to be smart by clearing rev 1's parents: "pcache[1] = []" at the
time hist[1] being accessed (note: hist[1] needs to be used twice, by rev 2
and rev 3). It can result in incorrect results if p1 of rev 4 deletes chunks
belonging to rev 0.
However, simply removing "needed" is not okay, because it will consume 10x
memory:
# without any change
% HGRCPATH= lrun ./hg annotate mercurial/commands.py -r d130a38 3>&2 [1]
MEMORY 49074176
CPUTIME 9.213
REALTIME 9.270
# with "needed" removed
MEMORY 637673472
CPUTIME 8.164
REALTIME 8.249
This patch moves "needed" (and "pcache") calculation to a separate DFS to
address the issue. It improves perf and fixes issue5360 by correctly reusing
hist, while maintaining low memory usage. Some additional attempt has been
made to further reduce memory usage, like changing "pcache[f] = []" to "del
pcache[f]". Therefore the result can be both faster and lower memory usage:
# with this patch applied
MEMORY 47575040
CPUTIME 7.870
REALTIME 7.926
[1]: lrun is a lightweight sandbox built on Linux cgroup and namespace. It's
used to measure CPU and memory usage here. Source code is available at
github.com/quark-zju/lrun.
2016-09-02 17:20:59 +03:00
|
|
|
curr = decorate(f.data(), f)
|
2011-03-08 00:44:43 +03:00
|
|
|
for p in pl:
|
annotate: pre-calculate the "needed" dictionary (issue5360)
The "needed" dict is used as a reference counter to free items in the giant
"hist" dict. However, currently it is not very accurate and can lead to
dropping "hist" items unnecessarily, for example, with the following DAG,
-3-
/ \
0--1--2--4--
The current algorithm will visit and calculate rev 1 twice, undesired. And
it tries to be smart by clearing rev 1's parents: "pcache[1] = []" at the
time hist[1] being accessed (note: hist[1] needs to be used twice, by rev 2
and rev 3). It can result in incorrect results if p1 of rev 4 deletes chunks
belonging to rev 0.
However, simply removing "needed" is not okay, because it will consume 10x
memory:
# without any change
% HGRCPATH= lrun ./hg annotate mercurial/commands.py -r d130a38 3>&2 [1]
MEMORY 49074176
CPUTIME 9.213
REALTIME 9.270
# with "needed" removed
MEMORY 637673472
CPUTIME 8.164
REALTIME 8.249
This patch moves "needed" (and "pcache") calculation to a separate DFS to
address the issue. It improves perf and fixes issue5360 by correctly reusing
hist, while maintaining low memory usage. Some additional attempt has been
made to further reduce memory usage, like changing "pcache[f] = []" to "del
pcache[f]". Therefore the result can be both faster and lower memory usage:
# with this patch applied
MEMORY 47575040
CPUTIME 7.870
REALTIME 7.926
[1]: lrun is a lightweight sandbox built on Linux cgroup and namespace. It's
used to measure CPU and memory usage here. Source code is available at
github.com/quark-zju/lrun.
2016-09-02 17:20:59 +03:00
|
|
|
curr = pair(hist[p], curr)
|
2011-03-08 00:44:43 +03:00
|
|
|
if needed[p] == 1:
|
|
|
|
del hist[p]
|
2013-04-18 14:50:04 +04:00
|
|
|
del needed[p]
|
2011-03-08 00:44:43 +03:00
|
|
|
else:
|
|
|
|
needed[p] -= 1
|
|
|
|
|
|
|
|
hist[f] = curr
|
annotate: pre-calculate the "needed" dictionary (issue5360)
The "needed" dict is used as a reference counter to free items in the giant
"hist" dict. However, currently it is not very accurate and can lead to
dropping "hist" items unnecessarily, for example, with the following DAG,
-3-
/ \
0--1--2--4--
The current algorithm will visit and calculate rev 1 twice, undesired. And
it tries to be smart by clearing rev 1's parents: "pcache[1] = []" at the
time hist[1] being accessed (note: hist[1] needs to be used twice, by rev 2
and rev 3). It can result in incorrect results if p1 of rev 4 deletes chunks
belonging to rev 0.
However, simply removing "needed" is not okay, because it will consume 10x
memory:
# without any change
% HGRCPATH= lrun ./hg annotate mercurial/commands.py -r d130a38 3>&2 [1]
MEMORY 49074176
CPUTIME 9.213
REALTIME 9.270
# with "needed" removed
MEMORY 637673472
CPUTIME 8.164
REALTIME 8.249
This patch moves "needed" (and "pcache") calculation to a separate DFS to
address the issue. It improves perf and fixes issue5360 by correctly reusing
hist, while maintaining low memory usage. Some additional attempt has been
made to further reduce memory usage, like changing "pcache[f] = []" to "del
pcache[f]". Therefore the result can be both faster and lower memory usage:
# with this patch applied
MEMORY 47575040
CPUTIME 7.870
REALTIME 7.926
[1]: lrun is a lightweight sandbox built on Linux cgroup and namespace. It's
used to measure CPU and memory usage here. Source code is available at
github.com/quark-zju/lrun.
2016-09-02 17:20:59 +03:00
|
|
|
del pcache[f]
|
2011-03-08 00:44:43 +03:00
|
|
|
|
|
|
|
return zip(hist[base][0], hist[base][1].splitlines(True))
|
2006-09-18 07:58:11 +04:00
|
|
|
|
2013-08-12 08:05:50 +04:00
|
|
|
def ancestors(self, followfirst=False):
|
|
|
|
visit = {}
|
|
|
|
c = self
|
2015-03-14 00:00:06 +03:00
|
|
|
if followfirst:
|
|
|
|
cut = 1
|
|
|
|
else:
|
|
|
|
cut = None
|
|
|
|
|
2013-08-12 08:05:50 +04:00
|
|
|
while True:
|
|
|
|
for parent in c.parents()[:cut]:
|
2015-02-02 01:23:07 +03:00
|
|
|
visit[(parent.linkrev(), parent.filenode())] = parent
|
2013-08-12 08:05:50 +04:00
|
|
|
if not visit:
|
|
|
|
break
|
|
|
|
c = visit.pop(max(visit))
|
|
|
|
yield c
|
|
|
|
|
2013-08-12 08:03:33 +04:00
|
|
|
class filectx(basefilectx):
|
|
|
|
"""A filecontext object makes access to data related to a particular
|
|
|
|
filerevision convenient."""
|
|
|
|
def __init__(self, repo, path, changeid=None, fileid=None,
|
|
|
|
filelog=None, changectx=None):
|
|
|
|
"""changeid can be a changeset revision, node, or tag.
|
|
|
|
fileid can be a file revision or node."""
|
|
|
|
self._repo = repo
|
|
|
|
self._path = path
|
|
|
|
|
|
|
|
assert (changeid is not None
|
|
|
|
or fileid is not None
|
|
|
|
or changectx is not None), \
|
|
|
|
("bad args: changeid=%r, fileid=%r, changectx=%r"
|
|
|
|
% (changeid, fileid, changectx))
|
|
|
|
|
|
|
|
if filelog is not None:
|
|
|
|
self._filelog = filelog
|
|
|
|
|
|
|
|
if changeid is not None:
|
|
|
|
self._changeid = changeid
|
|
|
|
if changectx is not None:
|
|
|
|
self._changectx = changectx
|
|
|
|
if fileid is not None:
|
|
|
|
self._fileid = fileid
|
|
|
|
|
|
|
|
@propertycache
|
|
|
|
def _changectx(self):
|
|
|
|
try:
|
|
|
|
return changectx(self._repo, self._changeid)
|
2014-12-24 04:13:51 +03:00
|
|
|
except error.FilteredRepoLookupError:
|
2013-08-12 08:03:33 +04:00
|
|
|
# Linkrev may point to any revision in the repository. When the
|
|
|
|
# repository is filtered this may lead to `filectx` trying to build
|
|
|
|
# `changectx` for filtered revision. In such case we fallback to
|
|
|
|
# creating `changectx` on the unfiltered version of the reposition.
|
|
|
|
# This fallback should not be an issue because `changectx` from
|
|
|
|
# `filectx` are not used in complex operations that care about
|
|
|
|
# filtering.
|
|
|
|
#
|
|
|
|
# This fallback is a cheap and dirty fix that prevent several
|
|
|
|
# crashes. It does not ensure the behavior is correct. However the
|
|
|
|
# behavior was not correct before filtering either and "incorrect
|
|
|
|
# behavior" is seen as better as "crash"
|
|
|
|
#
|
|
|
|
# Linkrevs have several serious troubles with filtering that are
|
|
|
|
# complicated to solve. Proper handling of the issue here should be
|
|
|
|
# considered when solving linkrev issue are on the table.
|
|
|
|
return changectx(self._repo.unfiltered(), self._changeid)
|
|
|
|
|
2015-01-09 22:21:29 +03:00
|
|
|
def filectx(self, fileid, changeid=None):
|
2013-08-12 08:03:33 +04:00
|
|
|
'''opens an arbitrary revision of the file without
|
|
|
|
opening a new filelog'''
|
|
|
|
return filectx(self._repo, self._path, fileid=fileid,
|
2015-01-09 22:21:29 +03:00
|
|
|
filelog=self._filelog, changeid=changeid)
|
2013-08-12 08:03:33 +04:00
|
|
|
|
2017-01-05 20:16:07 +03:00
|
|
|
def rawdata(self):
|
|
|
|
return self._filelog.revision(self._filenode, raw=True)
|
|
|
|
|
2013-08-12 08:03:33 +04:00
|
|
|
def data(self):
|
2014-10-14 23:46:16 +04:00
|
|
|
try:
|
|
|
|
return self._filelog.read(self._filenode)
|
|
|
|
except error.CensoredNodeError:
|
|
|
|
if self._repo.ui.config("censor", "policy", "abort") == "ignore":
|
|
|
|
return ""
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("censored node: %s") % short(self._filenode),
|
2014-10-31 20:43:08 +03:00
|
|
|
hint=_("set censor.policy to ignore errors"))
|
2014-10-14 23:46:16 +04:00
|
|
|
|
2013-08-12 08:03:33 +04:00
|
|
|
def size(self):
|
|
|
|
return self._filelog.size(self._filerev)
|
|
|
|
|
|
|
|
def renamed(self):
|
|
|
|
"""check if file was actually renamed in this changeset revision
|
|
|
|
|
|
|
|
If rename logged in file revision, we report copy for changeset only
|
|
|
|
if file revisions linkrev points back to the changeset in question
|
|
|
|
or both changeset parents contain different file revisions.
|
|
|
|
"""
|
|
|
|
|
|
|
|
renamed = self._filelog.renamed(self._filenode)
|
|
|
|
if not renamed:
|
|
|
|
return renamed
|
|
|
|
|
|
|
|
if self.rev() == self.linkrev():
|
|
|
|
return renamed
|
|
|
|
|
|
|
|
name = self.path()
|
|
|
|
fnode = self._filenode
|
|
|
|
for p in self._changectx.parents():
|
|
|
|
try:
|
|
|
|
if fnode == p.filenode(name):
|
|
|
|
return None
|
|
|
|
except error.LookupError:
|
|
|
|
pass
|
|
|
|
return renamed
|
|
|
|
|
|
|
|
def children(self):
|
|
|
|
# hard for renames
|
|
|
|
c = self._filelog.children(self._filenode)
|
|
|
|
return [filectx(self._repo, self._path, fileid=x,
|
|
|
|
filelog=self._filelog) for x in c]
|
|
|
|
|
2017-01-16 11:22:32 +03:00
|
|
|
def _changesrange(fctx1, fctx2, linerange2, diffopts):
|
|
|
|
"""Return `(diffinrange, linerange1)` where `diffinrange` is True
|
|
|
|
if diff from fctx2 to fctx1 has changes in linerange2 and
|
|
|
|
`linerange1` is the new line range for fctx1.
|
|
|
|
"""
|
|
|
|
blocks = mdiff.allblocks(fctx1.data(), fctx2.data(), diffopts)
|
|
|
|
filteredblocks, linerange1 = mdiff.blocksinrange(blocks, linerange2)
|
|
|
|
diffinrange = any(stype == '!' for _, stype in filteredblocks)
|
|
|
|
return diffinrange, linerange1
|
|
|
|
|
context: add a `blockancestors(fctx, fromline, toline)` function
This yields ancestors of `fctx` by only keeping changesets touching the file
within specified linerange = (fromline, toline).
Matching revisions are found by inspecting the result of `mdiff.allblocks()`,
filtered by `mdiff.blocksinrange()`, to find out if there are blocks of type
"!" within specified line range.
If, at some iteration, an ancestor with an empty line range is encountered,
the algorithm stops as it means that the considered block of lines actually
has been introduced in the revision of this iteration. Otherwise, we finally
yield the initial revision of the file as the block originates from it.
When a merge changeset is encountered during ancestors lookup, we consider
there's a diff in the current line range as long as there is a diff between
the merge changeset and at least one of its parents (in the current line
range).
2016-12-29 01:03:37 +03:00
|
|
|
def blockancestors(fctx, fromline, toline):
|
|
|
|
"""Yield ancestors of `fctx` with respect to the block of lines within
|
|
|
|
`fromline`-`toline` range.
|
|
|
|
"""
|
2017-01-16 11:22:32 +03:00
|
|
|
diffopts = patch.diffopts(fctx._repo.ui)
|
context: add a `blockancestors(fctx, fromline, toline)` function
This yields ancestors of `fctx` by only keeping changesets touching the file
within specified linerange = (fromline, toline).
Matching revisions are found by inspecting the result of `mdiff.allblocks()`,
filtered by `mdiff.blocksinrange()`, to find out if there are blocks of type
"!" within specified line range.
If, at some iteration, an ancestor with an empty line range is encountered,
the algorithm stops as it means that the considered block of lines actually
has been introduced in the revision of this iteration. Otherwise, we finally
yield the initial revision of the file as the block originates from it.
When a merge changeset is encountered during ancestors lookup, we consider
there's a diff in the current line range as long as there is a diff between
the merge changeset and at least one of its parents (in the current line
range).
2016-12-29 01:03:37 +03:00
|
|
|
visit = {(fctx.linkrev(), fctx.filenode()): (fctx, (fromline, toline))}
|
|
|
|
while visit:
|
|
|
|
c, linerange2 = visit.pop(max(visit))
|
|
|
|
pl = c.parents()
|
|
|
|
if not pl:
|
|
|
|
# The block originates from the initial revision.
|
|
|
|
yield c
|
|
|
|
continue
|
|
|
|
inrange = False
|
|
|
|
for p in pl:
|
2017-01-16 11:22:32 +03:00
|
|
|
inrangep, linerange1 = _changesrange(p, c, linerange2, diffopts)
|
context: add a `blockancestors(fctx, fromline, toline)` function
This yields ancestors of `fctx` by only keeping changesets touching the file
within specified linerange = (fromline, toline).
Matching revisions are found by inspecting the result of `mdiff.allblocks()`,
filtered by `mdiff.blocksinrange()`, to find out if there are blocks of type
"!" within specified line range.
If, at some iteration, an ancestor with an empty line range is encountered,
the algorithm stops as it means that the considered block of lines actually
has been introduced in the revision of this iteration. Otherwise, we finally
yield the initial revision of the file as the block originates from it.
When a merge changeset is encountered during ancestors lookup, we consider
there's a diff in the current line range as long as there is a diff between
the merge changeset and at least one of its parents (in the current line
range).
2016-12-29 01:03:37 +03:00
|
|
|
inrange = inrange or inrangep
|
|
|
|
if linerange1[0] == linerange1[1]:
|
|
|
|
# Parent's linerange is empty, meaning that the block got
|
|
|
|
# introduced in this revision; no need to go futher in this
|
|
|
|
# branch.
|
|
|
|
continue
|
|
|
|
visit[p.linkrev(), p.filenode()] = p, linerange1
|
|
|
|
if inrange:
|
|
|
|
yield c
|
|
|
|
|
2013-09-18 03:34:45 +04:00
|
|
|
class committablectx(basectx):
|
|
|
|
"""A committablectx object provides common functionality for a context that
|
2013-08-15 00:02:08 +04:00
|
|
|
wants the ability to commit, e.g. workingctx or memctx."""
|
2010-04-21 03:18:31 +04:00
|
|
|
def __init__(self, repo, text="", user=None, date=None, extra=None,
|
|
|
|
changes=None):
|
2006-10-03 07:03:14 +04:00
|
|
|
self._repo = repo
|
|
|
|
self._rev = None
|
|
|
|
self._node = None
|
2008-06-19 00:52:26 +04:00
|
|
|
self._text = text
|
2008-06-21 17:27:51 +04:00
|
|
|
if date:
|
2008-06-19 00:52:26 +04:00
|
|
|
self._date = util.parsedate(date)
|
2008-07-22 22:00:22 +04:00
|
|
|
if user:
|
|
|
|
self._user = user
|
2008-06-19 00:52:25 +04:00
|
|
|
if changes:
|
2014-04-25 02:31:20 +04:00
|
|
|
self._status = changes
|
2006-10-03 07:03:14 +04:00
|
|
|
|
2008-06-19 00:52:26 +04:00
|
|
|
self._extra = {}
|
|
|
|
if extra:
|
|
|
|
self._extra = extra.copy()
|
|
|
|
if 'branch' not in self._extra:
|
|
|
|
try:
|
2010-11-25 00:56:32 +03:00
|
|
|
branch = encoding.fromlocal(self._repo.dirstate.branch())
|
2008-06-19 00:52:26 +04:00
|
|
|
except UnicodeDecodeError:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('branch name not in UTF-8!'))
|
2008-06-19 00:52:26 +04:00
|
|
|
self._extra['branch'] = branch
|
|
|
|
if self._extra['branch'] == '':
|
|
|
|
self._extra['branch'] = 'default'
|
2006-10-03 07:03:14 +04:00
|
|
|
|
2013-08-15 00:25:14 +04:00
|
|
|
def __str__(self):
|
|
|
|
return str(self._parents[0]) + "+"
|
|
|
|
|
2013-08-15 00:28:43 +04:00
|
|
|
def __nonzero__(self):
|
|
|
|
return True
|
|
|
|
|
2011-10-23 01:12:33 +04:00
|
|
|
def _buildflagfunc(self):
|
|
|
|
# Create a fallback function for getting file flags when the
|
|
|
|
# filesystem doesn't support them
|
|
|
|
|
|
|
|
copiesget = self._repo.dirstate.copies().get
|
2015-11-22 06:21:01 +03:00
|
|
|
parents = self.parents()
|
|
|
|
if len(parents) < 2:
|
2011-10-23 01:12:33 +04:00
|
|
|
# when we have one parent, it's easy: copy from parent
|
2015-11-22 06:21:01 +03:00
|
|
|
man = parents[0].manifest()
|
2011-10-23 01:12:33 +04:00
|
|
|
def func(f):
|
|
|
|
f = copiesget(f, f)
|
|
|
|
return man.flags(f)
|
|
|
|
else:
|
|
|
|
# merges are tricky: we try to reconstruct the unstored
|
|
|
|
# result from the merge (issue1802)
|
2015-11-22 06:21:01 +03:00
|
|
|
p1, p2 = parents
|
2011-10-23 01:12:33 +04:00
|
|
|
pa = p1.ancestor(p2)
|
|
|
|
m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest()
|
|
|
|
|
|
|
|
def func(f):
|
|
|
|
f = copiesget(f, f) # may be wrong for merges with copies
|
|
|
|
fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f)
|
|
|
|
if fl1 == fl2:
|
|
|
|
return fl1
|
|
|
|
if fl1 == fla:
|
|
|
|
return fl2
|
|
|
|
if fl2 == fla:
|
|
|
|
return fl1
|
|
|
|
return '' # punt for conflicts
|
|
|
|
|
|
|
|
return func
|
|
|
|
|
2013-08-15 00:30:17 +04:00
|
|
|
@propertycache
|
|
|
|
def _flagfunc(self):
|
|
|
|
return self._repo.dirstate.flagfunc(self._buildflagfunc)
|
|
|
|
|
2009-04-24 20:47:15 +04:00
|
|
|
@propertycache
|
2008-11-14 14:44:26 +03:00
|
|
|
def _manifest(self):
|
2014-11-27 02:37:01 +03:00
|
|
|
"""generate a manifest corresponding to the values in self._status
|
|
|
|
|
|
|
|
This reuse the file nodeid from parent, but we append an extra letter
|
2014-04-18 00:47:38 +04:00
|
|
|
when modified. Modified files get an extra 'm' while added files get
|
|
|
|
an extra 'a'. This is used by manifests merge to see that files
|
2014-11-27 02:37:01 +03:00
|
|
|
are different and by update logic to avoid deleting newly added files.
|
|
|
|
"""
|
2015-11-22 06:21:01 +03:00
|
|
|
parents = self.parents()
|
2006-10-03 07:03:14 +04:00
|
|
|
|
2016-11-10 13:19:16 +03:00
|
|
|
man = parents[0].manifest().copy()
|
2011-10-23 01:12:33 +04:00
|
|
|
|
|
|
|
ff = self._flagfunc
|
2016-11-10 13:19:16 +03:00
|
|
|
for i, l in ((addednodeid, self._status.added),
|
|
|
|
(modifiednodeid, self._status.modified)):
|
2006-10-03 07:03:14 +04:00
|
|
|
for f in l:
|
2016-11-10 13:19:16 +03:00
|
|
|
man[f] = i
|
2006-12-08 22:14:57 +03:00
|
|
|
try:
|
2014-10-10 22:09:37 +04:00
|
|
|
man.setflag(f, ff(f))
|
2006-12-08 22:14:57 +03:00
|
|
|
except OSError:
|
|
|
|
pass
|
2006-10-03 07:03:14 +04:00
|
|
|
|
2014-10-05 08:05:41 +04:00
|
|
|
for f in self._status.deleted + self._status.removed:
|
2006-10-10 22:03:24 +04:00
|
|
|
if f in man:
|
|
|
|
del man[f]
|
2006-10-03 07:03:14 +04:00
|
|
|
|
2008-11-14 14:44:26 +03:00
|
|
|
return man
|
|
|
|
|
2013-08-15 00:41:22 +04:00
|
|
|
@propertycache
|
|
|
|
def _status(self):
|
2014-04-25 02:31:20 +04:00
|
|
|
return self._repo.status()
|
2013-08-15 00:41:22 +04:00
|
|
|
|
2013-08-15 19:51:53 +04:00
|
|
|
@propertycache
|
|
|
|
def _user(self):
|
|
|
|
return self._repo.ui.username()
|
|
|
|
|
2013-08-15 19:57:43 +04:00
|
|
|
@propertycache
|
|
|
|
def _date(self):
|
|
|
|
return util.makedate()
|
|
|
|
|
2013-09-21 07:07:58 +04:00
|
|
|
def subrev(self, subpath):
|
|
|
|
return None
|
|
|
|
|
2015-04-09 16:18:55 +03:00
|
|
|
def manifestnode(self):
|
|
|
|
return None
|
2013-08-15 00:57:24 +04:00
|
|
|
def user(self):
|
|
|
|
return self._user or self._repo.ui.username()
|
2013-08-15 01:03:32 +04:00
|
|
|
def date(self):
|
|
|
|
return self._date
|
2013-08-15 01:09:30 +04:00
|
|
|
def description(self):
|
|
|
|
return self._text
|
2013-08-15 01:09:45 +04:00
|
|
|
def files(self):
|
2014-10-05 08:05:41 +04:00
|
|
|
return sorted(self._status.modified + self._status.added +
|
|
|
|
self._status.removed)
|
2013-08-15 00:57:24 +04:00
|
|
|
|
2013-08-15 01:14:58 +04:00
|
|
|
def modified(self):
|
2014-10-05 08:05:41 +04:00
|
|
|
return self._status.modified
|
2013-08-15 01:15:18 +04:00
|
|
|
def added(self):
|
2014-10-05 08:05:41 +04:00
|
|
|
return self._status.added
|
2013-08-15 01:15:29 +04:00
|
|
|
def removed(self):
|
2014-10-05 08:05:41 +04:00
|
|
|
return self._status.removed
|
2013-08-15 01:21:55 +04:00
|
|
|
def deleted(self):
|
2014-10-05 08:05:41 +04:00
|
|
|
return self._status.deleted
|
2013-08-15 01:23:02 +04:00
|
|
|
def branch(self):
|
|
|
|
return encoding.tolocal(self._extra['branch'])
|
2013-08-15 01:23:16 +04:00
|
|
|
def closesbranch(self):
|
|
|
|
return 'close' in self._extra
|
2013-08-15 01:23:28 +04:00
|
|
|
def extra(self):
|
|
|
|
return self._extra
|
2013-08-15 01:14:58 +04:00
|
|
|
|
2013-08-15 01:24:16 +04:00
|
|
|
def tags(self):
|
2015-06-28 20:38:03 +03:00
|
|
|
return []
|
2013-08-15 01:24:16 +04:00
|
|
|
|
2013-08-15 01:24:33 +04:00
|
|
|
def bookmarks(self):
|
|
|
|
b = []
|
|
|
|
for p in self.parents():
|
|
|
|
b.extend(p.bookmarks())
|
|
|
|
return b
|
|
|
|
|
2013-08-15 01:24:59 +04:00
|
|
|
def phase(self):
|
|
|
|
phase = phases.draft # default phase to draft
|
|
|
|
for p in self.parents():
|
|
|
|
phase = max(phase, p.phase())
|
|
|
|
return phase
|
|
|
|
|
2013-08-15 01:25:17 +04:00
|
|
|
def hidden(self):
|
|
|
|
return False
|
|
|
|
|
2013-08-15 01:25:26 +04:00
|
|
|
def children(self):
|
|
|
|
return []
|
|
|
|
|
2013-08-15 01:25:43 +04:00
|
|
|
def flags(self, path):
|
|
|
|
if '_manifest' in self.__dict__:
|
|
|
|
try:
|
|
|
|
return self._manifest.flags(path)
|
|
|
|
except KeyError:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
try:
|
|
|
|
return self._flagfunc(path)
|
|
|
|
except OSError:
|
|
|
|
return ''
|
|
|
|
|
2013-08-15 01:37:01 +04:00
|
|
|
def ancestor(self, c2):
|
2014-08-19 03:13:10 +04:00
|
|
|
"""return the "best" ancestor context of self and c2"""
|
2013-08-15 01:37:01 +04:00
|
|
|
return self._parents[0].ancestor(c2) # punt on two parents for now
|
|
|
|
|
2013-08-15 01:37:11 +04:00
|
|
|
def walk(self, match):
|
2015-04-08 01:18:52 +03:00
|
|
|
'''Generates matching file names.'''
|
2013-08-15 01:37:11 +04:00
|
|
|
return sorted(self._repo.dirstate.walk(match, sorted(self.substate),
|
|
|
|
True, False))
|
|
|
|
|
2014-08-02 09:07:29 +04:00
|
|
|
def matches(self, match):
|
|
|
|
return sorted(self._repo.dirstate.matches(match))
|
|
|
|
|
2013-08-15 01:37:59 +04:00
|
|
|
def ancestors(self):
|
2014-12-18 20:37:14 +03:00
|
|
|
for p in self._parents:
|
|
|
|
yield p
|
2013-08-15 01:37:59 +04:00
|
|
|
for a in self._repo.changelog.ancestors(
|
|
|
|
[p.rev() for p in self._parents]):
|
|
|
|
yield changectx(self._repo, a)
|
|
|
|
|
2013-08-15 01:40:27 +04:00
|
|
|
def markcommitted(self, node):
|
|
|
|
"""Perform post-commit cleanup necessary after committing this ctx
|
|
|
|
|
|
|
|
Specifically, this updates backing stores this working context
|
|
|
|
wraps to reflect the fact that the changes reflected by this
|
|
|
|
workingctx have been committed. For example, it marks
|
|
|
|
modified and added files as normal in the dirstate.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2014-09-05 22:36:20 +04:00
|
|
|
self._repo.dirstate.beginparentchange()
|
2013-08-15 01:40:27 +04:00
|
|
|
for f in self.modified() + self.added():
|
|
|
|
self._repo.dirstate.normal(f)
|
|
|
|
for f in self.removed():
|
|
|
|
self._repo.dirstate.drop(f)
|
|
|
|
self._repo.dirstate.setparents(node)
|
2014-09-05 22:36:20 +04:00
|
|
|
self._repo.dirstate.endparentchange()
|
2013-08-15 01:40:27 +04:00
|
|
|
|
context: write dirstate out explicitly at the end of markcommitted
To detect change of a file without redundant comparison of file
content, dirstate recognizes a file as certainly clean, if:
(1) it is already known as "normal",
(2) dirstate entry for it has valid (= not "-1") timestamp, and
(3) mode, size and timestamp of it on the filesystem are as same as
ones expected in dirstate
This works as expected in many cases, but doesn't in the corner case
that changing a file keeps mode, size and timestamp of it on the
filesystem.
The timetable below shows steps in one of typical such situations:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
* *** ***
- 'hg transplant REV1 REV2 ...'
- transplanting REV1
....
N
- change "f", but keep size N
(via 'patch.patch()')
- 'dirstate.normal("f")' N ***
(via 'repo.commit()')
- transplanting REV2
- change "f", but keep size N
(via 'patch.patch()')
- aborted while patching
N+1
- release wlock
- 'dirstate.write()' N N N
- 'hg status' shows "r1" as "clean" N N N
---- ----------------------------------- ---- ----- -----
The most important point is that 'dirstate.write()' is executed at N+1
or later. This causes writing dirstate timestamp N of "f" out
successfully. If it is executed at N, 'parsers.pack_dirstate()'
replaces timestamp N with "-1" before actual writing dirstate out.
This issue can occur when 'hg transplant' satisfies conditions below:
- multiple revisions to be transplanted change the same file
- those revisions don't change mode and size of the file, and
- the 2nd or later revision of them fails after changing the file
The root cause of this issue is that files are changed without
flushing in-memory dirstate changes via 'repo.commit()' (even though
omitting 'dirstate.normallookup()' on files changed by 'patch.patch()'
for efficiency also causes this issue).
To detect changes of files correctly, this patch writes in-memory
dirstate changes out explicitly after marking files as clean in
'committablectx.markcommitted()', which is invoked via
'repo.commit()'.
After this change, timetable is changed as below:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
* *** ***
- 'hg transplant REV1 REV2 ...'
- transplanting REV1
....
N
- change "f", but keep size N
(via 'patch.patch()')
- 'dirstate.normal("f")' N ***
(via 'repo.commit()')
----------------------------------- ---- ----- -----
- 'dirsttate.write()' -1 -1
----------------------------------- ---- ----- -----
- transplanting REV2
- change "f", but keep size N
(via 'patch.patch()')
- aborted while patching
N+1
- release wlock
- 'dirstate.write()' -1 -1 N
- 'hg status' shows "r1" as "clean" -1 -1 N
---- ----------------------------------- ---- ----- -----
To reproduce this issue in tests certainly, this patch emulates some
timing critical actions as below:
- change "f" at N
'patch.patch()' with 'fakepatchtime.py' explicitly changes mtime
of patched files to "2000-01-01 00:00" (= N).
- 'dirstate.write()' via 'repo.commit()' at N
'fakedirstatewritetime.py' forces 'pack_dirstate()' to use
"2000-01-01 00:00" as "now", only if 'pack_dirstate()' is invoked
via 'committablectx.markcommitted()'.
- 'dirstate.write()' via releasing wlock at N+1 (or "not at N")
'pack_dirstate()' via releasing wlock uses actual timestamp at
runtime as "now", and it should be different from the "2000-01-01
00:00" of "f".
BTW, this patch doesn't test cases below, even though 'patch.patch()'
is used similarly in these cases:
1. failure of 'hg import' or 'hg qpush'
2. success of 'hg import', 'hg qpush' or 'hg transplant'
Case (1) above doesn't cause this kind of issue, because:
- if patching is aborted by conflicts, changed files are committed
changed files are marked as CLEAN, even though they are partially
patched.
- otherwise, dirstate are fully restored by 'dirstateguard'
For example in timetable above, timestamp of "f" in .hg/dirstate
is restored to -1 (or less than N), and subsequent 'hg status' can
detect changes correctly.
Case (2) always causes 'repo.status()' invocation via 'repo.commit()'
just after changing files inside same wlock scope.
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
N *** ***
- make file "f" clean N
- execute 'hg foobar'
....
- 'dirstate.normal("f")' N ***
(e.g. via dirty check
or previous 'repo.commit()')
- change "f", but keep size N
- 'repo.status()' (*1)
(via 'repo.commit()')
---- ----------------------------------- ---- ----- -----
At a glance, 'repo.status()' at (*1) seems to cause similar issue (=
"changed files are treated as clean"), but actually doesn't.
'dirstate._lastnormaltime' should be N at (*1) above, because
'dirstate.normal()' via dirty check is finished at N.
Therefore, "f" changed at N (= 'dirstate._lastnormaltime') is forcibly
treated as "unsure" at (*1), and changes are detected as expected (see
'dirstate.status()' for detail).
If 'hg import' is executed with '--no-commit', 'repo.status()' isn't
invoked just after changing files inside same wlock scope.
But preceding 'dirstate.normal()' is invoked inside another wlock
scope via 'cmdutil.bailifchanged()', and in-memory changes should be
flushed at the end of that scope.
Therefore, timestamp N of clean "f" should be replaced by -1, if
'dirstate.write()' is invoked at N. It means that condition of this
issue isn't satisfied.
2015-07-08 11:01:09 +03:00
|
|
|
# write changes out explicitly, because nesting wlock at
|
|
|
|
# runtime may prevent 'wlock.release()' in 'repo.commit()'
|
|
|
|
# from immediately doing so for subsequent changing files
|
2015-10-16 19:15:34 +03:00
|
|
|
self._repo.dirstate.write(self._repo.currenttransaction())
|
context: write dirstate out explicitly at the end of markcommitted
To detect change of a file without redundant comparison of file
content, dirstate recognizes a file as certainly clean, if:
(1) it is already known as "normal",
(2) dirstate entry for it has valid (= not "-1") timestamp, and
(3) mode, size and timestamp of it on the filesystem are as same as
ones expected in dirstate
This works as expected in many cases, but doesn't in the corner case
that changing a file keeps mode, size and timestamp of it on the
filesystem.
The timetable below shows steps in one of typical such situations:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
* *** ***
- 'hg transplant REV1 REV2 ...'
- transplanting REV1
....
N
- change "f", but keep size N
(via 'patch.patch()')
- 'dirstate.normal("f")' N ***
(via 'repo.commit()')
- transplanting REV2
- change "f", but keep size N
(via 'patch.patch()')
- aborted while patching
N+1
- release wlock
- 'dirstate.write()' N N N
- 'hg status' shows "r1" as "clean" N N N
---- ----------------------------------- ---- ----- -----
The most important point is that 'dirstate.write()' is executed at N+1
or later. This causes writing dirstate timestamp N of "f" out
successfully. If it is executed at N, 'parsers.pack_dirstate()'
replaces timestamp N with "-1" before actual writing dirstate out.
This issue can occur when 'hg transplant' satisfies conditions below:
- multiple revisions to be transplanted change the same file
- those revisions don't change mode and size of the file, and
- the 2nd or later revision of them fails after changing the file
The root cause of this issue is that files are changed without
flushing in-memory dirstate changes via 'repo.commit()' (even though
omitting 'dirstate.normallookup()' on files changed by 'patch.patch()'
for efficiency also causes this issue).
To detect changes of files correctly, this patch writes in-memory
dirstate changes out explicitly after marking files as clean in
'committablectx.markcommitted()', which is invoked via
'repo.commit()'.
After this change, timetable is changed as below:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
* *** ***
- 'hg transplant REV1 REV2 ...'
- transplanting REV1
....
N
- change "f", but keep size N
(via 'patch.patch()')
- 'dirstate.normal("f")' N ***
(via 'repo.commit()')
----------------------------------- ---- ----- -----
- 'dirsttate.write()' -1 -1
----------------------------------- ---- ----- -----
- transplanting REV2
- change "f", but keep size N
(via 'patch.patch()')
- aborted while patching
N+1
- release wlock
- 'dirstate.write()' -1 -1 N
- 'hg status' shows "r1" as "clean" -1 -1 N
---- ----------------------------------- ---- ----- -----
To reproduce this issue in tests certainly, this patch emulates some
timing critical actions as below:
- change "f" at N
'patch.patch()' with 'fakepatchtime.py' explicitly changes mtime
of patched files to "2000-01-01 00:00" (= N).
- 'dirstate.write()' via 'repo.commit()' at N
'fakedirstatewritetime.py' forces 'pack_dirstate()' to use
"2000-01-01 00:00" as "now", only if 'pack_dirstate()' is invoked
via 'committablectx.markcommitted()'.
- 'dirstate.write()' via releasing wlock at N+1 (or "not at N")
'pack_dirstate()' via releasing wlock uses actual timestamp at
runtime as "now", and it should be different from the "2000-01-01
00:00" of "f".
BTW, this patch doesn't test cases below, even though 'patch.patch()'
is used similarly in these cases:
1. failure of 'hg import' or 'hg qpush'
2. success of 'hg import', 'hg qpush' or 'hg transplant'
Case (1) above doesn't cause this kind of issue, because:
- if patching is aborted by conflicts, changed files are committed
changed files are marked as CLEAN, even though they are partially
patched.
- otherwise, dirstate are fully restored by 'dirstateguard'
For example in timetable above, timestamp of "f" in .hg/dirstate
is restored to -1 (or less than N), and subsequent 'hg status' can
detect changes correctly.
Case (2) always causes 'repo.status()' invocation via 'repo.commit()'
just after changing files inside same wlock scope.
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
N *** ***
- make file "f" clean N
- execute 'hg foobar'
....
- 'dirstate.normal("f")' N ***
(e.g. via dirty check
or previous 'repo.commit()')
- change "f", but keep size N
- 'repo.status()' (*1)
(via 'repo.commit()')
---- ----------------------------------- ---- ----- -----
At a glance, 'repo.status()' at (*1) seems to cause similar issue (=
"changed files are treated as clean"), but actually doesn't.
'dirstate._lastnormaltime' should be N at (*1) above, because
'dirstate.normal()' via dirty check is finished at N.
Therefore, "f" changed at N (= 'dirstate._lastnormaltime') is forcibly
treated as "unsure" at (*1), and changes are detected as expected (see
'dirstate.status()' for detail).
If 'hg import' is executed with '--no-commit', 'repo.status()' isn't
invoked just after changing files inside same wlock scope.
But preceding 'dirstate.normal()' is invoked inside another wlock
scope via 'cmdutil.bailifchanged()', and in-memory changes should be
flushed at the end of that scope.
Therefore, timestamp N of clean "f" should be replaced by -1, if
'dirstate.write()' is invoked at N. It means that condition of this
issue isn't satisfied.
2015-07-08 11:01:09 +03:00
|
|
|
|
2013-09-18 03:34:45 +04:00
|
|
|
class workingctx(committablectx):
|
2013-08-15 00:34:18 +04:00
|
|
|
"""A workingctx object makes access to data related to
|
|
|
|
the current working directory convenient.
|
|
|
|
date - any valid date string or (unixtime, offset), or None.
|
|
|
|
user - username string, or None.
|
|
|
|
extra - a dictionary of extra values, or None.
|
|
|
|
changes - a list of file lists as returned by localrepo.status()
|
|
|
|
or None to use the repository status.
|
|
|
|
"""
|
|
|
|
def __init__(self, repo, text="", user=None, date=None, extra=None,
|
|
|
|
changes=None):
|
|
|
|
super(workingctx, self).__init__(repo, text, user, date, extra, changes)
|
|
|
|
|
2011-05-01 17:29:50 +04:00
|
|
|
def __iter__(self):
|
|
|
|
d = self._repo.dirstate
|
|
|
|
for f in d:
|
|
|
|
if d[f] != 'r':
|
|
|
|
yield f
|
|
|
|
|
2014-07-04 08:01:37 +04:00
|
|
|
def __contains__(self, key):
|
|
|
|
return self._repo.dirstate[key] not in "?r"
|
|
|
|
|
context: override workingctx.hex() to avoid a crash
Since node is None for workingctx, it can't use the base class
implementation of 'hex(self.node())'.
It doesn't appear that there are any current callers of this, but there will be
when archive supports 'wdir()'. My first thought was to use "{p1node}+", but
that would cause headaches elsewhere [1].
We should probably fix up localrepository.__getitem__ to accept this hash for
consistency, as a followup. This works, if the full hash is specified:
@@ -480,7 +480,7 @@
return dirstate.dirstate(self.vfs, self.ui, self.root, validate)
def __getitem__(self, changeid):
- if changeid is None:
+ if changeid is None or changeid == 'ff' * 20:
return context.workingctx(self)
if isinstance(changeid, slice):
return [context.changectx(self, i)
That differs from null, where it will accept any number of 0s, as long as it
isn't ambiguous.
[1] https://www.selenic.com/pipermail/mercurial-devel/2015-June/071166.html
2015-06-15 05:04:17 +03:00
|
|
|
def hex(self):
|
2015-06-22 16:05:10 +03:00
|
|
|
return hex(wdirid)
|
context: override workingctx.hex() to avoid a crash
Since node is None for workingctx, it can't use the base class
implementation of 'hex(self.node())'.
It doesn't appear that there are any current callers of this, but there will be
when archive supports 'wdir()'. My first thought was to use "{p1node}+", but
that would cause headaches elsewhere [1].
We should probably fix up localrepository.__getitem__ to accept this hash for
consistency, as a followup. This works, if the full hash is specified:
@@ -480,7 +480,7 @@
return dirstate.dirstate(self.vfs, self.ui, self.root, validate)
def __getitem__(self, changeid):
- if changeid is None:
+ if changeid is None or changeid == 'ff' * 20:
return context.workingctx(self)
if isinstance(changeid, slice):
return [context.changectx(self, i)
That differs from null, where it will accept any number of 0s, as long as it
isn't ambiguous.
[1] https://www.selenic.com/pipermail/mercurial-devel/2015-June/071166.html
2015-06-15 05:04:17 +03:00
|
|
|
|
2009-04-24 20:47:15 +04:00
|
|
|
@propertycache
|
2008-11-14 14:44:26 +03:00
|
|
|
def _parents(self):
|
|
|
|
p = self._repo.dirstate.parents()
|
|
|
|
if p[1] == nullid:
|
|
|
|
p = p[:-1]
|
2012-08-02 19:48:58 +04:00
|
|
|
return [changectx(self._repo, x) for x in p]
|
2006-10-03 07:03:14 +04:00
|
|
|
|
2006-12-25 20:57:55 +03:00
|
|
|
def filectx(self, path, filelog=None):
|
2006-10-03 07:03:14 +04:00
|
|
|
"""get a file context from the working directory"""
|
2006-12-25 20:57:55 +03:00
|
|
|
return workingfilectx(self._repo, path, workingctx=self,
|
|
|
|
filelog=filelog)
|
2006-10-03 07:03:14 +04:00
|
|
|
|
2012-04-23 14:12:04 +04:00
|
|
|
def dirty(self, missing=False, merge=True, branch=True):
|
2009-06-05 01:21:55 +04:00
|
|
|
"check whether a working directory is modified"
|
2010-05-02 01:05:21 +04:00
|
|
|
# check subrepos first
|
2012-12-12 05:38:14 +04:00
|
|
|
for s in sorted(self.substate):
|
2010-05-02 01:05:21 +04:00
|
|
|
if self.sub(s).dirty():
|
|
|
|
return True
|
|
|
|
# check current working dir
|
2012-04-23 14:12:04 +04:00
|
|
|
return ((merge and self.p2()) or
|
|
|
|
(branch and self.branch() != self.p1().branch()) or
|
2009-06-05 01:21:55 +04:00
|
|
|
self.modified() or self.added() or self.removed() or
|
|
|
|
(missing and self.deleted()))
|
|
|
|
|
2010-09-13 15:09:20 +04:00
|
|
|
def add(self, list, prefix=""):
|
|
|
|
join = lambda f: os.path.join(prefix, f)
|
2016-01-16 00:14:46 +03:00
|
|
|
with self._repo.wlock():
|
|
|
|
ui, ds = self._repo.ui, self._repo.dirstate
|
2010-06-07 22:03:32 +04:00
|
|
|
rejected = []
|
2013-10-14 19:51:04 +04:00
|
|
|
lstat = self._repo.wvfs.lstat
|
2010-06-07 22:03:32 +04:00
|
|
|
for f in list:
|
2011-04-19 14:42:53 +04:00
|
|
|
scmutil.checkportable(ui, join(f))
|
2010-06-07 22:03:32 +04:00
|
|
|
try:
|
2013-10-14 19:51:04 +04:00
|
|
|
st = lstat(f)
|
2011-04-23 01:51:25 +04:00
|
|
|
except OSError:
|
2010-09-13 15:09:20 +04:00
|
|
|
ui.warn(_("%s does not exist!\n") % join(f))
|
2010-06-07 22:03:32 +04:00
|
|
|
rejected.append(f)
|
|
|
|
continue
|
|
|
|
if st.st_size > 10000000:
|
|
|
|
ui.warn(_("%s: up to %d MB of RAM may be required "
|
|
|
|
"to manage this file\n"
|
|
|
|
"(use 'hg revert %s' to cancel the "
|
|
|
|
"pending addition)\n")
|
2010-09-13 15:09:20 +04:00
|
|
|
% (f, 3 * st.st_size // 1000000, join(f)))
|
2010-06-07 22:03:32 +04:00
|
|
|
if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
|
|
|
|
ui.warn(_("%s not added: only files and symlinks "
|
2010-09-13 15:09:20 +04:00
|
|
|
"supported currently\n") % join(f))
|
2013-10-14 19:51:04 +04:00
|
|
|
rejected.append(f)
|
2010-06-07 22:03:32 +04:00
|
|
|
elif ds[f] in 'amn':
|
2010-09-13 15:09:20 +04:00
|
|
|
ui.warn(_("%s already tracked!\n") % join(f))
|
2010-06-07 22:03:32 +04:00
|
|
|
elif ds[f] == 'r':
|
|
|
|
ds.normallookup(f)
|
|
|
|
else:
|
|
|
|
ds.add(f)
|
|
|
|
return rejected
|
|
|
|
|
2012-01-18 04:10:59 +04:00
|
|
|
def forget(self, files, prefix=""):
|
|
|
|
join = lambda f: os.path.join(prefix, f)
|
2016-01-16 00:14:46 +03:00
|
|
|
with self._repo.wlock():
|
2012-01-18 04:10:59 +04:00
|
|
|
rejected = []
|
2011-05-27 02:15:35 +04:00
|
|
|
for f in files:
|
2012-02-16 15:56:48 +04:00
|
|
|
if f not in self._repo.dirstate:
|
2012-01-18 04:10:59 +04:00
|
|
|
self._repo.ui.warn(_("%s not tracked!\n") % join(f))
|
|
|
|
rejected.append(f)
|
2012-02-16 15:56:48 +04:00
|
|
|
elif self._repo.dirstate[f] != 'a':
|
|
|
|
self._repo.dirstate.remove(f)
|
2010-06-07 22:03:32 +04:00
|
|
|
else:
|
2011-05-27 02:15:35 +04:00
|
|
|
self._repo.dirstate.drop(f)
|
2012-01-18 04:10:59 +04:00
|
|
|
return rejected
|
2010-06-07 22:03:32 +04:00
|
|
|
|
|
|
|
def undelete(self, list):
|
|
|
|
pctxs = self.parents()
|
2016-01-16 00:14:46 +03:00
|
|
|
with self._repo.wlock():
|
2010-06-07 22:03:32 +04:00
|
|
|
for f in list:
|
|
|
|
if self._repo.dirstate[f] != 'r':
|
|
|
|
self._repo.ui.warn(_("%s not removed!\n") % f)
|
|
|
|
else:
|
2010-09-22 01:14:58 +04:00
|
|
|
fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f]
|
2010-06-07 22:03:32 +04:00
|
|
|
t = fctx.data()
|
|
|
|
self._repo.wwrite(f, t, fctx.flags())
|
|
|
|
self._repo.dirstate.normal(f)
|
|
|
|
|
|
|
|
def copy(self, source, dest):
|
2013-10-14 19:51:05 +04:00
|
|
|
try:
|
|
|
|
st = self._repo.wvfs.lstat(dest)
|
2015-06-24 08:20:08 +03:00
|
|
|
except OSError as err:
|
2013-10-14 19:51:05 +04:00
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
2010-06-07 22:03:32 +04:00
|
|
|
self._repo.ui.warn(_("%s does not exist!\n") % dest)
|
2013-10-14 19:51:05 +04:00
|
|
|
return
|
|
|
|
if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
|
2010-06-07 22:03:32 +04:00
|
|
|
self._repo.ui.warn(_("copy failed: %s is not a file or a "
|
|
|
|
"symbolic link\n") % dest)
|
|
|
|
else:
|
2016-01-16 00:14:46 +03:00
|
|
|
with self._repo.wlock():
|
2014-11-25 05:42:56 +03:00
|
|
|
if self._repo.dirstate[dest] in '?':
|
2010-06-07 22:03:32 +04:00
|
|
|
self._repo.dirstate.add(dest)
|
2014-11-25 05:42:56 +03:00
|
|
|
elif self._repo.dirstate[dest] in 'r':
|
|
|
|
self._repo.dirstate.normallookup(dest)
|
2010-06-07 22:03:32 +04:00
|
|
|
self._repo.dirstate.copy(source, dest)
|
|
|
|
|
2015-05-16 07:36:35 +03:00
|
|
|
def match(self, pats=[], include=None, exclude=None, default='glob',
|
2015-06-06 02:01:04 +03:00
|
|
|
listsubrepos=False, badfn=None):
|
match: add a subclass for dirstate normalizing of the matched patterns
This class is only needed on case insensitive filesystems, and only
for wdir context matches. It allows the user to not match the case of
the items in the filesystem- especially for naming directories, which
dirstate doesn't handle[1]. Making dirstate handle mismatched
directory cases is too expensive[2].
Since dirstate doesn't apply to committed csets, this is only created by
overriding basectx.match() in workingctx, and only on icasefs. The default
arguments have been dropped, because the ctx must be passed to the matcher in
order to function.
For operations that can apply to both wdir and some other context, this ends up
normalizing the filename to the case as it exists in the filesystem, and using
that case for the lookup in the other context. See the diff example in the
test.
Previously, given a directory with an inexact case:
- add worked as expected
- diff, forget and status would silently ignore the request
- files would exit with 1
- commit, revert and remove would fail (even when the commands leading up to
them worked):
$ hg ci -m "AbCDef" capsdir1/capsdir
abort: CapsDir1/CapsDir: no match under directory!
$ hg revert -r '.^' capsdir1/capsdir
capsdir1\capsdir: no such file in rev 64dae27060b7
$ hg remove capsdir1/capsdir
not removing capsdir1\capsdir: no tracked files
[1]
Globs are normalized, so that the -I and -X don't need to be specified with a
case match. Without that, the second last remove (with -X) removes the files,
leaving nothing for the last remove. However, specifying the files as
'glob:**.Txt' does not work. Perhaps this requires 're.IGNORECASE'?
There are only a handful of places that create matchers directly, instead of
being routed through the context.match() method. Some may benefit from changing
over to using ctx.match() as a factory function:
revset.checkstatus()
revset.contains()
revset.filelog()
revset._matchfiles()
localrepository._loadfilter()
ignore.ignore()
fileset.subrepo()
filemerge._picktool()
overrides.addlargefiles()
lfcommands.lfconvert()
kwtemplate.__init__()
eolfile.__init__()
eolfile.checkrev()
acl.buildmatch()
Currently, a toplevel subrepo can be named with an inexact case. However, the
path auditor gets in the way of naming _anything_ in the subrepo if the top
level case doesn't match. That is trickier to handle, because there's the user
provided case, the case in the filesystem, and the case stored in .hgsub. This
can be fixed next cycle.
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -170,8 +170,15 @@
R sub1/sub2/test.txt
$ hg update -Cq
$ touch sub1/sub2/folder/bar
+#if icasefs
+ $ hg addremove Sub1/sub2
+ abort: path 'Sub1\sub2' is inside nested repo 'Sub1'
+ [255]
+ $ hg -q addremove sub1/sub2
+#else
$ hg addremove sub1/sub2
adding sub1/sub2/folder/bar (glob)
+#endif
$ hg status -S
A sub1/sub2/folder/bar
? foo/bar/abc
The narrowmatcher class may need to be tweaked when that is fixed.
[1] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068183.html
[2] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068191.html
2015-04-12 08:39:21 +03:00
|
|
|
r = self._repo
|
|
|
|
|
|
|
|
# Only a case insensitive filesystem needs magic to translate user input
|
|
|
|
# to actual case in the filesystem.
|
2016-08-30 19:22:53 +03:00
|
|
|
if not util.fscasesensitive(r.root):
|
match: add a subclass for dirstate normalizing of the matched patterns
This class is only needed on case insensitive filesystems, and only
for wdir context matches. It allows the user to not match the case of
the items in the filesystem- especially for naming directories, which
dirstate doesn't handle[1]. Making dirstate handle mismatched
directory cases is too expensive[2].
Since dirstate doesn't apply to committed csets, this is only created by
overriding basectx.match() in workingctx, and only on icasefs. The default
arguments have been dropped, because the ctx must be passed to the matcher in
order to function.
For operations that can apply to both wdir and some other context, this ends up
normalizing the filename to the case as it exists in the filesystem, and using
that case for the lookup in the other context. See the diff example in the
test.
Previously, given a directory with an inexact case:
- add worked as expected
- diff, forget and status would silently ignore the request
- files would exit with 1
- commit, revert and remove would fail (even when the commands leading up to
them worked):
$ hg ci -m "AbCDef" capsdir1/capsdir
abort: CapsDir1/CapsDir: no match under directory!
$ hg revert -r '.^' capsdir1/capsdir
capsdir1\capsdir: no such file in rev 64dae27060b7
$ hg remove capsdir1/capsdir
not removing capsdir1\capsdir: no tracked files
[1]
Globs are normalized, so that the -I and -X don't need to be specified with a
case match. Without that, the second last remove (with -X) removes the files,
leaving nothing for the last remove. However, specifying the files as
'glob:**.Txt' does not work. Perhaps this requires 're.IGNORECASE'?
There are only a handful of places that create matchers directly, instead of
being routed through the context.match() method. Some may benefit from changing
over to using ctx.match() as a factory function:
revset.checkstatus()
revset.contains()
revset.filelog()
revset._matchfiles()
localrepository._loadfilter()
ignore.ignore()
fileset.subrepo()
filemerge._picktool()
overrides.addlargefiles()
lfcommands.lfconvert()
kwtemplate.__init__()
eolfile.__init__()
eolfile.checkrev()
acl.buildmatch()
Currently, a toplevel subrepo can be named with an inexact case. However, the
path auditor gets in the way of naming _anything_ in the subrepo if the top
level case doesn't match. That is trickier to handle, because there's the user
provided case, the case in the filesystem, and the case stored in .hgsub. This
can be fixed next cycle.
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -170,8 +170,15 @@
R sub1/sub2/test.txt
$ hg update -Cq
$ touch sub1/sub2/folder/bar
+#if icasefs
+ $ hg addremove Sub1/sub2
+ abort: path 'Sub1\sub2' is inside nested repo 'Sub1'
+ [255]
+ $ hg -q addremove sub1/sub2
+#else
$ hg addremove sub1/sub2
adding sub1/sub2/folder/bar (glob)
+#endif
$ hg status -S
A sub1/sub2/folder/bar
? foo/bar/abc
The narrowmatcher class may need to be tweaked when that is fixed.
[1] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068183.html
[2] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068191.html
2015-04-12 08:39:21 +03:00
|
|
|
return matchmod.icasefsmatcher(r.root, r.getcwd(), pats, include,
|
2015-05-16 07:36:35 +03:00
|
|
|
exclude, default, r.auditor, self,
|
2015-06-06 02:01:04 +03:00
|
|
|
listsubrepos=listsubrepos,
|
|
|
|
badfn=badfn)
|
match: add a subclass for dirstate normalizing of the matched patterns
This class is only needed on case insensitive filesystems, and only
for wdir context matches. It allows the user to not match the case of
the items in the filesystem- especially for naming directories, which
dirstate doesn't handle[1]. Making dirstate handle mismatched
directory cases is too expensive[2].
Since dirstate doesn't apply to committed csets, this is only created by
overriding basectx.match() in workingctx, and only on icasefs. The default
arguments have been dropped, because the ctx must be passed to the matcher in
order to function.
For operations that can apply to both wdir and some other context, this ends up
normalizing the filename to the case as it exists in the filesystem, and using
that case for the lookup in the other context. See the diff example in the
test.
Previously, given a directory with an inexact case:
- add worked as expected
- diff, forget and status would silently ignore the request
- files would exit with 1
- commit, revert and remove would fail (even when the commands leading up to
them worked):
$ hg ci -m "AbCDef" capsdir1/capsdir
abort: CapsDir1/CapsDir: no match under directory!
$ hg revert -r '.^' capsdir1/capsdir
capsdir1\capsdir: no such file in rev 64dae27060b7
$ hg remove capsdir1/capsdir
not removing capsdir1\capsdir: no tracked files
[1]
Globs are normalized, so that the -I and -X don't need to be specified with a
case match. Without that, the second last remove (with -X) removes the files,
leaving nothing for the last remove. However, specifying the files as
'glob:**.Txt' does not work. Perhaps this requires 're.IGNORECASE'?
There are only a handful of places that create matchers directly, instead of
being routed through the context.match() method. Some may benefit from changing
over to using ctx.match() as a factory function:
revset.checkstatus()
revset.contains()
revset.filelog()
revset._matchfiles()
localrepository._loadfilter()
ignore.ignore()
fileset.subrepo()
filemerge._picktool()
overrides.addlargefiles()
lfcommands.lfconvert()
kwtemplate.__init__()
eolfile.__init__()
eolfile.checkrev()
acl.buildmatch()
Currently, a toplevel subrepo can be named with an inexact case. However, the
path auditor gets in the way of naming _anything_ in the subrepo if the top
level case doesn't match. That is trickier to handle, because there's the user
provided case, the case in the filesystem, and the case stored in .hgsub. This
can be fixed next cycle.
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -170,8 +170,15 @@
R sub1/sub2/test.txt
$ hg update -Cq
$ touch sub1/sub2/folder/bar
+#if icasefs
+ $ hg addremove Sub1/sub2
+ abort: path 'Sub1\sub2' is inside nested repo 'Sub1'
+ [255]
+ $ hg -q addremove sub1/sub2
+#else
$ hg addremove sub1/sub2
adding sub1/sub2/folder/bar (glob)
+#endif
$ hg status -S
A sub1/sub2/folder/bar
? foo/bar/abc
The narrowmatcher class may need to be tweaked when that is fixed.
[1] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068183.html
[2] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068191.html
2015-04-12 08:39:21 +03:00
|
|
|
return matchmod.match(r.root, r.getcwd(), pats,
|
|
|
|
include, exclude, default,
|
2015-05-16 07:36:35 +03:00
|
|
|
auditor=r.auditor, ctx=self,
|
2015-06-06 02:01:04 +03:00
|
|
|
listsubrepos=listsubrepos, badfn=badfn)
|
match: add a subclass for dirstate normalizing of the matched patterns
This class is only needed on case insensitive filesystems, and only
for wdir context matches. It allows the user to not match the case of
the items in the filesystem- especially for naming directories, which
dirstate doesn't handle[1]. Making dirstate handle mismatched
directory cases is too expensive[2].
Since dirstate doesn't apply to committed csets, this is only created by
overriding basectx.match() in workingctx, and only on icasefs. The default
arguments have been dropped, because the ctx must be passed to the matcher in
order to function.
For operations that can apply to both wdir and some other context, this ends up
normalizing the filename to the case as it exists in the filesystem, and using
that case for the lookup in the other context. See the diff example in the
test.
Previously, given a directory with an inexact case:
- add worked as expected
- diff, forget and status would silently ignore the request
- files would exit with 1
- commit, revert and remove would fail (even when the commands leading up to
them worked):
$ hg ci -m "AbCDef" capsdir1/capsdir
abort: CapsDir1/CapsDir: no match under directory!
$ hg revert -r '.^' capsdir1/capsdir
capsdir1\capsdir: no such file in rev 64dae27060b7
$ hg remove capsdir1/capsdir
not removing capsdir1\capsdir: no tracked files
[1]
Globs are normalized, so that the -I and -X don't need to be specified with a
case match. Without that, the second last remove (with -X) removes the files,
leaving nothing for the last remove. However, specifying the files as
'glob:**.Txt' does not work. Perhaps this requires 're.IGNORECASE'?
There are only a handful of places that create matchers directly, instead of
being routed through the context.match() method. Some may benefit from changing
over to using ctx.match() as a factory function:
revset.checkstatus()
revset.contains()
revset.filelog()
revset._matchfiles()
localrepository._loadfilter()
ignore.ignore()
fileset.subrepo()
filemerge._picktool()
overrides.addlargefiles()
lfcommands.lfconvert()
kwtemplate.__init__()
eolfile.__init__()
eolfile.checkrev()
acl.buildmatch()
Currently, a toplevel subrepo can be named with an inexact case. However, the
path auditor gets in the way of naming _anything_ in the subrepo if the top
level case doesn't match. That is trickier to handle, because there's the user
provided case, the case in the filesystem, and the case stored in .hgsub. This
can be fixed next cycle.
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -170,8 +170,15 @@
R sub1/sub2/test.txt
$ hg update -Cq
$ touch sub1/sub2/folder/bar
+#if icasefs
+ $ hg addremove Sub1/sub2
+ abort: path 'Sub1\sub2' is inside nested repo 'Sub1'
+ [255]
+ $ hg -q addremove sub1/sub2
+#else
$ hg addremove sub1/sub2
adding sub1/sub2/folder/bar (glob)
+#endif
$ hg status -S
A sub1/sub2/folder/bar
? foo/bar/abc
The narrowmatcher class may need to be tweaked when that is fixed.
[1] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068183.html
[2] http://www.selenic.com/pipermail/mercurial-devel/2015-April/068191.html
2015-04-12 08:39:21 +03:00
|
|
|
|
2014-03-08 01:32:37 +04:00
|
|
|
def _filtersuspectsymlink(self, files):
|
|
|
|
if not files or self._repo.dirstate._checklink:
|
|
|
|
return files
|
|
|
|
|
|
|
|
# Symlink placeholders may get non-symlink-like contents
|
|
|
|
# via user error or dereferencing by NFS or Samba servers,
|
|
|
|
# so we filter out any placeholders that don't look like a
|
|
|
|
# symlink
|
|
|
|
sane = []
|
|
|
|
for f in files:
|
|
|
|
if self.flags(f) == 'l':
|
|
|
|
d = self[f].data()
|
|
|
|
if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d):
|
|
|
|
self._repo.ui.debug('ignoring suspect symlink placeholder'
|
|
|
|
' "%s"\n' % f)
|
|
|
|
continue
|
|
|
|
sane.append(f)
|
|
|
|
return sane
|
|
|
|
|
2014-03-12 03:10:00 +04:00
|
|
|
def _checklookup(self, files):
|
|
|
|
# check for any possibly clean files
|
|
|
|
if not files:
|
|
|
|
return [], []
|
|
|
|
|
|
|
|
modified = []
|
|
|
|
fixup = []
|
|
|
|
pctx = self._parents[0]
|
|
|
|
# do a full compare of any files that might have changed
|
|
|
|
for f in sorted(files):
|
|
|
|
if (f not in pctx or self.flags(f) != pctx.flags(f)
|
|
|
|
or pctx[f].cmp(self[f])):
|
|
|
|
modified.append(f)
|
|
|
|
else:
|
|
|
|
fixup.append(f)
|
|
|
|
|
|
|
|
# update dirstate for files that are actually clean
|
|
|
|
if fixup:
|
|
|
|
try:
|
|
|
|
# updating the dirstate is optional
|
|
|
|
# so we don't wait on the lock
|
2014-08-02 05:30:18 +04:00
|
|
|
# wlock can invalidate the dirstate, so cache normal _after_
|
|
|
|
# taking the lock
|
2016-01-16 00:14:46 +03:00
|
|
|
with self._repo.wlock(False):
|
|
|
|
normal = self._repo.dirstate.normal
|
2014-03-12 03:10:00 +04:00
|
|
|
for f in fixup:
|
|
|
|
normal(f)
|
context: write dirstate out explicitly after marking files as clean
To detect change of a file without redundant comparison of file
content, dirstate recognizes a file as certainly clean, if:
(1) it is already known as "normal",
(2) dirstate entry for it has valid (= not "-1") timestamp, and
(3) mode, size and timestamp of it on the filesystem are as same as
ones expected in dirstate
This works as expected in many cases, but doesn't in the corner case
that changing a file keeps mode, size and timestamp of it on the
filesystem.
The timetable below shows steps in one of typical such situations:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
N -1 ***
- make file "f" clean N
- execute 'hg foobar'
- instantiate 'dirstate' -1 -1
- 'dirstate.normal("f")' N -1
(e.g. via dirty check)
- change "f", but keep size N
N+1
- release wlock
- 'dirstate.write()' N N
- 'hg status' shows "f" as "clean" N N N
---- ----------------------------------- ---- ----- -----
The most important point is that 'dirstate.write()' is executed at N+1
or later. This causes writing dirstate timestamp N of "f" out
successfully. If it is executed at N, 'parsers.pack_dirstate()'
replaces timestamp N with "-1" before actual writing dirstate out.
Occasional test failure for unexpected file status is typical example
of this corner case. Batch execution with small working directory is
finished in no time, and rarely satisfies condition (2) above.
This issue can occur in cases below;
- 'hg revert --rev REV' for revisions other than the parent
- failure of 'merge.update()' before 'merge.recordupdates()'
The root cause of this issue is that files are changed without
flushing in-memory dirstate changes via 'repo.commit()' (even though
omitting 'dirstate.normallookup()' on changed files also causes this
issue).
To detect changes of files correctly, this patch writes in-memory
dirstate changes out explicitly after marking files as clean in
'workingctx._checklookup()', which is invoked via 'repo.status()'.
After this change, timetable is changed as below:
---- ----------------------------------- ----------------
timestamp of "f"
----------------
dirstate file-
time action mem file system
---- ----------------------------------- ---- ----- -----
N -1 ***
- make file "f" clean N
- execute 'hg foobar'
- instantiate 'dirstate' -1 -1
- 'dirstate.normal("f")' N -1
(e.g. via dirty check)
----------------------------------- ---- ----- -----
- 'dirsttate.write()' -1 -1
----------------------------------- ---- ----- -----
- change "f", but keep size N
N+1
- release wlock
- 'dirstate.write()' -1 -1
- 'hg status' -1 -1 N
---- ----------------------------------- ---- ----- -----
To reproduce this issue in tests certainly, this patch emulates some
timing critical actions as below:
- timestamp of "f" in '.hg/dirstate' is -1 at the beginning
'hg debugrebuildstate' before command invocation ensures it.
- make file "f" clean at N
- change "f" at N
'touch -t 200001010000' before and after command invocation
changes mtime of "f" to "2000-01-01 00:00" (= N).
- invoke 'dirstate.write()' via 'repo.status()' at N
'fakedirstatewritetime.py' forces 'pack_dirstate()' to use
"2000-01-01 00:00" as "now", only if 'pack_dirstate()' is invoked
via 'workingctx._checklookup()'.
- invoke 'dirstate.write()' via releasing wlock at N+1 (or "not at N")
'pack_dirstate()' via releasing wlock uses actual timestamp at
runtime as "now", and it should be different from the "2000-01-01
00:00" of "f".
BTW, this patch also changes 'test-largefiles-misc.t', because adding
'dirstate.write()' makes recent dirstate changes visible to external
process.
2015-07-08 11:01:09 +03:00
|
|
|
# write changes out explicitly, because nesting
|
|
|
|
# wlock at runtime may prevent 'wlock.release()'
|
2016-01-16 00:14:46 +03:00
|
|
|
# after this block from doing so for subsequent
|
|
|
|
# changing files
|
2015-10-16 19:15:34 +03:00
|
|
|
self._repo.dirstate.write(self._repo.currenttransaction())
|
2014-03-12 03:10:00 +04:00
|
|
|
except error.LockError:
|
|
|
|
pass
|
|
|
|
return modified, fixup
|
|
|
|
|
2014-04-16 00:43:30 +04:00
|
|
|
def _manifestmatches(self, match, s):
|
|
|
|
"""Slow path for workingctx
|
|
|
|
|
|
|
|
The fast path is when we compare the working directory to its parent
|
|
|
|
which means this function is comparing with a non-parent; therefore we
|
|
|
|
need to build a manifest and return what matches.
|
|
|
|
"""
|
|
|
|
mf = self._repo['.']._manifestmatches(match, s)
|
2014-11-13 09:20:36 +03:00
|
|
|
for f in s.modified + s.added:
|
2016-11-10 13:17:22 +03:00
|
|
|
mf[f] = newnodeid
|
2014-10-10 22:09:37 +04:00
|
|
|
mf.setflag(f, self.flags(f))
|
2014-11-13 09:20:36 +03:00
|
|
|
for f in s.removed:
|
2014-04-16 00:43:30 +04:00
|
|
|
if f in mf:
|
|
|
|
del mf[f]
|
|
|
|
return mf
|
|
|
|
|
2014-04-22 22:14:51 +04:00
|
|
|
def _dirstatestatus(self, match=None, ignored=False, clean=False,
|
|
|
|
unknown=False):
|
|
|
|
'''Gets the status from the dirstate -- internal use only.'''
|
|
|
|
listignored, listclean, listunknown = ignored, clean, unknown
|
|
|
|
match = match or matchmod.always(self._repo.root, self._repo.getcwd())
|
|
|
|
subrepos = []
|
|
|
|
if '.hgsub' in self:
|
|
|
|
subrepos = sorted(self.substate)
|
2014-10-04 08:44:10 +04:00
|
|
|
cmp, s = self._repo.dirstate.status(match, subrepos, listignored,
|
|
|
|
listclean, listunknown)
|
2014-04-22 22:14:51 +04:00
|
|
|
|
|
|
|
# check for any possibly clean files
|
|
|
|
if cmp:
|
|
|
|
modified2, fixup = self._checklookup(cmp)
|
2014-11-13 09:07:31 +03:00
|
|
|
s.modified.extend(modified2)
|
2014-04-22 22:14:51 +04:00
|
|
|
|
|
|
|
# update dirstate for files that are actually clean
|
|
|
|
if fixup and listclean:
|
2014-11-13 09:07:31 +03:00
|
|
|
s.clean.extend(fixup)
|
2014-04-22 22:14:51 +04:00
|
|
|
|
2015-01-09 00:12:44 +03:00
|
|
|
if match.always():
|
|
|
|
# cache for performance
|
|
|
|
if s.unknown or s.ignored or s.clean:
|
|
|
|
# "_status" is cached with list*=False in the normal route
|
|
|
|
self._status = scmutil.status(s.modified, s.added, s.removed,
|
|
|
|
s.deleted, [], [], [])
|
|
|
|
else:
|
|
|
|
self._status = s
|
|
|
|
|
2014-11-13 09:07:31 +03:00
|
|
|
return s
|
2014-04-22 22:14:51 +04:00
|
|
|
|
2014-04-24 17:34:44 +04:00
|
|
|
def _buildstatus(self, other, s, match, listignored, listclean,
|
2014-05-30 01:09:16 +04:00
|
|
|
listunknown):
|
2014-04-24 17:34:44 +04:00
|
|
|
"""build a status with respect to another context
|
|
|
|
|
|
|
|
This includes logic for maintaining the fast path of status when
|
|
|
|
comparing the working directory against its parent, which is to skip
|
|
|
|
building a new manifest if self (working directory) is not comparing
|
|
|
|
against its parent (repo['.']).
|
|
|
|
"""
|
2014-10-12 10:30:08 +04:00
|
|
|
s = self._dirstatestatus(match, listignored, listclean, listunknown)
|
2014-04-18 00:47:38 +04:00
|
|
|
# Filter out symlinks that, in the case of FAT32 and NTFS filesystems,
|
2014-10-24 03:19:56 +04:00
|
|
|
# might have accidentally ended up with the entire contents of the file
|
2014-04-18 00:47:38 +04:00
|
|
|
# they are supposed to be linking to.
|
2014-11-13 03:51:11 +03:00
|
|
|
s.modified[:] = self._filtersuspectsymlink(s.modified)
|
2014-10-24 04:00:38 +04:00
|
|
|
if other != self._repo['.']:
|
|
|
|
s = super(workingctx, self)._buildstatus(other, s, match,
|
|
|
|
listignored, listclean,
|
|
|
|
listunknown)
|
2014-04-24 17:34:44 +04:00
|
|
|
return s
|
|
|
|
|
2014-10-12 10:18:53 +04:00
|
|
|
def _matchstatus(self, other, match):
|
2014-04-24 17:32:28 +04:00
|
|
|
"""override the match method with a filter for directory patterns
|
|
|
|
|
|
|
|
We use inheritance to customize the match.bad method only in cases of
|
|
|
|
workingctx since it belongs only to the working directory when
|
|
|
|
comparing against the parent changeset.
|
|
|
|
|
|
|
|
If we aren't comparing against the working directory's parent, then we
|
|
|
|
just use the default match object sent to us.
|
|
|
|
"""
|
|
|
|
superself = super(workingctx, self)
|
2014-10-12 10:18:53 +04:00
|
|
|
match = superself._matchstatus(other, match)
|
2014-04-24 17:32:28 +04:00
|
|
|
if other != self._repo['.']:
|
|
|
|
def bad(f, msg):
|
|
|
|
# 'f' may be a directory pattern from 'match.files()',
|
|
|
|
# so 'f not in ctx1' is not enough
|
2015-03-14 01:36:11 +03:00
|
|
|
if f not in other and not other.hasdir(f):
|
2014-04-24 17:32:28 +04:00
|
|
|
self._repo.ui.warn('%s: %s\n' %
|
|
|
|
(self._repo.dirstate.pathto(f), msg))
|
|
|
|
match.bad = bad
|
|
|
|
return match
|
|
|
|
|
2013-09-18 03:34:45 +04:00
|
|
|
class committablefilectx(basefilectx):
|
|
|
|
"""A committablefilectx provides common functionality for a file context
|
|
|
|
that wants the ability to commit, e.g. workingfilectx or memfilectx."""
|
2013-08-15 22:11:51 +04:00
|
|
|
def __init__(self, repo, path, filelog=None, ctx=None):
|
2006-10-03 07:03:14 +04:00
|
|
|
self._repo = repo
|
|
|
|
self._path = path
|
|
|
|
self._changeid = None
|
|
|
|
self._filerev = self._filenode = None
|
|
|
|
|
2013-05-01 21:42:03 +04:00
|
|
|
if filelog is not None:
|
2006-10-03 07:03:14 +04:00
|
|
|
self._filelog = filelog
|
2013-08-15 22:12:50 +04:00
|
|
|
if ctx:
|
|
|
|
self._changectx = ctx
|
|
|
|
|
2013-08-15 22:23:06 +04:00
|
|
|
def __nonzero__(self):
|
|
|
|
return True
|
|
|
|
|
2015-03-19 17:31:53 +03:00
|
|
|
def linkrev(self):
|
|
|
|
# linked to self._changectx no matter if file is modified or not
|
|
|
|
return self.rev()
|
|
|
|
|
2006-10-03 07:03:14 +04:00
|
|
|
def parents(self):
|
|
|
|
'''return parent filectxs, following copies if necessary'''
|
2009-05-20 04:08:53 +04:00
|
|
|
def filenode(ctx, path):
|
|
|
|
return ctx._manifest.get(path, nullid)
|
|
|
|
|
|
|
|
path = self._path
|
2006-10-03 07:03:14 +04:00
|
|
|
fl = self._filelog
|
2009-05-20 04:08:53 +04:00
|
|
|
pcl = self._changectx._parents
|
|
|
|
renamed = self.renamed()
|
|
|
|
|
|
|
|
if renamed:
|
|
|
|
pl = [renamed + (None,)]
|
|
|
|
else:
|
|
|
|
pl = [(path, filenode(pcl[0], path), fl)]
|
|
|
|
|
|
|
|
for pc in pcl[1:]:
|
|
|
|
pl.append((path, filenode(pc, path), fl))
|
2006-10-03 07:03:14 +04:00
|
|
|
|
2015-04-18 08:10:55 +03:00
|
|
|
return [self._parentfilectx(p, fileid=n, filelog=l)
|
2010-01-25 09:05:27 +03:00
|
|
|
for p, n, l in pl if n != nullid]
|
2006-10-03 07:03:14 +04:00
|
|
|
|
2013-08-15 22:42:56 +04:00
|
|
|
def children(self):
|
|
|
|
return []
|
|
|
|
|
2013-09-18 03:34:45 +04:00
|
|
|
class workingfilectx(committablefilectx):
|
2013-08-15 22:42:33 +04:00
|
|
|
"""A workingfilectx object makes access to data related to a particular
|
|
|
|
file in the working directory convenient."""
|
|
|
|
def __init__(self, repo, path, filelog=None, workingctx=None):
|
|
|
|
super(workingfilectx, self).__init__(repo, path, filelog, workingctx)
|
|
|
|
|
|
|
|
@propertycache
|
|
|
|
def _changectx(self):
|
|
|
|
return workingctx(self._repo)
|
|
|
|
|
|
|
|
def data(self):
|
|
|
|
return self._repo.wread(self._path)
|
|
|
|
def renamed(self):
|
|
|
|
rp = self._repo.dirstate.copied(self._path)
|
|
|
|
if not rp:
|
|
|
|
return None
|
|
|
|
return rp, self._changectx._parents[0]._manifest.get(rp, nullid)
|
|
|
|
|
2010-01-25 09:05:27 +03:00
|
|
|
def size(self):
|
2013-10-14 19:51:04 +04:00
|
|
|
return self._repo.wvfs.lstat(self._path).st_size
|
2006-12-25 00:55:34 +03:00
|
|
|
def date(self):
|
|
|
|
t, tz = self._changectx.date()
|
|
|
|
try:
|
2015-11-19 22:15:17 +03:00
|
|
|
return (self._repo.wvfs.lstat(self._path).st_mtime, tz)
|
2015-06-24 08:20:08 +03:00
|
|
|
except OSError as err:
|
2010-01-25 09:05:27 +03:00
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
2006-12-25 00:55:34 +03:00
|
|
|
return (t, tz)
|
2006-10-10 10:13:03 +04:00
|
|
|
|
2010-07-27 18:40:46 +04:00
|
|
|
def cmp(self, fctx):
|
|
|
|
"""compare with other file context
|
2010-07-09 06:02:39 +04:00
|
|
|
|
2010-07-27 18:40:46 +04:00
|
|
|
returns True if different than fctx.
|
2010-07-09 06:02:39 +04:00
|
|
|
"""
|
2012-08-16 00:39:18 +04:00
|
|
|
# fctx should be a filectx (not a workingfilectx)
|
2010-07-29 05:39:59 +04:00
|
|
|
# invert comparison to reuse the same code path
|
|
|
|
return fctx.cmp(self)
|
2008-06-19 02:14:23 +04:00
|
|
|
|
2014-07-02 23:01:01 +04:00
|
|
|
def remove(self, ignoremissing=False):
|
|
|
|
"""wraps unlink for a repo's working directory"""
|
|
|
|
util.unlinkpath(self._repo.wjoin(self._path), ignoremissing)
|
|
|
|
|
|
|
|
def write(self, data, flags):
|
|
|
|
"""wraps repo.wwrite"""
|
|
|
|
self._repo.wwrite(self._path, data, flags)
|
|
|
|
|
2014-12-31 11:55:43 +03:00
|
|
|
class workingcommitctx(workingctx):
|
|
|
|
"""A workingcommitctx object makes access to data related to
|
|
|
|
the revision being committed convenient.
|
|
|
|
|
|
|
|
This hides changes in the working directory, if they aren't
|
|
|
|
committed in this context.
|
|
|
|
"""
|
|
|
|
def __init__(self, repo, changes,
|
|
|
|
text="", user=None, date=None, extra=None):
|
|
|
|
super(workingctx, self).__init__(repo, text, user, date, extra,
|
|
|
|
changes)
|
|
|
|
|
2014-12-31 11:55:43 +03:00
|
|
|
def _dirstatestatus(self, match=None, ignored=False, clean=False,
|
|
|
|
unknown=False):
|
|
|
|
"""Return matched files only in ``self._status``
|
|
|
|
|
|
|
|
Uncommitted files appear "clean" via this context, even if
|
|
|
|
they aren't actually so in the working directory.
|
|
|
|
"""
|
|
|
|
match = match or matchmod.always(self._repo.root, self._repo.getcwd())
|
|
|
|
if clean:
|
|
|
|
clean = [f for f in self._manifest if f not in self._changedset]
|
|
|
|
else:
|
|
|
|
clean = []
|
|
|
|
return scmutil.status([f for f in self._status.modified if match(f)],
|
|
|
|
[f for f in self._status.added if match(f)],
|
|
|
|
[f for f in self._status.removed if match(f)],
|
|
|
|
[], [], [], clean)
|
|
|
|
|
|
|
|
@propertycache
|
|
|
|
def _changedset(self):
|
|
|
|
"""Return the set of files changed in this context
|
|
|
|
"""
|
|
|
|
changed = set(self._status.modified)
|
|
|
|
changed.update(self._status.added)
|
|
|
|
changed.update(self._status.removed)
|
|
|
|
return changed
|
|
|
|
|
2016-01-17 23:10:30 +03:00
|
|
|
def makecachingfilectxfn(func):
|
|
|
|
"""Create a filectxfn that caches based on the path.
|
|
|
|
|
|
|
|
We can't use util.cachefunc because it uses all arguments as the cache
|
|
|
|
key and this creates a cycle since the arguments include the repo and
|
|
|
|
memctx.
|
|
|
|
"""
|
|
|
|
cache = {}
|
|
|
|
|
|
|
|
def getfilectx(repo, memctx, path):
|
|
|
|
if path not in cache:
|
|
|
|
cache[path] = func(repo, memctx, path)
|
|
|
|
return cache[path]
|
|
|
|
|
|
|
|
return getfilectx
|
|
|
|
|
2013-08-16 00:00:03 +04:00
|
|
|
class memctx(committablectx):
|
2008-10-11 15:07:29 +04:00
|
|
|
"""Use memctx to perform in-memory commits via localrepo.commitctx().
|
|
|
|
|
|
|
|
Revision information is supplied at initialization time while
|
|
|
|
related files data and is made available through a callback
|
|
|
|
mechanism. 'repo' is the current localrepo, 'parents' is a
|
|
|
|
sequence of two parent revisions identifiers (pass None for every
|
|
|
|
missing parent), 'text' is the commit message and 'files' lists
|
|
|
|
names of files touched by the revision (normalized and relative to
|
|
|
|
repository root).
|
|
|
|
|
|
|
|
filectxfn(repo, memctx, path) is a callable receiving the
|
|
|
|
repository, the current memctx object and the normalized path of
|
|
|
|
requested file, relative to repository root. It is fired by the
|
|
|
|
commit function for every file in 'files', but calls order is
|
|
|
|
undefined. If the file is available in the revision being
|
|
|
|
committed (updated or added), filectxfn returns a memfilectx
|
|
|
|
object. If the file was removed, filectxfn raises an
|
|
|
|
IOError. Moved files are represented by marking the source file
|
|
|
|
removed and the new file added with copy information (see
|
|
|
|
memfilectx).
|
|
|
|
|
|
|
|
user receives the committer name and defaults to current
|
|
|
|
repository username, date is the commit date in any format
|
|
|
|
supported by util.parsedate() and defaults to current date, extra
|
|
|
|
is a dictionary of metadata or is left empty.
|
2008-06-19 02:14:23 +04:00
|
|
|
"""
|
2014-08-30 16:29:38 +04:00
|
|
|
|
|
|
|
# Mercurial <= 3.1 expects the filectxfn to raise IOError for missing files.
|
|
|
|
# Extensions that need to retain compatibility across Mercurial 3.1 can use
|
|
|
|
# this field to determine what to do in filectxfn.
|
|
|
|
_returnnoneformissingfiles = True
|
|
|
|
|
2008-06-23 15:12:32 +04:00
|
|
|
def __init__(self, repo, parents, text, files, filectxfn, user=None,
|
2014-05-05 16:26:40 +04:00
|
|
|
date=None, extra=None, editor=False):
|
2013-08-16 00:03:03 +04:00
|
|
|
super(memctx, self).__init__(repo, text, user, date, extra)
|
2008-06-19 02:14:23 +04:00
|
|
|
self._rev = None
|
|
|
|
self._node = None
|
|
|
|
parents = [(p or nullid) for p in parents]
|
|
|
|
p1, p2 = parents
|
2008-06-26 23:35:46 +04:00
|
|
|
self._parents = [changectx(self._repo, p) for p in (p1, p2)]
|
2009-04-27 01:50:44 +04:00
|
|
|
files = sorted(set(files))
|
2014-12-17 09:09:38 +03:00
|
|
|
self._files = files
|
2014-07-16 22:07:39 +04:00
|
|
|
self.substate = {}
|
2008-06-19 02:14:23 +04:00
|
|
|
|
2014-07-26 04:36:01 +04:00
|
|
|
# if store is not callable, wrap it in a function
|
|
|
|
if not callable(filectxfn):
|
|
|
|
def getfilectx(repo, memctx, path):
|
|
|
|
fctx = filectxfn[path]
|
|
|
|
# this is weird but apparently we only keep track of one parent
|
|
|
|
# (why not only store that instead of a tuple?)
|
|
|
|
copied = fctx.renamed()
|
|
|
|
if copied:
|
|
|
|
copied = copied[0]
|
|
|
|
return memfilectx(repo, path, fctx.data(),
|
|
|
|
islink=fctx.islink(), isexec=fctx.isexec(),
|
|
|
|
copied=copied, memctx=memctx)
|
|
|
|
self._filectxfn = getfilectx
|
2014-12-17 09:09:38 +03:00
|
|
|
else:
|
2016-01-17 23:10:30 +03:00
|
|
|
# memoizing increases performance for e.g. vcs convert scenarios.
|
|
|
|
self._filectxfn = makecachingfilectxfn(filectxfn)
|
2014-07-26 04:36:01 +04:00
|
|
|
|
2015-03-14 00:00:06 +03:00
|
|
|
if extra:
|
|
|
|
self._extra = extra.copy()
|
|
|
|
else:
|
|
|
|
self._extra = {}
|
|
|
|
|
2011-06-04 17:20:49 +04:00
|
|
|
if self._extra.get('branch', '') == '':
|
2008-06-19 02:14:23 +04:00
|
|
|
self._extra['branch'] = 'default'
|
|
|
|
|
2014-05-05 16:26:40 +04:00
|
|
|
if editor:
|
|
|
|
self._text = editor(self._repo, self, [])
|
|
|
|
self._repo.savecommitmessage(self._text)
|
|
|
|
|
2008-06-19 02:14:23 +04:00
|
|
|
def filectx(self, path, filelog=None):
|
2014-08-27 00:03:32 +04:00
|
|
|
"""get a file context from the working directory
|
|
|
|
|
|
|
|
Returns None if file doesn't exist and should be removed."""
|
2008-06-19 02:14:23 +04:00
|
|
|
return self._filectxfn(self._repo, self, path)
|
|
|
|
|
2010-05-01 16:00:21 +04:00
|
|
|
def commit(self):
|
|
|
|
"""commit context to the repo"""
|
|
|
|
return self._repo.commitctx(self)
|
|
|
|
|
2014-05-30 01:12:59 +04:00
|
|
|
@propertycache
|
|
|
|
def _manifest(self):
|
|
|
|
"""generate a manifest based on the return values of filectxfn"""
|
|
|
|
|
|
|
|
# keep this simple for now; just worry about p1
|
|
|
|
pctx = self._parents[0]
|
|
|
|
man = pctx.manifest().copy()
|
|
|
|
|
2014-12-18 18:11:56 +03:00
|
|
|
for f in self._status.modified:
|
2014-05-30 01:12:59 +04:00
|
|
|
p1node = nullid
|
|
|
|
p2node = nullid
|
2014-06-18 07:55:06 +04:00
|
|
|
p = pctx[f].parents() # if file isn't in pctx, check p2?
|
2014-05-30 01:12:59 +04:00
|
|
|
if len(p) > 0:
|
2016-02-04 04:44:11 +03:00
|
|
|
p1node = p[0].filenode()
|
2014-05-30 01:12:59 +04:00
|
|
|
if len(p) > 1:
|
2016-02-04 04:44:11 +03:00
|
|
|
p2node = p[1].filenode()
|
2014-12-18 18:11:56 +03:00
|
|
|
man[f] = revlog.hash(self[f].data(), p1node, p2node)
|
2014-05-30 01:12:59 +04:00
|
|
|
|
2014-12-17 09:09:43 +03:00
|
|
|
for f in self._status.added:
|
|
|
|
man[f] = revlog.hash(self[f].data(), nullid, nullid)
|
|
|
|
|
2014-12-17 09:09:43 +03:00
|
|
|
for f in self._status.removed:
|
|
|
|
if f in man:
|
|
|
|
del man[f]
|
|
|
|
|
2014-05-30 01:12:59 +04:00
|
|
|
return man
|
|
|
|
|
2014-12-17 09:09:38 +03:00
|
|
|
@propertycache
|
|
|
|
def _status(self):
|
|
|
|
"""Calculate exact status from ``files`` specified at construction
|
|
|
|
"""
|
|
|
|
man1 = self.p1().manifest()
|
|
|
|
p2 = self._parents[1]
|
|
|
|
# "1 < len(self._parents)" can't be used for checking
|
|
|
|
# existence of the 2nd parent, because "memctx._parents" is
|
|
|
|
# explicitly initialized by the list, of which length is 2.
|
|
|
|
if p2.node() != nullid:
|
|
|
|
man2 = p2.manifest()
|
|
|
|
managing = lambda f: f in man1 or f in man2
|
|
|
|
else:
|
|
|
|
managing = lambda f: f in man1
|
|
|
|
|
|
|
|
modified, added, removed = [], [], []
|
|
|
|
for f in self._files:
|
|
|
|
if not managing(f):
|
|
|
|
added.append(f)
|
|
|
|
elif self[f]:
|
|
|
|
modified.append(f)
|
|
|
|
else:
|
|
|
|
removed.append(f)
|
|
|
|
|
|
|
|
return scmutil.status(modified, added, removed, [], [], [], [])
|
2014-05-30 01:12:59 +04:00
|
|
|
|
2013-08-16 00:23:36 +04:00
|
|
|
class memfilectx(committablefilectx):
|
2008-10-11 15:07:29 +04:00
|
|
|
"""memfilectx represents an in-memory file to commit.
|
|
|
|
|
2014-04-18 00:47:38 +04:00
|
|
|
See memctx and committablefilectx for more details.
|
2008-06-19 02:14:23 +04:00
|
|
|
"""
|
2013-08-16 01:49:27 +04:00
|
|
|
def __init__(self, repo, path, data, islink=False,
|
|
|
|
isexec=False, copied=None, memctx=None):
|
2008-10-11 15:07:29 +04:00
|
|
|
"""
|
|
|
|
path is the normalized file path relative to repository root.
|
|
|
|
data is the file content as a string.
|
|
|
|
islink is True if the file is a symbolic link.
|
|
|
|
isexec is True if the file is executable.
|
|
|
|
copied is the source file path if current file was copied in the
|
|
|
|
revision being committed, or None."""
|
2013-08-16 01:49:27 +04:00
|
|
|
super(memfilectx, self).__init__(repo, path, None, memctx)
|
2008-06-19 02:14:23 +04:00
|
|
|
self._data = data
|
|
|
|
self._flags = (islink and 'l' or '') + (isexec and 'x' or '')
|
|
|
|
self._copied = None
|
|
|
|
if copied:
|
|
|
|
self._copied = (copied, nullid)
|
|
|
|
|
2010-01-25 09:05:27 +03:00
|
|
|
def data(self):
|
|
|
|
return self._data
|
2014-06-04 00:49:51 +04:00
|
|
|
def size(self):
|
|
|
|
return len(self.data())
|
2010-01-25 09:05:27 +03:00
|
|
|
def flags(self):
|
|
|
|
return self._flags
|
|
|
|
def renamed(self):
|
|
|
|
return self._copied
|
2014-07-26 05:20:26 +04:00
|
|
|
|
|
|
|
def remove(self, ignoremissing=False):
|
|
|
|
"""wraps unlink for a repo's working directory"""
|
|
|
|
# need to figure out what to do here
|
|
|
|
del self._changectx[self._path]
|
|
|
|
|
|
|
|
def write(self, data, flags):
|
|
|
|
"""wraps repo.wwrite"""
|
|
|
|
self._data = data
|
2016-11-21 19:09:41 +03:00
|
|
|
|
|
|
|
class metadataonlyctx(committablectx):
|
|
|
|
"""Like memctx but it's reusing the manifest of different commit.
|
|
|
|
Intended to be used by lightweight operations that are creating
|
|
|
|
metadata-only changes.
|
|
|
|
|
|
|
|
Revision information is supplied at initialization time. 'repo' is the
|
|
|
|
current localrepo, 'ctx' is original revision which manifest we're reuisng
|
|
|
|
'parents' is a sequence of two parent revisions identifiers (pass None for
|
|
|
|
every missing parent), 'text' is the commit.
|
|
|
|
|
|
|
|
user receives the committer name and defaults to current repository
|
|
|
|
username, date is the commit date in any format supported by
|
|
|
|
util.parsedate() and defaults to current date, extra is a dictionary of
|
|
|
|
metadata or is left empty.
|
|
|
|
"""
|
2016-12-17 00:02:39 +03:00
|
|
|
def __new__(cls, repo, originalctx, *args, **kwargs):
|
2016-11-21 19:09:41 +03:00
|
|
|
return super(metadataonlyctx, cls).__new__(cls, repo)
|
|
|
|
|
|
|
|
def __init__(self, repo, originalctx, parents, text, user=None, date=None,
|
|
|
|
extra=None, editor=False):
|
|
|
|
super(metadataonlyctx, self).__init__(repo, text, user, date, extra)
|
|
|
|
self._rev = None
|
|
|
|
self._node = None
|
|
|
|
self._originalctx = originalctx
|
|
|
|
self._manifestnode = originalctx.manifestnode()
|
|
|
|
parents = [(p or nullid) for p in parents]
|
|
|
|
p1, p2 = self._parents = [changectx(self._repo, p) for p in parents]
|
|
|
|
|
|
|
|
# sanity check to ensure that the reused manifest parents are
|
|
|
|
# manifests of our commit parents
|
|
|
|
mp1, mp2 = self.manifestctx().parents
|
|
|
|
if p1 != nullid and p1.manifestctx().node() != mp1:
|
|
|
|
raise RuntimeError('can\'t reuse the manifest: '
|
|
|
|
'its p1 doesn\'t match the new ctx p1')
|
|
|
|
if p2 != nullid and p2.manifestctx().node() != mp2:
|
|
|
|
raise RuntimeError('can\'t reuse the manifest: '
|
|
|
|
'its p2 doesn\'t match the new ctx p2')
|
|
|
|
|
|
|
|
self._files = originalctx.files()
|
|
|
|
self.substate = {}
|
|
|
|
|
|
|
|
if extra:
|
|
|
|
self._extra = extra.copy()
|
|
|
|
else:
|
|
|
|
self._extra = {}
|
|
|
|
|
|
|
|
if self._extra.get('branch', '') == '':
|
|
|
|
self._extra['branch'] = 'default'
|
|
|
|
|
|
|
|
if editor:
|
|
|
|
self._text = editor(self._repo, self, [])
|
|
|
|
self._repo.savecommitmessage(self._text)
|
|
|
|
|
|
|
|
def manifestnode(self):
|
|
|
|
return self._manifestnode
|
|
|
|
|
|
|
|
@propertycache
|
|
|
|
def _manifestctx(self):
|
|
|
|
return self._repo.manifestlog[self._manifestnode]
|
|
|
|
|
|
|
|
def filectx(self, path, filelog=None):
|
|
|
|
return self._originalctx.filectx(path, filelog=filelog)
|
|
|
|
|
|
|
|
def commit(self):
|
|
|
|
"""commit context to the repo"""
|
|
|
|
return self._repo.commitctx(self)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _manifest(self):
|
|
|
|
return self._originalctx.manifest()
|
|
|
|
|
|
|
|
@propertycache
|
|
|
|
def _status(self):
|
|
|
|
"""Calculate exact status from ``files`` specified in the ``origctx``
|
|
|
|
and parents manifests.
|
|
|
|
"""
|
|
|
|
man1 = self.p1().manifest()
|
|
|
|
p2 = self._parents[1]
|
|
|
|
# "1 < len(self._parents)" can't be used for checking
|
|
|
|
# existence of the 2nd parent, because "metadataonlyctx._parents" is
|
|
|
|
# explicitly initialized by the list, of which length is 2.
|
|
|
|
if p2.node() != nullid:
|
|
|
|
man2 = p2.manifest()
|
|
|
|
managing = lambda f: f in man1 or f in man2
|
|
|
|
else:
|
|
|
|
managing = lambda f: f in man1
|
|
|
|
|
|
|
|
modified, added, removed = [], [], []
|
|
|
|
for f in self._files:
|
|
|
|
if not managing(f):
|
|
|
|
added.append(f)
|
|
|
|
elif self[f]:
|
|
|
|
modified.append(f)
|
|
|
|
else:
|
|
|
|
removed.append(f)
|
|
|
|
|
|
|
|
return scmutil.status(modified, added, removed, [], [], [], [])
|