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