[PATCH STABLE] context: start walking from "introrev" in blockancestors()

Denis Laxalde denis at laxalde.org
Fri Apr 21 17:47:39 EDT 2017


# HG changeset patch
# User Denis Laxalde <denis at laxalde.org>
# Date 1492717228 -7200
#      Thu Apr 20 21:40:28 2017 +0200
# Branch stable
# Node ID aa42fe719405c5df9ff2e402dae3609f05dd0710
# Parent  e5ffc91a2276e356a38eb75ad5055f65f90f1872
context: start walking from "introrev" in blockancestors()

Previously, calling blockancestors() with a fctx not touching file would
sometimes yield this filectx first, instead of the first "block ancestor",
because when compared to its parent it may have changes in specified line
range despite not touching the file at all.

Fixing this by starting the algorithm from the "base" filectx obtained using
fctx.introrev() (as done in annotate()).

In tests, add a changeset not touching file we want to follow lines of to
cover this case. Do this in test-annotate.t for followlines revset tests and
in test-hgweb-filelog.t for /log/<rev>/<file>?linerange=<from>:<to> tests.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1192,6 +1192,9 @@ def blockancestors(fctx, fromline, tolin
     `fromline`-`toline` range.
     """
     diffopts = patch.diffopts(fctx._repo.ui)
+    introrev = fctx.introrev()
+    if fctx.rev() != introrev:
+        fctx = fctx.filectx(fctx.filenode(), changeid=introrev)
     visit = {(fctx.linkrev(), fctx.filenode()): (fctx, (fromline, toline))}
     while visit:
         c, linerange2 = visit.pop(max(visit))
diff --git a/tests/test-annotate.t b/tests/test-annotate.t
--- a/tests/test-annotate.t
+++ b/tests/test-annotate.t
@@ -488,6 +488,8 @@ Test followlines() revset; we usually ch
 followlines(pat, range, descend=True) to make sure both give the same result
 when they should.
 
+  $ echo a >> foo
+  $ hg ci -m 'foo: add a'
   $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 3:5)'
   16: baz:0
   19: baz:3
@@ -528,17 +530,17 @@ when they should.
   16: baz:0
   19: baz:3
   20: baz:4
-  23: baz:3->3+
+  24: baz:3->3+
   $ 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+
+  24: baz:3->3+
   $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 1:2, descend=false)'
-  21: added two lines with 0
+  22: added two lines with 0
 
 file patterns are okay
   $ hg log -T '{rev}: {desc}\n' -r 'followlines("path:baz", 1:2)'
-  21: added two lines with 0
+  22: added two lines with 0
 
 renames are followed
   $ hg mv baz qux
@@ -549,15 +551,15 @@ renames are followed
   16: baz:0
   19: baz:3
   20: baz:4
-  23: baz:3->3+
-  24: qux:4->4+
+  24: baz:3->3+
+  25: qux:4->4+
 
 but are missed when following children
   $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7, startrev=22, descend=True)'
-  23: baz:3->3+
+  24: baz:3->3+
 
 merge
-  $ hg up 23 --quiet
+  $ hg up 24 --quiet
   $ echo 7 >> baz
   $ hg ci -m 'one more line, out of line range'
   created new head
@@ -568,9 +570,9 @@ merge
   16: baz:0
   19: baz:3
   20: baz:4
-  23: baz:3->3+
-  26: baz:3+->3-
-  $ hg merge 24
+  24: baz:3->3+
+  27: baz:3+->3-
+  $ hg merge 25
   merging baz and qux to qux
   0 files updated, 1 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
@@ -579,12 +581,12 @@ merge
   16: baz:0
   19: baz:3
   20: baz:4
-  23: baz:3->3+
-  24: qux:4->4+
-  26: baz:3+->3-
-  27: merge
-  $ hg up 24 --quiet
-  $ hg merge 26
+  24: baz:3->3+
+  25: qux:4->4+
+  27: baz:3+->3-
+  28: merge
+  $ hg up 25 --quiet
+  $ hg merge 27
   merging qux and baz to qux
   0 files updated, 1 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
@@ -594,28 +596,28 @@ merge
   16: baz:0
   19: baz:3
   20: baz:4
-  23: baz:3->3+
-  24: qux:4->4+
-  26: baz:3+->3-
-  28: merge from other side
-  $ hg up 23 --quiet
+  24: baz:3->3+
+  25: qux:4->4+
+  27: baz:3+->3-
+  29: merge from other side
+  $ hg up 24 --quiet
 
 we are missing the branch with rename when following children
-  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7, startrev=25, descend=True)'
-  26: baz:3+->3-
+  $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 5:7, startrev=26, descend=True)'
+  27: baz:3+->3-
 
 we follow all branches in descending direction
-  $ hg up 22 --quiet
+  $ hg up 23 --quiet
   $ sed 's/3/+3/' baz > baz.new
   $ mv baz.new baz
   $ hg ci -m 'baz:3->+3'
   created new head
   $ hg log -T '{rev}: {desc}\n' -r 'followlines(baz, 2:5, startrev=16, descend=True)' --graph
-  @  29: baz:3->+3
+  @  30: baz:3->+3
   :
-  : o  26: baz:3+->3-
+  : o  27: baz:3+->3-
   : :
-  : o  23: baz:3->3+
+  : o  24: baz:3->3+
   :/
   o    20: baz:4
   |\
@@ -628,7 +630,7 @@ we follow all branches in descending dir
   ~
 
 check error cases
-  $ hg up 23 --quiet
+  $ hg up 24 --quiet
   $ hg log -r 'followlines()'
   hg: parse error: followlines takes at least 1 positional arguments
   [255]
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
@@ -1220,6 +1220,8 @@ filelog with 'linerange' and 'patch'
   > f+
   > EOF
   $ hg ci -m 'touching beginning and end of c' c
+  $ echo c > cc
+  $ hg ci -Am 'tip does not touch c' cc
   $ hg log -r 'followlines(c, 3:4, startrev=tip) and follow(c)' -p
   changeset:   0:6563da9dcf87
   user:        test
@@ -1289,7 +1291,6 @@ filelog with 'linerange' and 'patch'
   
   changeset:   11:fb9bc322513a
   branch:      a-branch
-  tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     touching beginning and end of c
@@ -1369,7 +1370,7 @@ filelog with 'linerange' and 'patch'
   <div class="main">
   <h2 class="breadcrumb"><a href="/">Mercurial</a> </h2>
   <h3>
-   log c @ 11:<a href="/rev/fb9bc322513a">fb9bc322513a</a>
+   log c @ 12:<a href="/rev/6e4182052f7b">6e4182052f7b</a>
    <span class="branchname">a-branch</span> <span class="tag">tip</span> 
     (following lines 3:4 <a href="/log/tip/c">back to filelog</a>)
   </h3>
@@ -1400,7 +1401,7 @@ filelog with 'linerange' and 'patch'
     <td class="author">test</td>
     <td class="description">
      <a href="/rev/fb9bc322513a">touching beginning and end of c</a>
-     <span class="branchhead">a-branch</span> <span class="tag">tip</span> 
+     <span class="branchname">a-branch</span> 
     </td>
    </tr>
    <tr><td colspan="3"><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
@@ -1546,7 +1547,6 @@ filelog with 'linerange' and 'patch'
   
   changeset:   11:fb9bc322513a
   branch:      a-branch
-  tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     touching beginning and end of c
@@ -1675,7 +1675,7 @@ filelog with 'linerange' and 'patch'
     <td class="author">test</td>
     <td class="description">
      <a href="/rev/fb9bc322513a">touching beginning and end of c</a>
-     <span class="branchhead">a-branch</span> <span class="tag">tip</span> 
+     <span class="branchname">a-branch</span> 
     </td>
    </tr>
    


More information about the Mercurial-devel mailing list