Mercurial > hg
comparison hgext/largefiles/overrides.py @ 41061:98681293c890
largefiles: port commands to exthelper
One subtle change here is that the purge, rebase and transplant extensions are
wrapped in extsetup() instead of uisetup().
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 23 Dec 2018 17:26:25 -0500 |
parents | 3d76a8e627a6 |
children | 0a7f582f6f1f |
comparison
equal
deleted
inserted
replaced
41060:7250cbaabde0 | 41061:98681293c890 |
---|---|
16 | 16 |
17 from mercurial import ( | 17 from mercurial import ( |
18 archival, | 18 archival, |
19 cmdutil, | 19 cmdutil, |
20 error, | 20 error, |
21 exthelper, | |
21 hg, | 22 hg, |
22 logcmdutil, | 23 logcmdutil, |
23 match as matchmod, | 24 match as matchmod, |
24 pathutil, | 25 pathutil, |
25 pycompat, | 26 pycompat, |
32 from . import ( | 33 from . import ( |
33 lfcommands, | 34 lfcommands, |
34 lfutil, | 35 lfutil, |
35 storefactory, | 36 storefactory, |
36 ) | 37 ) |
38 | |
39 eh = exthelper.exthelper() | |
37 | 40 |
38 # -- Utility functions: commonly/repeatedly needed functionality --------------- | 41 # -- Utility functions: commonly/repeatedly needed functionality --------------- |
39 | 42 |
40 def composelargefilematcher(match, manifest): | 43 def composelargefilematcher(match, manifest): |
41 '''create a matcher that matches only the largefiles in the original | 44 '''create a matcher that matches only the largefiles in the original |
251 def decodepath(orig, path): | 254 def decodepath(orig, path): |
252 return lfutil.splitstandin(path) or path | 255 return lfutil.splitstandin(path) or path |
253 | 256 |
254 # -- Wrappers: modify existing commands -------------------------------- | 257 # -- Wrappers: modify existing commands -------------------------------- |
255 | 258 |
259 @eh.wrapcommand('add', | |
260 opts=[('', 'large', None, _('add as largefile')), | |
261 ('', 'normal', None, _('add as normal file')), | |
262 ('', 'lfsize', '', _('add all files above this size (in megabytes) ' | |
263 'as largefiles (default: 10)'))]) | |
256 def overrideadd(orig, ui, repo, *pats, **opts): | 264 def overrideadd(orig, ui, repo, *pats, **opts): |
257 if opts.get(r'normal') and opts.get(r'large'): | 265 if opts.get(r'normal') and opts.get(r'large'): |
258 raise error.Abort(_('--normal cannot be used with --large')) | 266 raise error.Abort(_('--normal cannot be used with --large')) |
259 return orig(ui, repo, *pats, **opts) | 267 return orig(ui, repo, *pats, **opts) |
260 | 268 |
284 repo._repo.lfstatus = True | 292 repo._repo.lfstatus = True |
285 return orig(repo, rev2, **opts) | 293 return orig(repo, rev2, **opts) |
286 finally: | 294 finally: |
287 repo._repo.lfstatus = False | 295 repo._repo.lfstatus = False |
288 | 296 |
297 @eh.wrapcommand('status') | |
289 def overridestatus(orig, ui, repo, *pats, **opts): | 298 def overridestatus(orig, ui, repo, *pats, **opts): |
290 try: | 299 try: |
291 repo.lfstatus = True | 300 repo.lfstatus = True |
292 return orig(ui, repo, *pats, **opts) | 301 return orig(ui, repo, *pats, **opts) |
293 finally: | 302 finally: |
298 repo._repo.lfstatus = True | 307 repo._repo.lfstatus = True |
299 return orig(repo, ignoreupdate=ignoreupdate, missing=missing) | 308 return orig(repo, ignoreupdate=ignoreupdate, missing=missing) |
300 finally: | 309 finally: |
301 repo._repo.lfstatus = False | 310 repo._repo.lfstatus = False |
302 | 311 |
312 @eh.wrapcommand('log') | |
303 def overridelog(orig, ui, repo, *pats, **opts): | 313 def overridelog(orig, ui, repo, *pats, **opts): |
304 def overridematchandpats(ctx, pats=(), opts=None, globbed=False, | 314 def overridematchandpats(ctx, pats=(), opts=None, globbed=False, |
305 default='relpath', badfn=None): | 315 default='relpath', badfn=None): |
306 """Matcher that merges root directory with .hglf, suitable for log. | 316 """Matcher that merges root directory with .hglf, suitable for log. |
307 It is still possible to match .hglf directly. | 317 It is still possible to match .hglf directly. |
404 return orig(ui, repo, *pats, **opts) | 414 return orig(ui, repo, *pats, **opts) |
405 finally: | 415 finally: |
406 restorematchandpatsfn() | 416 restorematchandpatsfn() |
407 setattr(logcmdutil, '_makenofollowfilematcher', oldmakefilematcher) | 417 setattr(logcmdutil, '_makenofollowfilematcher', oldmakefilematcher) |
408 | 418 |
419 @eh.wrapcommand('verify', | |
420 opts=[('', 'large', None, | |
421 _('verify that all largefiles in current revision exists')), | |
422 ('', 'lfa', None, | |
423 _('verify largefiles in all revisions, not just current')), | |
424 ('', 'lfc', None, | |
425 _('verify local largefile contents, not just existence'))]) | |
409 def overrideverify(orig, ui, repo, *pats, **opts): | 426 def overrideverify(orig, ui, repo, *pats, **opts): |
410 large = opts.pop(r'large', False) | 427 large = opts.pop(r'large', False) |
411 all = opts.pop(r'lfa', False) | 428 all = opts.pop(r'lfa', False) |
412 contents = opts.pop(r'lfc', False) | 429 contents = opts.pop(r'lfc', False) |
413 | 430 |
414 result = orig(ui, repo, *pats, **opts) | 431 result = orig(ui, repo, *pats, **opts) |
415 if large or all or contents: | 432 if large or all or contents: |
416 result = result or lfcommands.verifylfiles(ui, repo, all, contents) | 433 result = result or lfcommands.verifylfiles(ui, repo, all, contents) |
417 return result | 434 return result |
418 | 435 |
436 @eh.wrapcommand('debugstate', | |
437 opts=[('', 'large', None, _('display largefiles dirstate'))]) | |
419 def overridedebugstate(orig, ui, repo, *pats, **opts): | 438 def overridedebugstate(orig, ui, repo, *pats, **opts): |
420 large = opts.pop(r'large', False) | 439 large = opts.pop(r'large', False) |
421 if large: | 440 if large: |
422 class fakerepo(object): | 441 class fakerepo(object): |
423 dirstate = lfutil.openlfdirstate(ui, repo) | 442 dirstate = lfutil.openlfdirstate(ui, repo) |
797 lfcommands.updatelfiles(ui, repo, filelist, printmessage=False, | 816 lfcommands.updatelfiles(ui, repo, filelist, printmessage=False, |
798 normallookup=True) | 817 normallookup=True) |
799 | 818 |
800 # after pulling changesets, we need to take some extra care to get | 819 # after pulling changesets, we need to take some extra care to get |
801 # largefiles updated remotely | 820 # largefiles updated remotely |
821 @eh.wrapcommand('pull', | |
822 opts=[('', 'all-largefiles', None, | |
823 _('download all pulled versions of largefiles (DEPRECATED)')), | |
824 ('', 'lfrev', [], | |
825 _('download largefiles for these revisions'), _('REV'))]) | |
802 def overridepull(orig, ui, repo, source=None, **opts): | 826 def overridepull(orig, ui, repo, source=None, **opts): |
803 revsprepull = len(repo) | 827 revsprepull = len(repo) |
804 if not source: | 828 if not source: |
805 source = 'default' | 829 source = 'default' |
806 repo.lfpullsource = source | 830 repo.lfpullsource = source |
820 finally: | 844 finally: |
821 del repo.firstpulled | 845 del repo.firstpulled |
822 ui.status(_("%d largefiles cached\n") % numcached) | 846 ui.status(_("%d largefiles cached\n") % numcached) |
823 return result | 847 return result |
824 | 848 |
849 @eh.wrapcommand('push', | |
850 opts=[('', 'lfrev', [], | |
851 _('upload largefiles for these revisions'), _('REV'))]) | |
825 def overridepush(orig, ui, repo, *args, **kwargs): | 852 def overridepush(orig, ui, repo, *args, **kwargs): |
826 """Override push command and store --lfrev parameters in opargs""" | 853 """Override push command and store --lfrev parameters in opargs""" |
827 lfrevs = kwargs.pop(r'lfrev', None) | 854 lfrevs = kwargs.pop(r'lfrev', None) |
828 if lfrevs: | 855 if lfrevs: |
829 opargs = kwargs.setdefault(r'opargs', {}) | 856 opargs = kwargs.setdefault(r'opargs', {}) |
863 firstpulled = repo.firstpulled | 890 firstpulled = repo.firstpulled |
864 except AttributeError: | 891 except AttributeError: |
865 raise error.Abort(_("pulled() only available in --lfrev")) | 892 raise error.Abort(_("pulled() only available in --lfrev")) |
866 return smartset.baseset([r for r in subset if r >= firstpulled]) | 893 return smartset.baseset([r for r in subset if r >= firstpulled]) |
867 | 894 |
895 @eh.wrapcommand('clone', | |
896 opts=[('', 'all-largefiles', None, | |
897 _('download all versions of all largefiles'))]) | |
868 def overrideclone(orig, ui, source, dest=None, **opts): | 898 def overrideclone(orig, ui, source, dest=None, **opts): |
869 d = dest | 899 d = dest |
870 if d is None: | 900 if d is None: |
871 d = hg.defaultdest(source) | 901 d = hg.defaultdest(source) |
872 if opts.get(r'all_largefiles') and not hg.islocal(d): | 902 if opts.get(r'all_largefiles') and not hg.islocal(d): |
898 if missing != 0: | 928 if missing != 0: |
899 return None | 929 return None |
900 | 930 |
901 return result | 931 return result |
902 | 932 |
933 @eh.wrapcommand('rebase', extension='rebase') | |
903 def overriderebase(orig, ui, repo, **opts): | 934 def overriderebase(orig, ui, repo, **opts): |
904 if not util.safehasattr(repo, '_largefilesenabled'): | 935 if not util.safehasattr(repo, '_largefilesenabled'): |
905 return orig(ui, repo, **opts) | 936 return orig(ui, repo, **opts) |
906 | 937 |
907 resuming = opts.get(r'continue') | 938 resuming = opts.get(r'continue') |
911 return orig(ui, repo, **opts) | 942 return orig(ui, repo, **opts) |
912 finally: | 943 finally: |
913 repo._lfstatuswriters.pop() | 944 repo._lfstatuswriters.pop() |
914 repo._lfcommithooks.pop() | 945 repo._lfcommithooks.pop() |
915 | 946 |
947 @eh.wrapcommand('archive') | |
916 def overridearchivecmd(orig, ui, repo, dest, **opts): | 948 def overridearchivecmd(orig, ui, repo, dest, **opts): |
917 repo.unfiltered().lfstatus = True | 949 repo.unfiltered().lfstatus = True |
918 | 950 |
919 try: | 951 try: |
920 return orig(ui, repo.unfiltered(), dest, **opts) | 952 return orig(ui, repo.unfiltered(), dest, **opts) |
1165 for file in sorted(toupload): | 1197 for file in sorted(toupload): |
1166 ui.status(lfutil.splitstandin(file) + '\n') | 1198 ui.status(lfutil.splitstandin(file) + '\n') |
1167 showhashes(file) | 1199 showhashes(file) |
1168 ui.status('\n') | 1200 ui.status('\n') |
1169 | 1201 |
1202 @eh.wrapcommand('outgoing', | |
1203 opts=[('', 'large', None, _('display outgoing largefiles'))]) | |
1204 def _outgoingcmd(orig, *args, **kwargs): | |
1205 # Nothing to do here other than add the extra help option- the hook above | |
1206 # processes it. | |
1207 return orig(*args, **kwargs) | |
1208 | |
1170 def summaryremotehook(ui, repo, opts, changes): | 1209 def summaryremotehook(ui, repo, opts, changes): |
1171 largeopt = opts.get('large', False) | 1210 largeopt = opts.get('large', False) |
1172 if changes is None: | 1211 if changes is None: |
1173 if largeopt: | 1212 if largeopt: |
1174 return (False, True) # only outgoing check is needed | 1213 return (False, True) # only outgoing check is needed |
1194 else: | 1233 else: |
1195 # i18n: column positioning for "hg summary" | 1234 # i18n: column positioning for "hg summary" |
1196 ui.status(_('largefiles: %d entities for %d files to upload\n') | 1235 ui.status(_('largefiles: %d entities for %d files to upload\n') |
1197 % (len(lfhashes), len(toupload))) | 1236 % (len(lfhashes), len(toupload))) |
1198 | 1237 |
1238 @eh.wrapcommand('summary', | |
1239 opts=[('', 'large', None, _('display outgoing largefiles'))]) | |
1199 def overridesummary(orig, ui, repo, *pats, **opts): | 1240 def overridesummary(orig, ui, repo, *pats, **opts): |
1200 try: | 1241 try: |
1201 repo.lfstatus = True | 1242 repo.lfstatus = True |
1202 orig(ui, repo, *pats, **opts) | 1243 orig(ui, repo, *pats, **opts) |
1203 finally: | 1244 finally: |
1240 matcher = composenormalfilematcher(matcher, repo[None].manifest(), added) | 1281 matcher = composenormalfilematcher(matcher, repo[None].manifest(), added) |
1241 return orig(repo, matcher, prefix, opts) | 1282 return orig(repo, matcher, prefix, opts) |
1242 | 1283 |
1243 # Calling purge with --all will cause the largefiles to be deleted. | 1284 # Calling purge with --all will cause the largefiles to be deleted. |
1244 # Override repo.status to prevent this from happening. | 1285 # Override repo.status to prevent this from happening. |
1286 @eh.wrapcommand('purge', extension='purge') | |
1245 def overridepurge(orig, ui, repo, *dirs, **opts): | 1287 def overridepurge(orig, ui, repo, *dirs, **opts): |
1246 # XXX Monkey patching a repoview will not work. The assigned attribute will | 1288 # XXX Monkey patching a repoview will not work. The assigned attribute will |
1247 # be set on the unfiltered repo, but we will only lookup attributes in the | 1289 # be set on the unfiltered repo, but we will only lookup attributes in the |
1248 # unfiltered repo if the lookup in the repoview object itself fails. As the | 1290 # unfiltered repo if the lookup in the repoview object itself fails. As the |
1249 # monkey patched method exists on the repoview class the lookup will not | 1291 # monkey patched method exists on the repoview class the lookup will not |
1265 unknown, ignored, r.clean) | 1307 unknown, ignored, r.clean) |
1266 repo.status = overridestatus | 1308 repo.status = overridestatus |
1267 orig(ui, repo, *dirs, **opts) | 1309 orig(ui, repo, *dirs, **opts) |
1268 repo.status = oldstatus | 1310 repo.status = oldstatus |
1269 | 1311 |
1312 @eh.wrapcommand('rollback') | |
1270 def overriderollback(orig, ui, repo, **opts): | 1313 def overriderollback(orig, ui, repo, **opts): |
1271 with repo.wlock(): | 1314 with repo.wlock(): |
1272 before = repo.dirstate.parents() | 1315 before = repo.dirstate.parents() |
1273 orphans = set(f for f in repo.dirstate | 1316 orphans = set(f for f in repo.dirstate |
1274 if lfutil.isstandin(f) and repo.dirstate[f] != 'r') | 1317 if lfutil.isstandin(f) and repo.dirstate[f] != 'r') |
1302 for lfile in orphans: | 1345 for lfile in orphans: |
1303 lfdirstate.drop(lfile) | 1346 lfdirstate.drop(lfile) |
1304 lfdirstate.write() | 1347 lfdirstate.write() |
1305 return result | 1348 return result |
1306 | 1349 |
1350 @eh.wrapcommand('transplant', extension='transplant') | |
1307 def overridetransplant(orig, ui, repo, *revs, **opts): | 1351 def overridetransplant(orig, ui, repo, *revs, **opts): |
1308 resuming = opts.get(r'continue') | 1352 resuming = opts.get(r'continue') |
1309 repo._lfcommithooks.append(lfutil.automatedcommithook(resuming)) | 1353 repo._lfcommithooks.append(lfutil.automatedcommithook(resuming)) |
1310 repo._lfstatuswriters.append(lambda *msg, **opts: None) | 1354 repo._lfstatuswriters.append(lambda *msg, **opts: None) |
1311 try: | 1355 try: |
1313 finally: | 1357 finally: |
1314 repo._lfstatuswriters.pop() | 1358 repo._lfstatuswriters.pop() |
1315 repo._lfcommithooks.pop() | 1359 repo._lfcommithooks.pop() |
1316 return result | 1360 return result |
1317 | 1361 |
1362 @eh.wrapcommand('cat') | |
1318 def overridecat(orig, ui, repo, file1, *pats, **opts): | 1363 def overridecat(orig, ui, repo, file1, *pats, **opts): |
1319 opts = pycompat.byteskwargs(opts) | 1364 opts = pycompat.byteskwargs(opts) |
1320 ctx = scmutil.revsingle(repo, opts.get('rev')) | 1365 ctx = scmutil.revsingle(repo, opts.get('rev')) |
1321 err = 1 | 1366 err = 1 |
1322 notbad = set() | 1367 notbad = set() |