# HG changeset patch # User Mads Kiilerich # Date 2016-03-27 20:00:28 # Node ID a75c9665ef06d45c94af1231c3aef21ce7d5ba8c # Parent 8079639b20dcf7126df90368817ee86ea8ecfc25 largefiles: introduce push --lfrev to control which revisions are pushed The default of pushing all largefiles referenced in outgoing revisions is safe, but also expensive and sometimes not what is needed. We thus introduce a --lfrev option, similar to what pull already has. By specifying an empty set of revisions (or null), it is possible to get lazy (and insecure!) pushes of revisions without referenced largefiles, similar to how pull works. diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py --- a/hgext/largefiles/overrides.py +++ b/hgext/largefiles/overrides.py @@ -801,6 +801,21 @@ def overridepull(orig, ui, repo, source= ui.status(_("%d largefiles cached\n") % numcached) return result +def overridepush(orig, ui, repo, *args, **kwargs): + """Override push command and store --lfrev parameters in opargs""" + lfrevs = kwargs.pop('lfrev', None) + if lfrevs: + opargs = kwargs.setdefault('opargs', {}) + opargs['lfrevs'] = scmutil.revrange(repo, lfrevs) + return orig(ui, repo, *args, **kwargs) + +def exchangepushoperation(orig, *args, **kwargs): + """Override pushoperation constructor and store lfrevs parameter""" + lfrevs = kwargs.pop('lfrevs', None) + pushop = orig(*args, **kwargs) + pushop.lfrevs = lfrevs + return pushop + revsetpredicate = registrar.revsetpredicate() @revsetpredicate('pulled()') diff --git a/hgext/largefiles/reposetup.py b/hgext/largefiles/reposetup.py --- a/hgext/largefiles/reposetup.py +++ b/hgext/largefiles/reposetup.py @@ -353,10 +353,14 @@ def reposetup(ui, repo): repo._lfstatuswriters = [ui.status] def prepushoutgoinghook(pushop): - if pushop.outgoing.missing: + """Push largefiles for pushop before pushing revisions.""" + lfrevs = pushop.lfrevs + if lfrevs is None: + lfrevs = pushop.outgoing.missing + if lfrevs: toupload = set() addfunc = lambda fn, lfhash: toupload.add(lfhash) - lfutil.getlfilestoupload(pushop.repo, pushop.outgoing.missing, + lfutil.getlfilestoupload(pushop.repo, lfrevs, addfunc) lfcommands.uploadlfiles(ui, pushop.repo, pushop.remote, toupload) repo.prepushoutgoinghooks.add("largefiles", prepushoutgoinghook) 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, merge, scmutil, sshpeer, wireproto, subrepo, copies + httppeer, merge, scmutil, sshpeer, wireproto, subrepo, copies, exchange from mercurial.i18n import _ from mercurial.hgweb import hgweb_mod, webcommands @@ -84,6 +84,14 @@ def uisetup(ui): _('download largefiles for these revisions'), _('REV'))] entry[1].extend(pullopt) + entry = extensions.wrapcommand(commands.table, 'push', + overrides.overridepush) + pushopt = [('', 'lfrev', [], + _('upload largefiles for these revisions'), _('REV'))] + entry[1].extend(pushopt) + entry = extensions.wrapfunction(exchange, 'pushoperation', + overrides.exchangepushoperation) + entry = extensions.wrapcommand(commands.table, 'clone', overrides.overrideclone) cloneopt = [('', 'all-largefiles', None, diff --git a/tests/test-largefiles-cache.t b/tests/test-largefiles-cache.t --- a/tests/test-largefiles-cache.t +++ b/tests/test-largefiles-cache.t @@ -235,4 +235,20 @@ Test coverage of 'missing from store': abort: largefile e2fb5f2139d086ded2cb600d5a91a196e76bf020 missing from store (needs to be uploaded) [255] +Verify that --lfrev controls which revisions are checked for largefiles to push + + $ hg push http://localhost:$HGPORT2 -f --config largefiles.usercache=nocache --lfrev tip + pushing to http://localhost:$HGPORT2/ + searching for changes + abort: largefile e2fb5f2139d086ded2cb600d5a91a196e76bf020 missing from store (needs to be uploaded) + [255] + + $ hg push http://localhost:$HGPORT2 -f --config largefiles.usercache=nocache --lfrev null + pushing to http://localhost:$HGPORT2/ + searching for changes + remote: adding changesets + remote: adding manifests + remote: adding file changes + remote: added 1 changesets with 1 changes to 1 files (+1 heads) + #endif