log: resolve --follow with -rREV in cmdutil.getlogrevs()
authorYuya Nishihara <yuya@tcha.org>
Sun, 10 Dec 2017 17:28:44 +0900
changeset 35684 1c929b4942a3
parent 35683 ea3320015d54
child 35685 659dfbd852e2
log: resolve --follow with -rREV in cmdutil.getlogrevs() This also fixes alias expansion. Before, reverse() could be overridden by user alias. This isn't processed at _logrevs() as we'll need starting revisions to parse file patterns. See the subsequent patches for details.
mercurial/cmdutil.py
mercurial/commands.py
tests/test-glog.t
tests/test-log.t
--- a/mercurial/cmdutil.py	Sun Dec 10 18:22:06 2017 +0900
+++ b/mercurial/cmdutil.py	Sun Dec 10 17:28:44 2017 +0900
@@ -2518,10 +2518,19 @@
     is a callable taking a revision number and returning a match objects
     filtering the files to be detailed when displaying the revision.
     """
+    follow = opts.get('follow') or opts.get('follow_first')
+    followfirst = opts.get('follow_first')
+    if opts.get('rev'):
+        # TODO: do not mutate opts here
+        opts.pop('follow', None)
+        opts.pop('follow_first', None)
     limit = loglimit(opts)
     revs = _logrevs(repo, opts)
     if not revs:
         return smartset.baseset(), None
+    if opts.get('rev') and follow:
+        revs = dagop.revancestors(repo, revs, followfirst=followfirst)
+        revs.reverse()
     expr, filematcher = _makelogrevset(repo, pats, opts)
     if opts.get('graph') and opts.get('rev'):
         # User-specified revs might be unsorted, but don't sort before
--- a/mercurial/commands.py	Sun Dec 10 18:22:06 2017 +0900
+++ b/mercurial/commands.py	Sun Dec 10 17:28:44 2017 +0900
@@ -3405,14 +3405,6 @@
             _('FILE arguments are not compatible with --line-range option')
         )
 
-    if opts.get('follow_first') and opts.get('rev'):
-        opts['rev'] = [revsetlang.formatspec('reverse(_firstancestors(%lr))',
-                                             opts.get('rev'))]
-        del opts['follow_first']
-    elif opts.get('follow') and opts.get('rev'):
-        opts['rev'] = [revsetlang.formatspec('reverse(::%lr)', opts.get('rev'))]
-        del opts['follow']
-
     repo = scmutil.unhidehashlikerevs(repo, opts.get('rev'), 'nowarn')
     revs, filematcher = cmdutil.getlogrevs(repo, pats, opts)
     hunksfilter = None
--- a/tests/test-glog.t	Sun Dec 10 18:22:06 2017 +0900
+++ b/tests/test-glog.t	Sun Dec 10 17:28:44 2017 +0900
@@ -2295,28 +2295,28 @@
   -f
   +g
   $ testlog --follow -r6 -r8 -r5 -r7 -r4
-  ['reverse(::(((6) or (8)) or ((5) or ((7) or (4)))))']
+  ['6', '8', '5', '7', '4']
   []
   <generatorsetdesc->
 
 Test --follow-first and forward --rev
 
   $ testlog --follow-first -r6 -r8 -r5 -r7 -r4
-  ['reverse(_firstancestors((((6) or (8)) or ((5) or ((7) or (4))))))']
+  ['6', '8', '5', '7', '4']
   []
   <generatorsetdesc->
 
 Test --follow and backward --rev
 
   $ testlog --follow -r6 -r5 -r7 -r8 -r4
-  ['reverse(::(((6) or (5)) or ((7) or ((8) or (4)))))']
+  ['6', '5', '7', '8', '4']
   []
   <generatorsetdesc->
 
 Test --follow-first and backward --rev
 
   $ testlog --follow-first -r6 -r5 -r7 -r8 -r4
-  ['reverse(_firstancestors((((6) or (5)) or ((7) or ((8) or (4))))))']
+  ['6', '5', '7', '8', '4']
   []
   <generatorsetdesc->
 
--- a/tests/test-log.t	Sun Dec 10 18:22:06 2017 +0900
+++ b/tests/test-log.t	Sun Dec 10 17:28:44 2017 +0900
@@ -715,6 +715,15 @@
   date:        Thu Jan 01 00:00:01 1970 +0000
   summary:     base
   
+
+log -fr with aliases: 'A' should be expanded, but 'reverse()' should have no
+effect
+
+  $ hg log --config 'revsetalias.reverse(x)=x' --config 'revsetalias.A=1+4' -qfrA
+  4:ddb82e70d1a1
+  1:3d5bf5654eda
+  0:67e992f2c4f3
+
 log -r "follow('set:grep(b2)')"
 
   $ hg log -r "follow('set:grep(b2)')"