Mercurial > hg
annotate doc/docchecker @ 28364:f1460af18c50
branchmap: check node against changelog instead of repo
Testing 'node in repo' requires constructing a changectx, which is a little
expensive. Testing 'repo.changelog.hasnode(node)' is notably faster. This
saves 10-20ms off of every command, when testing a few thousand nodes from the
branch cache.
I considered changing the implementation of localrepository.__contains__ so
every place would benefit from the change, but since
localrepository.__contains__ uses changectx to check if the commit exists, it
means it supports a wider range of possible inputs (like revs, hashes, '.',
etc), so it seemed unnecessarily risky.
author | Durham Goode <durham@fb.com> |
---|---|
date | Mon, 07 Mar 2016 17:26:47 -0800 |
parents | c00f67c15c5a |
children | 9934362978e1 |
rev | line source |
---|---|
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
2 # |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
3 # docchecker - look for problematic markup |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
4 # |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
5 # Copyright 2016 timeless <timeless@mozdev.org> and others |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
6 # |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
7 # This software may be used and distributed according to the terms of the |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
8 # GNU General Public License version 2 or any later version. |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
9 import sys |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
10 import re |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
11 |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
12 leadingline = re.compile(r'(^\s*)(\S.*)$') |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
13 hg_backtick = re.compile(r""":hg:`[^`]*'[^`]*`""") |
27733
3d1baa702d1a
docchecker: scan for missing space before :hg:
timeless <timeless@mozdev.org>
parents:
27730
diff
changeset
|
14 hg_cramped = re.compile(r'\w:hg:`') |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
15 |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
16 def check(line): |
28049
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
17 if hg_backtick.search(line): |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
18 print(line) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
19 print("""warning: please avoid nesting ' in :hg:`...`""") |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
20 if hg_cramped.search(line): |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
21 print(line) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
22 print('warning: please have a space before :hg:') |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
23 |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
24 def work(file): |
28049
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
25 (llead, lline) = ('', '') |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
26 |
28049
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
27 for line in file: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
28 # this section unwraps lines |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
29 match = leadingline.match(line) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
30 if not match: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
31 check(lline) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
32 (llead, lline) = ('', '') |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
33 continue |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
34 |
28049
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
35 lead, line = match.group(1), match.group(2) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
36 if (lead == llead): |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
37 if (lline != ''): |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
38 lline += ' ' + line |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
39 else: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
40 lline = line |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
41 else: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
42 check(lline) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
43 (llead, lline) = (lead, line) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
44 check(lline) |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
45 |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
46 def main(): |
28049
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
47 for f in sys.argv[1:]: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
48 try: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
49 with open(f) as file: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
50 work(file) |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
51 except BaseException as e: |
c00f67c15c5a
docchecker: use indentation of 4 spaces
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28048
diff
changeset
|
52 print("failed to process %s: %s" % (f, e)) |
27730
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
53 |
ed86fb2a4187
docchecker: introduce a way to check for poor markup
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
54 main() |