comparison hgext/lfs/wrapper.py @ 50786:dde4b55a0785

wrapfunction: use sysstr instead of bytes as argument in "lfs" This is as valid and simpler, it will help us to eventually get ride of `safehasattr`.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 03 Feb 2023 04:23:12 +0100
parents f254fc73d956
children 609a3b8058c3
comparison
equal deleted inserted replaced
50785:bf92386f76fd 50786:dde4b55a0785
51 ) 51 )
52 52
53 eh = exthelper.exthelper() 53 eh = exthelper.exthelper()
54 54
55 55
56 @eh.wrapfunction(localrepo, b'makefilestorage') 56 @eh.wrapfunction(localrepo, 'makefilestorage')
57 def localrepomakefilestorage(orig, requirements, features, **kwargs): 57 def localrepomakefilestorage(orig, requirements, features, **kwargs):
58 if b'lfs' in requirements: 58 if b'lfs' in requirements:
59 features.add(repository.REPO_FEATURE_LFS) 59 features.add(repository.REPO_FEATURE_LFS)
60 60
61 return orig(requirements=requirements, features=features, **kwargs) 61 return orig(requirements=requirements, features=features, **kwargs)
62 62
63 63
64 @eh.wrapfunction(changegroup, b'allsupportedversions') 64 @eh.wrapfunction(changegroup, 'allsupportedversions')
65 def allsupportedversions(orig, ui): 65 def allsupportedversions(orig, ui):
66 versions = orig(ui) 66 versions = orig(ui)
67 versions.add(b'03') 67 versions.add(b'03')
68 return versions 68 return versions
69 69
70 70
71 @eh.wrapfunction(wireprotov1server, b'_capabilities') 71 @eh.wrapfunction(wireprotov1server, '_capabilities')
72 def _capabilities(orig, repo, proto): 72 def _capabilities(orig, repo, proto):
73 '''Wrap server command to announce lfs server capability''' 73 '''Wrap server command to announce lfs server capability'''
74 caps = orig(repo, proto) 74 caps = orig(repo, proto)
75 if util.safehasattr(repo.svfs, b'lfslocalblobstore'): 75 if util.safehasattr(repo.svfs, b'lfslocalblobstore'):
76 # Advertise a slightly different capability when lfs is *required*, so 76 # Advertise a slightly different capability when lfs is *required*, so
225 metadata = pointer.deserialize(rawtext) 225 metadata = pointer.deserialize(rawtext)
226 return int(metadata[b'size']) 226 return int(metadata[b'size'])
227 return orig(self, rev) 227 return orig(self, rev)
228 228
229 229
230 @eh.wrapfunction(revlog, b'_verify_revision') 230 @eh.wrapfunction(revlog, '_verify_revision')
231 def _verify_revision(orig, rl, skipflags, state, node): 231 def _verify_revision(orig, rl, skipflags, state, node):
232 if _islfs(rl, node=node): 232 if _islfs(rl, node=node):
233 rawtext = rl.rawdata(node) 233 rawtext = rl.rawdata(node)
234 metadata = pointer.deserialize(rawtext) 234 metadata = pointer.deserialize(rawtext)
235 235
244 state[b'safe_renamed'].add(node) 244 state[b'safe_renamed'].add(node)
245 245
246 orig(rl, skipflags, state, node) 246 orig(rl, skipflags, state, node)
247 247
248 248
249 @eh.wrapfunction(context.basefilectx, b'cmp') 249 @eh.wrapfunction(context.basefilectx, 'cmp')
250 def filectxcmp(orig, self, fctx): 250 def filectxcmp(orig, self, fctx):
251 """returns True if text is different than fctx""" 251 """returns True if text is different than fctx"""
252 # some fctx (ex. hg-git) is not based on basefilectx and do not have islfs 252 # some fctx (ex. hg-git) is not based on basefilectx and do not have islfs
253 if self.islfs() and getattr(fctx, 'islfs', lambda: False)(): 253 if self.islfs() and getattr(fctx, 'islfs', lambda: False)():
254 # fast path: check LFS oid 254 # fast path: check LFS oid
256 p2 = pointer.deserialize(fctx.rawdata()) 256 p2 = pointer.deserialize(fctx.rawdata())
257 return p1.oid() != p2.oid() 257 return p1.oid() != p2.oid()
258 return orig(self, fctx) 258 return orig(self, fctx)
259 259
260 260
261 @eh.wrapfunction(context.basefilectx, b'isbinary') 261 @eh.wrapfunction(context.basefilectx, 'isbinary')
262 def filectxisbinary(orig, self): 262 def filectxisbinary(orig, self):
263 if self.islfs(): 263 if self.islfs():
264 # fast path: use lfs metadata to answer isbinary 264 # fast path: use lfs metadata to answer isbinary
265 metadata = pointer.deserialize(self.rawdata()) 265 metadata = pointer.deserialize(self.rawdata())
266 # if lfs metadata says nothing, assume it's binary by default 266 # if lfs metadata says nothing, assume it's binary by default
270 270
271 def filectxislfs(self): 271 def filectxislfs(self):
272 return _islfs(self.filelog()._revlog, self.filenode()) 272 return _islfs(self.filelog()._revlog, self.filenode())
273 273
274 274
275 @eh.wrapfunction(cmdutil, b'_updatecatformatter') 275 @eh.wrapfunction(cmdutil, '_updatecatformatter')
276 def _updatecatformatter(orig, fm, ctx, matcher, path, decode): 276 def _updatecatformatter(orig, fm, ctx, matcher, path, decode):
277 orig(fm, ctx, matcher, path, decode) 277 orig(fm, ctx, matcher, path, decode)
278 fm.data(rawdata=ctx[path].rawdata()) 278 fm.data(rawdata=ctx[path].rawdata())
279 279
280 280
281 @eh.wrapfunction(scmutil, b'wrapconvertsink') 281 @eh.wrapfunction(scmutil, 'wrapconvertsink')
282 def convertsink(orig, sink): 282 def convertsink(orig, sink):
283 sink = orig(sink) 283 sink = orig(sink)
284 if sink.repotype == b'hg': 284 if sink.repotype == b'hg':
285 285
286 class lfssink(sink.__class__): 286 class lfssink(sink.__class__):
323 return sink 323 return sink
324 324
325 325
326 # bundlerepo uses "vfsmod.readonlyvfs(othervfs)", we need to make sure lfs 326 # bundlerepo uses "vfsmod.readonlyvfs(othervfs)", we need to make sure lfs
327 # options and blob stores are passed from othervfs to the new readonlyvfs. 327 # options and blob stores are passed from othervfs to the new readonlyvfs.
328 @eh.wrapfunction(vfsmod.readonlyvfs, b'__init__') 328 @eh.wrapfunction(vfsmod.readonlyvfs, '__init__')
329 def vfsinit(orig, self, othervfs): 329 def vfsinit(orig, self, othervfs):
330 orig(self, othervfs) 330 orig(self, othervfs)
331 # copy lfs related options 331 # copy lfs related options
332 for k, v in othervfs.options.items(): 332 for k, v in othervfs.options.items():
333 if k.startswith(b'lfs'): 333 if k.startswith(b'lfs'):
401 the remote blobstore. 401 the remote blobstore.
402 """ 402 """
403 return uploadblobsfromrevs(pushop.repo, pushop.outgoing.missing) 403 return uploadblobsfromrevs(pushop.repo, pushop.outgoing.missing)
404 404
405 405
406 @eh.wrapfunction(exchange, b'push') 406 @eh.wrapfunction(exchange, 'push')
407 def push(orig, repo, remote, *args, **kwargs): 407 def push(orig, repo, remote, *args, **kwargs):
408 """bail on push if the extension isn't enabled on remote when needed, and 408 """bail on push if the extension isn't enabled on remote when needed, and
409 update the remote store based on the destination path.""" 409 update the remote store based on the destination path."""
410 if b'lfs' in repo.requirements: 410 if b'lfs' in repo.requirements:
411 # If the remote peer is for a local repo, the requirement tests in the 411 # If the remote peer is for a local repo, the requirement tests in the
431 else: 431 else:
432 return orig(repo, remote, *args, **kwargs) 432 return orig(repo, remote, *args, **kwargs)
433 433
434 434
435 # when writing a bundle via "hg bundle" command, upload related LFS blobs 435 # when writing a bundle via "hg bundle" command, upload related LFS blobs
436 @eh.wrapfunction(bundle2, b'writenewbundle') 436 @eh.wrapfunction(bundle2, 'writenewbundle')
437 def writenewbundle( 437 def writenewbundle(
438 orig, ui, repo, source, filename, bundletype, outgoing, *args, **kwargs 438 orig, ui, repo, source, filename, bundletype, outgoing, *args, **kwargs
439 ): 439 ):
440 """upload LFS blobs added by outgoing revisions on 'hg bundle'""" 440 """upload LFS blobs added by outgoing revisions on 'hg bundle'"""
441 uploadblobsfromrevs(repo, outgoing.missing) 441 uploadblobsfromrevs(repo, outgoing.missing)
520 520
521 remoteblob = repo.svfs.lfsremoteblobstore 521 remoteblob = repo.svfs.lfsremoteblobstore
522 remoteblob.writebatch(pointers, repo.svfs.lfslocalblobstore) 522 remoteblob.writebatch(pointers, repo.svfs.lfslocalblobstore)
523 523
524 524
525 @eh.wrapfunction(upgrade_engine, b'finishdatamigration') 525 @eh.wrapfunction(upgrade_engine, 'finishdatamigration')
526 def upgradefinishdatamigration(orig, ui, srcrepo, dstrepo, requirements): 526 def upgradefinishdatamigration(orig, ui, srcrepo, dstrepo, requirements):
527 orig(ui, srcrepo, dstrepo, requirements) 527 orig(ui, srcrepo, dstrepo, requirements)
528 528
529 # Skip if this hasn't been passed to reposetup() 529 # Skip if this hasn't been passed to reposetup()
530 if util.safehasattr( 530 if util.safehasattr(
537 for oid in files: 537 for oid in files:
538 ui.write(_(b'copying lfs blob %s\n') % oid) 538 ui.write(_(b'copying lfs blob %s\n') % oid)
539 lfutil.link(srclfsvfs.join(oid), dstlfsvfs.join(oid)) 539 lfutil.link(srclfsvfs.join(oid), dstlfsvfs.join(oid))
540 540
541 541
542 @eh.wrapfunction(upgrade_actions, b'preservedrequirements') 542 @eh.wrapfunction(upgrade_actions, 'preservedrequirements')
543 @eh.wrapfunction(upgrade_actions, b'supporteddestrequirements') 543 @eh.wrapfunction(upgrade_actions, 'supporteddestrequirements')
544 def upgraderequirements(orig, repo): 544 def upgraderequirements(orig, repo):
545 reqs = orig(repo) 545 reqs = orig(repo)
546 if b'lfs' in repo.requirements: 546 if b'lfs' in repo.requirements:
547 reqs.add(b'lfs') 547 reqs.add(b'lfs')
548 return reqs 548 return reqs