Patchwork [3,of,9] log: resolve --follow with -rREV in cmdutil.getlogrevs()

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 15, 2018, 1:26 p.m.
Message ID <f9849de6ba434e9a303d.1516022797@mimosa>
Download mbox | patch
Permalink /patch/26764/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 15, 2018, 1:26 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1512894524 -32400
#      Sun Dec 10 17:28:44 2017 +0900
# Node ID f9849de6ba434e9a303d84474f0b22e84235578d
# Parent  c446d8a3c0e2aef4ec10fd654b6bc91b2972e06a
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.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2518,10 +2518,19 @@  def getlogrevs(repo, pats, opts):
     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
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3405,14 +3405,6 @@  def log(ui, repo, *pats, **opts):
             _('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
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -2295,28 +2295,28 @@  changessincelatesttag with no prior tag
   -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->
 
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -711,6 +711,15 @@  log -f -r '1 + 4'
   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)')"