[PATCH 3 of 3] context: possibly yield initial fctx in blockdescendants()

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


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1492172706 -7200
#      Fri Apr 14 14:25:06 2017 +0200
# Node ID 70d27ff6691001bdf51f0e0a2ca9898e4385d834
# Parent  7ddcc9c1844b284e72bcbbb4697fb88a46ac1b44
# Available At http://hg.logilab.org/users/dlaxalde/hg
#              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 70d27ff66910
context: possibly yield initial fctx in blockdescendants()

If initial 'fctx' has changes in line range with respect to its parents, we
yield it first. This makes 'followlines(..., descend=True)' consistent with
'descendants()' revset which yields the starting revision.

We reuse one iteration of blockancestors() which does exactly what we want.

In test-annotate.t, adjust 'startrev' in one case to cover the situation where
the starting revision does not touch specified line range.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1212,6 +1212,16 @@ def blockdescendants(fctx, fromline, tol
     """Yield descendants of `fctx` with respect to the block of lines within
     `fromline`-`toline` range.
     """
+    # First possibly yield 'fctx' if it has changes in range with respect to
+    # its parents.
+    try:
+        c, linerange1 = next(blockancestors(fctx, fromline, toline))
+    except StopIteration:
+        pass
+    else:
+        if c == fctx:
+            yield c, linerange1
+
     diffopts = patch.diffopts(fctx._repo.ui)
     fl = fctx.filelog()
     seen = {fctx.filerev(): (fctx, (fromline, toline))}
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -500,6 +500,7 @@ when they should.
   16: baz:0
   19: baz:3
   $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=19, descend=True)'
+  19: baz:3
   20: baz:4
   $ printf "0\n0\n" | cat - baz > baz1
   $ mv baz1 baz
@@ -509,6 +510,7 @@ when they should.
   19: baz:3
   20: baz:4
   $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, descend=True, startrev=19)'
+  19: baz:3
   20: baz:4
   $ echo 6 >> baz
   $ hg ci -m 'added line 8'
@@ -517,6 +519,7 @@ when they should.
   19: baz:3
   20: baz:4
   $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=19, descend=True)'
+  19: baz:3
   20: baz:4
   $ sed 's/3/3+/' baz > baz.new
   $ mv baz.new baz
@@ -526,7 +529,8 @@ when they should.
   19: baz:3
   20: baz:4
   23: baz:3->3+
-  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=19, descend=True)'
+  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5, startrev=17, descend=True)'
+  19: baz:3
   20: baz:4
   23: baz:3->3+
   $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 1:2)'
@@ -617,9 +621,11 @@ we follow all branches in descending dir
   |\
   | o  19: baz:3
   |/
-  o    18: baz:2
-  |\
-  ~ ~
+  o  18: baz:2
+  :
+  o  16: baz:0
+  |
+  ~
 
 check error cases
   $ hg up 23 --quiet
diff --git a/tests/test-hgweb-filelog.t b/tests/test-hgweb-filelog.t
--- a/tests/test-hgweb-filelog.t
+++ b/tests/test-hgweb-filelog.t
@@ -1502,6 +1502,29 @@ filelog with 'linerange' and 'patch'
   </html>
   
   $ hg log -r 'followlines(c, 3:4, startrev=8, descend=True) and follow(c)' -p
+  changeset:   8:5c6574614c37
+  branch:      a-branch
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     make c bigger and touch its beginning
+  
+  diff -r 46c1a66bd8fc -r 5c6574614c37 c
+  --- a/c	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/c	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,2 +1,11 @@
+  +0
+  +0
+   b
+  -c
+  +c+
+  +
+  +a
+  +a
+  +
+  +d
+  +e
+  +f
+  
   changeset:   10:e95928d60479
   branch:      a-branch
   user:        test
@@ -1633,6 +1656,15 @@ filelog with 'linerange' and 'patch'
     <td class="age">Thu, 01 Jan 1970 00:00:00 +0000</td>
     <td class="author">test</td>
     <td class="description">
+     <a href="/rev/5c6574614c37">make c bigger and touch its beginning</a>
+     <span class="branchname">a-branch</span> 
+    </td>
+   </tr>
+   
+   <tr>
+    <td class="age">Thu, 01 Jan 1970 00:00:00 +0000</td>
+    <td class="author">test</td>
+    <td class="description">
      <a href="/rev/e95928d60479">touch beginning of c</a>
      <span class="branchname">a-branch</span> 
     </td>


More information about the Mercurial-devel mailing list