[PATCH 1 of 3] largefiles: handle commit -A properly, after a --large commit (issue3542)

Matt Harbison matt_harbison at yahoo.com
Mon Aug 6 22:40:15 CDT 2012


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1343696201 14400
# Node ID 542cfb521b1297a887410173f5971afc537f2fb3
# Parent  b131e24e2984a610d77e124dd3f58b2b5eda6d1a
largefiles: handle commit -A properly, after a --large commit (issue3542)

Previous to this, 'commit -A' would add as normal files, files that were already
committed as largefiles, resulting in files being listed twice by 'status -A'.
It also missed when (only) a largefile was deleted, even though status reported
it as '!'.  This also has the side effect of properly reporting the state of the
affected largefiles in the post commit hook after a remove that also affected a
normal file (the largefiles used to be 'R', now are properly absent).

Since scmutil.addremove() is called both by the ui command (after some trivial
argument validation) and during the commit process when -A is specified, it
seems like a more appropriate method to wrap than the addremove command.

Currently, a repo is only enabled to use largefiles after an add that explicitly
identifies some file as large, and a subsequent commit.  Therefore, this patch
only changes behavior after such a largefile enabling commit.

Note that in the test, if the final commit had a '-v', 'removing large8' would
be printed twice.  Both of these originate in removelargefiles().  The first
print is in verbose mode after traversing remove + forget, the second is because
the '_isaddremove' attr is set and 'after' is not.

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -994,11 +994,12 @@
         else:
             ui.status(_('largefiles: %d to upload\n') % len(toupload))
 
-def overrideaddremove(orig, ui, repo, *pats, **opts):
+def scmutiladdremove(orig, repo, pats=[], opts={}, dry_run=None,
+                     similarity=None):
     if not lfutil.islfilesrepo(repo):
-        return orig(ui, repo, *pats, **opts)
+        return orig(repo, pats, opts, dry_run, similarity)
     # Get the list of missing largefiles so we can remove them
-    lfdirstate = lfutil.openlfdirstate(ui, repo)
+    lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
     s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False,
         False, False)
     (unsure, modified, added, removed, missing, unknown, ignored, clean) = s
@@ -1010,16 +1011,16 @@
     if missing:
         m = [repo.wjoin(f) for f in missing]
         repo._isaddremove = True
-        removelargefiles(ui, repo, *m, **opts)
+        removelargefiles(repo.ui, repo, *m, **opts)
         repo._isaddremove = False
     # Call into the normal add code, and any files that *should* be added as
     # largefiles will be
-    addlargefiles(ui, repo, *pats, **opts)
+    addlargefiles(repo.ui, repo, *pats, **opts)
     # Now that we've handled largefiles, hand off to the original addremove
     # function to take care of the rest.  Make sure it doesn't do anything with
     # largefiles by installing a matcher that will ignore them.
     installnormalfilesmatchfn(repo[None].manifest())
-    result = orig(ui, repo, *pats, **opts)
+    result = orig(repo, pats, opts, dry_run, similarity)
     restorematchfn()
     return result
 
diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py
+++ b/hgext/largefiles/uisetup.py
@@ -9,7 +9,7 @@
 '''setup for largefiles extension: uisetup'''
 
 from mercurial import archival, cmdutil, commands, extensions, filemerge, hg, \
-    httppeer, localrepo, merge, sshpeer, sshserver, wireproto
+    httppeer, localrepo, merge, scmutil, sshpeer, sshserver, wireproto
 from mercurial.i18n import _
 from mercurial.hgweb import hgweb_mod, protocol, webcommands
 from mercurial.subrepo import hgsubrepo
@@ -30,8 +30,10 @@
                                    '(default: 10)'))]
     entry[1].extend(addopt)
 
-    entry = extensions.wrapcommand(commands.table, 'addremove',
-            overrides.overrideaddremove)
+    # The scmutil function is called both by the (trivial) addremove command,
+    # and in the process of handling commit -A (issue3542)
+    entry = extensions.wrapfunction(scmutil, 'addremove',
+                                    overrides.scmutiladdremove)
     entry = extensions.wrapcommand(commands.table, 'remove',
                                    overrides.overrideremove)
     entry = extensions.wrapcommand(commands.table, 'forget',
diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t
--- a/tests/test-largefiles.t
+++ b/tests/test-largefiles.t
@@ -525,6 +525,33 @@
   C sub2/large6
   C sub2/large7
 
+Test commit -A (issue 3542)
+  $ echo large8 > large8
+  $ hg add --large large8
+  $ hg ci -Am 'this used to add large8 as normal and commit both'
+  Invoking status precommit hook
+  A large8
+  Invoking status postcommit hook
+  C large8
+  C normal
+  C normal3
+  C sub/large4
+  C sub/normal4
+  C sub2/large6
+  C sub2/large7
+  $ rm large8
+  $ hg ci -Am 'this used to not notice the rm'
+  removing large8
+  Invoking status precommit hook
+  R large8
+  Invoking status postcommit hook
+  C normal
+  C normal3
+  C sub/large4
+  C sub/normal4
+  C sub2/large6
+  C sub2/large7
+
 Test that a standin can't be added as a large file
 
   $ touch large
@@ -570,8 +597,19 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     removed large
   
+  changeset:   13:0a3e75774479
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     this used to add large8 as normal and commit both
+  
+  changeset:   14:84f3d378175c
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     this used to not notice the rm
+  
   searching for changes
   largefiles to upload:
+  large8
   large
   foo
   


More information about the Mercurial-devel mailing list