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