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'] [] 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'] [] 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'] [] 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'] [] diff --git a/tests/test-log.t b/tests/test-log.t --- a/tests/test-log.t +++ b/tests/test-log.t @@ -715,6 +715,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)')"