Patchwork [2,of,3,V2] lfs: teach '{lfs_files}' to handle removed files

login
register
mail settings
Submitter Matt Harbison
Date Feb. 11, 2018, 2:41 a.m.
Message ID <589f4ea15c31383964e2.1518316888@Envy>
Download mbox | patch
Permalink /patch/27521/
State Accepted
Headers show

Comments

Matt Harbison - Feb. 11, 2018, 2:41 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1517098935 18000
#      Sat Jan 27 19:22:15 2018 -0500
# Node ID 589f4ea15c31383964e2b7d812bb5431b7dd682e
# Parent  b1c1762fe8b9bb0c89602810e2db8b1e5e63b8c9
lfs: teach '{lfs_files}' to handle removed files

Patch

diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -360,10 +360,11 @@ 
 
 @templatekeyword('lfs_files')
 def lfsfiles(repo, ctx, **args):
-    """List of strings. LFS files added or modified by the changeset."""
+    """List of strings. All files modified, added, or removed by this
+    changeset."""
     args = pycompat.byteskwargs(args)
 
-    pointers = wrapper.pointersfromctx(ctx) # {path: pointer}
+    pointers = wrapper.pointersfromctx(ctx, removed=True) # {path: pointer}
     files = sorted(pointers.keys())
 
     def pointer(v):
@@ -374,7 +375,7 @@ 
 
     makemap = lambda v: {
         'file': v,
-        'lfsoid': pointers[v].oid(),
+        'lfsoid': pointers[v].oid() if pointers[v] else None,
         'lfspointer': templatekw.hybriddict(pointer(v)),
     }
 
diff --git a/tests/test-lfs-largefiles.t b/tests/test-lfs-largefiles.t
--- a/tests/test-lfs-largefiles.t
+++ b/tests/test-lfs-largefiles.t
@@ -298,7 +298,7 @@ 
   $TESTTMP/nolargefiles/.hg/hgrc:*: extensions.lfs= (glob)
 
   $ hg log -r 'all()' -G -T '{rev} {join(lfs_files, ", ")} ({desc})\n'
-  o  8  (remove large_by_size.bin)
+  o  8 large_by_size.bin (remove large_by_size.bin)
   |
   o  7 large_by_size.bin (large by size)
   |
diff --git a/tests/test-lfs.t b/tests/test-lfs.t
--- a/tests/test-lfs.t
+++ b/tests/test-lfs.t
@@ -186,7 +186,7 @@ 
 
   $ hg log -r 'all()' -T '{rev} {join(lfs_files, ", ")}\n'
   0 large
-  1 l
+  1 l, large
   2 s
   3 s
   4 l
@@ -1032,6 +1032,16 @@ 
   $ hg rm lfs.test
   $ hg ci -qm 'remove lfs'
 
+{lfs_files} will list deleted files too
+
+  $ hg log -T "{lfs_files % '{rev} {file}: {lfspointer.oid}\n'}"
+  6 lfs.test: 
+  5 lfs.test: sha256:43f8f41171b6f62a6b61ba4ce98a8a6c1649240a47ebafd43120aa215ac9e7f6
+  3 lfs.catchall: sha256:31f43b9c62b540126b0ad5884dc013d21a61c9329b77de1fceeae2fc58511573
+  3 lfs.test: sha256:8acd23467967bc7b8cc5a280056589b0ba0b17ff21dbd88a7b6474d6290378a6
+  2 lfs.catchall: sha256:d4ec46c2869ba22eceb42a729377432052d9dd75d82fc40390ebaadecee87ee9
+  2 lfs.test: sha256:5489e6ced8c36a7b267292bde9fd5242a5f80a7482e8f23fa0477393dfaa4d6c
+
 TODO: This should notice the deleted lfs files in rev 6
   $ hg log -r 'file("set:lfs()")' -T '{rev} {join(lfs_files, ", ")}\n'
   2 lfs.catchall, lfs.test