[PATCH 38 of 41] basefilectx: move ancestor from filectx

Sean Farley sean.michael.farley at gmail.com
Mon Aug 12 11:27:34 CDT 2013


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1376280308 18000
#      Sun Aug 11 23:05:08 2013 -0500
# Node ID 6a5e7efe1ce482a3d41dea16496abdd03558217d
# Parent  be66e264287aecc83fa3a9f9e6672755bf4695ea
basefilectx: move ancestor from filectx

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -659,10 +659,59 @@
                 hist[f] = curr
                 pcache[f] = []
 
         return zip(hist[base][0], hist[base][1].splitlines(True))
 
+    def ancestor(self, fc2, actx):
+        """
+        find the common ancestor file context, if any, of self, and fc2
+
+        actx must be the changectx of the common ancestor
+        of self's and fc2's respective changesets.
+        """
+
+        # the easy case: no (relevant) renames
+        if fc2.path() == self.path() and self.path() in actx:
+            return actx[self.path()]
+
+        # the next easiest cases: unambiguous predecessor (name trumps
+        # history)
+        if self.path() in actx and fc2.path() not in actx:
+            return actx[self.path()]
+        if fc2.path() in actx and self.path() not in actx:
+            return actx[fc2.path()]
+
+        # prime the ancestor cache for the working directory
+        acache = {}
+        for c in (self, fc2):
+            if c.filenode() is None:
+                pl = [(n.path(), n.filenode()) for n in c.parents()]
+                acache[(c._path, None)] = pl
+
+        flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog}
+        def parents(vertex):
+            if vertex in acache:
+                return acache[vertex]
+            f, n = vertex
+            if f not in flcache:
+                flcache[f] = self._repo.file(f)
+            fl = flcache[f]
+            pl = [(f, p) for p in fl.parents(n) if p != nullid]
+            re = fl.renamed(n)
+            if re:
+                pl.append(re)
+            acache[vertex] = pl
+            return pl
+
+        a, b = (self._path, self._filenode), (fc2._path, fc2._filenode)
+        v = ancestor.genericancestor(a, b, parents)
+        if v:
+            f, n = v
+            return filectx(self._repo, f, fileid=n, filelog=flcache[f])
+
+        return None
+
 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):
@@ -750,59 +799,10 @@
         # hard for renames
         c = self._filelog.children(self._filenode)
         return [filectx(self._repo, self._path, fileid=x,
                         filelog=self._filelog) for x in c]
 
-    def ancestor(self, fc2, actx):
-        """
-        find the common ancestor file context, if any, of self, and fc2
-
-        actx must be the changectx of the common ancestor
-        of self's and fc2's respective changesets.
-        """
-
-        # the easy case: no (relevant) renames
-        if fc2.path() == self.path() and self.path() in actx:
-            return actx[self.path()]
-
-        # the next easiest cases: unambiguous predecessor (name trumps
-        # history)
-        if self.path() in actx and fc2.path() not in actx:
-            return actx[self.path()]
-        if fc2.path() in actx and self.path() not in actx:
-            return actx[fc2.path()]
-
-        # prime the ancestor cache for the working directory
-        acache = {}
-        for c in (self, fc2):
-            if c.filenode() is None:
-                pl = [(n.path(), n.filenode()) for n in c.parents()]
-                acache[(c._path, None)] = pl
-
-        flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog}
-        def parents(vertex):
-            if vertex in acache:
-                return acache[vertex]
-            f, n = vertex
-            if f not in flcache:
-                flcache[f] = self._repo.file(f)
-            fl = flcache[f]
-            pl = [(f, p) for p in fl.parents(n) if p != nullid]
-            re = fl.renamed(n)
-            if re:
-                pl.append(re)
-            acache[vertex] = pl
-            return pl
-
-        a, b = (self._path, self._filenode), (fc2._path, fc2._filenode)
-        v = ancestor.genericancestor(a, b, parents)
-        if v:
-            f, n = v
-            return filectx(self._repo, f, fileid=n, filelog=flcache[f])
-
-        return None
-
     def ancestors(self, followfirst=False):
         visit = {}
         c = self
         cut = followfirst and 1 or None
         while True:


More information about the Mercurial-devel mailing list