[PATCH 4 of 5] graphlog: imitate log slowpath when inputs are explicit files

Patrick Mezard patrick at mezard.eu
Thu Feb 23 11:10:30 CST 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1330016107 -3600
# Node ID 1bfc7ba8b404b650bb360d36bd41c11a80d6f5ab
# Parent  ec33539b61f674130dd85656f1e2ae0dd065f2eb
graphlog: imitate log slowpath when inputs are explicit files

diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -245,7 +245,7 @@
         raise util.Abort(_("-G/--graph option is incompatible with --follow "
                            "with file argument"))
 
-def revset(pats, opts):
+def revset(repo, pats, opts):
     """Return revset str built of revisions, log options and file patterns.
     """
     opt2revset = {
@@ -258,6 +258,7 @@
         'exclude':     ('not file(%(val)r)', ' and '),
         'include':     ('file(%(val)r)', ' and '),
         '_pats':       ('file(%(val)r)', ' or '),
+        '_patslog':    ('filelog(%(val)r)', ' or '),
         'keyword':     ('keyword(%(val)r)', ' or '),
         'prune':       ('not (%(val)r or ancestors(%(val)r))', ' and '),
         'user':        ('user(%(val)r)', ' or '),
@@ -269,7 +270,21 @@
     # the same time
     if 'branch' in opts and 'only_branch' in opts:
         opts['branch'] = opts['branch'] + opts.pop('only_branch')
-    opts['_pats'] = list(pats)
+
+    match = scmutil.match(repo[None], pats, opts)
+    slowpath = match.anypats() or (match.files() and opts.get('removed'))
+    if not slowpath:
+        for f in match.files():
+            filelog = repo.file(f)
+            if not len(filelog):
+                # A zero count may be a directory or deleted file, so
+                # try to find matching entries on the slow path.
+                slowpath = True
+    if slowpath:
+        # See cmdutil.walkchangerevs() slow path
+        opts['_pats'] = list(pats)
+    else:
+        opts['_patslog'] = list(pats)
 
     revset = []
     for op, val in opts.iteritems():
@@ -324,7 +339,7 @@
 
     check_unsupported_flags(pats, opts)
 
-    revs = sorted(scmutil.revrange(repo, [revset(pats, opts)]), reverse=1)
+    revs = sorted(scmutil.revrange(repo, [revset(repo, pats, opts)]), reverse=1)
     limit = cmdutil.loglimit(opts)
     if limit is not None:
         revs = revs[:limit]
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -90,7 +90,7 @@
   > def uisetup(ui):
   >     def printrevset(orig, ui, repo, *pats, **opts):
   >         if opts.get('print_revset'):
-  >             expr = graphlog.revset(pats, opts)
+  >             expr = graphlog.revset(repo, pats, opts)
   >             tree = revset.parse(expr)[0]
   >             ui.write(tree, "\n")
   >             return 0
@@ -1519,5 +1519,12 @@
   o  (0) add a
   
 
+  $ testlog a
+  ('group', ('group', ('func', ('symbol', 'filelog'), ('string', 'a'))))
+  $ testlog a b
+  ('group', ('group', ('or', ('func', ('symbol', 'filelog'), ('string', 'a')), ('func', ('symbol', 'filelog'), ('string', 'b')))))
+
+Test falling back to slow path for non-existing files
+
   $ testlog a c
   ('group', ('group', ('or', ('func', ('symbol', 'file'), ('string', 'a')), ('func', ('symbol', 'file'), ('string', 'c')))))


More information about the Mercurial-devel mailing list