##// END OF EJS Templates
sparse: add an action argument to parseconfig()...
Pulkit Goyal -
r38874:8fe62ad9 default
parent child Browse files
Show More
@@ -31,9 +31,11 b' from . import ('
31 31 # a per-repo option, possibly a repo requirement.
32 32 enabled = False
33 33
34 def parseconfig(ui, raw):
34 def parseconfig(ui, raw, action):
35 35 """Parse sparse config file content.
36 36
37 action is the command which is trigerring this read, can be narrow, sparse
38
37 39 Returns a tuple of includes, excludes, and profiles.
38 40 """
39 41 includes = set()
@@ -54,8 +56,8 b' def parseconfig(ui, raw):'
54 56 elif line == '[include]':
55 57 if havesection and current != includes:
56 58 # TODO pass filename into this API so we can report it.
57 raise error.Abort(_('sparse config cannot have includes ' +
58 'after excludes'))
59 raise error.Abort(_('%s config cannot have includes ' +
60 'after excludes') % action)
59 61 havesection = True
60 62 current = includes
61 63 continue
@@ -64,14 +66,15 b' def parseconfig(ui, raw):'
64 66 current = excludes
65 67 elif line:
66 68 if current is None:
67 raise error.Abort(_('sparse config entry outside of '
68 'section: %s') % line,
69 raise error.Abort(_('%s config entry outside of '
70 'section: %s') % (action, line),
69 71 hint=_('add an [include] or [exclude] line '
70 72 'to declare the entry type'))
71 73
72 74 if line.strip().startswith('/'):
73 ui.warn(_('warning: sparse profile cannot use' +
74 ' paths starting with /, ignoring %s\n') % line)
75 ui.warn(_('warning: %s profile cannot use' +
76 ' paths starting with /, ignoring %s\n')
77 % (action, line))
75 78 continue
76 79 current.add(line)
77 80
@@ -102,7 +105,7 b' def patternsforrev(repo, rev):'
102 105 raise error.Abort(_('cannot parse sparse patterns from working '
103 106 'directory'))
104 107
105 includes, excludes, profiles = parseconfig(repo.ui, raw)
108 includes, excludes, profiles = parseconfig(repo.ui, raw, 'sparse')
106 109 ctx = repo[rev]
107 110
108 111 if profiles:
@@ -128,7 +131,7 b' def patternsforrev(repo, rev):'
128 131 repo.ui.debug(msg)
129 132 continue
130 133
131 pincludes, pexcludes, subprofs = parseconfig(repo.ui, raw)
134 pincludes, pexcludes, subprofs = parseconfig(repo.ui, raw, 'sparse')
132 135 includes.update(pincludes)
133 136 excludes.update(pexcludes)
134 137 profiles.update(subprofs)
@@ -516,7 +519,7 b' def _updateconfigandrefreshwdir(repo, in'
516 519 force=False, removing=False):
517 520 """Update the sparse config and working directory state."""
518 521 raw = repo.vfs.tryread('sparse')
519 oldincludes, oldexcludes, oldprofiles = parseconfig(repo.ui, raw)
522 oldincludes, oldexcludes, oldprofiles = parseconfig(repo.ui, raw, 'sparse')
520 523
521 524 oldstatus = repo.status()
522 525 oldmatch = matcher(repo)
@@ -556,7 +559,7 b' def clearrules(repo, force=False):'
556 559 """
557 560 with repo.wlock():
558 561 raw = repo.vfs.tryread('sparse')
559 includes, excludes, profiles = parseconfig(repo.ui, raw)
562 includes, excludes, profiles = parseconfig(repo.ui, raw, 'sparse')
560 563
561 564 if not includes and not excludes:
562 565 return
@@ -572,7 +575,7 b' def importfromfiles(repo, opts, paths, f'
572 575 with repo.wlock():
573 576 # read current configuration
574 577 raw = repo.vfs.tryread('sparse')
575 includes, excludes, profiles = parseconfig(repo.ui, raw)
578 includes, excludes, profiles = parseconfig(repo.ui, raw, 'sparse')
576 579 aincludes, aexcludes, aprofiles = activeconfig(repo)
577 580
578 581 # Import rules on top; only take in rules that are not yet
@@ -582,7 +585,8 b' def importfromfiles(repo, opts, paths, f'
582 585 with util.posixfile(util.expandpath(p), mode='rb') as fh:
583 586 raw = fh.read()
584 587
585 iincludes, iexcludes, iprofiles = parseconfig(repo.ui, raw)
588 iincludes, iexcludes, iprofiles = parseconfig(repo.ui, raw,
589 'sparse')
586 590 oldsize = len(includes) + len(excludes) + len(profiles)
587 591 includes.update(iincludes - aincludes)
588 592 excludes.update(iexcludes - aexcludes)
@@ -615,7 +619,8 b' def updateconfig(repo, pats, opts, inclu'
615 619 """
616 620 with repo.wlock():
617 621 raw = repo.vfs.tryread('sparse')
618 oldinclude, oldexclude, oldprofiles = parseconfig(repo.ui, raw)
622 oldinclude, oldexclude, oldprofiles = parseconfig(repo.ui, raw,
623 'sparse')
619 624
620 625 if reset:
621 626 newinclude = set()
General Comments 0
You need to be logged in to leave comments. Login now