D10150: revlog: guarantee that p1 != null if a non-null parent exists
joerg.sonnenberger (Joerg Sonnenberger)
phabricator at mercurial-scm.org
Wed Mar 10 17:10:03 UTC 2021
joerg.sonnenberger created this revision.
Herald added a reviewer: indygreg.
Herald added a reviewer: durin42.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
This change does not affect the hashing (which already did this
transformation), but can change the log output in the rare case where
this behavior was observed in repositories. The change can simplify
iteration code where regular changesets and merges are distinct
branches.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D10150
AFFECTED FILES
mercurial/revlog.py
relnotes/next
tests/test-narrow-shallow-merges.t
CHANGE DETAILS
diff --git a/tests/test-narrow-shallow-merges.t b/tests/test-narrow-shallow-merges.t
--- a/tests/test-narrow-shallow-merges.t
+++ b/tests/test-narrow-shallow-merges.t
@@ -179,7 +179,7 @@
$ hg log -T '{if(ellipsis,"...")}{node|short} {p1node|short} {p2node|short} {desc}\n' | sort
- ...2a20009de83e 000000000000 3ac1f5779de3 outside 10
+ ...2a20009de83e 3ac1f5779de3 000000000000 outside 10
...3ac1f5779de3 bb96a08b062a 465567bdfb2d merge a/b/c/d 9
...8d874d57adea 7ef88b4dd4fa 000000000000 outside 12
...b844052e7b3b 000000000000 000000000000 outside 2c
diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -21,6 +21,13 @@
== Backwards Compatibility Changes ==
+ * In normal repositories, the first parent of a changeset is not null,
+ unless both parents are null (like the first changeset). Some legacy
+ repositories violate this condition. The revlog code will now
+ silentely swap the parents if this condition is tested. This can
+ change the output of `hg log` when explicitly asking for first or
+ second parent.
+
== Internal API Changes ==
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -878,8 +878,10 @@
if rev == wdirrev:
raise error.WdirUnsupported
raise
-
- return entry[5], entry[6]
+ if entry[5] == nullrev:
+ return entry[6], entry[5]
+ else:
+ return entry[5], entry[6]
# fast parentrevs(rev) where rev isn't filtered
_uncheckedparentrevs = parentrevs
@@ -900,7 +902,11 @@
def parents(self, node):
i = self.index
d = i[self.rev(node)]
- return i[d[5]][7], i[d[6]][7] # map revisions to nodes inline
+ # inline node() to avoid function call overhead
+ if d[5] == nullid:
+ return i[d[6]][7], i[d[5]][7]
+ else:
+ return i[d[5]][7], i[d[6]][7]
def chainlen(self, rev):
return self._chaininfo(rev)[0]
To: joerg.sonnenberger, indygreg, durin42, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list