[PATCH 2 of 6] revset: make default kind of pattern for "contains()" rooted at cwd

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Fri Jan 17 08:57:04 CST 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1389969732 -32400
#      Fri Jan 17 23:42:12 2014 +0900
# Node ID fbeb931aa253e163ebfd44f7859f97aae7a398bf
# Parent  d601202366e79f2ede928d66b75055e01a105e29
revset: make default kind of pattern for "contains()" rooted at cwd

Before this patch, default kind of pattern for revset predicate
"contains()" is treated as the exact file path rooted at the root of
the repository. This decreases usability, because:

  - all other predicates taking pattern argument (also "filelog()")
    treat such pattern as the path rooted at the current working
    directory

  - "contains()" doesn't describe this difference in its help

  - this difference may confuse users

    for example, this prevents revset aliases from sharing same
    argument between "contains()" and other predicates


This patch makes default kind of pattern for revset predicate
"contains()" be rooted at the current working directory.

This patch uses "pathutil.canonpath()" instead of creating "match"
object for efficiency.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -12,6 +12,7 @@
 from i18n import _
 import encoding
 import obsolete as obsmod
+import pathutil
 import repoview
 
 def _revancestors(repo, revs, followfirst):
@@ -530,6 +531,7 @@
     pat = getstring(x, _("contains requires a pattern"))
     s = []
     if not matchmod.patkind(pat):
+        pat = pathutil.canonpath(repo.root, repo.getcwd(), pat)
         for r in subset:
             if pat in repo[r]:
                 s.append(r)
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -273,6 +273,11 @@
   1
   3
   5
+  $ log 'contains("../repo/a")'
+  0
+  1
+  3
+  5
   $ log 'desc(B)'
   5
   $ log 'descendants(2 or 3)'


More information about the Mercurial-devel mailing list