[PATCH 2 of 3] context: add an assertion checking linerange consistency in blockdescendants()

Denis Laxalde denis at laxalde.org
Fri Apr 14 09:03:55 EDT 2017


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1492171766 -7200
#      Fri Apr 14 14:09:26 2017 +0200
# Node ID 7ddcc9c1844b284e72bcbbb4697fb88a46ac1b44
# Parent  45c2968ee4ed385aa6ab64b7136a38180ca03ec5
# Available At http://hg.logilab.org/users/dlaxalde/hg
#              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 7ddcc9c1844b
context: add an assertion checking linerange consistency in blockdescendants()

If this assertion fails, this indicates a flaw in the algorithm. So fail fast
instead of possibly producing wrong results.

Also extend the target line range in test to catch a merge changeset with all
its parents.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1226,6 +1226,12 @@ def blockdescendants(fctx, fromline, tol
                 continue
             inrangep, linerange1 = _changesrange(c, p, linerange2, diffopts)
             inrange = inrange or inrangep
+            # If revision 'i' has been seen (it's a merge), we assume that its
+            # line range is the same independently of which parents was used
+            # to compute it.
+            assert i not in seen or seen[i][1] == linerange1, (
+                'computed line range for %s is not consistent between '
+                'ancestor branches' % c)
             seen[i] = c, linerange1
         if inrange:
             yield c, linerange1
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -606,7 +606,7 @@ we follow all branches in descending dir
   $ mv baz.new baz
   $ hg ci -m 'baz:3->+3'
   created new head
-  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=16, descend=True)' --graph
+  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 2:5, startrev=16, descend=True)' --graph
   @  29: baz:3->+3
   :
   : o  26: baz:3+->3-
@@ -615,10 +615,11 @@ we follow all branches in descending dir
   :/
   o    20: baz:4
   |\
-  | ~
-  o  19: baz:3
-  |
-  ~
+  | o  19: baz:3
+  |/
+  o    18: baz:2
+  |\
+  ~ ~
 
 check error cases
   $ hg up 23 --quiet


More information about the Mercurial-devel mailing list