Patchwork [2,of,2] filectx.parents: filter nullrev parent sooner

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 30, 2014, 4:03 a.m.
Message ID <fbd6a3fba78ade5c4549.1419912225@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/7262/
State Accepted
Commit 20932983d520bbac083a4aff8875384026abc032
Headers show

Comments

Pierre-Yves David - Dec. 30, 2014, 4:03 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1419388143 28800
#      Tue Dec 23 18:29:03 2014 -0800
# Node ID fbd6a3fba78ade5c45495c933bf118389248c496
# Parent  44f97ee76cb556e6357d8638c660954c3088bd37
filectx.parents: filter nullrev parent sooner

We are going to introduce a linkrev-correction phases  when computing parents.
It will be more convenient to have the nullid parent filtered out earlier. I
had to make a minimal adjustment to the rename handling logic to keep it
functional.  That logic have been documented in the process since it took me
some time to check all the cases out.
Matt Mackall - Dec. 30, 2014, 9:21 p.m.
On Mon, 2014-12-29 at 20:03 -0800, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1419388143 28800
> #      Tue Dec 23 18:29:03 2014 -0800
> # Node ID fbd6a3fba78ade5c45495c933bf118389248c496
> # Parent  44f97ee76cb556e6357d8638c660954c3088bd37
> filectx.parents: filter nullrev parent sooner

These are queued for default, thanks.
Matt Mackall - Dec. 30, 2014, 9:31 p.m.
On Mon, 2014-12-29 at 20:03 -0800, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1419388143 28800
> #      Tue Dec 23 18:29:03 2014 -0800
> # Node ID fbd6a3fba78ade5c45495c933bf118389248c496
> # Parent  44f97ee76cb556e6357d8638c660954c3088bd37
> filectx.parents: filter nullrev parent sooner

These are queued for default, thanks.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -734,18 +734,26 @@  class basefilectx(object):
         return True
 
     def parents(self):
         _path = self._path
         fl = self._filelog
-        pl = [(_path, n, fl) for n in self._filelog.parents(self._filenode)]
+        parents = self._filelog.parents(self._filenode)
+        pl = [(_path, node, fl) for node in parents if node != nullid]
 
         r = self._filelog.renamed(self._filenode)
         if r:
-            pl[0] = (r[0], r[1], None)
+            # - 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.
+            #
+            # As null id have alway been filtered out in the previous list
+            # comprehension, inserting to 0 will always result in "replacing
+            # first nullid parent with rename information.
+            pl.insert(0, (r[0], r[1], None))
 
-        return [filectx(self._repo, p, fileid=n, filelog=l)
-                for p, n, l in pl if n != nullid]
+        return [filectx(self._repo, p, fileid=n, filelog=l) for p, n, l in pl]
 
     def p1(self):
         return self.parents()[0]
 
     def p2(self):