comparison hgext/lfs/wrapper.py @ 35921:47e737d27e01

lfs: factor out a method for extracting the pointer of a single file This will be useful for filesets, among other things, instead of traversing the whole context.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 27 Jan 2018 14:53:16 -0500
parents b91bca85ba73
children 0b79f99fd7b0
comparison
equal deleted inserted replaced
35920:2912bed9b0c7 35921:47e737d27e01
305 ctx = repo[r] 305 ctx = repo[r]
306 for p in pointersfromctx(ctx).values(): 306 for p in pointersfromctx(ctx).values():
307 pointers[p.oid()] = p 307 pointers[p.oid()] = p
308 return sorted(pointers.values()) 308 return sorted(pointers.values())
309 309
310 def pointerfromctx(ctx, f):
311 """return a pointer for the named file from the given changectx, or None if
312 the file isn't LFS."""
313 if f not in ctx:
314 return None
315 fctx = ctx[f]
316 if not _islfs(fctx.filelog(), fctx.filenode()):
317 return None
318 try:
319 return pointer.deserialize(fctx.rawdata())
320 except pointer.InvalidPointer as ex:
321 raise error.Abort(_('lfs: corrupted pointer (%s@%s): %s\n')
322 % (f, short(ctx.node()), ex))
323
310 def pointersfromctx(ctx): 324 def pointersfromctx(ctx):
311 """return a dict {path: pointer} for given single changectx""" 325 """return a dict {path: pointer} for given single changectx"""
312 result = {} 326 result = {}
313 for f in ctx.files(): 327 for f in ctx.files():
314 if f not in ctx: 328 p = pointerfromctx(ctx, f)
315 continue 329 if p:
316 fctx = ctx[f] 330 result[f] = p
317 if not _islfs(fctx.filelog(), fctx.filenode()):
318 continue
319 try:
320 result[f] = pointer.deserialize(fctx.rawdata())
321 except pointer.InvalidPointer as ex:
322 raise error.Abort(_('lfs: corrupted pointer (%s@%s): %s\n')
323 % (f, short(ctx.node()), ex))
324 return result 331 return result
325 332
326 def uploadblobs(repo, pointers): 333 def uploadblobs(repo, pointers):
327 """upload given pointers from local blobstore""" 334 """upload given pointers from local blobstore"""
328 if not pointers: 335 if not pointers: