Show More
@@ -1,93 +1,95 b'' | |||||
1 | # __init__.py - narrowhg extension |
|
1 | # __init__.py - narrowhg extension | |
2 | # |
|
2 | # | |
3 | # Copyright 2017 Google, Inc. |
|
3 | # Copyright 2017 Google, Inc. | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
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. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 | '''create clones which fetch history data for subset of files (EXPERIMENTAL)''' |
|
7 | '''create clones which fetch history data for subset of files (EXPERIMENTAL)''' | |
8 |
|
8 | |||
9 | from __future__ import absolute_import |
|
9 | from __future__ import absolute_import | |
10 |
|
10 | |||
11 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
|
11 | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | |
12 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
|
12 | # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | |
13 | # be specifying the version(s) of Mercurial they are tested with, or |
|
13 | # be specifying the version(s) of Mercurial they are tested with, or | |
14 | # leave the attribute unspecified. |
|
14 | # leave the attribute unspecified. | |
15 | testedwith = 'ships-with-hg-core' |
|
15 | testedwith = 'ships-with-hg-core' | |
16 |
|
16 | |||
17 | from mercurial import ( |
|
17 | from mercurial import ( | |
18 | extensions, |
|
18 | extensions, | |
19 | hg, |
|
19 | hg, | |
20 | localrepo, |
|
20 | localrepo, | |
21 | registrar, |
|
21 | registrar, | |
22 | verify as verifymod, |
|
22 | verify as verifymod, | |
23 | ) |
|
23 | ) | |
24 |
|
24 | |||
25 | from . import ( |
|
25 | from . import ( | |
26 | narrowbundle2, |
|
26 | narrowbundle2, | |
27 | narrowchangegroup, |
|
27 | narrowchangegroup, | |
28 | narrowcommands, |
|
28 | narrowcommands, | |
29 | narrowcopies, |
|
29 | narrowcopies, | |
30 | narrowdirstate, |
|
30 | narrowdirstate, | |
31 | narrowmerge, |
|
31 | narrowmerge, | |
32 | narrowpatch, |
|
32 | narrowpatch, | |
33 | narrowrepo, |
|
33 | narrowrepo, | |
34 | narrowrevlog, |
|
34 | narrowrevlog, | |
35 | narrowtemplates, |
|
35 | narrowtemplates, | |
36 | narrowwirepeer, |
|
36 | narrowwirepeer, | |
37 | ) |
|
37 | ) | |
38 |
|
38 | |||
39 | configtable = {} |
|
39 | configtable = {} | |
40 | configitem = registrar.configitem(configtable) |
|
40 | configitem = registrar.configitem(configtable) | |
41 | # Narrowhg *has* support for serving ellipsis nodes (which are used at |
|
41 | # Narrowhg *has* support for serving ellipsis nodes (which are used at | |
42 | # least by Google's internal server), but that support is pretty |
|
42 | # least by Google's internal server), but that support is pretty | |
43 | # fragile and has a lot of problems on real-world repositories that |
|
43 | # fragile and has a lot of problems on real-world repositories that | |
44 | # have complex graph topologies. This could probably be corrected, but |
|
44 | # have complex graph topologies. This could probably be corrected, but | |
45 | # absent someone needing the full support for ellipsis nodes in |
|
45 | # absent someone needing the full support for ellipsis nodes in | |
46 | # repositories with merges, it's unlikely this work will get done. As |
|
46 | # repositories with merges, it's unlikely this work will get done. As | |
47 | # of this writining in late 2017, all repositories large enough for |
|
47 | # of this writining in late 2017, all repositories large enough for | |
48 | # ellipsis nodes to be a hard requirement also enforce strictly linear |
|
48 | # ellipsis nodes to be a hard requirement also enforce strictly linear | |
49 | # history for other scaling reasons. |
|
49 | # history for other scaling reasons. | |
50 | configitem('experimental', 'narrowservebrokenellipses', |
|
50 | configitem('experimental', 'narrowservebrokenellipses', | |
51 | default=False, |
|
51 | default=False, | |
52 | alias=[('narrow', 'serveellipses')], |
|
52 | alias=[('narrow', 'serveellipses')], | |
53 | ) |
|
53 | ) | |
54 |
|
54 | |||
55 | # Export the commands table for Mercurial to see. |
|
55 | # Export the commands table for Mercurial to see. | |
56 | cmdtable = narrowcommands.table |
|
56 | cmdtable = narrowcommands.table | |
57 |
|
57 | |||
58 | localrepo.localrepository._basesupported.add(narrowrepo.REQUIREMENT) |
|
58 | localrepo.localrepository._basesupported.add(narrowrepo.REQUIREMENT) | |
59 |
|
59 | |||
60 | def uisetup(ui): |
|
60 | def uisetup(ui): | |
61 | """Wraps user-facing mercurial commands with narrow-aware versions.""" |
|
61 | """Wraps user-facing mercurial commands with narrow-aware versions.""" | |
62 | narrowrevlog.setup() |
|
62 | narrowrevlog.setup() | |
63 | narrowbundle2.setup() |
|
63 | narrowbundle2.setup() | |
64 | narrowmerge.setup() |
|
64 | narrowmerge.setup() | |
65 | narrowtemplates.setup() |
|
|||
66 | narrowcommands.setup() |
|
65 | narrowcommands.setup() | |
67 | narrowchangegroup.setup() |
|
66 | narrowchangegroup.setup() | |
68 | narrowwirepeer.uisetup() |
|
67 | narrowwirepeer.uisetup() | |
69 |
|
68 | |||
70 | def reposetup(ui, repo): |
|
69 | def reposetup(ui, repo): | |
71 | """Wraps local repositories with narrow repo support.""" |
|
70 | """Wraps local repositories with narrow repo support.""" | |
72 | if not isinstance(repo, localrepo.localrepository): |
|
71 | if not isinstance(repo, localrepo.localrepository): | |
73 | return |
|
72 | return | |
74 |
|
73 | |||
75 | if narrowrepo.REQUIREMENT in repo.requirements: |
|
74 | if narrowrepo.REQUIREMENT in repo.requirements: | |
76 | narrowrepo.wraprepo(repo, True) |
|
75 | narrowrepo.wraprepo(repo, True) | |
77 | narrowcopies.setup(repo) |
|
76 | narrowcopies.setup(repo) | |
78 | narrowdirstate.setup(repo) |
|
77 | narrowdirstate.setup(repo) | |
79 | narrowpatch.setup(repo) |
|
78 | narrowpatch.setup(repo) | |
80 | narrowwirepeer.reposetup(repo) |
|
79 | narrowwirepeer.reposetup(repo) | |
81 |
|
80 | |||
82 | def _verifierinit(orig, self, repo, matcher=None): |
|
81 | def _verifierinit(orig, self, repo, matcher=None): | |
83 | # The verifier's matcher argument was desgined for narrowhg, so it should |
|
82 | # The verifier's matcher argument was desgined for narrowhg, so it should | |
84 | # be None from core. If another extension passes a matcher (unlikely), |
|
83 | # be None from core. If another extension passes a matcher (unlikely), | |
85 | # we'll have to fail until matchers can be composed more easily. |
|
84 | # we'll have to fail until matchers can be composed more easily. | |
86 | assert matcher is None |
|
85 | assert matcher is None | |
87 | matcher = getattr(repo, 'narrowmatch', lambda: None)() |
|
86 | matcher = getattr(repo, 'narrowmatch', lambda: None)() | |
88 | orig(self, repo, matcher) |
|
87 | orig(self, repo, matcher) | |
89 |
|
88 | |||
90 | def extsetup(ui): |
|
89 | def extsetup(ui): | |
91 | extensions.wrapfunction(verifymod.verifier, '__init__', _verifierinit) |
|
90 | extensions.wrapfunction(verifymod.verifier, '__init__', _verifierinit) | |
92 | extensions.wrapfunction(hg, 'postshare', narrowrepo.wrappostshare) |
|
91 | extensions.wrapfunction(hg, 'postshare', narrowrepo.wrappostshare) | |
93 | extensions.wrapfunction(hg, 'copystore', narrowrepo.unsharenarrowspec) |
|
92 | extensions.wrapfunction(hg, 'copystore', narrowrepo.unsharenarrowspec) | |
|
93 | ||||
|
94 | templatekeyword = narrowtemplates.templatekeyword | |||
|
95 | revsetpredicate = narrowtemplates.revsetpredicate |
@@ -1,49 +1,48 b'' | |||||
1 | # narrowtemplates.py - added template keywords for narrow clones |
|
1 | # narrowtemplates.py - added template keywords for narrow clones | |
2 | # |
|
2 | # | |
3 | # Copyright 2017 Google, Inc. |
|
3 | # Copyright 2017 Google, Inc. | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
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. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | from mercurial import ( |
|
10 | from mercurial import ( | |
|
11 | registrar, | |||
11 | revlog, |
|
12 | revlog, | |
12 | revset, |
|
|||
13 | templatekw, |
|
|||
14 | util, |
|
13 | util, | |
15 | ) |
|
14 | ) | |
16 |
|
15 | |||
|
16 | keywords = {} | |||
|
17 | templatekeyword = registrar.templatekeyword(keywords) | |||
|
18 | revsetpredicate = registrar.revsetpredicate() | |||
|
19 | ||||
17 | def _isellipsis(repo, rev): |
|
20 | def _isellipsis(repo, rev): | |
18 | if repo.changelog.flags(rev) & revlog.REVIDX_ELLIPSIS: |
|
21 | if repo.changelog.flags(rev) & revlog.REVIDX_ELLIPSIS: | |
19 | return True |
|
22 | return True | |
20 | return False |
|
23 | return False | |
21 |
|
24 | |||
|
25 | @templatekeyword('ellipsis') | |||
22 | def ellipsis(repo, ctx, templ, **args): |
|
26 | def ellipsis(repo, ctx, templ, **args): | |
23 | """:ellipsis: String. 'ellipsis' if the change is an ellipsis node, |
|
27 | """:ellipsis: String. 'ellipsis' if the change is an ellipsis node, | |
24 | else ''.""" |
|
28 | else ''.""" | |
25 | if _isellipsis(repo, ctx.rev()): |
|
29 | if _isellipsis(repo, ctx.rev()): | |
26 | return 'ellipsis' |
|
30 | return 'ellipsis' | |
27 | return '' |
|
31 | return '' | |
28 |
|
32 | |||
|
33 | @templatekeyword('outsidenarrow') | |||
29 | def outsidenarrow(repo, ctx, templ, **args): |
|
34 | def outsidenarrow(repo, ctx, templ, **args): | |
30 | """:outsidenarrow: String. 'outsidenarrow' if the change affects no |
|
35 | """:outsidenarrow: String. 'outsidenarrow' if the change affects no | |
31 | tracked files, else ''.""" |
|
36 | tracked files, else ''.""" | |
32 | if util.safehasattr(repo, 'narrowmatch'): |
|
37 | if util.safehasattr(repo, 'narrowmatch'): | |
33 | m = repo.narrowmatch() |
|
38 | m = repo.narrowmatch() | |
34 | if not any(m(f) for f in ctx.files()): |
|
39 | if not any(m(f) for f in ctx.files()): | |
35 | return 'outsidenarrow' |
|
40 | return 'outsidenarrow' | |
36 | return '' |
|
41 | return '' | |
37 |
|
42 | |||
|
43 | @revsetpredicate('ellipsis') | |||
38 | def ellipsisrevset(repo, subset, x): |
|
44 | def ellipsisrevset(repo, subset, x): | |
39 | """``ellipsis()`` |
|
45 | """``ellipsis()`` | |
40 | Changesets that are ellipsis nodes. |
|
46 | Changesets that are ellipsis nodes. | |
41 | """ |
|
47 | """ | |
42 | return subset.filter(lambda r: _isellipsis(repo, r)) |
|
48 | return subset.filter(lambda r: _isellipsis(repo, r)) | |
43 |
|
||||
44 | def setup(): |
|
|||
45 | templatekw.keywords['ellipsis'] = ellipsis |
|
|||
46 | templatekw.keywords['outsidenarrow'] = outsidenarrow |
|
|||
47 |
|
||||
48 | revset.symbols['ellipsis'] = ellipsisrevset |
|
|||
49 | revset.safesymbols.add('ellipsis') |
|
General Comments 0
You need to be logged in to leave comments.
Login now