comparison hgext/largefiles/overrides.py @ 43294:03dae1044edd

largefiles: add context manager for setting/clearing "lfstatus" attribute Differential Revision: https://phab.mercurial-scm.org/D7136
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 18 Oct 2019 14:40:50 -0700
parents 649d3ac37a12
children 013637f4812e
comparison
equal deleted inserted replaced
43293:d0f89e8c615a 43294:03dae1044edd
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 8
9 '''Overridden Mercurial commands and functions for the largefiles extension''' 9 '''Overridden Mercurial commands and functions for the largefiles extension'''
10 from __future__ import absolute_import 10 from __future__ import absolute_import
11 11
12 import contextlib
12 import copy 13 import copy
13 import os 14 import os
14 15
15 from mercurial.i18n import _ 16 from mercurial.i18n import _
16 17
155 156
156 added = [f for f in lfnames if f not in bad] 157 added = [f for f in lfnames if f not in bad]
157 return added, bad 158 return added, bad
158 159
159 160
161 @contextlib.contextmanager
162 def lfstatus(repo):
163 repo.lfstatus = True
164 try:
165 yield
166 finally:
167 repo.lfstatus = False
168
169
160 def removelargefiles(ui, repo, isaddremove, matcher, uipathfn, dryrun, **opts): 170 def removelargefiles(ui, repo, isaddremove, matcher, uipathfn, dryrun, **opts):
161 after = opts.get(r'after') 171 after = opts.get(r'after')
162 m = composelargefilematcher(matcher, repo[None].manifest()) 172 m = composelargefilematcher(matcher, repo[None].manifest())
163 try: 173 with lfstatus(repo):
164 repo.lfstatus = True
165 s = repo.status(match=m, clean=not isaddremove) 174 s = repo.status(match=m, clean=not isaddremove)
166 finally:
167 repo.lfstatus = False
168 manifest = repo[None].manifest() 175 manifest = repo[None].manifest()
169 modified, added, deleted, clean = [ 176 modified, added, deleted, clean = [
170 [f for f in list if lfutil.standin(f) in manifest] 177 [f for f in list if lfutil.standin(f) in manifest]
171 for list in (s.modified, s.added, s.deleted, s.clean) 178 for list in (s.modified, s.added, s.deleted, s.clean)
172 ] 179 ]
306 ) 313 )
307 314
308 315
309 @eh.wrapfunction(subrepo.hgsubrepo, b'status') 316 @eh.wrapfunction(subrepo.hgsubrepo, b'status')
310 def overridestatusfn(orig, repo, rev2, **opts): 317 def overridestatusfn(orig, repo, rev2, **opts):
311 try: 318 with lfstatus(repo._repo):
312 repo._repo.lfstatus = True
313 return orig(repo, rev2, **opts) 319 return orig(repo, rev2, **opts)
314 finally:
315 repo._repo.lfstatus = False
316 320
317 321
318 @eh.wrapcommand(b'status') 322 @eh.wrapcommand(b'status')
319 def overridestatus(orig, ui, repo, *pats, **opts): 323 def overridestatus(orig, ui, repo, *pats, **opts):
320 try: 324 with lfstatus(repo):
321 repo.lfstatus = True
322 return orig(ui, repo, *pats, **opts) 325 return orig(ui, repo, *pats, **opts)
323 finally:
324 repo.lfstatus = False
325 326
326 327
327 @eh.wrapfunction(subrepo.hgsubrepo, b'dirty') 328 @eh.wrapfunction(subrepo.hgsubrepo, b'dirty')
328 def overridedirty(orig, repo, ignoreupdate=False, missing=False): 329 def overridedirty(orig, repo, ignoreupdate=False, missing=False):
329 try: 330 with lfstatus(repo._repo):
330 repo._repo.lfstatus = True
331 return orig(repo, ignoreupdate=ignoreupdate, missing=missing) 331 return orig(repo, ignoreupdate=ignoreupdate, missing=missing)
332 finally:
333 repo._repo.lfstatus = False
334 332
335 333
336 @eh.wrapcommand(b'log') 334 @eh.wrapcommand(b'log')
337 def overridelog(orig, ui, repo, *pats, **opts): 335 def overridelog(orig, ui, repo, *pats, **opts):
338 def overridematchandpats( 336 def overridematchandpats(
1115 repo._lfcommithooks.pop() 1113 repo._lfcommithooks.pop()
1116 1114
1117 1115
1118 @eh.wrapcommand(b'archive') 1116 @eh.wrapcommand(b'archive')
1119 def overridearchivecmd(orig, ui, repo, dest, **opts): 1117 def overridearchivecmd(orig, ui, repo, dest, **opts):
1120 repo.unfiltered().lfstatus = True 1118 with lfstatus(repo.unfiltered()):
1121
1122 try:
1123 return orig(ui, repo.unfiltered(), dest, **opts) 1119 return orig(ui, repo.unfiltered(), dest, **opts)
1124 finally:
1125 repo.unfiltered().lfstatus = False
1126 1120
1127 1121
1128 @eh.wrapfunction(webcommands, b'archive') 1122 @eh.wrapfunction(webcommands, b'archive')
1129 def hgwebarchive(orig, web): 1123 def hgwebarchive(orig, web):
1130 web.repo.lfstatus = True 1124 with lfstatus(web.repo):
1131
1132 try:
1133 return orig(web) 1125 return orig(web)
1134 finally:
1135 web.repo.lfstatus = False
1136 1126
1137 1127
1138 @eh.wrapfunction(archival, b'archive') 1128 @eh.wrapfunction(archival, b'archive')
1139 def overridearchive( 1129 def overridearchive(
1140 orig, 1130 orig,
1284 # if the repo has uncommitted changes. Wrap it to also check if 1274 # if the repo has uncommitted changes. Wrap it to also check if
1285 # largefiles were changed. This is used by bisect, backout and fetch. 1275 # largefiles were changed. This is used by bisect, backout and fetch.
1286 @eh.wrapfunction(cmdutil, b'bailifchanged') 1276 @eh.wrapfunction(cmdutil, b'bailifchanged')
1287 def overridebailifchanged(orig, repo, *args, **kwargs): 1277 def overridebailifchanged(orig, repo, *args, **kwargs):
1288 orig(repo, *args, **kwargs) 1278 orig(repo, *args, **kwargs)
1289 repo.lfstatus = True 1279 with lfstatus(repo):
1290 s = repo.status() 1280 s = repo.status()
1291 repo.lfstatus = False
1292 if s.modified or s.added or s.removed or s.deleted: 1281 if s.modified or s.added or s.removed or s.deleted:
1293 raise error.Abort(_(b'uncommitted changes')) 1282 raise error.Abort(_(b'uncommitted changes'))
1294 1283
1295 1284
1296 @eh.wrapfunction(cmdutil, b'postcommitstatus') 1285 @eh.wrapfunction(cmdutil, b'postcommitstatus')
1297 def postcommitstatus(orig, repo, *args, **kwargs): 1286 def postcommitstatus(orig, repo, *args, **kwargs):
1298 repo.lfstatus = True 1287 with lfstatus(repo):
1299 try:
1300 return orig(repo, *args, **kwargs) 1288 return orig(repo, *args, **kwargs)
1301 finally:
1302 repo.lfstatus = False
1303 1289
1304 1290
1305 @eh.wrapfunction(cmdutil, b'forget') 1291 @eh.wrapfunction(cmdutil, b'forget')
1306 def cmdutilforget( 1292 def cmdutilforget(
1307 orig, ui, repo, match, prefix, uipathfn, explicitonly, dryrun, interactive 1293 orig, ui, repo, match, prefix, uipathfn, explicitonly, dryrun, interactive
1317 dryrun, 1303 dryrun,
1318 interactive, 1304 interactive,
1319 ) 1305 )
1320 m = composelargefilematcher(match, repo[None].manifest()) 1306 m = composelargefilematcher(match, repo[None].manifest())
1321 1307
1322 try: 1308 with lfstatus(repo):
1323 repo.lfstatus = True
1324 s = repo.status(match=m, clean=True) 1309 s = repo.status(match=m, clean=True)
1325 finally:
1326 repo.lfstatus = False
1327 manifest = repo[None].manifest() 1310 manifest = repo[None].manifest()
1328 forget = sorted(s.modified + s.added + s.deleted + s.clean) 1311 forget = sorted(s.modified + s.added + s.deleted + s.clean)
1329 forget = [f for f in forget if lfutil.standin(f) in manifest] 1312 forget = [f for f in forget if lfutil.standin(f) in manifest]
1330 1313
1331 for f in forget: 1314 for f in forget:
1471 1454
1472 @eh.wrapcommand( 1455 @eh.wrapcommand(
1473 b'summary', opts=[(b'', b'large', None, _(b'display outgoing largefiles'))] 1456 b'summary', opts=[(b'', b'large', None, _(b'display outgoing largefiles'))]
1474 ) 1457 )
1475 def overridesummary(orig, ui, repo, *pats, **opts): 1458 def overridesummary(orig, ui, repo, *pats, **opts):
1476 try: 1459 with lfstatus(repo):
1477 repo.lfstatus = True
1478 orig(ui, repo, *pats, **opts) 1460 orig(ui, repo, *pats, **opts)
1479 finally:
1480 repo.lfstatus = False
1481 1461
1482 1462
1483 @eh.wrapfunction(scmutil, b'addremove') 1463 @eh.wrapfunction(scmutil, b'addremove')
1484 def scmutiladdremove(orig, repo, matcher, prefix, uipathfn, opts=None): 1464 def scmutiladdremove(orig, repo, matcher, prefix, uipathfn, opts=None):
1485 if opts is None: 1465 if opts is None: