lfs: don't require the .hglfs file to be tracked to control the policy stable
authorMatt Harbison <matt_harbison@yahoo.com>
Mon, 29 Jan 2018 21:42:18 -0500
branchstable
changeset 35807 4425790f2373
parent 35806 ab239e3de23b
child 35808 178aacdc25db
lfs: don't require the .hglfs file to be tracked to control the policy The .hgignore file doesn't need to be tracked, nor does the git equivalent of this file. I'm still a little concerned about the effects of forgetting to commit this file. But the fact that conversions maintain the hashes if only the normal vs external storage changes, should make this less risky.
hgext/lfs/__init__.py
tests/test-lfs.t
--- a/hgext/lfs/__init__.py	Sat Jan 27 21:50:04 2018 -0500
+++ b/hgext/lfs/__init__.py	Mon Jan 29 21:42:18 2018 -0500
@@ -25,14 +25,15 @@
 not be able to communicate with each other unless the extension is
 enabled on both.
 
-To start a new repository, or add new LFS files, just create and add
-an ``.hglfs`` file as described below.  Because the file is tracked in
-the repository, all clones will use the same selection policy.  During
-subsequent commits, Mercurial will consult this file to determine if
-an added or modified file should be stored externally.  The type of
-storage depends on the characteristics of the file at each commit.  A
-file that is near a size threshold may switch back and forth between
-LFS and normal storage, as needed.
+To start a new repository, or to add LFS files to an existing one, just
+create an ``.hglfs`` file as described below in the root directory of
+the repository.  Typically, this file should be put under version
+control, so that the settings will propagate to other repositories with
+push and pull.  During any commit, Mercurial will consult this file to
+determine if an added or modified file should be stored externally.  The
+type of storage depends on the characteristics of the file at each
+commit.  A file that is near a size threshold may switch back and forth
+between LFS and normal storage, as needed.
 
 Alternately, both normal repositories and largefile controlled
 repositories can be converted to LFS by using :hg:`convert` and the
@@ -240,29 +241,19 @@
 def _trackedmatcher(repo, ctx):
     """Return a function (path, size) -> bool indicating whether or not to
     track a given file with lfs."""
-    data = ''
-
-    if '.hglfs' in ctx.added() or '.hglfs' in ctx.modified():
-        data = ctx['.hglfs'].data()
-    elif '.hglfs' not in ctx.removed():
-        p1 = repo['.']
-
-        if '.hglfs' not in p1:
-            # No '.hglfs' in wdir or in parent.  Fallback to config
-            # for now.
-            trackspec = repo.ui.config('lfs', 'track')
+    if not repo.wvfs.exists('.hglfs'):
+        # No '.hglfs' in wdir.  Fallback to config for now.
+        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)
+        # 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)
+        return minifileset.compile(trackspec)
 
-        data = p1['.hglfs'].data()
-
-    # In removed, or not in parent
+    data = repo.wvfs.tryread('.hglfs')
     if not data:
         return lambda p, s: False
 
--- a/tests/test-lfs.t	Sat Jan 27 21:50:04 2018 -0500
+++ b/tests/test-lfs.t	Mon Jan 29 21:42:18 2018 -0500
@@ -984,27 +984,28 @@
   > ** = size(">10B")
   > EOF
 
-The LFS policy takes effect as the .hglfs file is committed
+The LFS policy takes effect without tracking the .hglfs file
 
   $ echo 'largefile' > lfs.test
   $ echo '012345678901234567890' > nolfs.exclude
   $ echo '01234567890123456' > lfs.catchall
-  $ hg ci -Aqm 'added .hglfs'
+  $ hg add *
+  $ hg ci -qm 'before add .hglfs'
   $ hg log -r . -T '{rev}: {lfs_files % "{file}: {lfsoid}\n"}\n'
   2: lfs.catchall: d4ec46c2869ba22eceb42a729377432052d9dd75d82fc40390ebaadecee87ee9
   lfs.test: 5489e6ced8c36a7b267292bde9fd5242a5f80a7482e8f23fa0477393dfaa4d6c
   
-The existing .hglfs file is used even when it is not in the 'A' or 'M' states
+The .hglfs file works when tracked
 
   $ echo 'largefile2' > lfs.test
   $ echo '012345678901234567890a' > nolfs.exclude
   $ echo '01234567890123456a' > lfs.catchall
-  $ hg ci -qm 'unmodified .hglfs'
+  $ hg ci -Aqm 'after adding .hglfs'
   $ hg log -r . -T '{rev}: {lfs_files % "{file}: {lfsoid}\n"}\n'
   3: lfs.catchall: 31f43b9c62b540126b0ad5884dc013d21a61c9329b77de1fceeae2fc58511573
   lfs.test: 8acd23467967bc7b8cc5a280056589b0ba0b17ff21dbd88a7b6474d6290378a6
   
-Excluding the .hglfs file from the commit postpones the policy change
+The LFS policy stops when the .hglfs is gone
 
   $ hg rm .hglfs
   $ echo 'largefile3' > lfs.test
@@ -1012,17 +1013,7 @@
   $ echo '01234567890123456abc' > lfs.catchall
   $ hg ci -qm 'file test' -X .hglfs
   $ hg log -r . -T '{rev}: {lfs_files % "{file}: {lfsoid}\n"}\n'
-  4: lfs.catchall: 6747cfb1b83965b4a884e7a6061813ae31e4122028bc6a88d2ac5e5f9e05c5af
-  lfs.test: 3f40b70c2294e91e0fa789ebcf73c5a1d1c7aef270f83e477e40cb0513237e8c
-  
-The policy change takes effect when the .hglfs is committed
-
-  $ echo 'largefile4' > lfs.test
-  $ echo '012345678901234567890abcdef' > nolfs.exclude
-  $ echo '01234567890123456abcdef' > lfs.catchall
-  $ hg ci -qm 'file test'
-  $ hg log -r . -T '{rev}: {lfs_files % "{file}: {lfsoid}\n"}\n'
-  5: 
+  4: 
 
   $ cd ..