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.
--- a/mercurial/context.py Tue Dec 23 17:13:51 2014 -0800
+++ b/mercurial/context.py Tue Dec 23 18:29:03 2014 -0800
@@ -736,14 +736,22 @@
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]