Patchwork [V3] largefiles: pass a matcher instead of a raw file list to removelargefiles()

login
register
mail settings
Submitter Matt Harbison
Date Jan. 6, 2015, 3:09 a.m.
Message ID <7837783c374faf01778a.1420513770@Envy>
Download mbox | patch
Permalink /patch/7323/
State Accepted
Commit f2893cd8d1e543a0baa3c378b222f8f3e4a9d638
Headers show

Comments

Matt Harbison - Jan. 6, 2015, 3:09 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1417222252 18000
#      Fri Nov 28 19:50:52 2014 -0500
# Node ID 7837783c374faf01778a0f47dacea8a6cc433b9a
# Parent  05f9d251dd7924028e2f78749ced2dfa00ab0bc3
largefiles: pass a matcher instead of a raw file list to removelargefiles()

This is consistent with addlargefiles(), and will make it easier to get the
paths that are printed correct when recursing into subrepos or invoking from
outside the repository.  It also now restricts the path that the addremove is
performed on if a path is given, as is done with normal files.

The repo.status() call needs to exclude clean files when performing an
addremove, because the addremove override method calling this used to pass the
list of files to delete, which caused the matcher to only consider those files
in building the status list.  Now the matcher is restricted only to the extent
that the caller requested- usually directories if at all.  There's no reason for
addremove to care about clean files anyway- we don't want them deleted.
Matt Mackall - Jan. 7, 2015, 9:11 p.m.
On Mon, 2015-01-05 at 22:09 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1417222252 18000
> #      Fri Nov 28 19:50:52 2014 -0500
> # Node ID 7837783c374faf01778a0f47dacea8a6cc433b9a
> # Parent  05f9d251dd7924028e2f78749ced2dfa00ab0bc3
> largefiles: pass a matcher instead of a raw file list to removelargefiles()

Queued for default, thanks.

Patch

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -154,13 +154,12 @@ 
         wlock.release()
     return bad
 
-def removelargefiles(ui, repo, isaddremove, *pats, **opts):
+def removelargefiles(ui, repo, isaddremove, matcher, **opts):
     after = opts.get('after')
-    m = composelargefilematcher(scmutil.match(repo[None], pats, opts),
-                                repo[None].manifest())
+    m = composelargefilematcher(matcher, repo[None].manifest())
     try:
         repo.lfstatus = True
-        s = repo.status(match=m, clean=True)
+        s = repo.status(match=m, clean=not isaddremove)
     finally:
         repo.lfstatus = False
     manifest = repo[None].manifest()
@@ -252,7 +251,8 @@ 
     installnormalfilesmatchfn(repo[None].manifest())
     result = orig(ui, repo, *pats, **opts)
     restorematchfn()
-    return removelargefiles(ui, repo, False, *pats, **opts) or result
+    matcher = scmutil.match(repo[None], pats, opts)
+    return removelargefiles(ui, repo, False, matcher, **opts) or result
 
 def overridestatusfn(orig, repo, rev2, **opts):
     try:
@@ -1111,8 +1111,16 @@ 
     # we don't remove the standin in the largefiles code, preventing a very
     # confused state later.
     if s.deleted:
-        m = [repo.wjoin(f) for f in s.deleted]
-        removelargefiles(repo.ui, repo, True, *m, **opts)
+        m = copy.copy(matcher)
+
+        # The m._files and m._map attributes are not changed to the deleted list
+        # because that affects the m.exact() test, which in turn governs whether
+        # or not the file name is printed, and how.  Simply limit the original
+        # matches to those in the deleted status list.
+        matchfn = m.matchfn
+        m.matchfn = lambda f: f in s.deleted and matchfn(f)
+
+        removelargefiles(repo.ui, repo, True, m, **opts)
     # Call into the normal add code, and any files that *should* be added as
     # largefiles will be
     addlargefiles(repo.ui, repo, matcher, **opts)
diff --git a/tests/test-largefiles-misc.t b/tests/test-largefiles-misc.t
--- a/tests/test-largefiles-misc.t
+++ b/tests/test-largefiles-misc.t
@@ -269,11 +269,13 @@ 
   $ mv subrepo/renamed-large.txt subrepo/large.txt
   $ hg -R subrepo add subrepo/normal.txt
 
-  $ hg addremove
+  $ hg addremove subrepo
+  $ hg addremove -S
   adding large.dat as a largefile
   $ rm large.dat
 
-  $ hg addremove
+  $ hg addremove subrepo
+  $ hg addremove -S
   removing large.dat
 
 Lock in subrepo, otherwise the change isn't archived