Show More
@@ -1,112 +1,116 b'' | |||||
1 | # narrowrepo.py - repository which supports narrow revlogs, lazy loading |
|
1 | # narrowrepo.py - repository which supports narrow revlogs, lazy loading | |
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 | bundlerepo, |
|
11 | bundlerepo, | |
12 | localrepo, |
|
12 | localrepo, | |
13 | match as matchmod, |
|
13 | match as matchmod, | |
14 | scmutil, |
|
14 | scmutil, | |
15 | ) |
|
15 | ) | |
16 |
|
16 | |||
17 | from .. import ( |
|
17 | from .. import ( | |
18 | share, |
|
18 | share, | |
19 | ) |
|
19 | ) | |
20 |
|
20 | |||
21 | from . import ( |
|
21 | from . import ( | |
22 | narrowrevlog, |
|
22 | narrowrevlog, | |
23 | narrowspec, |
|
23 | narrowspec, | |
24 | ) |
|
24 | ) | |
25 |
|
25 | |||
26 | # When narrowing is finalized and no longer subject to format changes, |
|
26 | # When narrowing is finalized and no longer subject to format changes, | |
27 | # we should move this to just "narrow" or similar. |
|
27 | # we should move this to just "narrow" or similar. | |
28 | REQUIREMENT = 'narrowhg-experimental' |
|
28 | REQUIREMENT = 'narrowhg-experimental' | |
29 |
|
29 | |||
30 | def wrappostshare(orig, sourcerepo, destrepo, **kwargs): |
|
30 | def wrappostshare(orig, sourcerepo, destrepo, **kwargs): | |
31 | orig(sourcerepo, destrepo, **kwargs) |
|
31 | orig(sourcerepo, destrepo, **kwargs) | |
32 | if REQUIREMENT in sourcerepo.requirements: |
|
32 | if REQUIREMENT in sourcerepo.requirements: | |
33 | with destrepo.wlock(): |
|
33 | with destrepo.wlock(): | |
34 | with destrepo.vfs('shared', 'a') as fp: |
|
34 | with destrepo.vfs('shared', 'a') as fp: | |
35 | fp.write(narrowspec.FILENAME + '\n') |
|
35 | fp.write(narrowspec.FILENAME + '\n') | |
36 |
|
36 | |||
37 | def unsharenarrowspec(orig, ui, repo, repopath): |
|
37 | def unsharenarrowspec(orig, ui, repo, repopath): | |
38 | if (REQUIREMENT in repo.requirements |
|
38 | if (REQUIREMENT in repo.requirements | |
39 | and repo.path == repopath and repo.shared()): |
|
39 | and repo.path == repopath and repo.shared()): | |
40 | srcrepo = share._getsrcrepo(repo) |
|
40 | srcrepo = share._getsrcrepo(repo) | |
41 | with srcrepo.vfs(narrowspec.FILENAME) as f: |
|
41 | with srcrepo.vfs(narrowspec.FILENAME) as f: | |
42 | spec = f.read() |
|
42 | spec = f.read() | |
43 | with repo.vfs(narrowspec.FILENAME, 'w') as f: |
|
43 | with repo.vfs(narrowspec.FILENAME, 'w') as f: | |
44 | f.write(spec) |
|
44 | f.write(spec) | |
45 | return orig(ui, repo, repopath) |
|
45 | return orig(ui, repo, repopath) | |
46 |
|
46 | |||
47 | def wraprepo(repo, opts_narrow): |
|
47 | def wraprepo(repo, opts_narrow): | |
48 | """Enables narrow clone functionality on a single local repository.""" |
|
48 | """Enables narrow clone functionality on a single local repository.""" | |
49 |
|
49 | |||
50 | cacheprop = localrepo.storecache |
|
50 | cacheprop = localrepo.storecache | |
51 | if isinstance(repo, bundlerepo.bundlerepository): |
|
51 | if isinstance(repo, bundlerepo.bundlerepository): | |
52 | # We have to use a different caching property decorator for |
|
52 | # We have to use a different caching property decorator for | |
53 | # bundlerepo because storecache blows up in strange ways on a |
|
53 | # bundlerepo because storecache blows up in strange ways on a | |
54 | # bundlerepo. Fortunately, there's no risk of data changing in |
|
54 | # bundlerepo. Fortunately, there's no risk of data changing in | |
55 | # a bundlerepo. |
|
55 | # a bundlerepo. | |
56 | cacheprop = lambda name: localrepo.unfilteredpropertycache |
|
56 | cacheprop = lambda name: localrepo.unfilteredpropertycache | |
57 |
|
57 | |||
58 | class narrowrepository(repo.__class__): |
|
58 | class narrowrepository(repo.__class__): | |
59 |
|
59 | |||
60 | def _constructmanifest(self): |
|
60 | def _constructmanifest(self): | |
61 | manifest = super(narrowrepository, self)._constructmanifest() |
|
61 | manifest = super(narrowrepository, self)._constructmanifest() | |
62 | narrowrevlog.makenarrowmanifestrevlog(manifest, repo) |
|
62 | narrowrevlog.makenarrowmanifestrevlog(manifest, repo) | |
63 | return manifest |
|
63 | return manifest | |
64 |
|
64 | |||
65 | @cacheprop('00manifest.i') |
|
65 | @cacheprop('00manifest.i') | |
66 | def manifestlog(self): |
|
66 | def manifestlog(self): | |
67 | mfl = super(narrowrepository, self).manifestlog |
|
67 | mfl = super(narrowrepository, self).manifestlog | |
68 | narrowrevlog.makenarrowmanifestlog(mfl, self) |
|
68 | narrowrevlog.makenarrowmanifestlog(mfl, self) | |
69 | return mfl |
|
69 | return mfl | |
70 |
|
70 | |||
71 | def file(self, f): |
|
71 | def file(self, f): | |
72 | fl = super(narrowrepository, self).file(f) |
|
72 | fl = super(narrowrepository, self).file(f) | |
73 | narrowrevlog.makenarrowfilelog(fl, self.narrowmatch()) |
|
73 | narrowrevlog.makenarrowfilelog(fl, self.narrowmatch()) | |
74 | return fl |
|
74 | return fl | |
75 |
|
75 | |||
76 | @localrepo.repofilecache(narrowspec.FILENAME) |
|
76 | @localrepo.repofilecache(narrowspec.FILENAME) | |
77 | def narrowpats(self): |
|
77 | def narrowpats(self): | |
|
78 | """matcher patterns for this repository's narrowspec | |||
|
79 | ||||
|
80 | A tuple of (includes, excludes). | |||
|
81 | """ | |||
78 | return narrowspec.load(self) |
|
82 | return narrowspec.load(self) | |
79 |
|
83 | |||
80 | @localrepo.repofilecache(narrowspec.FILENAME) |
|
84 | @localrepo.repofilecache(narrowspec.FILENAME) | |
81 | def _narrowmatch(self): |
|
85 | def _narrowmatch(self): | |
82 | include, exclude = self.narrowpats |
|
86 | include, exclude = self.narrowpats | |
83 | if not opts_narrow and not include and not exclude: |
|
87 | if not opts_narrow and not include and not exclude: | |
84 | return matchmod.always(self.root, '') |
|
88 | return matchmod.always(self.root, '') | |
85 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
89 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
86 |
|
90 | |||
87 | # TODO(martinvonz): make this property-like instead? |
|
91 | # TODO(martinvonz): make this property-like instead? | |
88 | def narrowmatch(self): |
|
92 | def narrowmatch(self): | |
89 | return self._narrowmatch |
|
93 | return self._narrowmatch | |
90 |
|
94 | |||
91 | def setnarrowpats(self, newincludes, newexcludes): |
|
95 | def setnarrowpats(self, newincludes, newexcludes): | |
92 | narrowspec.save(self, newincludes, newexcludes) |
|
96 | narrowspec.save(self, newincludes, newexcludes) | |
93 | self.invalidate(clearfilecache=True) |
|
97 | self.invalidate(clearfilecache=True) | |
94 |
|
98 | |||
95 | # I'm not sure this is the right place to do this filter. |
|
99 | # I'm not sure this is the right place to do this filter. | |
96 | # context._manifestmatches() would probably be better, or perhaps |
|
100 | # context._manifestmatches() would probably be better, or perhaps | |
97 | # move it to a later place, in case some of the callers do want to know |
|
101 | # move it to a later place, in case some of the callers do want to know | |
98 | # which directories changed. This seems to work for now, though. |
|
102 | # which directories changed. This seems to work for now, though. | |
99 | def status(self, *args, **kwargs): |
|
103 | def status(self, *args, **kwargs): | |
100 | s = super(narrowrepository, self).status(*args, **kwargs) |
|
104 | s = super(narrowrepository, self).status(*args, **kwargs) | |
101 | narrowmatch = self.narrowmatch() |
|
105 | narrowmatch = self.narrowmatch() | |
102 | modified = filter(narrowmatch, s.modified) |
|
106 | modified = filter(narrowmatch, s.modified) | |
103 | added = filter(narrowmatch, s.added) |
|
107 | added = filter(narrowmatch, s.added) | |
104 | removed = filter(narrowmatch, s.removed) |
|
108 | removed = filter(narrowmatch, s.removed) | |
105 | deleted = filter(narrowmatch, s.deleted) |
|
109 | deleted = filter(narrowmatch, s.deleted) | |
106 | unknown = filter(narrowmatch, s.unknown) |
|
110 | unknown = filter(narrowmatch, s.unknown) | |
107 | ignored = filter(narrowmatch, s.ignored) |
|
111 | ignored = filter(narrowmatch, s.ignored) | |
108 | clean = filter(narrowmatch, s.clean) |
|
112 | clean = filter(narrowmatch, s.clean) | |
109 | return scmutil.status(modified, added, removed, deleted, unknown, |
|
113 | return scmutil.status(modified, added, removed, deleted, unknown, | |
110 | ignored, clean) |
|
114 | ignored, clean) | |
111 |
|
115 | |||
112 | repo.__class__ = narrowrepository |
|
116 | repo.__class__ = narrowrepository |
General Comments 0
You need to be logged in to leave comments.
Login now