[PATCH 5 of 7 V2] context: floor adjustlinkrev graph walk during copy tracing
Boris Feld
boris.feld at octobus.net
Mon Oct 1 16:46:28 UTC 2018
# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1536255188 14400
# Thu Sep 06 13:33:08 2018 -0400
# Node ID f0474004509e6dbb7c534b8ea27ae44d9cf71a28
# Parent cc6fb373cf83293cac66743fd13e7909f8d40031
# EXP-Topic copy-perf
# Available At https://bitbucket.org/octobus/mercurial-devel/
# hg pull https://bitbucket.org/octobus/mercurial-devel/ -r f0474004509e
context: floor adjustlinkrev graph walk during copy tracing
The `_adjustlinkrev` method gains an optional "stoprev" argument. The linkrev
adjustment will give up once this floor is reached. The relevant functions
using `_adjustlinkrev` are updated to pass an appropriate value in the copy
tracing code.
In some private repository, about 10% of the status call triggered
pathological case addressed by this change. The speedup varies from one call
to another, the best-observed win is moving from 170s to 11s.
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -631,7 +631,7 @@ class basefilectx(object):
def _changeid(self):
return self._findchangerev()
- def _findchangerev(self):
+ def _findchangerev(self, stoprev=None):
if r'_changeid' in self.__dict__:
changeid = self._changeid
elif r'_changectx' in self.__dict__:
@@ -639,10 +639,11 @@ class basefilectx(object):
elif r'_descendantrev' in self.__dict__:
# this file context was created from a revision with a known
# descendant, we can (lazily) correct for linkrev aliases
- changeid = self._adjustlinkrev(self._descendantrev)
+ changeid = self._adjustlinkrev(self._descendantrev, stoprev=stoprev)
else:
changeid = self._filelog.linkrev(self._filerev)
- self._changeid = changeid
+ if changeid is not None:
+ self._changeid = changeid
return changeid
@propertycache
@@ -786,7 +787,7 @@ class basefilectx(object):
return True
- def _adjustlinkrev(self, srcrev, inclusive=False):
+ def _adjustlinkrev(self, srcrev, inclusive=False, stoprev=None):
"""return the first ancestor of <srcrev> introducing <fnode>
If the linkrev of the file revision does not point to an ancestor of
@@ -795,6 +796,10 @@ class basefilectx(object):
:srcrev: the changeset revision we search ancestors from
:inclusive: if true, the src revision will also be checked
+ :stoprev: an optional revision to stop the walk at. If no introduction
+ of this file content could be found before this floor
+ revision, the function will returns "None" and stops its
+ iteration.
"""
repo = self._repo
cl = repo.unfiltered().changelog
@@ -820,6 +825,8 @@ class basefilectx(object):
fnode = self._filenode
path = self._path
for a in iteranc:
+ if stoprev is not None and a < stoprev:
+ return None
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
@@ -835,8 +842,12 @@ class basefilectx(object):
def isintroducedafter(self, changelogrev):
"""True if a filectx have been introduced after a given floor revision
"""
- return (changelogrev <= self.linkrev()
- or changelogrev <= self._introrev())
+ if changelogrev <= self.linkrev():
+ return True
+ introrev = self._introrev(stoprev=changelogrev)
+ if introrev is None:
+ return False
+ return changelogrev <= introrev
def _lazyrev(self):
"""return self.rev() if it is available without computation,
@@ -866,16 +877,25 @@ class basefilectx(object):
"""
return self._introrev()
- def _introrev(self):
+ def _introrev(self, stoprev=None):
+ """
+ Same as `introrev` but, with an extra argument to limit changelog
+ iteration range in some internal usecase.
+
+ If `stoprev` is set, the `introrev` will not be searched past that
+ `stoprev` revision and "None" might be returned. This is useful to
+ limit iteration range.
+ """
lkr = self.linkrev()
lazyrev = self._lazyrev()
if lazyrev is not None:
if lazyrev == lkr:
return lazyrev
else:
- return self._adjustlinkrev(lazyrev, inclusive=True)
+ return self._adjustlinkrev(lazyrev, inclusive=True,
+ stoprev=stoprev)
else:
- return self._findchangerev()
+ return self._findchangerev(stoprev=stoprev)
def introfilectx(self):
"""Return filectx having identical contents, but pointing to the
More information about the Mercurial-devel
mailing list