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

login
register
mail settings
Submitter Matt Harbison
Date Jan. 17, 2018, 6:02 a.m.
Message ID <03d737594660bb748233.1516168946@Envy>
Download mbox | patch
Permalink /patch/26804/
State Accepted
Headers show

Comments

Matt Harbison - Jan. 17, 2018, 6:02 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@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.

Patch

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