changeset 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 2912bed9b0c7
children 0b79f99fd7b0
files hgext/lfs/wrapper.py
diffstat 1 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/lfs/wrapper.py	Mon Feb 05 13:24:02 2018 +0530
+++ b/hgext/lfs/wrapper.py	Sat Jan 27 14:53:16 2018 -0500
@@ -307,20 +307,27 @@
             pointers[p.oid()] = p
     return sorted(pointers.values())
 
+def pointerfromctx(ctx, f):
+    """return a pointer for the named file from the given changectx, or None if
+    the file isn't LFS."""
+    if f not in ctx:
+        return None
+    fctx = ctx[f]
+    if not _islfs(fctx.filelog(), fctx.filenode()):
+        return None
+    try:
+        return pointer.deserialize(fctx.rawdata())
+    except pointer.InvalidPointer as ex:
+        raise error.Abort(_('lfs: corrupted pointer (%s@%s): %s\n')
+                          % (f, short(ctx.node()), ex))
+
 def pointersfromctx(ctx):
     """return a dict {path: pointer} for given single changectx"""
     result = {}
     for f in ctx.files():
-        if f not in ctx:
-            continue
-        fctx = ctx[f]
-        if not _islfs(fctx.filelog(), fctx.filenode()):
-            continue
-        try:
-            result[f] = pointer.deserialize(fctx.rawdata())
-        except pointer.InvalidPointer as ex:
-            raise error.Abort(_('lfs: corrupted pointer (%s@%s): %s\n')
-                              % (f, short(ctx.node()), ex))
+        p = pointerfromctx(ctx, f)
+        if p:
+            result[f] = p
     return result
 
 def uploadblobs(repo, pointers):