Mercurial > hg
comparison hgext/narrow/__init__.py @ 36079:a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Adjustments:
* renamed src to hgext/narrow
* marked extension experimental
* added correct copyright header where it was missing
* updated hgrc extension enable line in library.sh
* renamed library.sh to narrow-library.sh
* dropped all files from repo root as they're not interesting
* dropped test-pyflakes.t, test-check-code.t and test-check-py3-compat.t
* renamed remaining tests to all be test-narrow-* when they didn't already
* fixed test-narrow-expanddirstate.t to refer to narrow and not narrowhg
* fixed tests that wanted `update -C .` instead of `merge --abort`
* corrected a two-space indent in narrowspec.py
* added a missing _() in narrowcommands.py
* fixed imports to pass the import checker
* narrow only adds its --include and --exclude to clone if sparse isn't
enabled to avoid breaking test-duplicateoptions.py. This is a kludge,
and we'll need to come up with a better solution in the future.
These were more or less the minimum to import something that would
pass tests and not create a bunch of files we'll never use.
Changes I intend to make as followups:
* rework the test-narrow-*-tree.t tests to use the new testcases
functionality in run-tests.py
* remove lots of monkeypatches of core things
Differential Revision: https://phab.mercurial-scm.org/D1974
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 29 Jan 2018 16:19:33 -0500 |
parents | |
children | 9dc28d8ea61e |
comparison
equal
deleted
inserted
replaced
36078:7f68235f23ff | 36079:a2a6e724d61a |
---|---|
1 # __init__.py - narrowhg extension | |
2 # | |
3 # Copyright 2017 Google, Inc. | |
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 '''create clones which fetch history data for subset of files (EXPERIMENTAL)''' | |
8 | |
9 from __future__ import absolute_import | |
10 | |
11 from mercurial import __version__ | |
12 if __version__.version < '3.7': | |
13 raise ImportError( | |
14 'narrowhg requires mercurial 3.7 or newer') | |
15 | |
16 try: | |
17 from .__versionnum__ import version | |
18 __version__ = version | |
19 except ImportError: | |
20 pass | |
21 | |
22 from mercurial import ( | |
23 extensions, | |
24 hg, | |
25 localrepo, | |
26 registrar, | |
27 util, | |
28 verify as verifymod, | |
29 ) | |
30 | |
31 from . import ( | |
32 narrowbundle2, | |
33 narrowchangegroup, | |
34 narrowcommands, | |
35 narrowcopies, | |
36 narrowdirstate, | |
37 narrowmerge, | |
38 narrowpatch, | |
39 narrowrepo, | |
40 narrowrevlog, | |
41 narrowtemplates, | |
42 narrowwirepeer, | |
43 ) | |
44 | |
45 configtable = {} | |
46 configitem = registrar.configitem(configtable) | |
47 # Narrowhg *has* support for serving ellipsis nodes (which are used at | |
48 # least by Google's internal server), but that support is pretty | |
49 # fragile and has a lot of problems on real-world repositories that | |
50 # have complex graph topologies. This could probably be corrected, but | |
51 # absent someone needing the full support for ellipsis nodes in | |
52 # repositories with merges, it's unlikely this work will get done. As | |
53 # of this writining in late 2017, all repositories large enough for | |
54 # ellipsis nodes to be a hard requirement also enforce strictly linear | |
55 # history for other scaling reasons. | |
56 configitem('experimental', 'narrowservebrokenellipses', | |
57 default=False, | |
58 alias=[('narrow', 'serveellipses')], | |
59 ) | |
60 | |
61 # Export the commands table for Mercurial to see. | |
62 cmdtable = narrowcommands.table | |
63 | |
64 localrepo.localrepository._basesupported.add(narrowrepo.requirement) | |
65 | |
66 def uisetup(ui): | |
67 """Wraps user-facing mercurial commands with narrow-aware versions.""" | |
68 narrowrevlog.setup() | |
69 narrowbundle2.setup() | |
70 narrowmerge.setup() | |
71 narrowtemplates.setup() | |
72 narrowcommands.setup() | |
73 narrowchangegroup.setup() | |
74 narrowwirepeer.uisetup() | |
75 | |
76 def reposetup(ui, repo): | |
77 """Wraps local repositories with narrow repo support.""" | |
78 if not isinstance(repo, localrepo.localrepository): | |
79 return | |
80 | |
81 if narrowrepo.requirement in repo.requirements: | |
82 narrowrepo.wraprepo(repo, True) | |
83 narrowcopies.setup(repo) | |
84 narrowdirstate.setup(repo) | |
85 narrowpatch.setup(repo) | |
86 narrowwirepeer.reposetup(repo) | |
87 | |
88 def _narrowvalidpath(orig, repo, path): | |
89 matcher = getattr(repo, 'narrowmatch', None) | |
90 if matcher is None: | |
91 return orig(repo, path) | |
92 matcher = matcher() | |
93 if matcher.visitdir(path) or matcher(path): | |
94 return orig(repo, path) | |
95 return False | |
96 | |
97 def _verifierinit(orig, self, repo, matcher=None): | |
98 # The verifier's matcher argument was desgined for narrowhg, so it should | |
99 # be None from core. If another extension passes a matcher (unlikely), | |
100 # we'll have to fail until matchers can be composed more easily. | |
101 assert matcher is None | |
102 matcher = getattr(repo, 'narrowmatch', lambda: None)() | |
103 orig(self, repo, matcher) | |
104 | |
105 def extsetup(ui): | |
106 if util.safehasattr(verifymod, '_validpath'): | |
107 extensions.wrapfunction(verifymod, '_validpath', _narrowvalidpath) | |
108 else: | |
109 extensions.wrapfunction(verifymod.verifier, '__init__', _verifierinit) | |
110 extensions.wrapfunction(hg, 'postshare', narrowrepo.wrappostshare) | |
111 extensions.wrapfunction(hg, 'copystore', narrowrepo.unsharenarrowspec) |