519 oldstatus = repo.status() |
520 oldstatus = repo.status() |
520 oldmatch = matcher(repo) |
521 oldmatch = matcher(repo) |
521 writeconfig(repo, set(), set(), profiles) |
522 writeconfig(repo, set(), set(), profiles) |
522 refreshwdir(repo, oldstatus, oldmatch, force=force) |
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 def printchanges(ui, opts, profilecount=0, includecount=0, excludecount=0, |
586 def printchanges(ui, opts, profilecount=0, includecount=0, excludecount=0, |
525 added=0, dropped=0, conflicting=0): |
587 added=0, dropped=0, conflicting=0): |
526 """Print output summarizing sparse config changes.""" |
588 """Print output summarizing sparse config changes.""" |
527 with ui.formatter('sparse', opts) as fm: |
589 with ui.formatter('sparse', opts) as fm: |
528 fm.startitem() |
590 fm.startitem() |