changeset 21110:49e13e76ec5a

largefiles: changed overridelog to work with graphlog Log for largefiles was failing for graph log since it was overriding match instead of matchandpats. [Mads Kiilerich modified this patch to address his review comments and ended up rewriting/removing most of it.]
author Lucas Moscovicz <lmoscovicz@fb.com>
date Wed, 05 Mar 2014 15:55:09 -0800
parents 4b15a369e067
children 9d28fd795215
files hgext/largefiles/overrides.py tests/test-largefiles.t
diffstat 2 files changed, 47 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/overrides.py	Thu Mar 06 14:52:07 2014 -0800
+++ b/hgext/largefiles/overrides.py	Wed Mar 05 15:55:09 2014 -0800
@@ -55,6 +55,22 @@
     restore matchfn to reverse'''
     scmutil.match = getattr(scmutil.match, 'oldmatch')
 
+def installmatchandpatsfn(f):
+    oldmatchandpats = scmutil.matchandpats
+    setattr(f, 'oldmatchandpats', oldmatchandpats)
+    scmutil.matchandpats = f
+    return oldmatchandpats
+
+def restorematchandpatsfn():
+    '''restores scmutil.matchandpats to what it was before
+    installnormalfilesmatchandpatsfn was called.  no-op if scmutil.matchandpats
+    is its original function.
+
+    Note that n calls to installnormalfilesmatchandpatsfn will require n calls
+    to restore matchfn to reverse'''
+    scmutil.matchandpats = getattr(scmutil.matchandpats, 'oldmatchandpats',
+            scmutil.matchandpats)
+
 def addlargefiles(ui, repo, *pats, **opts):
     large = opts.pop('large', None)
     lfsize = lfutil.getminsize(
@@ -241,19 +257,30 @@
         repo._repo.lfstatus = False
 
 def overridelog(orig, ui, repo, *pats, **opts):
-    def overridematch(ctx, pats=[], opts={}, globbed=False,
+    def overridematchandpats(ctx, pats=[], opts={}, globbed=False,
             default='relpath'):
         """Matcher that merges root directory with .hglf, suitable for log.
         It is still possible to match .hglf directly.
         For any listed files run log on the standin too.
         matchfn tries both the given filename and with .hglf stripped.
         """
-        match = oldmatch(ctx, pats, opts, globbed, default)
-        m = copy.copy(match)
+        matchandpats = oldmatchandpats(ctx, pats, opts, globbed, default)
+        m, p = copy.copy(matchandpats)
+
+        pats = set(p)
+        # TODO: handling of patterns in both cases below
+        if m._cwd:
+            back = (m._cwd.count('/') + 1) * '../'
+            pats.update(back + lfutil.standin(m._cwd + '/' + f) for f in p)
+        else:
+            pats.update(lfutil.standin(f) for f in p)
+
         for i in range(0, len(m._files)):
             standin = lfutil.standin(m._files[i])
             if standin in repo[ctx.node()]:
                 m._files[i] = standin
+            pats.add(standin)
+
         m._fmap = set(m._files)
         m._always = False
         origmatchfn = m.matchfn
@@ -264,14 +291,16 @@
             r = origmatchfn(f)
             return r
         m.matchfn = lfmatchfn
-        return m
-    oldmatch = installmatchfn(overridematch)
+
+        return m, pats
+
+    oldmatchandpats = installmatchandpatsfn(overridematchandpats)
     try:
         repo.lfstatus = True
         return orig(ui, repo, *pats, **opts)
     finally:
         repo.lfstatus = False
-        restorematchfn()
+        restorematchandpatsfn()
 
 def overrideverify(orig, ui, repo, *pats, **opts):
     large = opts.pop('large', False)
--- a/tests/test-largefiles.t	Thu Mar 06 14:52:07 2014 -0800
+++ b/tests/test-largefiles.t	Wed Mar 05 15:55:09 2014 -0800
@@ -760,8 +760,8 @@
   $ hg log -qf sub2/large7
   7:daea875e9014
   $ hg log -Gqf sub2/large7
-  abort: cannot follow file not in parent revision: "sub2/large7"
-  [255]
+  @  7:daea875e9014
+  |
   $ cd ..
   $ hg clone a -r 3 c
   adding changesets
@@ -1143,6 +1143,8 @@
   $ hg log -G --template '{rev}:{node|short}  {desc|firstline}\n' sub
   @  9:598410d3eb9a  modify normal file largefile in repo d
   |
+  o  8:a381d2c8c80e  modify normal file and largefile in repo b
+  |
   o  6:4355d653f84f  edit files yet again
   |
   o  5:9d5af5072dbd  edit files again
@@ -1165,6 +1167,8 @@
   $ hg log -G --template '{rev}:{node|short}  {desc|firstline}\n' 'glob:sub/*'
   @  9:598410d3eb9a  modify normal file largefile in repo d
   |
+  o  8:a381d2c8c80e  modify normal file and largefile in repo b
+  |
   o  6:4355d653f84f  edit files yet again
   |
   o  5:9d5af5072dbd  edit files again
@@ -2203,6 +2207,12 @@
   summary:     anotherlarge
   
   $ hg log -G anotherlarge
+  @  changeset:   1:9627a577c5e9
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     anotherlarge
+  |
   $ echo more >> anotherlarge
   $ hg st .
   M anotherlarge