lfs: move the tracked file function creation to a method
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 14 Jan 2018 01:04:45 -0500
changeset 35664 3c838bdc57b6
parent 35663 a985834961f7
child 35665 1ad1e59b405e
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.
hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py	Tue Jan 16 20:15:07 2018 -0500
+++ b/hgext/lfs/__init__.py	Sun Jan 14 01:04:45 2018 -0500
@@ -124,15 +124,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)
 
@@ -158,6 +150,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