Mercurial > hg
comparison hgext/lfs/__init__.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 | 268662aac075 |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
145 scmutil, | 145 scmutil, |
146 templateutil, | 146 templateutil, |
147 util, | 147 util, |
148 ) | 148 ) |
149 | 149 |
150 from mercurial.interfaces import ( | 150 from mercurial.interfaces import repository |
151 repository, | |
152 ) | |
153 | 151 |
154 from . import ( | 152 from . import ( |
155 blobstore, | 153 blobstore, |
156 wireprotolfsserver, | 154 wireprotolfsserver, |
157 wrapper, | 155 wrapper, |
173 uisetup = eh.finaluisetup | 171 uisetup = eh.finaluisetup |
174 filesetpredicate = eh.filesetpredicate | 172 filesetpredicate = eh.filesetpredicate |
175 reposetup = eh.finalreposetup | 173 reposetup = eh.finalreposetup |
176 templatekeyword = eh.templatekeyword | 174 templatekeyword = eh.templatekeyword |
177 | 175 |
178 eh.configitem('experimental', 'lfs.serve', | 176 eh.configitem( |
179 default=True, | 177 'experimental', 'lfs.serve', default=True, |
180 ) | 178 ) |
181 eh.configitem('experimental', 'lfs.user-agent', | 179 eh.configitem( |
182 default=None, | 180 'experimental', 'lfs.user-agent', default=None, |
183 ) | 181 ) |
184 eh.configitem('experimental', 'lfs.disableusercache', | 182 eh.configitem( |
185 default=False, | 183 'experimental', 'lfs.disableusercache', default=False, |
186 ) | 184 ) |
187 eh.configitem('experimental', 'lfs.worker-enable', | 185 eh.configitem( |
188 default=False, | 186 'experimental', 'lfs.worker-enable', default=False, |
189 ) | 187 ) |
190 | 188 |
191 eh.configitem('lfs', 'url', | 189 eh.configitem( |
192 default=None, | 190 'lfs', 'url', default=None, |
193 ) | 191 ) |
194 eh.configitem('lfs', 'usercache', | 192 eh.configitem( |
195 default=None, | 193 'lfs', 'usercache', default=None, |
196 ) | 194 ) |
197 # Deprecated | 195 # Deprecated |
198 eh.configitem('lfs', 'threshold', | 196 eh.configitem( |
199 default=None, | 197 'lfs', 'threshold', default=None, |
200 ) | 198 ) |
201 eh.configitem('lfs', 'track', | 199 eh.configitem( |
202 default='none()', | 200 'lfs', 'track', default='none()', |
203 ) | 201 ) |
204 eh.configitem('lfs', 'retry', | 202 eh.configitem( |
205 default=5, | 203 'lfs', 'retry', default=5, |
206 ) | 204 ) |
207 | 205 |
208 lfsprocessor = ( | 206 lfsprocessor = ( |
209 wrapper.readfromstore, | 207 wrapper.readfromstore, |
210 wrapper.writetostore, | 208 wrapper.writetostore, |
211 wrapper.bypasscheckhash, | 209 wrapper.bypasscheckhash, |
212 ) | 210 ) |
213 | 211 |
212 | |
214 def featuresetup(ui, supported): | 213 def featuresetup(ui, supported): |
215 # don't die on seeing a repo with the lfs requirement | 214 # don't die on seeing a repo with the lfs requirement |
216 supported |= {'lfs'} | 215 supported |= {'lfs'} |
217 | 216 |
217 | |
218 @eh.uisetup | 218 @eh.uisetup |
219 def _uisetup(ui): | 219 def _uisetup(ui): |
220 localrepo.featuresetupfuncs.add(featuresetup) | 220 localrepo.featuresetupfuncs.add(featuresetup) |
221 | |
221 | 222 |
222 @eh.reposetup | 223 @eh.reposetup |
223 def _reposetup(ui, repo): | 224 def _reposetup(ui, repo): |
224 # Nothing to do with a remote repo | 225 # Nothing to do with a remote repo |
225 if not repo.local(): | 226 if not repo.local(): |
235 return super(lfsrepo, self).commitctx(ctx, error, origctx=origctx) | 236 return super(lfsrepo, self).commitctx(ctx, error, origctx=origctx) |
236 | 237 |
237 repo.__class__ = lfsrepo | 238 repo.__class__ = lfsrepo |
238 | 239 |
239 if 'lfs' not in repo.requirements: | 240 if 'lfs' not in repo.requirements: |
241 | |
240 def checkrequireslfs(ui, repo, **kwargs): | 242 def checkrequireslfs(ui, repo, **kwargs): |
241 if 'lfs' in repo.requirements: | 243 if 'lfs' in repo.requirements: |
242 return 0 | 244 return 0 |
243 | 245 |
244 last = kwargs.get(r'node_last') | 246 last = kwargs.get(r'node_last') |
248 else: | 250 else: |
249 s = repo.set('%n', _bin(kwargs[r'node'])) | 251 s = repo.set('%n', _bin(kwargs[r'node'])) |
250 match = repo._storenarrowmatch | 252 match = repo._storenarrowmatch |
251 for ctx in s: | 253 for ctx in s: |
252 # TODO: is there a way to just walk the files in the commit? | 254 # TODO: is there a way to just walk the files in the commit? |
253 if any(ctx[f].islfs() for f in ctx.files() | 255 if any( |
254 if f in ctx and match(f)): | 256 ctx[f].islfs() for f in ctx.files() if f in ctx and match(f) |
257 ): | |
255 repo.requirements.add('lfs') | 258 repo.requirements.add('lfs') |
256 repo.features.add(repository.REPO_FEATURE_LFS) | 259 repo.features.add(repository.REPO_FEATURE_LFS) |
257 repo._writerequirements() | 260 repo._writerequirements() |
258 repo.prepushoutgoinghooks.add('lfs', wrapper.prepush) | 261 repo.prepushoutgoinghooks.add('lfs', wrapper.prepush) |
259 break | 262 break |
260 | 263 |
261 ui.setconfig('hooks', 'commit.lfs', checkrequireslfs, 'lfs') | 264 ui.setconfig('hooks', 'commit.lfs', checkrequireslfs, 'lfs') |
262 ui.setconfig('hooks', 'pretxnchangegroup.lfs', checkrequireslfs, 'lfs') | 265 ui.setconfig('hooks', 'pretxnchangegroup.lfs', checkrequireslfs, 'lfs') |
263 else: | 266 else: |
264 repo.prepushoutgoinghooks.add('lfs', wrapper.prepush) | 267 repo.prepushoutgoinghooks.add('lfs', wrapper.prepush) |
268 | |
265 | 269 |
266 def _trackedmatcher(repo): | 270 def _trackedmatcher(repo): |
267 """Return a function (path, size) -> bool indicating whether or not to | 271 """Return a function (path, size) -> bool indicating whether or not to |
268 track a given file with lfs.""" | 272 track a given file with lfs.""" |
269 if not repo.wvfs.exists('.hglfs'): | 273 if not repo.wvfs.exists('.hglfs'): |
286 # and line number. | 290 # and line number. |
287 cfg = config.config() | 291 cfg = config.config() |
288 cfg.parse('.hglfs', data) | 292 cfg.parse('.hglfs', data) |
289 | 293 |
290 try: | 294 try: |
291 rules = [(minifileset.compile(pattern), minifileset.compile(rule)) | 295 rules = [ |
292 for pattern, rule in cfg.items('track')] | 296 (minifileset.compile(pattern), minifileset.compile(rule)) |
297 for pattern, rule in cfg.items('track') | |
298 ] | |
293 except error.ParseError as e: | 299 except error.ParseError as e: |
294 # The original exception gives no indicator that the error is in the | 300 # The original exception gives no indicator that the error is in the |
295 # .hglfs file, so add that. | 301 # .hglfs file, so add that. |
296 | 302 |
297 # TODO: See if the line number of the file can be made available. | 303 # TODO: See if the line number of the file can be made available. |
304 | 310 |
305 return False | 311 return False |
306 | 312 |
307 return _match | 313 return _match |
308 | 314 |
315 | |
309 # Called by remotefilelog | 316 # Called by remotefilelog |
310 def wrapfilelog(filelog): | 317 def wrapfilelog(filelog): |
311 wrapfunction = extensions.wrapfunction | 318 wrapfunction = extensions.wrapfunction |
312 | 319 |
313 wrapfunction(filelog, 'addrevision', wrapper.filelogaddrevision) | 320 wrapfunction(filelog, 'addrevision', wrapper.filelogaddrevision) |
314 wrapfunction(filelog, 'renamed', wrapper.filelogrenamed) | 321 wrapfunction(filelog, 'renamed', wrapper.filelogrenamed) |
315 wrapfunction(filelog, 'size', wrapper.filelogsize) | 322 wrapfunction(filelog, 'size', wrapper.filelogsize) |
323 | |
316 | 324 |
317 @eh.wrapfunction(localrepo, 'resolverevlogstorevfsoptions') | 325 @eh.wrapfunction(localrepo, 'resolverevlogstorevfsoptions') |
318 def _resolverevlogstorevfsoptions(orig, ui, requirements, features): | 326 def _resolverevlogstorevfsoptions(orig, ui, requirements, features): |
319 opts = orig(ui, requirements, features) | 327 opts = orig(ui, requirements, features) |
320 for name, module in extensions.extensions(ui): | 328 for name, module in extensions.extensions(ui): |
321 if module is sys.modules[__name__]: | 329 if module is sys.modules[__name__]: |
322 if revlog.REVIDX_EXTSTORED in opts[b'flagprocessors']: | 330 if revlog.REVIDX_EXTSTORED in opts[b'flagprocessors']: |
323 msg = (_(b"cannot register multiple processors on flag '%#x'.") | 331 msg = ( |
324 % revlog.REVIDX_EXTSTORED) | 332 _(b"cannot register multiple processors on flag '%#x'.") |
333 % revlog.REVIDX_EXTSTORED | |
334 ) | |
325 raise error.Abort(msg) | 335 raise error.Abort(msg) |
326 | 336 |
327 opts[b'flagprocessors'][revlog.REVIDX_EXTSTORED] = lfsprocessor | 337 opts[b'flagprocessors'][revlog.REVIDX_EXTSTORED] = lfsprocessor |
328 break | 338 break |
329 | 339 |
330 return opts | 340 return opts |
341 | |
331 | 342 |
332 @eh.extsetup | 343 @eh.extsetup |
333 def _extsetup(ui): | 344 def _extsetup(ui): |
334 wrapfilelog(filelog.filelog) | 345 wrapfilelog(filelog.filelog) |
335 | 346 |
339 | 350 |
340 # Make bundle choose changegroup3 instead of changegroup2. This affects | 351 # Make bundle choose changegroup3 instead of changegroup2. This affects |
341 # "hg bundle" command. Note: it does not cover all bundle formats like | 352 # "hg bundle" command. Note: it does not cover all bundle formats like |
342 # "packed1". Using "packed1" with lfs will likely cause trouble. | 353 # "packed1". Using "packed1" with lfs will likely cause trouble. |
343 exchange._bundlespeccontentopts["v2"]["cg.version"] = "03" | 354 exchange._bundlespeccontentopts["v2"]["cg.version"] = "03" |
355 | |
344 | 356 |
345 @eh.filesetpredicate('lfs()') | 357 @eh.filesetpredicate('lfs()') |
346 def lfsfileset(mctx, x): | 358 def lfsfileset(mctx, x): |
347 """File that uses LFS storage.""" | 359 """File that uses LFS storage.""" |
348 # i18n: "lfs" is a keyword | 360 # i18n: "lfs" is a keyword |
349 filesetlang.getargs(x, 0, 0, _("lfs takes no arguments")) | 361 filesetlang.getargs(x, 0, 0, _("lfs takes no arguments")) |
350 ctx = mctx.ctx | 362 ctx = mctx.ctx |
363 | |
351 def lfsfilep(f): | 364 def lfsfilep(f): |
352 return wrapper.pointerfromctx(ctx, f, removed=True) is not None | 365 return wrapper.pointerfromctx(ctx, f, removed=True) is not None |
366 | |
353 return mctx.predicate(lfsfilep, predrepr='<lfs>') | 367 return mctx.predicate(lfsfilep, predrepr='<lfs>') |
368 | |
354 | 369 |
355 @eh.templatekeyword('lfs_files', requires={'ctx'}) | 370 @eh.templatekeyword('lfs_files', requires={'ctx'}) |
356 def lfsfiles(context, mapping): | 371 def lfsfiles(context, mapping): |
357 """List of strings. All files modified, added, or removed by this | 372 """List of strings. All files modified, added, or removed by this |
358 changeset.""" | 373 changeset.""" |
359 ctx = context.resource(mapping, 'ctx') | 374 ctx = context.resource(mapping, 'ctx') |
360 | 375 |
361 pointers = wrapper.pointersfromctx(ctx, removed=True) # {path: pointer} | 376 pointers = wrapper.pointersfromctx(ctx, removed=True) # {path: pointer} |
362 files = sorted(pointers.keys()) | 377 files = sorted(pointers.keys()) |
363 | 378 |
364 def pointer(v): | 379 def pointer(v): |
365 # In the file spec, version is first and the other keys are sorted. | 380 # In the file spec, version is first and the other keys are sorted. |
366 sortkeyfunc = lambda x: (x[0] != 'version', x) | 381 sortkeyfunc = lambda x: (x[0] != 'version', x) |
375 | 390 |
376 # TODO: make the separator ', '? | 391 # TODO: make the separator ', '? |
377 f = templateutil._showcompatlist(context, mapping, 'lfs_file', files) | 392 f = templateutil._showcompatlist(context, mapping, 'lfs_file', files) |
378 return templateutil.hybrid(f, files, makemap, pycompat.identity) | 393 return templateutil.hybrid(f, files, makemap, pycompat.identity) |
379 | 394 |
380 @eh.command('debuglfsupload', | 395 |
381 [('r', 'rev', [], _('upload large files introduced by REV'))]) | 396 @eh.command( |
397 'debuglfsupload', | |
398 [('r', 'rev', [], _('upload large files introduced by REV'))], | |
399 ) | |
382 def debuglfsupload(ui, repo, **opts): | 400 def debuglfsupload(ui, repo, **opts): |
383 """upload lfs blobs added by the working copy parent or given revisions""" | 401 """upload lfs blobs added by the working copy parent or given revisions""" |
384 revs = opts.get(r'rev', []) | 402 revs = opts.get(r'rev', []) |
385 pointers = wrapper.extractpointers(repo, scmutil.revrange(repo, revs)) | 403 pointers = wrapper.extractpointers(repo, scmutil.revrange(repo, revs)) |
386 wrapper.uploadblobs(repo, pointers) | 404 wrapper.uploadblobs(repo, pointers) |