mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 16:31:02 +03:00
fastannotate: some clean-ups before the remotefilelog change
Summary: The upcoming remotefilelog change would require some cleanups to avoid code duplication. Namely: - Add a `fctxannotatecontext` so we can easily get a `annotatecontext` from within `filectx.annotate` or `remotefilectx.annotate`. - Print something instead of ignoring errors silently in `_fctxannotate`. Test Plan: `arc unit` Reviewers: #sourcecontrol, stash Reviewed By: stash Subscribers: stash, mjpieters Differential Revision: https://phabricator.intern.facebook.com/D4256469 Signature: t1:4256469:1480612106:63756d64014a5b9e798bce52eda0d3e7368d6cba
This commit is contained in:
parent
786439a1c0
commit
bf8615b740
@ -782,3 +782,14 @@ def annotatecontext(repo, path, opts=defaultopts, rebuild=False):
|
||||
finally:
|
||||
if actx is not None:
|
||||
actx.close()
|
||||
|
||||
def fctxannotatecontext(fctx, follow=True, diffopts=None, rebuild=False):
|
||||
"""like annotatecontext but get the context from a fctx. convenient when
|
||||
used in fctx.annotate
|
||||
"""
|
||||
repo = fctx._repo
|
||||
path = fctx._path
|
||||
if repo.ui.configbool('fastannotate', 'forcefollow', True):
|
||||
follow = True
|
||||
aopts = annotateopts(diffopts=diffopts, followrename=follow)
|
||||
return annotatecontext(repo, path, aopts, rebuild)
|
||||
|
@ -51,30 +51,26 @@ def _convertoutputs(repo, annotated, contents):
|
||||
results.append(((fctxmap[(hsh, path)], linenum + 1), contents[i]))
|
||||
return results
|
||||
|
||||
def _doannotate(fctx, follow=True, diffopts=None, ui=None):
|
||||
def _getmaster(fctx):
|
||||
"""(fctx) -> str"""
|
||||
return fctx._repo.ui.config('fastannotate', 'mainbranch') or 'default'
|
||||
|
||||
def _doannotate(fctx, follow=True, diffopts=None):
|
||||
"""like the vanilla fctx.annotate, but do it via fastannotate, and make
|
||||
the output format compatible with the vanilla fctx.annotate.
|
||||
may raise Exception, and always return line numbers.
|
||||
"""
|
||||
repo = fctx._repo
|
||||
if ui is None:
|
||||
ui = repo.ui
|
||||
path = fctx._path
|
||||
|
||||
master = ui.config('fastannotate', 'mainbranch') or 'default'
|
||||
if ui.configbool('fastannotate', 'forcefollow', True):
|
||||
follow = True
|
||||
|
||||
aopts = context.annotateopts(diffopts=diffopts, followrename=follow)
|
||||
master = _getmaster(fctx)
|
||||
annotated = contents = None
|
||||
|
||||
with context.annotatecontext(repo, path, aopts) as ac:
|
||||
with context.fctxannotatecontext(fctx, follow, diffopts) as ac:
|
||||
try:
|
||||
annotated, contents = ac.annotate(fctx.rev(), master=master,
|
||||
showpath=True, showlines=True)
|
||||
except Exception:
|
||||
ac.rebuild() # try rebuild once
|
||||
ui.debug('fastannotate: %s: rebuilding broken cache\n' % path)
|
||||
fctx._repo.ui.debug('fastannotate: %s: rebuilding broken cache\n'
|
||||
% fctx._path)
|
||||
try:
|
||||
annotated, contents = ac.annotate(fctx.rev(), master=master,
|
||||
showpath=True, showlines=True)
|
||||
@ -82,18 +78,19 @@ def _doannotate(fctx, follow=True, diffopts=None, ui=None):
|
||||
raise
|
||||
|
||||
assert annotated and contents
|
||||
return _convertoutputs(repo, annotated, contents)
|
||||
return _convertoutputs(fctx._repo, annotated, contents)
|
||||
|
||||
def _hgwebannotate(orig, fctx, ui):
|
||||
diffopts = patch.difffeatureopts(ui, untrusted=True,
|
||||
section='annotate', whitespace=True)
|
||||
return _doannotate(fctx, diffopts=diffopts, ui=ui)
|
||||
return _doannotate(fctx, diffopts=diffopts)
|
||||
|
||||
def _fctxannotate(orig, self, follow=False, linenumber=False, diffopts=None):
|
||||
try:
|
||||
return _doannotate(self, follow, diffopts)
|
||||
except Exception:
|
||||
# fallback to the original method
|
||||
except Exception as ex:
|
||||
self._repo.ui.debug('fastannotate: falling back to the vanilla '
|
||||
'annotate: %r' % ex)
|
||||
return orig(self, follow, linenumber, diffopts)
|
||||
|
||||
def replacehgwebannotate():
|
||||
|
Loading…
Reference in New Issue
Block a user