Patchwork [3,of,4,resend,revset,log] largefiles: changed overridelog to work with graphlog

login
register
mail settings
Submitter Mads Kiilerich
Date April 15, 2014, 12:23 a.m.
Message ID <8460539633a1ed98d711.1397521438@mk-desktop>
Download mbox | patch
Permalink /patch/4350/
State Accepted
Commit 49e13e76ec5a34fa6aab2c86b15c77ed0c6b394a
Headers show

Comments

Mads Kiilerich - April 15, 2014, 12:23 a.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1394063709 28800
#      Wed Mar 05 15:55:09 2014 -0800
# Node ID 8460539633a1ed98d7119c90699a5f8b0d0a4122
# Parent  512b8c3f891a7ccd998619f40e5c2321f4fe8354
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.]
Matt Mackall - April 17, 2014, 8:11 p.m.
On Tue, 2014-04-15 at 02:23 +0200, Mads Kiilerich wrote:
> # HG changeset patch
> # User Lucas Moscovicz <lmoscovicz@fb.com>
> # Date 1394063709 28800
> #      Wed Mar 05 15:55:09 2014 -0800
> # Node ID 8460539633a1ed98d7119c90699a5f8b0d0a4122
> # Parent  512b8c3f891a7ccd998619f40e5c2321f4fe8354
> largefiles: changed overridelog to work with graphlog

Queued the first three, thanks for tidying them up. Going to think a bit
harder about the last one.

Patch

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -55,6 +55,22 @@  def restorematchfn():
     restore matchfn to reverse'''
     scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match)
 
+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 @@  def overridedirty(orig, repo, ignoreupda
         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 @@  def overridelog(orig, ui, repo, *pats, *
             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)
diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t
--- a/tests/test-largefiles.t
+++ b/tests/test-largefiles.t
@@ -761,8 +761,8 @@  Test graph log
   $ 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
@@ -1144,6 +1144,8 @@  Log on largefiles
   $ 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
@@ -1166,6 +1168,8 @@  Log on largefiles
   $ 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
@@ -2197,6 +2201,12 @@  Test actions on largefiles using relativ
   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