Mercurial > hg
annotate mercurial/pushkey.py @ 35616:706aa203b396
fileset: add a lightweight file filtering language
This patch was inspired by one that Jun Wu authored for the fb-experimental
repo, to avoid using matcher for efficiency[1]. We want a way to specify what
files will be converted to LFS at commit time. And per discussion, we also want
to specify what files to skip, text diff, or merge in another config option.
The current `lfs.threshold` config option could not satisfy complex needs. I'm
putting it in a core package because Augie floated the idea of also using it for
narrow and sparse.
Yuya suggested farming out to fileset.parse(), which added support for more
symbols. The only fileset element not supported here is 'negate'. (List isn't
supported by filesets either.) I also changed the 'always' token to the 'all()'
predicate for consistency, and introduced 'none()' to improve readability in a
future tracked file based config. The extension operator was changed from '.'
to '**', to match how recursive path globs are specified. Finally, I changed
the path matcher from '/' to 'path:' at Yuya's suggestion, for consistency with
matcher. Unfortunately, ':' is currently reserved in filesets, so this has to
be quoted to be processed as a string instead of a symbol[2]. We should
probably revisit that, because it's seriously ugly. But it's only used by an
experimental extension, and I think using a file based config for LFS may drive
some more tweaks, so I'm settling for this for now.
I reserved all of the glob characters in fileset except '.' and '_' for the
extension test because those are likely valid extension characters.
Sample filter settings:
all() # everything
size(">20MB") # larger than 20MB
!**.txt # except for .txt files
**.zip | **.tar.gz | **.7z # some types of compressed files
"path:bin" # files under "bin" in the project root
[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-December/109387.html
[2] https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-January/109729.html
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 10 Jan 2018 22:23:34 -0500 |
parents | 7b200566e474 |
children | 57875cf423c9 |
rev | line source |
---|---|
11367 | 1 # pushkey.py - dispatching for pushing and pulling keys |
2 # | |
3 # Copyright 2010 Matt Mackall <mpm@selenic.com> | |
4 # | |
5 # This software may be used and distributed according to the terms of the | |
6 # GNU General Public License version 2 or any later version. | |
7 | |
25969
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
8 from __future__ import absolute_import |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
9 |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
10 from . import ( |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
11 bookmarks, |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
12 encoding, |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
13 obsolete, |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
14 phases, |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
15 ) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
11367
diff
changeset
|
16 |
11367 | 17 def _nslist(repo): |
18 n = {} | |
19 for k in _namespaces: | |
20 n[k] = "" | |
22953
b1d694d3975e
obsolete: add exchange option
Durham Goode <durham@fb.com>
parents:
21661
diff
changeset
|
21 if not obsolete.isenabled(repo, obsolete.exchangeopt): |
17298
59c14bf5a48c
pushkey: do not exchange obsole markers if feature is disabled
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17075
diff
changeset
|
22 n.pop('obsolete') |
11367 | 23 return n |
24 | |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
11367
diff
changeset
|
25 _namespaces = {"namespaces": (lambda *x: False, _nslist), |
15648
79cc89de5be1
phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
13353
diff
changeset
|
26 "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks), |
79cc89de5be1
phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
13353
diff
changeset
|
27 "phases": (phases.pushphase, phases.listphases), |
17075
28ed1c4511ce
obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents:
15648
diff
changeset
|
28 "obsolete": (obsolete.pushmarker, obsolete.listmarkers), |
15648
79cc89de5be1
phases: add basic pushkey support
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
13353
diff
changeset
|
29 } |
11367 | 30 |
31 def register(namespace, pushkey, listkeys): | |
32 _namespaces[namespace] = (pushkey, listkeys) | |
33 | |
34 def _get(namespace): | |
35 return _namespaces.get(namespace, (lambda *x: False, lambda *x: {})) | |
36 | |
37 def push(repo, namespace, key, old, new): | |
38 '''should succeed iff value was old''' | |
39 pk = _get(namespace)[0] | |
40 return pk(repo, key, old, new) | |
41 | |
42 def list(repo, namespace): | |
43 '''return a dict''' | |
44 lk = _get(namespace)[1] | |
45 return lk(repo) | |
46 | |
21661
2f52a16f2bee
pushkey: add an ``encode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21659
diff
changeset
|
47 encode = encoding.fromlocal |
2f52a16f2bee
pushkey: add an ``encode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21659
diff
changeset
|
48 |
21659
a319842539f5
pushkey: add a ``decode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21652
diff
changeset
|
49 decode = encoding.tolocal |
a319842539f5
pushkey: add a ``decode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21652
diff
changeset
|
50 |
21650
a2c7ae21e8f4
pushkey: introduce an ``encodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
17298
diff
changeset
|
51 def encodekeys(keys): |
a2c7ae21e8f4
pushkey: introduce an ``encodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
17298
diff
changeset
|
52 """encode the content of a pushkey namespace for exchange over the wire""" |
21661
2f52a16f2bee
pushkey: add an ``encode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21659
diff
changeset
|
53 return '\n'.join(['%s\t%s' % (encode(k), encode(v)) for k, v in keys]) |
21652
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
54 |
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
55 def decodekeys(data): |
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
56 """decode the content of a pushkey namespace from exchange over the wire""" |
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
57 result = {} |
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
58 for l in data.splitlines(): |
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
59 k, v = l.split('\t') |
21659
a319842539f5
pushkey: add a ``decode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21652
diff
changeset
|
60 result[decode(k)] = decode(v) |
21652
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
61 return result |