Show More
@@ -361,7 +361,7 b' def debugsparse(ui, repo, *pats, **opts)' | |||
|
361 | 361 | disableprofile=disableprofile, force=force) |
|
362 | 362 | |
|
363 | 363 | if importrules: |
|
364 |
|
|
|
364 | sparse.importfromfiles(repo, opts, pats, force=force) | |
|
365 | 365 | |
|
366 | 366 | if clearrules: |
|
367 | 367 | sparse.clearrules(repo, force=force) |
@@ -444,51 +444,3 b' def _config(ui, repo, pats, opts, includ' | |||
|
444 | 444 | raise |
|
445 | 445 | finally: |
|
446 | 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) |
@@ -18,6 +18,7 b' from . import (' | |||
|
18 | 18 | match as matchmod, |
|
19 | 19 | merge as mergemod, |
|
20 | 20 | pycompat, |
|
21 | util, | |
|
21 | 22 | ) |
|
22 | 23 | |
|
23 | 24 | # Whether sparse features are enabled. This variable is intended to be |
@@ -521,6 +522,67 b' def clearrules(repo, force=False):' | |||
|
521 | 522 | writeconfig(repo, set(), set(), profiles) |
|
522 | 523 | refreshwdir(repo, oldstatus, oldmatch, force=force) |
|
523 | 524 | |
|
525 | def importfromfiles(repo, opts, paths, force=False): | |
|
526 | """Import sparse config rules from files. | |
|
527 | ||
|
528 | The updated sparse config is written out and the working directory | |
|
529 | is refreshed, as needed. | |
|
530 | """ | |
|
531 | with repo.wlock(): | |
|
532 | # read current configuration | |
|
533 | raw = repo.vfs.tryread('sparse') | |
|
534 | oincludes, oexcludes, oprofiles = parseconfig(repo.ui, raw) | |
|
535 | includes, excludes, profiles = map( | |
|
536 | set, (oincludes, oexcludes, oprofiles)) | |
|
537 | ||
|
538 | aincludes, aexcludes, aprofiles = activeconfig(repo) | |
|
539 | ||
|
540 | # Import rules on top; only take in rules that are not yet | |
|
541 | # part of the active rules. | |
|
542 | changed = False | |
|
543 | for p in paths: | |
|
544 | with util.posixfile(util.expandpath(p)) as fh: | |
|
545 | raw = fh.read() | |
|
546 | ||
|
547 | iincludes, iexcludes, iprofiles = parseconfig(repo.ui, raw) | |
|
548 | oldsize = len(includes) + len(excludes) + len(profiles) | |
|
549 | includes.update(iincludes - aincludes) | |
|
550 | excludes.update(iexcludes - aexcludes) | |
|
551 | profiles.update(set(iprofiles) - aprofiles) | |
|
552 | if len(includes) + len(excludes) + len(profiles) > oldsize: | |
|
553 | changed = True | |
|
554 | ||
|
555 | profilecount = includecount = excludecount = 0 | |
|
556 | fcounts = (0, 0, 0) | |
|
557 | ||
|
558 | if changed: | |
|
559 | profilecount = len(profiles - aprofiles) | |
|
560 | includecount = len(includes - aincludes) | |
|
561 | excludecount = len(excludes - aexcludes) | |
|
562 | ||
|
563 | oldstatus = repo.status() | |
|
564 | oldsparsematch = matcher(repo) | |
|
565 | ||
|
566 | # TODO remove this try..except once the matcher integrates better | |
|
567 | # with dirstate. We currently have to write the updated config | |
|
568 | # because that will invalidate the matcher cache and force a | |
|
569 | # re-read. We ideally want to update the cached matcher on the | |
|
570 | # repo instance then flush the new config to disk once wdir is | |
|
571 | # updated. But this requires massive rework to matcher() and its | |
|
572 | # consumers. | |
|
573 | writeconfig(repo, includes, excludes, profiles) | |
|
574 | ||
|
575 | try: | |
|
576 | fcounts = map( | |
|
577 | len, | |
|
578 | refreshwdir(repo, oldstatus, oldsparsematch, force=force)) | |
|
579 | except Exception: | |
|
580 | writeconfig(repo, oincludes, oexcludes, oprofiles) | |
|
581 | raise | |
|
582 | ||
|
583 | printchanges(repo.ui, opts, profilecount, includecount, excludecount, | |
|
584 | *fcounts) | |
|
585 | ||
|
524 | 586 | def printchanges(ui, opts, profilecount=0, includecount=0, excludecount=0, |
|
525 | 587 | added=0, dropped=0, conflicting=0): |
|
526 | 588 | """Print output summarizing sparse config changes.""" |
General Comments 0
You need to be logged in to leave comments.
Login now