Patchwork [4,of,5,RFC] lfs: move the tracked file function creation to a method

login
register
mail settings
Submitter Matt Harbison
Date Jan. 15, 2018, 4:58 a.m.
Message ID <7e5d513b38c169856b51.1515992331@Envy>
Download mbox | patch
Permalink /patch/26754/
State Superseded
Headers show

Comments

Matt Harbison - Jan. 15, 2018, 4:58 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 7e5d513b38c169856b51b6207d992abbef10d2d5
# Parent  197a87c27995bc3c59f0e22165ff60c7d43d2efc
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