Mercurial > hg
comparison hgext/remotefilelog/shallowbundle.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 1d9031b6cb7e |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
24 | 24 |
25 NoFiles = 0 | 25 NoFiles = 0 |
26 LocalFiles = 1 | 26 LocalFiles = 1 |
27 AllFiles = 2 | 27 AllFiles = 2 |
28 | 28 |
29 | |
29 def shallowgroup(cls, self, nodelist, rlog, lookup, units=None, reorder=None): | 30 def shallowgroup(cls, self, nodelist, rlog, lookup, units=None, reorder=None): |
30 if not isinstance(rlog, remotefilelog.remotefilelog): | 31 if not isinstance(rlog, remotefilelog.remotefilelog): |
31 for c in super(cls, self).group(nodelist, rlog, lookup, | 32 for c in super(cls, self).group(nodelist, rlog, lookup, units=units): |
32 units=units): | |
33 yield c | 33 yield c |
34 return | 34 return |
35 | 35 |
36 if len(nodelist) == 0: | 36 if len(nodelist) == 0: |
37 yield self.close() | 37 yield self.close() |
50 for c in self.nodechunk(rlog, curr, prev, linknode): | 50 for c in self.nodechunk(rlog, curr, prev, linknode): |
51 yield c | 51 yield c |
52 | 52 |
53 yield self.close() | 53 yield self.close() |
54 | 54 |
55 | |
55 class shallowcg1packer(changegroup.cgpacker): | 56 class shallowcg1packer(changegroup.cgpacker): |
56 def generate(self, commonrevs, clnodes, fastpathlinkrev, source): | 57 def generate(self, commonrevs, clnodes, fastpathlinkrev, source): |
57 if shallowutil.isenabled(self._repo): | 58 if shallowutil.isenabled(self._repo): |
58 fastpathlinkrev = False | 59 fastpathlinkrev = False |
59 | 60 |
60 return super(shallowcg1packer, self).generate(commonrevs, clnodes, | 61 return super(shallowcg1packer, self).generate( |
61 fastpathlinkrev, source) | 62 commonrevs, clnodes, fastpathlinkrev, source |
63 ) | |
62 | 64 |
63 def group(self, nodelist, rlog, lookup, units=None, reorder=None): | 65 def group(self, nodelist, rlog, lookup, units=None, reorder=None): |
64 return shallowgroup(shallowcg1packer, self, nodelist, rlog, lookup, | 66 return shallowgroup( |
65 units=units) | 67 shallowcg1packer, self, nodelist, rlog, lookup, units=units |
68 ) | |
66 | 69 |
67 def generatefiles(self, changedfiles, *args): | 70 def generatefiles(self, changedfiles, *args): |
68 try: | 71 try: |
69 linknodes, commonrevs, source = args | 72 linknodes, commonrevs, source = args |
70 except ValueError: | 73 except ValueError: |
76 # bundlerepo is heavily tied to revlogs. Instead require that | 79 # bundlerepo is heavily tied to revlogs. Instead require that |
77 # the user use unbundle instead. | 80 # the user use unbundle instead. |
78 # Force load the filelog data. | 81 # Force load the filelog data. |
79 bundlerepo.bundlerepository.file(repo, 'foo') | 82 bundlerepo.bundlerepository.file(repo, 'foo') |
80 if repo._cgfilespos: | 83 if repo._cgfilespos: |
81 raise error.Abort("cannot pull from full bundles", | 84 raise error.Abort( |
82 hint="use `hg unbundle` instead") | 85 "cannot pull from full bundles", |
86 hint="use `hg unbundle` instead", | |
87 ) | |
83 return [] | 88 return [] |
84 filestosend = self.shouldaddfilegroups(source) | 89 filestosend = self.shouldaddfilegroups(source) |
85 if filestosend == NoFiles: | 90 if filestosend == NoFiles: |
86 changedfiles = list([f for f in changedfiles | 91 changedfiles = list( |
87 if not repo.shallowmatch(f)]) | 92 [f for f in changedfiles if not repo.shallowmatch(f)] |
88 | 93 ) |
89 return super(shallowcg1packer, self).generatefiles( | 94 |
90 changedfiles, *args) | 95 return super(shallowcg1packer, self).generatefiles(changedfiles, *args) |
91 | 96 |
92 def shouldaddfilegroups(self, source): | 97 def shouldaddfilegroups(self, source): |
93 repo = self._repo | 98 repo = self._repo |
94 if not shallowutil.isenabled(repo): | 99 if not shallowutil.isenabled(repo): |
95 return AllFiles | 100 return AllFiles |
108 | 113 |
109 return NoFiles | 114 return NoFiles |
110 | 115 |
111 def prune(self, rlog, missing, commonrevs): | 116 def prune(self, rlog, missing, commonrevs): |
112 if not isinstance(rlog, remotefilelog.remotefilelog): | 117 if not isinstance(rlog, remotefilelog.remotefilelog): |
113 return super(shallowcg1packer, self).prune(rlog, missing, | 118 return super(shallowcg1packer, self).prune( |
114 commonrevs) | 119 rlog, missing, commonrevs |
120 ) | |
115 | 121 |
116 repo = self._repo | 122 repo = self._repo |
117 results = [] | 123 results = [] |
118 for fnode in missing: | 124 for fnode in missing: |
119 fctx = repo.filectx(rlog.filename, fileid=fnode) | 125 fctx = repo.filectx(rlog.filename, fileid=fnode) |
136 l = len(meta) + len(delta) | 142 l = len(meta) + len(delta) |
137 yield changegroup.chunkheader(l) | 143 yield changegroup.chunkheader(l) |
138 yield meta | 144 yield meta |
139 yield delta | 145 yield delta |
140 | 146 |
147 | |
141 def makechangegroup(orig, repo, outgoing, version, source, *args, **kwargs): | 148 def makechangegroup(orig, repo, outgoing, version, source, *args, **kwargs): |
142 if not shallowutil.isenabled(repo): | 149 if not shallowutil.isenabled(repo): |
143 return orig(repo, outgoing, version, source, *args, **kwargs) | 150 return orig(repo, outgoing, version, source, *args, **kwargs) |
144 | 151 |
145 original = repo.shallowmatch | 152 original = repo.shallowmatch |
147 # if serving, only send files the clients has patterns for | 154 # if serving, only send files the clients has patterns for |
148 if source == 'serve': | 155 if source == 'serve': |
149 bundlecaps = kwargs.get(r'bundlecaps') | 156 bundlecaps = kwargs.get(r'bundlecaps') |
150 includepattern = None | 157 includepattern = None |
151 excludepattern = None | 158 excludepattern = None |
152 for cap in (bundlecaps or []): | 159 for cap in bundlecaps or []: |
153 if cap.startswith("includepattern="): | 160 if cap.startswith("includepattern="): |
154 raw = cap[len("includepattern="):] | 161 raw = cap[len("includepattern=") :] |
155 if raw: | 162 if raw: |
156 includepattern = raw.split('\0') | 163 includepattern = raw.split('\0') |
157 elif cap.startswith("excludepattern="): | 164 elif cap.startswith("excludepattern="): |
158 raw = cap[len("excludepattern="):] | 165 raw = cap[len("excludepattern=") :] |
159 if raw: | 166 if raw: |
160 excludepattern = raw.split('\0') | 167 excludepattern = raw.split('\0') |
161 if includepattern or excludepattern: | 168 if includepattern or excludepattern: |
162 repo.shallowmatch = match.match(repo.root, '', None, | 169 repo.shallowmatch = match.match( |
163 includepattern, excludepattern) | 170 repo.root, '', None, includepattern, excludepattern |
171 ) | |
164 else: | 172 else: |
165 repo.shallowmatch = match.always() | 173 repo.shallowmatch = match.always() |
166 return orig(repo, outgoing, version, source, *args, **kwargs) | 174 return orig(repo, outgoing, version, source, *args, **kwargs) |
167 finally: | 175 finally: |
168 repo.shallowmatch = original | 176 repo.shallowmatch = original |
177 | |
169 | 178 |
170 def addchangegroupfiles(orig, repo, source, revmap, trp, expectedfiles, *args): | 179 def addchangegroupfiles(orig, repo, source, revmap, trp, expectedfiles, *args): |
171 if not shallowutil.isenabled(repo): | 180 if not shallowutil.isenabled(repo): |
172 return orig(repo, source, revmap, trp, expectedfiles, *args) | 181 return orig(repo, source, revmap, trp, expectedfiles, *args) |
173 | 182 |
216 | 225 |
217 if chain is None: | 226 if chain is None: |
218 raise error.Abort(_("received file revlog group is empty")) | 227 raise error.Abort(_("received file revlog group is empty")) |
219 | 228 |
220 processed = set() | 229 processed = set() |
230 | |
221 def available(f, node, depf, depnode): | 231 def available(f, node, depf, depnode): |
222 if depnode != nullid and (depf, depnode) not in processed: | 232 if depnode != nullid and (depf, depnode) not in processed: |
223 if not (depf, depnode) in revisiondatas: | 233 if not (depf, depnode) in revisiondatas: |
224 # It's not in the changegroup, assume it's already | 234 # It's not in the changegroup, assume it's already |
225 # in the repo | 235 # in the repo |