[PATCH] log: allow patterns with -f
Durham Goode
durham at fb.com
Mon Aug 4 18:54:57 CDT 2014
# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1406094016 25200
# Tue Jul 22 22:40:16 2014 -0700
# Node ID 1f65f28adc72cd6fcfcb1a1d23e2284b888b2376
# Parent c6e1f2c6d5f19538869338fa50ad519be6eb9b24
log: allow patterns with -f
It's not uncommon for a user to want to run log with a pattern or directory name
on the history of their current commit. Currently we prevent that, but
I can't think of any reason to continue blocking that.
This commit removes the restriction and allows 'hg log -f <dir/pat>'
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1570,8 +1570,14 @@
if not slowpath:
for f in match.files():
if follow and f not in pctx:
- raise util.Abort(_('cannot follow file not in parent '
- 'revision: "%s"') % f)
+ # If the file exists, it may be a directory, so let it
+ # take the slow path.
+ if os.path.exists(repo.wjoin(f)):
+ slowpath = True
+ continue
+ else:
+ raise util.Abort(_('cannot follow file not in parent '
+ 'revision: "%s"') % f)
filelog = repo.file(f)
if not filelog:
# A zero count may be a directory or deleted file, so
@@ -1595,9 +1601,6 @@
if slowpath:
# See walkchangerevs() slow path.
#
- if follow:
- raise util.Abort(_('can only follow copies/renames for explicit '
- 'filenames'))
# pats/include/exclude cannot be represented as separate
# revset expressions as their filtering logic applies at file
# level. For instance "-I a -X a" matches a revision touching
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -1645,13 +1645,28 @@
('symbol', 'filelog')
('string', 'aa'))))
-Test --follow on a directory
+Test --follow on a non-existent directory
$ testlog -f dir
abort: cannot follow file not in parent revision: "dir"
abort: cannot follow file not in parent revision: "dir"
abort: cannot follow file not in parent revision: "dir"
+Test --follow on a directory
+
+ $ hg up -q .^
+ $ testlog -f dir
+ []
+ (group
+ (func
+ ('symbol', '_matchfiles')
+ (list
+ (list
+ ('string', 'r:')
+ ('string', 'd:relpath'))
+ ('string', 'p:dir'))))
+ $ hg up -q tip
+
Test --follow on file not in parent revision
$ testlog -f a
@@ -1662,9 +1677,15 @@
Test --follow and patterns
$ testlog -f 'glob:*'
- abort: can only follow copies/renames for explicit filenames
- abort: can only follow copies/renames for explicit filenames
- abort: can only follow copies/renames for explicit filenames
+ []
+ (group
+ (func
+ ('symbol', '_matchfiles')
+ (list
+ (list
+ ('string', 'r:')
+ ('string', 'd:relpath'))
+ ('string', 'p:glob:*'))))
Test --follow on a single rename
@@ -1829,9 +1850,15 @@
('string', 'd:relpath'))
('string', 'p:a'))))
$ testlog --removed --follow a
- abort: can only follow copies/renames for explicit filenames
- abort: can only follow copies/renames for explicit filenames
- abort: can only follow copies/renames for explicit filenames
+ []
+ (group
+ (func
+ ('symbol', '_matchfiles')
+ (list
+ (list
+ ('string', 'r:')
+ ('string', 'd:relpath'))
+ ('string', 'p:a'))))
Test --patch and --stat with --follow and --follow-first
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -78,12 +78,31 @@
summary: c
--f, directory
+-f, non-existent directory
$ hg log -f dir
abort: cannot follow file not in parent revision: "dir"
[255]
+-f, directory
+
+ $ hg up -q 3
+ $ hg log -f dir
+ changeset: 2:f8954cd4dc1f
+ user: test
+ date: Thu Jan 01 00:00:03 1970 +0000
+ summary: c
+
+-f, pattern
+
+ $ hg log -f -I 'dir**'
+ changeset: 2:f8954cd4dc1f
+ user: test
+ date: Thu Jan 01 00:00:03 1970 +0000
+ summary: c
+
+ $ hg up -q 4
+
-f, a wrong style
$ hg log -f -l1 --style something
More information about the Mercurial-devel
mailing list