D12186: sparse: add timing block for parsing sparse configs
durin42 (Augie Fackler)
phabricator at mercurial-scm.org
Tue Feb 15 19:02:51 UTC 2022
durin42 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
This was showing up in an operation I was doing today, and I'd like to
be able to get trace spans for it instead of just profiler samples.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D12186
AFFECTED FILES
mercurial/sparse.py
CHANGE DETAILS
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -38,63 +38,66 @@
Returns a tuple of includes, excludes, and profiles.
"""
- includes = set()
- excludes = set()
- profiles = set()
- current = None
- havesection = False
+ with util.timedcm(
+ 'sparse.parseconfig(ui, %d bytes, action=%s)', len(raw), action
+ ):
+ includes = set()
+ excludes = set()
+ profiles = set()
+ current = None
+ havesection = False
- for line in raw.split(b'\n'):
- line = line.strip()
- if not line or line.startswith(b'#'):
- # empty or comment line, skip
- continue
- elif line.startswith(b'%include '):
- line = line[9:].strip()
- if line:
- profiles.add(line)
- elif line == b'[include]':
- if havesection and current != includes:
- # TODO pass filename into this API so we can report it.
- raise error.Abort(
- _(
- b'%(action)s config cannot have includes '
- b'after excludes'
+ for line in raw.split(b'\n'):
+ line = line.strip()
+ if not line or line.startswith(b'#'):
+ # empty or comment line, skip
+ continue
+ elif line.startswith(b'%include '):
+ line = line[9:].strip()
+ if line:
+ profiles.add(line)
+ elif line == b'[include]':
+ if havesection and current != includes:
+ # TODO pass filename into this API so we can report it.
+ raise error.Abort(
+ _(
+ b'%(action)s config cannot have includes '
+ b'after excludes'
+ )
+ % {b'action': action}
)
- % {b'action': action}
- )
- havesection = True
- current = includes
- continue
- elif line == b'[exclude]':
- havesection = True
- current = excludes
- elif line:
- if current is None:
- raise error.Abort(
- _(
- b'%(action)s config entry outside of '
- b'section: %(line)s'
+ havesection = True
+ current = includes
+ continue
+ elif line == b'[exclude]':
+ havesection = True
+ current = excludes
+ elif line:
+ if current is None:
+ raise error.Abort(
+ _(
+ b'%(action)s config entry outside of '
+ b'section: %(line)s'
+ )
+ % {b'action': action, b'line': line},
+ hint=_(
+ b'add an [include] or [exclude] line '
+ b'to declare the entry type'
+ ),
)
- % {b'action': action, b'line': line},
- hint=_(
- b'add an [include] or [exclude] line '
- b'to declare the entry type'
- ),
- )
- if line.strip().startswith(b'/'):
- ui.warn(
- _(
- b'warning: %(action)s profile cannot use'
- b' paths starting with /, ignoring %(line)s\n'
+ if line.strip().startswith(b'/'):
+ ui.warn(
+ _(
+ b'warning: %(action)s profile cannot use'
+ b' paths starting with /, ignoring %(line)s\n'
+ )
+ % {b'action': action, b'line': line}
)
- % {b'action': action, b'line': line}
- )
- continue
- current.add(line)
+ continue
+ current.add(line)
- return includes, excludes, profiles
+ return includes, excludes, profiles
# Exists as separate function to facilitate monkeypatching.
To: durin42, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list