Patchwork [1,of,2] fileset: use filectx.isbinary() to filter out binaries in eol()

login
register
mail settings
Submitter Matt Harbison
Date June 21, 2018, 4:53 a.m.
Message ID <34268c3b609860088271.1529556828@Envy>
Download mbox | patch
Permalink /patch/32352/
State Accepted
Headers show

Comments

Matt Harbison - June 21, 2018, 4:53 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1529553926 14400
#      Thu Jun 21 00:05:26 2018 -0400
# Node ID 34268c3b609860088271789ddcaf30f8fbd624dd
# Parent  96871ca322705c08b56cc4e7037e9f1a6d8fa786
fileset: use filectx.isbinary() to filter out binaries in eol()

Since LFS stores the binary attribute in the pointer file, this means that the
file doesn't need to be downloaded in order to be skipped.  This function also
catches an IOError if the data can't be loaded in the non-LFS case.

I wonder if it's worth storing the unix/dos attributes in the pointer file as
well, though I'd expect LFS files to be binary most of the time.
Yuya Nishihara - June 21, 2018, 11:30 a.m.
On Thu, 21 Jun 2018 00:53:48 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1529553926 14400
> #      Thu Jun 21 00:05:26 2018 -0400
> # Node ID 34268c3b609860088271789ddcaf30f8fbd624dd
> # Parent  96871ca322705c08b56cc4e7037e9f1a6d8fa786
> fileset: use filectx.isbinary() to filter out binaries in eol()

Queued, thanks.

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -448,9 +448,10 @@  def eol(mctx, x):
 
     s = []
     for f in mctx.existing():
-        d = mctx.ctx[f].data()
-        if stringutil.binary(d):
+        fctx = mctx.ctx[f]
+        if fctx.isbinary():
             continue
+        d = fctx.data()
         if (enc == 'dos' or enc == 'win') and '\r\n' in d:
             s.append(f)
         elif enc == 'unix' and re.search('(?<!\r)\n', d):
diff --git a/tests/test-lfs.t b/tests/test-lfs.t
--- a/tests/test-lfs.t
+++ b/tests/test-lfs.t
@@ -515,6 +515,17 @@  enabled adds the lfs requirement
   d: binary=False
   b55353847f02 tip
 
+Binary blobs don't need to be present to be skipped in filesets.  (And their
+absence doesn't cause an abort.)
+
+  $ rm .hg/store/lfs/objects/96/a296d224f285c67bee93c30f8a309157f0daa35dc5b87e410b78630a09cfc7
+  $ rm .hg/store/lfs/objects/92/f76135a4baf4faccb8586a60faf830c2bdfce147cefa188aaf4b790bd01b7e
+
+  $ hg files --debug -r . 'set:eol("unix")' --config 'experimental.lfs.disableusercache=True'
+  lfs: found c04b5bb1a5b2eb3e9cd4805420dba5a9d133da5b7adeeafb5474c4adae9faa80 in the local lfs store
+  lfs: found 5dde896887f6754c9b15bfe3a441ae4806df2fde94001311e08bf110622e0bbe in the local lfs store
+           2   b
+
   $ cd ..
 
 # Test fctx.cmp fastpath - diff without LFS blobs