[PATCH 2 of 3] lfs: allow a pointer to be extracted from a context that removes the file

Matt Harbison mharbison72 at gmail.com
Fri Feb 9 00:30:22 EST 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1517097384 18000
#      Sat Jan 27 18:56:24 2018 -0500
# Node ID 2b6579d78fe2dde40f8e0e99abeb35df93a4ade5
# Parent  5b3ca0f7f4b676863d5b3a481ce7ed88bf6acd55
lfs: allow a pointer to be extracted from a context that removes the file

This is needed to let 'set:lfs()' and '{lfs_files}' work normally on removed
files.  In the case of merging A and A', then removing it before committing, the
bias is toward p1(), since that's what status/diff do without extra arguments.

diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -349,11 +349,18 @@
             pointers[p.oid()] = p
     return sorted(pointers.values())
 
-def pointerfromctx(ctx, f):
+def pointerfromctx(ctx, f, removed=False):
     """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
+        if not removed:
+            return None
+        if f in ctx.p1():
+            ctx = ctx.p1()
+        elif f in ctx.p2():
+            ctx = ctx.p2()
+        else:
+            return None
     fctx = ctx[f]
     if not _islfs(fctx.filelog(), fctx.filenode()):
         return None
@@ -363,11 +370,11 @@
         raise error.Abort(_('lfs: corrupted pointer (%s@%s): %s\n')
                           % (f, short(ctx.node()), ex))
 
-def pointersfromctx(ctx):
+def pointersfromctx(ctx, removed=False):
     """return a dict {path: pointer} for given single changectx"""
     result = {}
     for f in ctx.files():
-        p = pointerfromctx(ctx, f)
+        p = pointerfromctx(ctx, f, removed=removed)
         if p:
             result[f] = p
     return result


More information about the Mercurial-devel mailing list