From patchwork Fri Jan 19 05:05:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [V2] lfs: add the '{lfsattrs}' template keyword to '{lfs_files}' From: Matt Harbison X-Patchwork-Id: 26942 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Fri, 19 Jan 2018 00:05:42 -0500 # HG changeset patch # User Matt Harbison # Date 1515967224 18000 # Sun Jan 14 17:00:24 2018 -0500 # Node ID fccf09e44f5124abf18ae898fab553ea6d91e951 # Parent 45b678bf3a787085d56fad5bee494e0c160aa120 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 --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py --- a/hgext/lfs/__init__.py +++ b/hgext/lfs/__init__.py @@ -97,6 +97,7 @@ scmutil, templatekw, upgrade, + util, vfs as vfsmod, wireproto, ) @@ -303,6 +304,8 @@ # when writing a bundle via "hg bundle" command, upload related LFS blobs wrapfunction(bundle2, 'writenewbundle', wrapper.writenewbundle) + templatekw.defaulttempl['lfsattr'] = '{key}={value}' + @templatekeyword('lfs_files') def lfsfiles(repo, ctx, **args): """List of strings. LFS files added or modified by the changeset.""" @@ -311,9 +314,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(kv for kv in items) + makemap = lambda v: { 'file': v, 'oid': pointers[v].oid(), + 'lfsattrs': templatekw.hybriddict(lfsattrs(v)), } # TODO: make the separator ', '? diff --git a/tests/test-lfs.t b/tests/test-lfs.t --- a/tests/test-lfs.t +++ b/tests/test-lfs.t @@ -865,6 +865,17 @@ oid sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024 size 29 x-is-binary 0 + $ hg --cwd convert_lfs log -r 0 -T "{lfs_files % '{lfsattrs % \"{lfsattr}\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