[PATCH 2 of 4 STABLE] filectx: extract function to create parent fctx keeping ancestry info

Yuya Nishihara yuya at tcha.org
Sat Apr 18 06:28:12 CDT 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1429333421 -32400
#      Sat Apr 18 14:03:41 2015 +0900
# Branch stable
# Node ID 54242b301d723b516a27932e13d83fd213a0e3bb
# Parent  0ff963ddcf2be79598659cc75f5992dc3cd0950f
filectx: extract function to create parent fctx keeping ancestry info

committablefilectx.parents() should use this to take advantage of the linkrev
adjustment.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -806,6 +806,22 @@ class basefilectx(object):
         return self._adjustlinkrev(self._path, self._filelog, self._filenode,
                                    self.rev(), inclusive=True)
 
+    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
+
     def parents(self):
         _path = self._path
         fl = self._filelog
@@ -824,22 +840,7 @@ class basefilectx(object):
             # first nullid parent with rename information.
             pl.insert(0, (r[0], r[1], self._repo.file(r[0])))
 
-        ret = []
-        for path, fnode, l in pl:
-            fctx = filectx(self._repo, path, fileid=fnode, filelog=l)
-            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)
-            ret.append(fctx)
-        return ret
+        return [self._parentfilectx(path, fnode, l) for path, fnode, l in pl]
 
     def p1(self):
         return self.parents()[0]


More information about the Mercurial-devel mailing list