Patchwork [3,of,3,RFC] lfs: add support for supplying a pattern/fileset

login
register
mail settings
Submitter Matt Harbison
Date Dec. 29, 2017, 9:43 p.m.
Message ID <50ae298ab962ea184b89.1514583804@Envy>
Download mbox | patch
Permalink /patch/26500/
State RFC, archived
Headers show

Comments

Matt Harbison - Dec. 29, 2017, 9:43 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1514530388 18000
#      Fri Dec 29 01:53:08 2017 -0500
# Node ID 50ae298ab962ea184b89f58f45fb3d99daf16ccd
# Parent  ab695d4cf960440e92aca0c07ec1753d0c26a56d
lfs: add support for supplying a pattern/fileset

The goal here was to experiment with alternate ways of matching an lfs object.
After further reflection, a config option for this is probably the wrong step,
and this should go right to a tracked file.  The question is, what format?

The ignore file uses a simple non *.ini syntax, so I don't see a way to stuff a
size threshold in there.  (And I think it should be in there for consistency,
and maybe 'lfs.threshold' deprecated and removed.)  Additionally, there's a
special note in `hg help patterns` that ignore patterns aren't rooted.  These
patterns probably should be.

Alternately, .hgeol uses the standard *.ini syntax.  If the pattern is also the
key here, I'm not sure what the value would be (it's LF, CRLF or NATIVE in eol),
unless we make it the threshold value.  e.g.:

  [patterns]
  **.exe = 512K
  # These should never be lfs
  rarely_changed/**.exe = -1
  **.bin = 1MB
  # Always for stuff in ^artifacts/
  artifacts = 0

This solves the problem of where to store the threshold, and gives a bit more
flexibility (i.e. sometimes source files can be bigger than the binaries that
should be treated as lfs, but you don't want the source files treated as lfs).
But it may be unnecessarily complicated.  And without a global threshold, it is
left open to accidently committing something big as a normal file.  (Maybe we
should add a server side hook to check non-lfs files and reject based on a
specified config option if they are too big?)  I'm open to suggestions on all of
this.

Patch

diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -76,6 +76,9 @@ 
 configitem('lfs', 'usercache',
     default=None,
 )
+configitem('lfs', 'patterns',
+    default=None,
+)
 configitem('lfs', 'threshold',
     default=None,
 )
@@ -129,6 +132,11 @@ 
             if threshold:
                 pats.append("set:size('>= %s')" % threshold)
 
+            patterns = self.ui.config('lfs', 'patterns')
+            if patterns:
+                # TODO: Handle multiple patterns
+                pats.append(patterns)
+
             m = lambda x: False
             if pats:
                 m = scmutil.match(ctx, pats=pats, default='glob')
diff --git a/tests/test-lfs.t b/tests/test-lfs.t
--- a/tests/test-lfs.t
+++ b/tests/test-lfs.t
@@ -872,6 +872,29 @@ 
   $ hg commit -m 'add A' -A A
   $ hg rm A
   $ hg commit -m 'rm A'
+  $ cat > patch.diff <<EOF
+  > # HG changeset patch
+  > 2
+  > 
+  > diff --git a/a b/a
+  > new file mode 100755
+  > --- /dev/null
+  > +++ b/testfile
+  > @@ -0,0 +1,1 @@
+  > + short
+  > EOF
+
+TODO: Figure out why 'set:exec()' doesn't work here.
+  $ hg --config lfs.threshold=100MB --config lfs.patterns='*file' \
+  >    import -q --bypass patch.diff
+  $ hg debugdata testfile 0
+  version https://git-lfs.github.com/spec/v1
+  oid sha256:9e886850e00759892e1ed0887cf5f9796d81e14d31f902535c3ef3b30264553a
+  size 7
+  x-is-binary 0
+  $ hg files -vr tip
+           0 x a
+           7   testfile
   $ cd ..
 
 Unbundling adds a requirement to a non-lfs repo, if necessary.