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.
This commit is contained in:
Matt Harbison 2012-07-30 20:56:41 -04:00
parent e08cbc5b19
commit 2aaabbf1cc
3 changed files with 50 additions and 9 deletions

View File

@ -1018,11 +1018,12 @@ def overridesummary(orig, ui, repo, *pats, **opts):
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
@ -1034,16 +1035,16 @@ def overrideaddremove(orig, ui, repo, *pats, **opts):
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

View File

@ -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 @@ def uisetup(ui):
'(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',

View File

@ -543,6 +543,33 @@ Test 3507 (both normal files and largefiles were a problem)
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
@ -588,8 +615,19 @@ Test that outgoing --large works (with revsets too)
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