Patchwork [2,of,2] lfs: allow the pointer file to be viewed with `hg cat -T '{rawdata}'`

login
register
mail settings
Submitter Matt Harbison
Date Jan. 17, 2018, 2:29 a.m.
Message ID <2c12a42e20df3499a721.1516156167@Envy>
Download mbox | patch
Permalink /patch/26803/
State Accepted
Headers show

Comments

Matt Harbison - Jan. 17, 2018, 2:29 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1516151707 18000
#      Tue Jan 16 20:15:07 2018 -0500
# Node ID 2c12a42e20df3499a72194cd0f2911573ab82dc7
# Parent  ac8052ec552b36d4bee5bc24bc92fcee36d843cb
lfs: allow the pointer file to be viewed with `hg cat -T '{rawdata}'`

The only other interface to this data is `hg debugdata`, which requires
knowledge of the filelog revision that corresponds to the changeset.  Since the
data is uninterpreted, this is an important debugging capability, and needs to
be simpler to use than that.

For non-LFS files, this displays the regular data.

Alternately, we could forego the messy function extraction in the last patch if
this template keyword can just be added unconditionally.

Patch

diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -52,6 +52,7 @@ 
 from mercurial import (
     bundle2,
     changegroup,
+    cmdutil,
     context,
     exchange,
     extensions,
@@ -169,6 +170,7 @@ 
 
     wrapfunction = extensions.wrapfunction
 
+    wrapfunction(cmdutil, '_updatecatformatter', wrapper._updatecatformatter)
     wrapfunction(scmutil, 'wrapconvertsink', wrapper.convertsink)
 
     wrapfunction(upgrade, '_finishdatamigration',
diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -179,6 +179,10 @@ 
 def filectxislfs(self):
     return _islfs(self.filelog(), self.filenode())
 
+def _updatecatformatter(orig, fm, ctx, matcher, path, decode):
+    orig(fm, ctx, matcher, path, decode)
+    fm.data(rawdata=ctx[path].rawdata())
+
 def convertsink(orig, sink):
     sink = orig(sink)
     if sink.repotype == 'hg':
diff --git a/tests/test-lfs.t b/tests/test-lfs.t
--- a/tests/test-lfs.t
+++ b/tests/test-lfs.t
@@ -842,7 +842,7 @@ 
   0 meta
   $ grep 'lfs' convert_normal/.hg/requires
   [1]
-  $ hg --cwd convert_normal debugdata a1 0
+  $ hg --cwd convert_normal cat a1 -r 0 -T '{rawdata}'
   THIS-IS-LFS-BECAUSE-10-BYTES
 
   $ hg --config extensions.convert= --config lfs.threshold=10B \
@@ -854,6 +854,12 @@ 
   2 a
   1 b
   0 meta
+
+  $ hg --cwd convert_lfs cat -r 0 a1 -T '{rawdata}'
+  version https://git-lfs.github.com/spec/v1
+  oid sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024
+  size 29
+  x-is-binary 0
   $ hg --cwd convert_lfs debugdata a1 0
   version https://git-lfs.github.com/spec/v1
   oid sha256:5bb8341bee63b3649f222b2215bde37322bea075a30575aa685d8f8d21c77024