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

login
register
mail settings
Submitter Matt Harbison
Date Feb. 9, 2018, 5:30 a.m.
Message ID <e545487fa7fa9ff2fa4f.1518154223@Envy>
Download mbox | patch
Permalink /patch/27498/
State Accepted
Headers show

Comments

Matt Harbison - Feb. 9, 2018, 5:30 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 e545487fa7fa9ff2fa4f85e2482bea8ba4040ef6
# Parent  2b6579d78fe2dde40f8e0e99abeb35df93a4ade5
lfs: teach '{lfs_files}' to handle removed files
Yuya Nishihara - Feb. 9, 2018, 1:04 p.m.
On Fri, 09 Feb 2018 00:30:23 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1517098935 18000
> #      Sat Jan 27 19:22:15 2018 -0500
> # Node ID e545487fa7fa9ff2fa4f85e2482bea8ba4040ef6
> # Parent  2b6579d78fe2dde40f8e0e99abeb35df93a4ade5
> lfs: teach '{lfs_files}' to handle removed files
> 
> 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())

> +{lfs_files} will list deleted files too
> +
> +  $ hg log -T "{lfs_files % '{rev} {file}: {lfspointer.oid}\n'}"
> +  6 lfs.test: sha256:43f8f41171b6f62a6b61ba4ce98a8a6c1649240a47ebafd43120aa215ac9e7f6
> +  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

Including removed files makes sense, but I think the pointer should be "null"
in which case because the file doesn't exist. I have no idea how the "null"
lfs pointer should look like, though.

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):
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: sha256:43f8f41171b6f62a6b61ba4ce98a8a6c1649240a47ebafd43120aa215ac9e7f6
+  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