--- a/hgext/fastannotate/commands.py Sat Oct 05 10:29:34 2019 -0400
+++ b/hgext/fastannotate/commands.py Sun Oct 06 09:45:02 2019 -0400
@@ -31,6 +31,7 @@
cmdtable = {}
command = registrar.command(cmdtable)
+
def _matchpaths(repo, rev, pats, opts, aopts=facontext.defaultopts):
"""generate paths matching given patterns"""
perfhack = repo.ui.configbool('fastannotate', 'perfhack')
@@ -45,16 +46,23 @@
reldir = os.path.relpath(encoding.getcwd(), reporoot)
if reldir == '.':
reldir = ''
- if any(opts.get(o[1]) for o in commands.walkopts): # a)
+ if any(opts.get(o[1]) for o in commands.walkopts): # a)
perfhack = False
- else: # b)
- relpats = [os.path.relpath(p, reporoot) if os.path.isabs(p) else p
- for p in pats]
+ else: # b)
+ relpats = [
+ os.path.relpath(p, reporoot) if os.path.isabs(p) else p
+ for p in pats
+ ]
# disable perfhack on '..' since it allows escaping from the repo
- if any(('..' in f or
- not os.path.isfile(
- facontext.pathhelper(repo, f, aopts).linelogpath))
- for f in relpats):
+ if any(
+ (
+ '..' in f
+ or not os.path.isfile(
+ facontext.pathhelper(repo, f, aopts).linelogpath
+ )
+ )
+ for f in relpats
+ ):
perfhack = False
# perfhack: emit paths directory without checking with manifest
@@ -63,13 +71,16 @@
for p in relpats:
yield os.path.join(reldir, p)
else:
+
def bad(x, y):
raise error.Abort("%s: %s" % (x, y))
+
ctx = scmutil.revsingle(repo, rev)
m = scmutil.match(ctx, pats, opts, badfn=bad)
for p in ctx.walk(m):
yield p
+
fastannotatecommandargs = {
r'options': [
('r', 'rev', '.', _('annotate the specified revision'), _('REV')),
@@ -78,21 +89,40 @@
('d', 'date', None, _('list the date (short with -q)')),
('n', 'number', None, _('list the revision number (default)')),
('c', 'changeset', None, _('list the changeset')),
- ('l', 'line-number', None, _('show line number at the first '
- 'appearance')),
+ (
+ 'l',
+ 'line-number',
+ None,
+ _('show line number at the first ' 'appearance'),
+ ),
('e', 'deleted', None, _('show deleted lines (slow) (EXPERIMENTAL)')),
('', 'no-content', None, _('do not show file content (EXPERIMENTAL)')),
('', 'no-follow', None, _("don't follow copies and renames")),
- ('', 'linear', None, _('enforce linear history, ignore second parent '
- 'of merges (EXPERIMENTAL)')),
+ (
+ '',
+ 'linear',
+ None,
+ _(
+ 'enforce linear history, ignore second parent '
+ 'of merges (EXPERIMENTAL)'
+ ),
+ ),
('', 'long-hash', None, _('show long changeset hash (EXPERIMENTAL)')),
- ('', 'rebuild', None, _('rebuild cache even if it exists '
- '(EXPERIMENTAL)')),
- ] + commands.diffwsopts + commands.walkopts + commands.formatteropts,
+ (
+ '',
+ 'rebuild',
+ None,
+ _('rebuild cache even if it exists ' '(EXPERIMENTAL)'),
+ ),
+ ]
+ + commands.diffwsopts
+ + commands.walkopts
+ + commands.formatteropts,
r'synopsis': _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'),
r'inferrepo': True,
}
+
def fastannotate(ui, repo, *pats, **opts):
"""show changeset information by line for each file
@@ -136,15 +166,18 @@
rev = opts.get('rev', '.')
rebuild = opts.get('rebuild', False)
- diffopts = patch.difffeatureopts(ui, opts, section='annotate',
- whitespace=True)
+ diffopts = patch.difffeatureopts(
+ ui, opts, section='annotate', whitespace=True
+ )
aopts = facontext.annotateopts(
diffopts=diffopts,
followmerge=not opts.get('linear', False),
- followrename=not opts.get('no_follow', False))
+ followrename=not opts.get('no_follow', False),
+ )
- if not any(opts.get(s)
- for s in ['user', 'date', 'file', 'number', 'changeset']):
+ if not any(
+ opts.get(s) for s in ['user', 'date', 'file', 'number', 'changeset']
+ ):
# default 'number' for compatibility. but fastannotate is more
# efficient with "changeset", "line-number" and "no-content".
for name in ui.configlist('fastannotate', 'defaultformat', ['number']):
@@ -175,20 +208,24 @@
while True:
try:
with facontext.annotatecontext(repo, path, aopts, rebuild) as a:
- result = a.annotate(rev, master=master, showpath=showpath,
- showlines=(showlines and
- not showdeleted))
+ result = a.annotate(
+ rev,
+ master=master,
+ showpath=showpath,
+ showlines=(showlines and not showdeleted),
+ )
if showdeleted:
existinglines = set((l[0], l[1]) for l in result)
result = a.annotatealllines(
- rev, showpath=showpath, showlines=showlines)
+ rev, showpath=showpath, showlines=showlines
+ )
break
except (faerror.CannotReuseError, faerror.CorruptedFileError):
# happens if master moves backwards, or the file was deleted
# and readded, or renamed to an existing name, or corrupted.
- if rebuild: # give up since we have tried rebuild already
+ if rebuild: # give up since we have tried rebuild already
raise
- else: # try a second time rebuilding the cache (slow)
+ else: # try a second time rebuilding the cache (slow)
rebuild = True
continue
@@ -198,9 +235,13 @@
formatter.write(result, lines, existinglines=existinglines)
formatter.end()
+
_newopts = set()
-_knownopts = {opt[1].replace('-', '_') for opt in
- (fastannotatecommandargs[r'options'] + commands.globalopts)}
+_knownopts = {
+ opt[1].replace('-', '_')
+ for opt in (fastannotatecommandargs[r'options'] + commands.globalopts)
+}
+
def _annotatewrapper(orig, ui, repo, *pats, **opts):
"""used by wrapdefault"""
@@ -220,19 +261,24 @@
return orig(ui, repo, *pats, **opts)
+
def registercommand():
"""register the fastannotate command"""
name = 'fastannotate|fastblame|fa'
command(name, helpbasic=True, **fastannotatecommandargs)(fastannotate)
+
def wrapdefault():
"""wrap the default annotate command, to be aware of the protocol"""
extensions.wrapcommand(commands.table, 'annotate', _annotatewrapper)
-@command('debugbuildannotatecache',
- [('r', 'rev', '', _('build up to the specific revision'), _('REV'))
- ] + commands.walkopts,
- _('[-r REV] FILE...'))
+
+@command(
+ 'debugbuildannotatecache',
+ [('r', 'rev', '', _('build up to the specific revision'), _('REV'))]
+ + commands.walkopts,
+ _('[-r REV] FILE...'),
+)
def debugbuildannotatecache(ui, repo, *pats, **opts):
"""incrementally build fastannotate cache up to REV for specified files
@@ -247,8 +293,10 @@
opts = pycompat.byteskwargs(opts)
rev = opts.get('REV') or ui.config('fastannotate', 'mainbranch')
if not rev:
- raise error.Abort(_('you need to provide a revision'),
- hint=_('set fastannotate.mainbranch or use --rev'))
+ raise error.Abort(
+ _('you need to provide a revision'),
+ hint=_('set fastannotate.mainbranch or use --rev'),
+ )
if ui.configbool('fastannotate', 'unfilteredrepo'):
repo = repo.unfiltered()
ctx = scmutil.revsingle(repo, rev)
@@ -272,14 +320,20 @@
except (faerror.CannotReuseError, faerror.CorruptedFileError):
# the cache is broken (could happen with renaming so the
# file history gets invalidated). rebuild and try again.
- ui.debug('fastannotate: %s: rebuilding broken cache\n'
- % path)
+ ui.debug(
+ 'fastannotate: %s: rebuilding broken cache\n' % path
+ )
actx.rebuild()
try:
actx.annotate(rev, rev)
except Exception as ex:
# possibly a bug, but should not stop us from building
# cache for other files.
- ui.warn(_('fastannotate: %s: failed to '
- 'build cache: %r\n') % (path, ex))
+ ui.warn(
+ _(
+ 'fastannotate: %s: failed to '
+ 'build cache: %r\n'
+ )
+ % (path, ex)
+ )
progress.complete()