Mercurial > hg-stable
changeset 48778:c4149a110b5f
sparse: add timing block for parsing sparse configs
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.
Differential Revision: https://phab.mercurial-scm.org/D12186
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 15 Feb 2022 13:32:30 -0500 |
parents | eb9c55453249 |
children | 17eaeb06562c |
files | mercurial/sparse.py |
diffstat | 1 files changed, 54 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/sparse.py Tue Feb 15 13:32:11 2022 -0500 +++ b/mercurial/sparse.py Tue Feb 15 13:32:30 2022 -0500 @@ -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.