##// END OF EJS Templates
lfs: allow a pointer to be extracted from a context that removes the file...
Matt Harbison -
r36016:dce43aaa default
parent child Browse files
Show More
@@ -349,26 +349,46 b' def extractpointers(repo, revs):'
349 pointers[p.oid()] = p
349 pointers[p.oid()] = p
350 return sorted(pointers.values())
350 return sorted(pointers.values())
351
351
352 def pointerfromctx(ctx, f):
352 def pointerfromctx(ctx, f, removed=False):
353 """return a pointer for the named file from the given changectx, or None if
353 """return a pointer for the named file from the given changectx, or None if
354 the file isn't LFS."""
354 the file isn't LFS.
355
356 Optionally, the pointer for a file deleted from the context can be returned.
357 Since no such pointer is actually stored, and to distinguish from a non LFS
358 file, this pointer is represented by an empty dict.
359 """
360 _ctx = ctx
355 if f not in ctx:
361 if f not in ctx:
356 return None
362 if not removed:
357 fctx = ctx[f]
363 return None
364 if f in ctx.p1():
365 _ctx = ctx.p1()
366 elif f in ctx.p2():
367 _ctx = ctx.p2()
368 else:
369 return None
370 fctx = _ctx[f]
358 if not _islfs(fctx.filelog(), fctx.filenode()):
371 if not _islfs(fctx.filelog(), fctx.filenode()):
359 return None
372 return None
360 try:
373 try:
361 return pointer.deserialize(fctx.rawdata())
374 p = pointer.deserialize(fctx.rawdata())
375 if ctx == _ctx:
376 return p
377 return {}
362 except pointer.InvalidPointer as ex:
378 except pointer.InvalidPointer as ex:
363 raise error.Abort(_('lfs: corrupted pointer (%s@%s): %s\n')
379 raise error.Abort(_('lfs: corrupted pointer (%s@%s): %s\n')
364 % (f, short(ctx.node()), ex))
380 % (f, short(_ctx.node()), ex))
365
381
366 def pointersfromctx(ctx):
382 def pointersfromctx(ctx, removed=False):
367 """return a dict {path: pointer} for given single changectx"""
383 """return a dict {path: pointer} for given single changectx.
384
385 If ``removed`` == True and the LFS file was removed from ``ctx``, the value
386 stored for the path is an empty dict.
387 """
368 result = {}
388 result = {}
369 for f in ctx.files():
389 for f in ctx.files():
370 p = pointerfromctx(ctx, f)
390 p = pointerfromctx(ctx, f, removed=removed)
371 if p:
391 if p is not None:
372 result[f] = p
392 result[f] = p
373 return result
393 return result
374
394
General Comments 0
You need to be logged in to leave comments. Login now