Mercurial > hg
comparison hgext/sparse.py @ 33371:c6415195fa78
sparse: move code for importing rules from files into core
This is a pretty straightforward port. Some code cleanup was
performed. But no major changes to the logic were made.
I'm not a huge fan of this function because it does multiple
things. I'd like to get things into core first to facilitate
refactoring later.
Please also note the added inline comment about the oddities
of writeconfig() and the try..except to undo it. This is because
of the hackiness in which the sparse matcher is obtained by
various consumers, notably dirstate. We'll need a massive
refactor to address this. That refactor is effectively blocked
on having the sparse dirstate hacks live in core.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 08 Jul 2017 14:15:07 -0700 |
parents | 482320104672 |
children | 4481f1fd27b1 |
comparison
equal
deleted
inserted
replaced
33370:482320104672 | 33371:c6415195fa78 |
---|---|
359 _config(ui, repo, pats, opts, include=include, exclude=exclude, | 359 _config(ui, repo, pats, opts, include=include, exclude=exclude, |
360 reset=reset, delete=delete, enableprofile=enableprofile, | 360 reset=reset, delete=delete, enableprofile=enableprofile, |
361 disableprofile=disableprofile, force=force) | 361 disableprofile=disableprofile, force=force) |
362 | 362 |
363 if importrules: | 363 if importrules: |
364 _import(ui, repo, pats, opts, force=force) | 364 sparse.importfromfiles(repo, opts, pats, force=force) |
365 | 365 |
366 if clearrules: | 366 if clearrules: |
367 sparse.clearrules(repo, force=force) | 367 sparse.clearrules(repo, force=force) |
368 | 368 |
369 if refresh: | 369 if refresh: |
442 except Exception: | 442 except Exception: |
443 sparse.writeconfig(repo, oldinclude, oldexclude, oldprofiles) | 443 sparse.writeconfig(repo, oldinclude, oldexclude, oldprofiles) |
444 raise | 444 raise |
445 finally: | 445 finally: |
446 wlock.release() | 446 wlock.release() |
447 | |
448 def _import(ui, repo, files, opts, force=False): | |
449 with repo.wlock(): | |
450 # read current configuration | |
451 raw = repo.vfs.tryread('sparse') | |
452 oincludes, oexcludes, oprofiles = sparse.parseconfig(ui, raw) | |
453 includes, excludes, profiles = map( | |
454 set, (oincludes, oexcludes, oprofiles)) | |
455 | |
456 aincludes, aexcludes, aprofiles = sparse.activeconfig(repo) | |
457 | |
458 # import rules on top; only take in rules that are not yet | |
459 # part of the active rules. | |
460 changed = False | |
461 for file in files: | |
462 with util.posixfile(util.expandpath(file)) as importfile: | |
463 iincludes, iexcludes, iprofiles = sparse.parseconfig( | |
464 ui, importfile.read()) | |
465 oldsize = len(includes) + len(excludes) + len(profiles) | |
466 includes.update(iincludes - aincludes) | |
467 excludes.update(iexcludes - aexcludes) | |
468 profiles.update(set(iprofiles) - aprofiles) | |
469 if len(includes) + len(excludes) + len(profiles) > oldsize: | |
470 changed = True | |
471 | |
472 profilecount = includecount = excludecount = 0 | |
473 fcounts = (0, 0, 0) | |
474 | |
475 if changed: | |
476 profilecount = len(profiles - aprofiles) | |
477 includecount = len(includes - aincludes) | |
478 excludecount = len(excludes - aexcludes) | |
479 | |
480 oldstatus = repo.status() | |
481 oldsparsematch = sparse.matcher(repo) | |
482 sparse.writeconfig(repo, includes, excludes, profiles) | |
483 | |
484 try: | |
485 fcounts = map( | |
486 len, | |
487 sparse.refreshwdir(repo, oldstatus, oldsparsematch, | |
488 force=force)) | |
489 except Exception: | |
490 sparse.writeconfig(repo, oincludes, oexcludes, oprofiles) | |
491 raise | |
492 | |
493 sparse.printchanges(ui, opts, profilecount, includecount, excludecount, | |
494 *fcounts) |