##// END OF EJS Templates
fastannotate: drop unused local variable assignments...
Matt Harbison -
r44441:de358da7 default
parent child Browse files
Show More
@@ -1,138 +1,137 b''
1 1 # Copyright 2016-present Facebook. All Rights Reserved.
2 2 #
3 3 # support: fastannotate support for hgweb, and filectx
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from __future__ import absolute_import
9 9
10 10 from mercurial.pycompat import getattr
11 11 from mercurial import (
12 12 context as hgcontext,
13 13 dagop,
14 14 extensions,
15 15 hgweb,
16 16 patch,
17 17 util,
18 18 )
19 19
20 20 from . import (
21 21 context,
22 22 revmap,
23 23 )
24 24
25 25
26 26 class _lazyfctx(object):
27 27 """delegates to fctx but do not construct fctx when unnecessary"""
28 28
29 29 def __init__(self, repo, node, path):
30 30 self._node = node
31 31 self._path = path
32 32 self._repo = repo
33 33
34 34 def node(self):
35 35 return self._node
36 36
37 37 def path(self):
38 38 return self._path
39 39
40 40 @util.propertycache
41 41 def _fctx(self):
42 42 return context.resolvefctx(self._repo, self._node, self._path)
43 43
44 44 def __getattr__(self, name):
45 45 return getattr(self._fctx, name)
46 46
47 47
48 48 def _convertoutputs(repo, annotated, contents):
49 49 """convert fastannotate outputs to vanilla annotate format"""
50 50 # fastannotate returns: [(nodeid, linenum, path)], [linecontent]
51 51 # convert to what fctx.annotate returns: [annotateline]
52 52 results = []
53 53 fctxmap = {}
54 54 annotateline = dagop.annotateline
55 55 for i, (hsh, linenum, path) in enumerate(annotated):
56 56 if (hsh, path) not in fctxmap:
57 57 fctxmap[(hsh, path)] = _lazyfctx(repo, hsh, path)
58 58 # linenum: the user wants 1-based, we have 0-based.
59 59 lineno = linenum + 1
60 60 fctx = fctxmap[(hsh, path)]
61 61 line = contents[i]
62 62 results.append(annotateline(fctx=fctx, lineno=lineno, text=line))
63 63 return results
64 64
65 65
66 66 def _getmaster(fctx):
67 67 """(fctx) -> str"""
68 68 return fctx._repo.ui.config(b'fastannotate', b'mainbranch') or b'default'
69 69
70 70
71 71 def _doannotate(fctx, follow=True, diffopts=None):
72 72 """like the vanilla fctx.annotate, but do it via fastannotate, and make
73 73 the output format compatible with the vanilla fctx.annotate.
74 74 may raise Exception, and always return line numbers.
75 75 """
76 76 master = _getmaster(fctx)
77 annotated = contents = None
78 77
79 78 with context.fctxannotatecontext(fctx, follow, diffopts) as ac:
80 79 try:
81 80 annotated, contents = ac.annotate(
82 81 fctx.rev(), master=master, showpath=True, showlines=True
83 82 )
84 83 except Exception:
85 84 ac.rebuild() # try rebuild once
86 85 fctx._repo.ui.debug(
87 86 b'fastannotate: %s: rebuilding broken cache\n' % fctx._path
88 87 )
89 88 try:
90 89 annotated, contents = ac.annotate(
91 90 fctx.rev(), master=master, showpath=True, showlines=True
92 91 )
93 92 except Exception:
94 93 raise
95 94
96 95 assert annotated and contents
97 96 return _convertoutputs(fctx._repo, annotated, contents)
98 97
99 98
100 99 def _hgwebannotate(orig, fctx, ui):
101 100 diffopts = patch.difffeatureopts(
102 101 ui, untrusted=True, section=b'annotate', whitespace=True
103 102 )
104 103 return _doannotate(fctx, diffopts=diffopts)
105 104
106 105
107 106 def _fctxannotate(
108 107 orig, self, follow=False, linenumber=False, skiprevs=None, diffopts=None
109 108 ):
110 109 if skiprevs:
111 110 # skiprevs is not supported yet
112 111 return orig(
113 112 self, follow, linenumber, skiprevs=skiprevs, diffopts=diffopts
114 113 )
115 114 try:
116 115 return _doannotate(self, follow, diffopts)
117 116 except Exception as ex:
118 117 self._repo.ui.debug(
119 118 b'fastannotate: falling back to the vanilla annotate: %r\n' % ex
120 119 )
121 120 return orig(self, follow=follow, skiprevs=skiprevs, diffopts=diffopts)
122 121
123 122
124 123 def _remotefctxannotate(orig, self, follow=False, skiprevs=None, diffopts=None):
125 124 # skipset: a set-like used to test if a fctx needs to be downloaded
126 125 with context.fctxannotatecontext(self, follow, diffopts) as ac:
127 126 skipset = revmap.revmap(ac.revmappath)
128 127 return orig(
129 128 self, follow, skiprevs=skiprevs, diffopts=diffopts, prefetchskip=skipset
130 129 )
131 130
132 131
133 132 def replacehgwebannotate():
134 133 extensions.wrapfunction(hgweb.webutil, b'annotate', _hgwebannotate)
135 134
136 135
137 136 def replacefctxannotate():
138 137 extensions.wrapfunction(hgcontext.basefilectx, b'annotate', _fctxannotate)
General Comments 0
You need to be logged in to leave comments. Login now