log: speed up hg log for untracked files (
issue1340)
'hg log' on untracked files tends to be fairly slow. The root cause is that we end up using the 'slowpath' when we can't find a revlog for the files listed. This could happen if the file in question is an untracked file, or it is a directory.
This diff tries to speed up 'hg log' (by avoiding the slowpath) for files if we can determine if that file is not (and was never) a directory. We use the previously added store.__contains__ methods to test if the directory exists (or existed) in the store.
To avoid changing any existing semantics, this 'optimization' kicks in only when none of the files listed as arguments to the hg log command exist in the store.
--- a/mercurial/cmdutil.py Thu Sep 13 17:57:43 2012 -0700
+++ b/mercurial/cmdutil.py Thu Sep 13 23:50:45 2012 -0700
@@ -1111,6 +1111,17 @@
wanted.add(rev)
if copied:
copies.append(copied)
+
+ # We decided to fall back to the slowpath because at least one
+ # of the paths was not a file. Check to see if at least one of them
+ # existed in history, otherwise simply return
+ if slowpath:
+ for path in match.files():
+ if path == '.' or path in repo.store:
+ break
+ else:
+ return []
+
if slowpath:
# We have to read the changelog to match filenames against
# changed files
@@ -1286,6 +1297,18 @@
raise util.Abort(
_('cannot follow nonexistent file: "%s"') % f)
slowpath = True
+
+ # We decided to fall back to the slowpath because at least one
+ # of the paths was not a file. Check to see if at least one of them
+ # existed in history - in that case, we'll continue down the
+ # slowpath; otherwise, we can turn off the slowpath
+ if slowpath:
+ for path in match.files():
+ if path == '.' or path in repo.store:
+ break
+ else:
+ slowpath = False
+
if slowpath:
# See walkchangerevs() slow path.
#
--- a/tests/test-log.t Thu Sep 13 17:57:43 2012 -0700
+++ b/tests/test-log.t Thu Sep 13 23:50:45 2012 -0700
@@ -1213,3 +1213,52 @@
1
$ cd ..
+
+test hg log on non-existent files and on directories
+ $ hg init issue1340
+ $ cd issue1340
+ $ mkdir d1; mkdir D2; mkdir D3.i; mkdir d4.hg; mkdir d5.d; mkdir .d6
+ $ echo 1 > d1/f1
+ $ echo 1 > D2/f1
+ $ echo 1 > D3.i/f1
+ $ echo 1 > d4.hg/f1
+ $ echo 1 > d5.d/f1
+ $ echo 1 > .d6/f1
+ $ hg add .
+ adding .d6/f1
+ adding D2/f1
+ adding D3.i/f1
+ adding d1/f1
+ adding d4.hg/f1
+ adding d5.d/f1
+ $ hg commit -m "a bunch of weird directories"
+ $ hg log -l1 d1/f1 | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 f1
+ $ hg log -l1 . | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 ./ | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 d1 | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 D2 | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 D2/f1 | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 D3.i | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 D3.i/f1 | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 d4.hg | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 d4.hg/f1 | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 d5.d | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 d5.d/f1 | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 .d6 | grep changeset
+ changeset: 0:65624cd9070a
+ $ hg log -l1 .d6/f1 | grep changeset
+ changeset: 0:65624cd9070a
+ $ cd ..