[PATCH 1 of 1 STABLE] largefiles: handle commit -A properly (issue3542)

Matt Harbison matt_harbison at yahoo.com
Wed Jul 25 15:38:57 CDT 2012


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1343240857 14400
# Branch stable
# Node ID f403b9d5e2d03e4c340ebb5fa73d9aadd95bab37
# Parent  ffc49100151b68c0bcd061b900d9993e9e1a0d7d
largefiles: handle commit -A properly (issue3542)

Previously, 'commit -A' would add files that were already committed as
largefiles a second time as normal files, resulting in the file 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 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.

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
@@ -488,6 +488,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


More information about the Mercurial-devel mailing list