[PATCH 1 of 2 V2] lfs: move the tracked file function creation to a method

Matt Harbison mharbison72 at gmail.com
Wed Jan 17 06:02:26 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1515909885 18000
#      Sun Jan 14 01:04:45 2018 -0500
# Node ID 03d737594660bb74823317e02a6ad2e91456c12d
# Parent  821d8a5ab4ff890a7732c2e4cdcc7f32191e5942
lfs: move the tracked file function creation to a method

Once a commitable file format for tracked config is agreed upon, I can't see any
reason to have a config based way to control this.  (Other than convert.  That
will be necessary to override the file when converting to normal files.  Also,
converting to lfs needs this if not splicing the file in at the beginning.  So
maybe the existing config option should be `convert` specific.)  Looking to
hgeol for precedent, it looks like policy that affects how items are stored are
handled only by the tracked file, while policy that affects the checkout can be
handled by either a user config or the tracked file (but the latter takes
precedence).

We probably need a transition period, so this transition policy can be
controlled by the function.  Additionally, it provides a place for convert to
wrap to override the file based config.

diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -123,15 +123,7 @@
     if not repo.local():
         return
 
-    trackspec = repo.ui.config('lfs', 'track')
-
-    # deprecated config: lfs.threshold
-    threshold = repo.ui.configbytes('lfs', 'threshold')
-    if threshold:
-        fileset.parse(trackspec)  # make sure syntax errors are confined
-        trackspec = "(%s) | size('>%d')" % (trackspec, threshold)
-
-    repo.svfs.options['lfstrack'] = minifileset.compile(trackspec)
+    repo.svfs.options['lfstrack'] = _trackedmatcher(repo)
     repo.svfs.lfslocalblobstore = blobstore.local(repo)
     repo.svfs.lfsremoteblobstore = blobstore.remote(repo)
 
@@ -157,6 +149,19 @@
         ui.setconfig('hooks', 'commit.lfs', checkrequireslfs, 'lfs')
         ui.setconfig('hooks', 'pretxnchangegroup.lfs', checkrequireslfs, 'lfs')
 
+def _trackedmatcher(repo):
+    """Return a function (path, size) -> bool indicating whether or not to
+    track a given file with lfs."""
+    trackspec = repo.ui.config('lfs', 'track')
+
+    # deprecated config: lfs.threshold
+    threshold = repo.ui.configbytes('lfs', 'threshold')
+    if threshold:
+        fileset.parse(trackspec)  # make sure syntax errors are confined
+        trackspec = "(%s) | size('>%d')" % (trackspec, threshold)
+
+    return minifileset.compile(trackspec)
+
 def wrapfilelog(filelog):
     wrapfunction = extensions.wrapfunction
 


More information about the Mercurial-devel mailing list