Mercurial > hg
annotate hgext/fastannotate/commands.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 | 566daffc607d |
children | 687b865b95ad |
rev | line source |
---|---|
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 # Copyright 2016-present Facebook. All Rights Reserved. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 # |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 # commands: fastannotate commands |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 # |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 import os |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 from mercurial.i18n import _ |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 from mercurial import ( |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 commands, |
39818
24e493ec2229
py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
39666
diff
changeset
|
15 encoding, |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 error, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 extensions, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 patch, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
19 pycompat, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 registrar, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
21 scmutil, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 util, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 ) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 from . import ( |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 context as facontext, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 error as faerror, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 formatter as faformatter, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
29 ) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
31 cmdtable = {} |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 command = registrar.command(cmdtable) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
34 |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 def _matchpaths(repo, rev, pats, opts, aopts=facontext.defaultopts): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 """generate paths matching given patterns""" |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 perfhack = repo.ui.configbool('fastannotate', 'perfhack') |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 # disable perfhack if: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 # a) any walkopt is used |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 # b) if we treat pats as plain file names, some of them do not have |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 # corresponding linelog files |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 if perfhack: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 # cwd related to reporoot |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 reporoot = os.path.dirname(repo.path) |
39818
24e493ec2229
py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
39666
diff
changeset
|
46 reldir = os.path.relpath(encoding.getcwd(), reporoot) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 if reldir == '.': |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
48 reldir = '' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
49 if any(opts.get(o[1]) for o in commands.walkopts): # a) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 perfhack = False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
51 else: # b) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
52 relpats = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
53 os.path.relpath(p, reporoot) if os.path.isabs(p) else p |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
54 for p in pats |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
55 ] |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 # disable perfhack on '..' since it allows escaping from the repo |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
57 if any( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
58 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
59 '..' in f |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
60 or not os.path.isfile( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
61 facontext.pathhelper(repo, f, aopts).linelogpath |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
62 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
63 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
64 for f in relpats |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
65 ): |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
66 perfhack = False |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
67 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
68 # perfhack: emit paths directory without checking with manifest |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
69 # this can be incorrect if the rev dos not have file. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
70 if perfhack: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
71 for p in relpats: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
72 yield os.path.join(reldir, p) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
73 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
74 |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
75 def bad(x, y): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
76 raise error.Abort("%s: %s" % (x, y)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
77 |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
78 ctx = scmutil.revsingle(repo, rev) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
79 m = scmutil.match(ctx, pats, opts, badfn=bad) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
80 for p in ctx.walk(m): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
81 yield p |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
83 |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
84 fastannotatecommandargs = { |
39406
b3572f733dbd
py3: add r'' prefix to prevent b'' being prepended
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39210
diff
changeset
|
85 r'options': [ |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
86 ('r', 'rev', '.', _('annotate the specified revision'), _('REV')), |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
87 ('u', 'user', None, _('list the author (long with -v)')), |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
88 ('f', 'file', None, _('list the filename')), |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
89 ('d', 'date', None, _('list the date (short with -q)')), |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
90 ('n', 'number', None, _('list the revision number (default)')), |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
91 ('c', 'changeset', None, _('list the changeset')), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
92 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
93 'l', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
94 'line-number', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
95 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
96 _('show line number at the first ' 'appearance'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
97 ), |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
98 ('e', 'deleted', None, _('show deleted lines (slow) (EXPERIMENTAL)')), |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
99 ('', 'no-content', None, _('do not show file content (EXPERIMENTAL)')), |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
100 ('', 'no-follow', None, _("don't follow copies and renames")), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
101 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
102 '', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
103 'linear', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
104 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
105 _( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
106 'enforce linear history, ignore second parent ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
107 'of merges (EXPERIMENTAL)' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
108 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
109 ), |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
110 ('', 'long-hash', None, _('show long changeset hash (EXPERIMENTAL)')), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
111 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
112 '', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
113 'rebuild', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
114 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
115 _('rebuild cache even if it exists ' '(EXPERIMENTAL)'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
116 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
117 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
118 + commands.diffwsopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
119 + commands.walkopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
120 + commands.formatteropts, |
39406
b3572f733dbd
py3: add r'' prefix to prevent b'' being prepended
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39210
diff
changeset
|
121 r'synopsis': _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'), |
b3572f733dbd
py3: add r'' prefix to prevent b'' being prepended
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39210
diff
changeset
|
122 r'inferrepo': True, |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
123 } |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
124 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
125 |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
126 def fastannotate(ui, repo, *pats, **opts): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 """show changeset information by line for each file |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
128 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
129 List changes in files, showing the revision id responsible for each line. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 This command is useful for discovering when a change was made and by whom. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
132 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
133 By default this command prints revision numbers. If you include --file, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 --user, or --date, the revision number is suppressed unless you also |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
135 include --number. The default format can also be customized by setting |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
136 fastannotate.defaultformat. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
137 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
138 Returns 0 on success. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
139 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
140 .. container:: verbose |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
141 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
142 This command uses an implementation different from the vanilla annotate |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
143 command, which may produce slightly different (while still reasonable) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
144 outputs for some cases. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
145 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
146 Unlike the vanilla anootate, fastannotate follows rename regardless of |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
147 the existence of --file. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
148 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
149 For the best performance when running on a full repo, use -c, -l, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
150 avoid -u, -d, -n. Use --linear and --no-content to make it even faster. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
151 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
152 For the best performance when running on a shallow (remotefilelog) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
153 repo, avoid --linear, --no-follow, or any diff options. As the server |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
154 won't be able to populate annotate cache when non-default options |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
155 affecting results are used. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
156 """ |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
157 if not pats: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
158 raise error.Abort(_('at least one filename or pattern is required')) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
159 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
160 # performance hack: filtered repo can be slow. unfilter by default. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
161 if ui.configbool('fastannotate', 'unfilteredrepo'): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
162 repo = repo.unfiltered() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
163 |
39666
b77f2ea51da5
py3: fix kwargs handling in hgext/fastannotate.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39406
diff
changeset
|
164 opts = pycompat.byteskwargs(opts) |
b77f2ea51da5
py3: fix kwargs handling in hgext/fastannotate.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39406
diff
changeset
|
165 |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
166 rev = opts.get('rev', '.') |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
167 rebuild = opts.get('rebuild', False) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
168 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
169 diffopts = patch.difffeatureopts( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
170 ui, opts, section='annotate', whitespace=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
171 ) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
172 aopts = facontext.annotateopts( |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
173 diffopts=diffopts, |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
174 followmerge=not opts.get('linear', False), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
175 followrename=not opts.get('no_follow', False), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
176 ) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
177 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
178 if not any( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
179 opts.get(s) for s in ['user', 'date', 'file', 'number', 'changeset'] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
180 ): |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
181 # default 'number' for compatibility. but fastannotate is more |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
182 # efficient with "changeset", "line-number" and "no-content". |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
183 for name in ui.configlist('fastannotate', 'defaultformat', ['number']): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
184 opts[name] = True |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
185 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
186 ui.pager('fastannotate') |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
187 template = opts.get('template') |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
188 if template == 'json': |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
189 formatter = faformatter.jsonformatter(ui, repo, opts) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
190 else: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
191 formatter = faformatter.defaultformatter(ui, repo, opts) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
192 showdeleted = opts.get('deleted', False) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
193 showlines = not bool(opts.get('no_content')) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
194 showpath = opts.get('file', False) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
195 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
196 # find the head of the main (master) branch |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
197 master = ui.config('fastannotate', 'mainbranch') or rev |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
198 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
199 # paths will be used for prefetching and the real annotating |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
200 paths = list(_matchpaths(repo, rev, pats, opts, aopts)) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
201 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
202 # for client, prefetch from the server |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
203 if util.safehasattr(repo, 'prefetchfastannotate'): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
204 repo.prefetchfastannotate(paths) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
205 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
206 for path in paths: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
207 result = lines = existinglines = None |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
208 while True: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
209 try: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
210 with facontext.annotatecontext(repo, path, aopts, rebuild) as a: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
211 result = a.annotate( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
212 rev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
213 master=master, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
214 showpath=showpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
215 showlines=(showlines and not showdeleted), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
216 ) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
217 if showdeleted: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
218 existinglines = set((l[0], l[1]) for l in result) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
219 result = a.annotatealllines( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
220 rev, showpath=showpath, showlines=showlines |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
221 ) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
222 break |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
223 except (faerror.CannotReuseError, faerror.CorruptedFileError): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
224 # happens if master moves backwards, or the file was deleted |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
225 # and readded, or renamed to an existing name, or corrupted. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
226 if rebuild: # give up since we have tried rebuild already |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
227 raise |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
228 else: # try a second time rebuilding the cache (slow) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
229 rebuild = True |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
230 continue |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
231 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
232 if showlines: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
233 result, lines = result |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
234 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
235 formatter.write(result, lines, existinglines=existinglines) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
236 formatter.end() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
237 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
238 |
42057
566daffc607d
cleanup: use set literals where possible
Martin von Zweigbergk <martinvonz@google.com>
parents:
40838
diff
changeset
|
239 _newopts = set() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
240 _knownopts = { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
241 opt[1].replace('-', '_') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
242 for opt in (fastannotatecommandargs[r'options'] + commands.globalopts) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
243 } |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
244 |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
245 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
246 def _annotatewrapper(orig, ui, repo, *pats, **opts): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
247 """used by wrapdefault""" |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
248 # we need this hack until the obsstore has 0.0 seconds perf impact |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
249 if ui.configbool('fastannotate', 'unfilteredrepo'): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
250 repo = repo.unfiltered() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
251 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
252 # treat the file as text (skip the isbinary check) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
253 if ui.configbool('fastannotate', 'forcetext'): |
39666
b77f2ea51da5
py3: fix kwargs handling in hgext/fastannotate.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39406
diff
changeset
|
254 opts[r'text'] = True |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
255 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
256 # check if we need to do prefetch (client-side) |
39666
b77f2ea51da5
py3: fix kwargs handling in hgext/fastannotate.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39406
diff
changeset
|
257 rev = opts.get(r'rev') |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
258 if util.safehasattr(repo, 'prefetchfastannotate') and rev is not None: |
39666
b77f2ea51da5
py3: fix kwargs handling in hgext/fastannotate.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39406
diff
changeset
|
259 paths = list(_matchpaths(repo, rev, pats, pycompat.byteskwargs(opts))) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
260 repo.prefetchfastannotate(paths) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
261 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
262 return orig(ui, repo, *pats, **opts) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
263 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
264 |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
265 def registercommand(): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
266 """register the fastannotate command""" |
40295
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
39818
diff
changeset
|
267 name = 'fastannotate|fastblame|fa' |
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
39818
diff
changeset
|
268 command(name, helpbasic=True, **fastannotatecommandargs)(fastannotate) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
269 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
270 |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
271 def wrapdefault(): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
272 """wrap the default annotate command, to be aware of the protocol""" |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
273 extensions.wrapcommand(commands.table, 'annotate', _annotatewrapper) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
274 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
275 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
276 @command( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
277 'debugbuildannotatecache', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
278 [('r', 'rev', '', _('build up to the specific revision'), _('REV'))] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
279 + commands.walkopts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
280 _('[-r REV] FILE...'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
281 ) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
282 def debugbuildannotatecache(ui, repo, *pats, **opts): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
283 """incrementally build fastannotate cache up to REV for specified files |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
284 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
285 If REV is not specified, use the config 'fastannotate.mainbranch'. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
286 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
287 If fastannotate.client is True, download the annotate cache from the |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
288 server. Otherwise, build the annotate cache locally. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
289 |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
290 The annotate cache will be built using the default diff and follow |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
291 options and lives in '.hg/fastannotate/default'. |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
292 """ |
39666
b77f2ea51da5
py3: fix kwargs handling in hgext/fastannotate.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39406
diff
changeset
|
293 opts = pycompat.byteskwargs(opts) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
294 rev = opts.get('REV') or ui.config('fastannotate', 'mainbranch') |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
295 if not rev: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
296 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
297 _('you need to provide a revision'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
298 hint=_('set fastannotate.mainbranch or use --rev'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
299 ) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
300 if ui.configbool('fastannotate', 'unfilteredrepo'): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
301 repo = repo.unfiltered() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
302 ctx = scmutil.revsingle(repo, rev) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
303 m = scmutil.match(ctx, pats, opts) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
304 paths = list(ctx.walk(m)) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
305 if util.safehasattr(repo, 'prefetchfastannotate'): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
306 # client |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
307 if opts.get('REV'): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
308 raise error.Abort(_('--rev cannot be used for client')) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
309 repo.prefetchfastannotate(paths) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
310 else: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
311 # server, or full repo |
40838
901f6ef670ca
debugbuildannotatecache: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
40295
diff
changeset
|
312 progress = ui.makeprogress(_('building'), total=len(paths)) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
313 for i, path in enumerate(paths): |
40838
901f6ef670ca
debugbuildannotatecache: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
40295
diff
changeset
|
314 progress.update(i) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
315 with facontext.annotatecontext(repo, path) as actx: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
316 try: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
317 if actx.isuptodate(rev): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
318 continue |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
319 actx.annotate(rev, rev) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
320 except (faerror.CannotReuseError, faerror.CorruptedFileError): |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
321 # the cache is broken (could happen with renaming so the |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
322 # file history gets invalidated). rebuild and try again. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
323 ui.debug( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
324 'fastannotate: %s: rebuilding broken cache\n' % path |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
325 ) |
39210
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
326 actx.rebuild() |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
327 try: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
328 actx.annotate(rev, rev) |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
329 except Exception as ex: |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
330 # possibly a bug, but should not stop us from building |
1ddb296e0dee
fastannotate: initial import from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
331 # cache for other files. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
332 ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
333 _( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
334 'fastannotate: %s: failed to ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
335 'build cache: %r\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
336 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
337 % (path, ex) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42057
diff
changeset
|
338 ) |
40838
901f6ef670ca
debugbuildannotatecache: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
40295
diff
changeset
|
339 progress.complete() |