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