Patchwork [1,of,7,V2] lfs: factor out a method for extracting the pointer of a single file

login
register
mail settings
Submitter Matt Harbison
Date Feb. 6, 2018, 5:29 a.m.
Message ID <ae7b40a6cb0863e26e24.1517894944@Envy>
Download mbox | patch
Permalink /patch/27344/
State Accepted
Headers show

Comments

Matt Harbison - Feb. 6, 2018, 5:29 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1517082796 18000
#      Sat Jan 27 14:53:16 2018 -0500
# Node ID ae7b40a6cb0863e26e245966388d766adf065bac
# Parent  2912bed9b0c7d02a1cac6f56584c0c0a2f9debe4
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.
Yuya Nishihara - Feb. 6, 2018, 12:16 p.m.
On Tue, 06 Feb 2018 00:29:04 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1517082796 18000
> #      Sat Jan 27 14:53:16 2018 -0500
> # Node ID ae7b40a6cb0863e26e245966388d766adf065bac
> # Parent  2912bed9b0c7d02a1cac6f56584c0c0a2f9debe4
> lfs: factor out a method for extracting the pointer of a single file

Queued the series, thanks.

Patch

diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -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):