changeset 35731:f58245b9e3ea

lfs: add the '{lfsattrs}' template keyword to '{lfs_files}' This provides access to the metadata dictionary contained within the tracked pointer file. The OID is probably the most important attribute, and has its own keyword. But we might as well have this for completeness. I liked {pointer} better, but couldn't make it work with the singular/plural forms.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 14 Jan 2018 17:00:24 -0500
parents 05d415790761
children 10e62d5efa73
files hgext/lfs/__init__.py tests/test-lfs.t
diffstat 2 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/lfs/__init__.py	Thu Jan 18 16:47:14 2018 +0100
+++ b/hgext/lfs/__init__.py	Sun Jan 14 17:00:24 2018 -0500
@@ -97,6 +97,7 @@
     scmutil,
     templatekw,
     upgrade,
+    util,
     vfs as vfsmod,
     wireproto,
 )
@@ -311,9 +312,16 @@
     pointers = wrapper.pointersfromctx(ctx) # {path: pointer}
     files = sorted(pointers.keys())
 
+    def lfsattrs(v):
+        # In the file spec, version is first and the other keys are sorted.
+        sortkeyfunc = lambda x: (x[0] != 'version', x)
+        items = sorted(pointers[v].iteritems(), key=sortkeyfunc)
+        return util.sortdict(items)
+
     makemap = lambda v: {
         'file': v,
         'oid': pointers[v].oid(),
+        'lfsattrs': templatekw.hybriddict(lfsattrs(v)),
     }
 
     # TODO: make the separator ', '?
--- a/tests/test-lfs.t	Thu Jan 18 16:47:14 2018 +0100
+++ b/tests/test-lfs.t	Sun Jan 14 17:00:24 2018 -0500
@@ -865,6 +865,17 @@
   oid sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
   size 29
   x-is-binary 0
+  $ hg --cwd convert_lfs log -r 0 -T "{lfs_files % '{lfsattrs % '{key}={value}\n'}'}"
+  version=https://git-lfs.github.com/spec/v1
+  oid=sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
+  size=29
+  x-is-binary=0
+  $ hg --cwd convert_lfs log -r 0 \
+  >    -T '{lfs_files % "{get(lfsattrs, "oid")}\n"}{lfs_files % "{lfsattrs.oid}\n"}'
+  sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
+  sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
+  $ hg --cwd convert_lfs log -r 0 -T '{lfs_files % "{lfsattrs}\n"}'
+  version=https://git-lfs.github.com/spec/v1 oid=sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024 size=29 x-is-binary=0
   $ hg --cwd convert_lfs \
   >     log -r 'all()' -T '{rev}: {lfs_files % "{file}: {oid}\n"}'
   0: a1: 5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024