Mercurial > public > mercurial-scm > hg
comparison hgext/fastannotate/support.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 876494fd967d |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
19 from . import ( | 19 from . import ( |
20 context, | 20 context, |
21 revmap, | 21 revmap, |
22 ) | 22 ) |
23 | 23 |
24 | |
24 class _lazyfctx(object): | 25 class _lazyfctx(object): |
25 """delegates to fctx but do not construct fctx when unnecessary""" | 26 """delegates to fctx but do not construct fctx when unnecessary""" |
26 | 27 |
27 def __init__(self, repo, node, path): | 28 def __init__(self, repo, node, path): |
28 self._node = node | 29 self._node = node |
40 return context.resolvefctx(self._repo, self._node, self._path) | 41 return context.resolvefctx(self._repo, self._node, self._path) |
41 | 42 |
42 def __getattr__(self, name): | 43 def __getattr__(self, name): |
43 return getattr(self._fctx, name) | 44 return getattr(self._fctx, name) |
44 | 45 |
46 | |
45 def _convertoutputs(repo, annotated, contents): | 47 def _convertoutputs(repo, annotated, contents): |
46 """convert fastannotate outputs to vanilla annotate format""" | 48 """convert fastannotate outputs to vanilla annotate format""" |
47 # fastannotate returns: [(nodeid, linenum, path)], [linecontent] | 49 # fastannotate returns: [(nodeid, linenum, path)], [linecontent] |
48 # convert to what fctx.annotate returns: [annotateline] | 50 # convert to what fctx.annotate returns: [annotateline] |
49 results = [] | 51 results = [] |
57 fctx = fctxmap[(hsh, path)] | 59 fctx = fctxmap[(hsh, path)] |
58 line = contents[i] | 60 line = contents[i] |
59 results.append(annotateline(fctx=fctx, lineno=lineno, text=line)) | 61 results.append(annotateline(fctx=fctx, lineno=lineno, text=line)) |
60 return results | 62 return results |
61 | 63 |
64 | |
62 def _getmaster(fctx): | 65 def _getmaster(fctx): |
63 """(fctx) -> str""" | 66 """(fctx) -> str""" |
64 return fctx._repo.ui.config('fastannotate', 'mainbranch') or 'default' | 67 return fctx._repo.ui.config('fastannotate', 'mainbranch') or 'default' |
68 | |
65 | 69 |
66 def _doannotate(fctx, follow=True, diffopts=None): | 70 def _doannotate(fctx, follow=True, diffopts=None): |
67 """like the vanilla fctx.annotate, but do it via fastannotate, and make | 71 """like the vanilla fctx.annotate, but do it via fastannotate, and make |
68 the output format compatible with the vanilla fctx.annotate. | 72 the output format compatible with the vanilla fctx.annotate. |
69 may raise Exception, and always return line numbers. | 73 may raise Exception, and always return line numbers. |
71 master = _getmaster(fctx) | 75 master = _getmaster(fctx) |
72 annotated = contents = None | 76 annotated = contents = None |
73 | 77 |
74 with context.fctxannotatecontext(fctx, follow, diffopts) as ac: | 78 with context.fctxannotatecontext(fctx, follow, diffopts) as ac: |
75 try: | 79 try: |
76 annotated, contents = ac.annotate(fctx.rev(), master=master, | 80 annotated, contents = ac.annotate( |
77 showpath=True, showlines=True) | 81 fctx.rev(), master=master, showpath=True, showlines=True |
82 ) | |
78 except Exception: | 83 except Exception: |
79 ac.rebuild() # try rebuild once | 84 ac.rebuild() # try rebuild once |
80 fctx._repo.ui.debug('fastannotate: %s: rebuilding broken cache\n' | 85 fctx._repo.ui.debug( |
81 % fctx._path) | 86 'fastannotate: %s: rebuilding broken cache\n' % fctx._path |
87 ) | |
82 try: | 88 try: |
83 annotated, contents = ac.annotate(fctx.rev(), master=master, | 89 annotated, contents = ac.annotate( |
84 showpath=True, showlines=True) | 90 fctx.rev(), master=master, showpath=True, showlines=True |
91 ) | |
85 except Exception: | 92 except Exception: |
86 raise | 93 raise |
87 | 94 |
88 assert annotated and contents | 95 assert annotated and contents |
89 return _convertoutputs(fctx._repo, annotated, contents) | 96 return _convertoutputs(fctx._repo, annotated, contents) |
90 | 97 |
98 | |
91 def _hgwebannotate(orig, fctx, ui): | 99 def _hgwebannotate(orig, fctx, ui): |
92 diffopts = patch.difffeatureopts(ui, untrusted=True, | 100 diffopts = patch.difffeatureopts( |
93 section='annotate', whitespace=True) | 101 ui, untrusted=True, section='annotate', whitespace=True |
102 ) | |
94 return _doannotate(fctx, diffopts=diffopts) | 103 return _doannotate(fctx, diffopts=diffopts) |
95 | 104 |
96 def _fctxannotate(orig, self, follow=False, linenumber=False, skiprevs=None, | 105 |
97 diffopts=None): | 106 def _fctxannotate( |
107 orig, self, follow=False, linenumber=False, skiprevs=None, diffopts=None | |
108 ): | |
98 if skiprevs: | 109 if skiprevs: |
99 # skiprevs is not supported yet | 110 # skiprevs is not supported yet |
100 return orig(self, follow, linenumber, skiprevs=skiprevs, | 111 return orig( |
101 diffopts=diffopts) | 112 self, follow, linenumber, skiprevs=skiprevs, diffopts=diffopts |
113 ) | |
102 try: | 114 try: |
103 return _doannotate(self, follow, diffopts) | 115 return _doannotate(self, follow, diffopts) |
104 except Exception as ex: | 116 except Exception as ex: |
105 self._repo.ui.debug('fastannotate: falling back to the vanilla ' | 117 self._repo.ui.debug( |
106 'annotate: %r\n' % ex) | 118 'fastannotate: falling back to the vanilla ' 'annotate: %r\n' % ex |
107 return orig(self, follow=follow, skiprevs=skiprevs, | 119 ) |
108 diffopts=diffopts) | 120 return orig(self, follow=follow, skiprevs=skiprevs, diffopts=diffopts) |
121 | |
109 | 122 |
110 def _remotefctxannotate(orig, self, follow=False, skiprevs=None, diffopts=None): | 123 def _remotefctxannotate(orig, self, follow=False, skiprevs=None, diffopts=None): |
111 # skipset: a set-like used to test if a fctx needs to be downloaded | 124 # skipset: a set-like used to test if a fctx needs to be downloaded |
112 with context.fctxannotatecontext(self, follow, diffopts) as ac: | 125 with context.fctxannotatecontext(self, follow, diffopts) as ac: |
113 skipset = revmap.revmap(ac.revmappath) | 126 skipset = revmap.revmap(ac.revmappath) |
114 return orig(self, follow, skiprevs=skiprevs, diffopts=diffopts, | 127 return orig( |
115 prefetchskip=skipset) | 128 self, follow, skiprevs=skiprevs, diffopts=diffopts, prefetchskip=skipset |
129 ) | |
130 | |
116 | 131 |
117 def replacehgwebannotate(): | 132 def replacehgwebannotate(): |
118 extensions.wrapfunction(hgweb.webutil, 'annotate', _hgwebannotate) | 133 extensions.wrapfunction(hgweb.webutil, 'annotate', _hgwebannotate) |
119 | 134 |
135 | |
120 def replacefctxannotate(): | 136 def replacefctxannotate(): |
121 extensions.wrapfunction(hgcontext.basefilectx, 'annotate', _fctxannotate) | 137 extensions.wrapfunction(hgcontext.basefilectx, 'annotate', _fctxannotate) |