# HG changeset patch # User Matt Harbison # Date 1515967224 18000 # Node ID f58245b9e3ea6e8945a81b951110cde155819345 # Parent 05d41579076182f57d0a8bf216196d29653f56bc 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. diff -r 05d415790761 -r f58245b9e3ea hgext/lfs/__init__.py --- 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 ', '? diff -r 05d415790761 -r f58245b9e3ea tests/test-lfs.t --- 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