Patchwork [1,of,5,V5] context: spell out the logic around linkrev adjustement starting point

login
register
mail settings
Submitter Boris Feld
Date Oct. 10, 2018, 8:41 a.m.
Message ID <37ee24df8c3b342bde56.1539160905@localhost.localdomain>
Download mbox | patch
Permalink /patch/35594/
State New
Headers show

Comments

Boris Feld - Oct. 10, 2018, 8:41 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1539125370 -7200
#      Wed Oct 10 00:49:30 2018 +0200
# Node ID 37ee24df8c3b342bde56b950aa09ac0d123e0145
# Parent  a66594c5fad422499bfaf669d182e02fe3c0be32
# EXP-Topic copy-perf
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 37ee24df8c3b
context: spell out the logic around linkrev adjustement starting point

We make the intend of the `_changeid` and `_changectx` check explicit. The
same logic was previously performed by the `self.rev()` call. The new code is
a bit redundant, but much clearer.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -771,10 +771,17 @@  class basefilectx(object):
         'linkrev-shadowing' when a file revision is used by multiple
         changesets.
         """
+        toprev = None
         attrs = vars(self)
-        hastoprev = (r'_changeid' in attrs or r'_changectx' in attrs)
-        if hastoprev:
-            return self._adjustlinkrev(self.rev(), inclusive=True)
+        if r'_changeid' in attrs:
+            # We have a cached value already
+            toprev = self._changeid
+        elif r'_changectx' in attrs:
+            # We know which changelog entry we are coming from
+            toprev = self._changectx.rev()
+
+        if toprev is not None:
+            return self._adjustlinkrev(toprev, inclusive=True)
         else:
             return self.linkrev()