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

mail settings
Submitter Matt Harbison
Date Feb. 9, 2018, 5:30 a.m.
Message ID <2b6579d78fe2dde40f8e.1518154222@Envy>
Download mbox | patch
Permalink /patch/27497/
State Accepted
Headers show


Matt Harbison - Feb. 9, 2018, 5:30 a.m.
# HG changeset patch
# User Matt Harbison <>
# 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/ b/hgext/lfs/
--- a/hgext/lfs/
+++ b/hgext/lfs/
@@ -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