context: start walking from "introrev" in blockancestors() stable
authorDenis Laxalde <denis@laxalde.org>
Thu, 20 Apr 2017 21:40:28 +0200
branchstable
changeset 32063 befefdd34cf8
parent 32062 ad6c5497cd15
child 32064 f82cdd5ee57e
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.
mercurial/context.py
tests/test-annotate.t
tests/test-hgweb-filelog.t
--- a/mercurial/context.py	Thu Apr 13 16:09:40 2017 -0400
+++ b/mercurial/context.py	Thu Apr 20 21:40:28 2017 +0200
@@ -1192,6 +1192,9 @@
     `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))
--- a/tests/test-annotate.t	Thu Apr 13 16:09:40 2017 -0400
+++ b/tests/test-annotate.t	Thu Apr 20 21:40:28 2017 +0200
@@ -488,6 +488,8 @@
 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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   ~
 
 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]
--- a/tests/test-hgweb-filelog.t	Thu Apr 13 16:09:40 2017 -0400
+++ b/tests/test-hgweb-filelog.t	Thu Apr 20 21:40:28 2017 +0200
@@ -1220,6 +1220,8 @@
   > 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 @@
   
   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 @@
   <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 @@
     <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 @@
   
   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 @@
     <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>