# HG changeset patch # User Yuya Nishihara # Date 1599715392 -32400 # Node ID 8ceb5b4b2728181162986c842a4a5ee7983ec285 # Parent 3dc848d5ec7744f7315d3be399646890ed98fd09 grep: make -frREV follow history from the specified revision (BC) This is close to what "log -frREV" will do, and is backported from 8b4b9ee6001a, "log: make -fr show complete history from the given revs" except for the "del opts['follow']" bit. I'm planning to rewrite cmdutil.walkchangerevs() to share the core logic with logcmdutil, and this is the first step towards that. There are still many broken tests, but the fundamental behavior should be fixed by this patch. .. bc:: `hg grep -fr REV` now follows history from the specified `REV`, works in the same way as `hg log -fr REV`. The previous behavior was to limit the search space to `REV` while following the history. diff -r 3dc848d5ec77 -r 8ceb5b4b2728 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Fri Sep 11 18:33:41 2020 +0900 +++ b/mercurial/cmdutil.py Thu Sep 10 14:23:12 2020 +0900 @@ -2254,8 +2254,12 @@ # Default --rev value depends on --follow but --follow behavior # depends on revisions resolved from --rev... follow = opts.get(b'follow') or opts.get(b'follow_first') - if opts.get(b'rev'): - revs = scmutil.revrange(repo, opts[b'rev']) + revspec = opts.get(b'rev') + if follow and revspec: + revs = scmutil.revrange(repo, revspec) + revs = repo.revs(b'reverse(::%ld)', revs) + elif revspec: + revs = scmutil.revrange(repo, revspec) elif follow and repo.dirstate.p1() == nullid: revs = smartset.baseset() elif follow: diff -r 3dc848d5ec77 -r 8ceb5b4b2728 tests/test-grep.t --- a/tests/test-grep.t Fri Sep 11 18:33:41 2020 +0900 +++ b/tests/test-grep.t Thu Sep 10 14:23:12 2020 +0900 @@ -949,12 +949,18 @@ 2: A add0-cp2, A add0-cp2-mod2, M add0-mod2, R add0-rm2 0: A add0, A add0-mod1, A add0-mod2, A add0-mod3, A add0-mod4, A add0-rm1, A add0-rm2, A add0-rm4 - BROKEN: should follow history $ hg grep --diff -fr2 data add0-cp2-mod2:2:+:data2 add0-mod2:2:+:data2 + add0:0:+:data0 + add0-mod1:0:+:data0 + add0-mod2:0:+:data0 + add0-mod3:0:+:data0 + add0-mod4:0:+:data0 + add0-rm1:0:+:data0 + add0-rm2:0:+:data0 + add0-rm4:0:+:data0 - BROKEN: should follow history $ hg grep -fr2 data add0:2:data0 add0-cp2:2:data0 @@ -967,6 +973,14 @@ add0-mod4:2:data0 add0-rm1:2:data0 add0-rm4:2:data0 + add0:0:data0 + add0-mod1:0:data0 + add0-mod2:0:data0 + add0-mod3:0:data0 + add0-mod4:0:data0 + add0-rm1:0:data0 + add0-rm2:0:data0 + add0-rm4:0:data0 follow revision history from wdir: @@ -984,7 +998,6 @@ add0-rm4:2147483647:-:abort: add0-rm4@None: not found in manifest! [255] - BROKEN: should follow history $ hg grep -fr'wdir()' data add0:2147483647:data0 add0-cp1:2147483647:data0 @@ -1005,24 +1018,22 @@ add0-mod4:2147483647:data0 add0-mod4:2147483647:data4 add0-rm2:2147483647:data0 - -follow revision history from multiple revisions: - - $ hg log -fr'1+2' - 2: A add0-cp2, A add0-cp2-mod2, M add0-mod2, R add0-rm2 - 1: A add0-cp1, A add0-cp1-mod1, A add0-cp1-mod1-rm3, M add0-mod1, R add0-rm1 - 0: A add0, A add0-mod1, A add0-mod2, A add0-mod3, A add0-mod4, A add0-rm1, A add0-rm2, A add0-rm4 - - BROKEN: should follow history - BROKEN: should include the revision 2 - $ hg grep --diff -fr'1+2' data - add0-cp1-mod1:1:+:data1 - add0-cp1-mod1-rm3:1:+:data1 - add0-mod1:1:+:data1 - - BROKEN: should follow history - BROKEN: should include the revision 2 - $ hg grep -fr'1+2' data + add0:3:data0 + add0-cp1:3:data0 + add0-cp1-cp3:3:data0 + add0-cp1-mod1:3:data0 + add0-cp1-mod1:3:data1 + add0-cp1-mod1-cp3-mod3:3:data0 + add0-cp1-mod1-cp3-mod3:3:data1 + add0-cp1-mod1-cp3-mod3:3:data3 + add0-mod1:3:data0 + add0-mod1:3:data1 + add0-mod2:3:data0 + add0-mod3:3:data0 + add0-mod3:3:data3 + add0-mod4:3:data0 + add0-rm2:3:data0 + add0-rm4:3:data0 add0:1:data0 add0-cp1:1:data0 add0-cp1-mod1:1:data0 @@ -1036,6 +1047,56 @@ add0-mod4:1:data0 add0-rm2:1:data0 add0-rm4:1:data0 + add0:0:data0 + add0-mod1:0:data0 + add0-mod2:0:data0 + add0-mod3:0:data0 + add0-mod4:0:data0 + add0-rm1:0:data0 + add0-rm2:0:data0 + add0-rm4:0:data0 + +follow revision history from multiple revisions: + + $ hg log -fr'1+2' + 2: A add0-cp2, A add0-cp2-mod2, M add0-mod2, R add0-rm2 + 1: A add0-cp1, A add0-cp1-mod1, A add0-cp1-mod1-rm3, M add0-mod1, R add0-rm1 + 0: A add0, A add0-mod1, A add0-mod2, A add0-mod3, A add0-mod4, A add0-rm1, A add0-rm2, A add0-rm4 + + BROKEN: should include the revision 1 + $ hg grep --diff -fr'1+2' data + add0-cp2-mod2:2:+:data2 + add0-mod2:2:+:data2 + add0:0:+:data0 + add0-mod1:0:+:data0 + add0-mod2:0:+:data0 + add0-mod3:0:+:data0 + add0-mod4:0:+:data0 + add0-rm1:0:+:data0 + add0-rm2:0:+:data0 + add0-rm4:0:+:data0 + + BROKEN: should include the revision 1 + $ hg grep -fr'1+2' data + add0:2:data0 + add0-cp2:2:data0 + add0-cp2-mod2:2:data0 + add0-cp2-mod2:2:data2 + add0-mod1:2:data0 + add0-mod2:2:data0 + add0-mod2:2:data2 + add0-mod3:2:data0 + add0-mod4:2:data0 + add0-rm1:2:data0 + add0-rm4:2:data0 + add0:0:data0 + add0-mod1:0:data0 + add0-mod2:0:data0 + add0-mod3:0:data0 + add0-mod4:0:data0 + add0-rm1:0:data0 + add0-rm2:0:data0 + add0-rm4:0:data0 follow file history from wdir parent, unmodified in wdir: @@ -1143,7 +1204,8 @@ BROKEN: should abort $ hg grep -fr. data add0-cp1-mod1-rm3 - [1] + add0-cp1-mod1-rm3:1:data0 + add0-cp1-mod1-rm3:1:data1 follow file history from wdir parent, removed in wdir: @@ -1167,13 +1229,13 @@ $ hg log -fr. add0-rm4 0: A add0, A add0-mod1, A add0-mod2, A add0-mod3, A add0-mod4, A add0-rm1, A add0-rm2, A add0-rm4 - BROKEN: should follow history $ hg grep --diff -fr. data add0-rm4 - [1] + add0-rm4:0:+:data0 - BROKEN: should follow history $ hg grep -fr. data add0-rm4 add0-rm4:3:data0 + add0-rm4:1:data0 + add0-rm4:0:data0 follow file history from wdir parent, multiple files: @@ -1207,14 +1269,14 @@ 2: A add0-cp2, A add0-cp2-mod2, M add0-mod2, R add0-rm2 0: A add0, A add0-mod1, A add0-mod2, A add0-mod3, A add0-mod4, A add0-rm1, A add0-rm2, A add0-rm4 - BROKEN: should follow history from the specified revision + BROKEN: should include the revision 2 $ hg grep --diff -fr2 data add0-mod2 - [1] + add0-mod2:0:+:data0 - BROKEN: should follow history $ hg grep -fr2 data add0-mod2 add0-mod2:2:data0 add0-mod2:2:data2 + add0-mod2:0:data0 follow file history from specified revision, copied but unmodified: @@ -1255,11 +1317,11 @@ BROKEN: should abort $ hg grep --diff -fr2 data add0-rm2 - [1] + add0-rm2:0:+:data0 BROKEN: should abort $ hg grep -fr2 data add0-rm2 - [1] + add0-rm2:0:data0 follow file history from specified revision, multiple files: @@ -1272,11 +1334,12 @@ abort: cannot follow file not in parent revision: "add0-cp2" [255] - BROKEN: should follow history + BROKEN: should follow history across renames $ hg grep -fr2 data add0-cp2 add0-mod2 add0-cp2:2:data0 add0-mod2:2:data0 add0-mod2:2:data2 + add0-mod2:0:data0 follow file history from wdir, unmodified: @@ -1285,14 +1348,17 @@ 3: A add0-cp1-cp3, A add0-cp1-mod1-cp3-mod3, R add0-cp1-mod1-rm3, M add0-mod3 0: A add0, A add0-mod1, A add0-mod2, A add0-mod3, A add0-mod4, A add0-rm1, A add0-rm2, A add0-rm4 - BROKEN: should follow history $ hg grep --diff -fr'wdir()' data add0-mod3 - [1] + add0-mod3:3:+:data3 + add0-mod3:0:+:data0 - BROKEN: should follow history $ hg grep -fr'wdir()' data add0-mod3 add0-mod3:2147483647:data0 add0-mod3:2147483647:data3 + add0-mod3:3:data0 + add0-mod3:3:data3 + add0-mod3:1:data0 + add0-mod3:0:data0 follow file history from wdir, modified: @@ -1300,14 +1366,16 @@ 2147483647: A add0-cp4, A add0-cp4-mod4, M add0-mod4, R add0-rm4 0: A add0, A add0-mod1, A add0-mod2, A add0-mod3, A add0-mod4, A add0-rm1, A add0-rm2, A add0-rm4 - BROKEN: should follow history and show the changes in wdir + BROKEN: should include the changes in wdir $ hg grep --diff -fr'wdir()' data add0-mod4 - [1] + add0-mod4:0:+:data0 - BROKEN: should follow history $ hg grep -fr'wdir()' data add0-mod4 add0-mod4:2147483647:data0 add0-mod4:2147483647:data4 + add0-mod4:3:data0 + add0-mod4:1:data0 + add0-mod4:0:data0 follow file history from wdir, copied but unmodified: @@ -1352,12 +1420,19 @@ abort: cannot follow file not in parent revision: "add0-cp4" [255] - BROKEN: should follow history + BROKEN: should follow history across renames $ hg grep -fr'wdir()' data add0-cp4 add0-mod4 add0-mod3 add0-cp4:2147483647:data0 add0-mod3:2147483647:data0 add0-mod3:2147483647:data3 add0-mod4:2147483647:data0 add0-mod4:2147483647:data4 + add0-mod3:3:data0 + add0-mod3:3:data3 + add0-mod4:3:data0 + add0-mod3:1:data0 + add0-mod4:1:data0 + add0-mod3:0:data0 + add0-mod4:0:data0 $ cd ..