comparison hgext/lfs/__init__.py @ 35618:c780e0649e41

lfs: migrate most file filtering from threshold to custom filter Migrate `lfs.threshold` to more powerful `lfs.filter` added by D4990618 so people can specify what files to be stored in LFS with more flexibility. This patch was authored by Jun Wu for the fb-experimental repo, to avoid using matcher for efficiency[1]. All I've changed here is to register the new 'lfs.track' default so that the tests run cleanly, and adapt the subsequent language changes. Migrating the remaining uses of 'lfs.threshold' can be done separately since there's a fallback in place. [1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-December/109388.html
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 31 Dec 2017 02:54:49 -0500
parents 6d6d20658cce
children 8580e5898cb7
comparison
equal deleted inserted replaced
35617:b75ea116603d 35618:c780e0649e41
17 # local filesystem, usually for testing 17 # local filesystem, usually for testing
18 # if unset, lfs will prompt setting this when it must use this value. 18 # if unset, lfs will prompt setting this when it must use this value.
19 # (default: unset) 19 # (default: unset)
20 url = https://example.com/lfs 20 url = https://example.com/lfs
21 21
22 # size of a file to make it use LFS 22 # Which files to track in LFS. Path tests are "**.extname" for file
23 threshold = 10M 23 # extensions, and "path:under/some/directory" for path prefix. Both
24 # are relative to the repository root, and the latter must be quoted.
25 # File size can be tested with the "size()" fileset, and tests can be
26 # joined with fileset operators. (See "hg help filesets.operators".)
27 #
28 # Some examples:
29 # - all() # everything
30 # - none() # nothing
31 # - size(">20MB") # larger than 20MB
32 # - !**.txt # anything not a *.txt file
33 # - **.zip | **.tar.gz | **.7z # some types of compressed files
34 # - "path:bin" # files under "bin" in the project root
35 # - (**.php & size(">2MB")) | (**.js & size(">5MB")) | **.tar.gz
36 # | ("path:bin" & !"path:/bin/README") | size(">1GB")
37 # (default: none())
38 track = size(">10M")
24 39
25 # how many times to retry before giving up on transferring an object 40 # how many times to retry before giving up on transferring an object
26 retry = 5 41 retry = 5
27 42
28 # the local directory to store lfs files for sharing across local clones. 43 # the local directory to store lfs files for sharing across local clones.
39 changegroup, 54 changegroup,
40 context, 55 context,
41 exchange, 56 exchange,
42 extensions, 57 extensions,
43 filelog, 58 filelog,
59 fileset,
44 hg, 60 hg,
45 localrepo, 61 localrepo,
62 minifileset,
46 node, 63 node,
47 registrar, 64 registrar,
48 revlog, 65 revlog,
49 scmutil, 66 scmutil,
50 upgrade, 67 upgrade,
74 default=None, 91 default=None,
75 ) 92 )
76 configitem('lfs', 'usercache', 93 configitem('lfs', 'usercache',
77 default=None, 94 default=None,
78 ) 95 )
96 # Deprecated
79 configitem('lfs', 'threshold', 97 configitem('lfs', 'threshold',
80 default=None, 98 default=None,
99 )
100 configitem('lfs', 'track',
101 default='none()',
81 ) 102 )
82 configitem('lfs', 'retry', 103 configitem('lfs', 'retry',
83 default=5, 104 default=5,
84 ) 105 )
85 106
98 def reposetup(ui, repo): 119 def reposetup(ui, repo):
99 # Nothing to do with a remote repo 120 # Nothing to do with a remote repo
100 if not repo.local(): 121 if not repo.local():
101 return 122 return
102 123
124 trackspec = repo.ui.config('lfs', 'track')
125
126 # deprecated config: lfs.threshold
103 threshold = repo.ui.configbytes('lfs', 'threshold') 127 threshold = repo.ui.configbytes('lfs', 'threshold')
104 128 if threshold:
105 repo.svfs.options['lfsthreshold'] = threshold 129 fileset.parse(trackspec) # make sure syntax errors are confined
130 trackspec = "(%s) | size('>%d')" % (trackspec, threshold)
131
132 repo.svfs.options['lfstrack'] = minifileset.compile(trackspec)
106 repo.svfs.lfslocalblobstore = blobstore.local(repo) 133 repo.svfs.lfslocalblobstore = blobstore.local(repo)
107 repo.svfs.lfsremoteblobstore = blobstore.remote(repo) 134 repo.svfs.lfsremoteblobstore = blobstore.remote(repo)
108 135
109 # Push hook 136 # Push hook
110 repo.prepushoutgoinghooks.add('lfs', wrapper.prepush) 137 repo.prepushoutgoinghooks.add('lfs', wrapper.prepush)