Debian Codegraph @

hgext/fastannotate/__init__.py

raw
1 # Copyright 2016-present Facebook. All Rights Reserved.
2 #
3 # fastannotate: faster annotate implementation using linelog
4 #
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.
7 """yet another annotate implementation that might be faster (EXPERIMENTAL)
8
9 The fastannotate extension provides a 'fastannotate' command that makes
10 use of the linelog data structure as a cache layer and is expected to
11 be faster than the vanilla 'annotate' if the cache is present.
12
13 In most cases, fastannotate requires a setup that mainbranch is some pointer
14 that always moves forward, to be most efficient.
15
16 Using fastannotate together with linkrevcache would speed up building the
17 annotate cache greatly. Run "debugbuildlinkrevcache" before
18 "debugbuildannotatecache".
19
20 ::
21
22 [fastannotate]
23 # specify the main branch head. the internal linelog will only contain
24 # the linear (ignoring p2) "mainbranch". since linelog cannot move
25 # backwards without a rebuild, this should be something that always moves
26 # forward, usually it is "master" or "@".
27 mainbranch = master
28
29 # fastannotate supports different modes to expose its feature.
30 # a list of combination:
31 # - fastannotate: expose the feature via the "fastannotate" command which
32 # deals with everything in a most efficient way, and provides extra
33 # features like --deleted etc.
34 # - fctx: replace fctx.annotate implementation. note:
35 # a. it is less efficient than the "fastannotate" command
36 # b. it will make it practically impossible to access the old (disk
37 # side-effect free) annotate implementation
38 # c. it implies "hgweb".
39 # - hgweb: replace hgweb's annotate implementation. conflict with "fctx".
40 # (default: fastannotate)
41 modes = fastannotate
42
43 # default format when no format flags are used (default: number)
44 defaultformat = changeset, user, date
45
46 # serve the annotate cache via wire protocol (default: False)
47 # tip: the .hg/fastannotate directory is portable - can be rsynced
48 server = True
49
50 # build annotate cache on demand for every client request (default: True)
51 # disabling it could make server response faster, useful when there is a
52 # cronjob building the cache.
53 serverbuildondemand = True
54
55 # update local annotate cache from remote on demand
56 client = False
57
58 # path to use when connecting to the remote server (default: default)
59 remotepath = default
60
61 # minimal length of the history of a file required to fetch linelog from
62 # the server. (default: 10)
63 clientfetchthreshold = 10
64
65 # for "fctx" mode, always follow renames regardless of command line option.
66 # this is a BC with the original command but will reduced the space needed
67 # for annotate cache, and is useful for client-server setup since the
68 # server will only provide annotate cache with default options (i.e. with
69 # follow). do not affect "fastannotate" mode. (default: True)
70 forcefollow = True
71
72 # for "fctx" mode, always treat file as text files, to skip the "isbinary"
73 # check. this is consistent with the "fastannotate" command and could help
74 # to avoid a file fetch if remotefilelog is used. (default: True)
75 forcetext = True
76
77 # use unfiltered repo for better performance.
78 unfilteredrepo = True
79
80 # sacrifice correctness in some corner cases for performance. it does not
81 # affect the correctness of the annotate cache being built. the option
82 # is experimental and may disappear in the future (default: False)
83 perfhack = True
84 """
85
86 # TODO from import:
87 # * `branch` is probably the wrong term, throughout the code.
88 #
89 # * replace the fastannotate `modes` configuration with a collection
90 # of booleans.
91 #
92 # * Use the templater instead of bespoke formatting
93 #
94 # * rename the config knob for updating the local cache from a remote server
95 #
96 # * revise wireprotocol for sharing annotate files
97 #
98 # * figure out a sensible default for `mainbranch` (with the caveat
99 # that we probably also want to figure out a better term than
100 # `branch`, see above)
101 #
102 # * format changes to the revmap file (maybe use length-encoding
103 # instead of null-terminated file paths at least?)
104
105 from __future__ import annotations
106
107 from mercurial.i18n import _
108 from mercurial import (
109 error as hgerror,
110 localrepo,
111 registrar,
112 )
113
114 from . import (
115 commands,
116 protocol,
117 )
118
119 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
120 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
121 # be specifying the version(s) of Mercurial they are tested with, or
122 # leave the attribute unspecified.
123 testedwith = b'ships-with-hg-core'
124
125 cmdtable = commands.cmdtable
126
127 configtable = {}
128 configitem = registrar.configitem(configtable)
129
130 configitem(b'fastannotate', b'modes', default=[b'fastannotate'])
131 configitem(b'fastannotate', b'server', default=False)
132 configitem(b'fastannotate', b'client', default=False)
133 configitem(b'fastannotate', b'unfilteredrepo', default=True)
134 configitem(b'fastannotate', b'defaultformat', default=[b'number'])
135 configitem(b'fastannotate', b'perfhack', default=False)
136 configitem(b'fastannotate', b'mainbranch')
137 configitem(b'fastannotate', b'forcetext', default=True)
138 configitem(b'fastannotate', b'forcefollow', default=True)
139 configitem(b'fastannotate', b'clientfetchthreshold', default=10)
140 configitem(b'fastannotate', b'serverbuildondemand', default=True)
141 configitem(b'fastannotate', b'remotepath', default=b'default')
142
143
144 def uisetup(ui):
145 modes = set(ui.configlist(b'fastannotate', b'modes'))
146 if b'fctx' in modes:
147 modes.discard(b'hgweb')
148 for name in modes:
149 if name == b'fastannotate':
150 commands.registercommand()
151 elif name == b'hgweb':
152 from . import support
153
154 support.replacehgwebannotate()
155 elif name == b'fctx':
156 from . import support
157
158 support.replacefctxannotate()
159 commands.wrapdefault()
160 else:
161 raise hgerror.Abort(_(b'fastannotate: invalid mode: %s') % name)
162
163 if ui.configbool(b'fastannotate', b'server'):
164 protocol.serveruisetup(ui)
165
166
167 def extsetup(ui):
168 # fastannotate has its own locking, without depending on repo lock
169 # TODO: avoid mutating this unless the specific repo has it enabled
170 localrepo.localrepository._wlockfreeprefix.add(b'fastannotate/')
171
172
173 def reposetup(ui, repo):
174 if ui.configbool(b'fastannotate', b'client'):
175 protocol.clientreposetup(ui, repo)