Patchwork [4,of,6] revset: use "canonpath()" for "filelog()" pattern without explicit kind

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Jan. 17, 2014, 2:57 p.m.
Message ID <107b42f24ba9ff316fc4.1389970626@juju>
Download mbox | patch
Permalink /patch/3371/
State Accepted
Commit b61ad01c4e7334e369b0fa6f20983c6bb25c035a
Headers show

Comments

Katsunori FUJIWARA - Jan. 17, 2014, 2:57 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1389970503 -32400
#      Fri Jan 17 23:55:03 2014 +0900
# Node ID 107b42f24ba9ff316fc45ea89c5c7d093258b15e
# Parent  2a4c78d82827918ffbb7109c75e083cfdb260616
revset: use "canonpath()" for "filelog()" pattern without explicit kind

Before this patch, revset predicate "filelog()" uses "match.files()"
to get filename also for the pattern without explicit kind.

But in such case, only canonicalization of relative path is required,
and other initializations of "match" object including regexp
compilation are meaningless.

This patch uses "pathutil.canonpath()" directly for "filelog()"
pattern without explicit kind like "glob:", for efficiency.

This patch also does below as a part of introducing "canonpath()":

  - move location of "matchmod.match()" invocation, because "m" is no
    more used in "if not matchmod.patkind(pat)" code path

  - omit passing "default" argument to "matchmod.match()", because
    "pat" should have explicit kind of pattern in this code path

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -717,16 +717,15 @@ 
 
     # i18n: "filelog" is a keyword
     pat = getstring(x, _("filelog requires a pattern"))
-    m = matchmod.match(repo.root, repo.getcwd(), [pat], default='relpath',
-                       ctx=repo[None])
     s = set()
 
     if not matchmod.patkind(pat):
-        f = m.files()[0]
+        f = pathutil.canonpath(repo.root, repo.getcwd(), pat)
         fl = repo.file(f)
         for fr in fl:
             s.add(fl.linkrev(fr))
     else:
+        m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None])
         for f in repo[None]:
             if m(f):
                 fl = repo.file(f)
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -292,6 +292,12 @@ 
   $ log 'file("b*")'
   1
   4
+  $ log 'filelog("b")'
+  1
+  4
+  $ log 'filelog("../repo/b")'
+  1
+  4
   $ log 'follow()'
   0
   1