[PATCH 2 of 5] graphlog: restore FILE glob expansion on Windows

Patrick Mezard patrick at mezard.eu
Sat Feb 25 21:17:42 UTC 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1330204294 -3600
# Node ID 54483f79d991dbabb67df84bf0a12c5779200495
# Parent  3ab31d63dc9c5546201c22cef1b5c8b93b13b6ff
graphlog: restore FILE glob expansion on Windows

On platforms not supporting shell expansion, scmutil.match() performs glob
expansion on 'pats' arguments. But _matchfiles() revset calls match.match()
directly, bypassing this behaviour. To avoid duplicating scmutil.match(), a
secondary scmutil.matchandpats() is introduced returning both the match object
and the expanded inputs. Note the expanded pats are also needed in the fast
path, and will be used by --follow code path.

diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -268,7 +268,11 @@
     if 'branch' in opts and 'only_branch' in opts:
         opts['branch'] = opts['branch'] + opts.pop('only_branch')
 
-    match = scmutil.match(repo[None], pats, opts)
+    # pats/include/exclude are passed to match.match() directly in
+    # _matchfile() revset but walkchangerevs() builds its matcher with
+    # scmutil.match(). The difference is input pats are globbed on
+    # platforms without shell expansion (windows).
+    match, pats = scmutil.matchandpats(repo[None], pats, opts)
     slowpath = match.anypats() or (match.files() and opts.get('removed'))
     if not slowpath:
         for f in match.files():
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -579,7 +579,7 @@
         ret.append(p)
     return ret
 
-def match(ctx, pats=[], opts={}, globbed=False, default='relpath'):
+def matchandpats(ctx, pats=[], opts={}, globbed=False, default='relpath'):
     if pats == ("",):
         pats = []
     if not globbed and default == 'relpath':
@@ -590,7 +590,10 @@
     def badfn(f, msg):
         ctx._repo.ui.warn("%s: %s\n" % (m.rel(f), msg))
     m.bad = badfn
-    return m
+    return m, pats
+
+def match(ctx, pats=[], opts={}, globbed=False, default='relpath'):
+    return matchandpats(ctx, pats, opts, globbed, default)[0]
 
 def matchall(repo):
     return matchmod.always(repo.root, repo.getcwd())
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -1510,8 +1510,10 @@
   $ hg init follow
   $ cd follow
   $ echo a > a
+  $ echo aa > aa
   $ hg ci -Am "add a"
   adding a
+  adding aa
   $ hg cp a b
   $ hg ci -m "copy a b"
   $ mkdir dir
@@ -1549,3 +1551,14 @@
 
   $ testlog --include a --include e --exclude b --exclude e a e
   ('group', ('group', ('func', ('symbol', '_matchfiles'), ('list', ('list', ('list', ('list', ('list', ('string', 'p:a'), ('string', 'p:e')), ('string', 'i:a')), ('string', 'i:e')), ('string', 'x:b')), ('string', 'x:e')))))
+
+Test glob expansion of pats
+
+  $ expandglobs=`python -c "import mercurial.util; \
+  >   print mercurial.util.expandglobs and 'true' or 'false'"`
+  $ if [ $expandglobs = "true" ]; then
+  >    testlog 'a*';
+  > else
+  >    testlog a*;
+  > fi;
+  ('group', ('group', ('func', ('symbol', 'filelog'), ('string', 'aa'))))



More information about the Mercurial-devel mailing list