view doc/docchecker @ 28008:86c4cbdaffee

revset: use manifest.matches in _follow revset The old _follow revset iterated over every file in the commit and checked if it matched. For repos with large manifests, this could take 500ms. By switching to use manifest.matches() we can take advantage of the fastpaths built in to manifest.py that allows iterating over only the files in the matcher when it's a simple matcher. This brings the time spent down from 500ms to 0ms during simple operations like 'hg log -f file.txt'.
author Durham Goode <durham@fb.com>
date Fri, 05 Feb 2016 13:30:25 -0800
parents 3d1baa702d1a
children 72b02b498b35
line wrap: on
line source

#!/usr/bin/env python
#
# docchecker - look for problematic markup
#
# Copyright 2016 timeless <timeless@mozdev.org> and others
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
import sys
import re

leadingline = re.compile(r'(^\s*)(\S.*)$')
hg_backtick = re.compile(r""":hg:`[^`]*'[^`]*`""")
hg_cramped = re.compile(r'\w:hg:`')

def check(line):
  if hg_backtick.search(line):
    print(line)
    print("""warning: please avoid nesting ' in :hg:`...`""")
  if hg_cramped.search(line):
    print(line)
    print('warning: please have a space before :hg:')

def work(file):
  (llead, lline) = ('', '')

  for line in file:
    # this section unwraps lines
    match = leadingline.match(line)
    if not match:
      check(lline)
      (llead, lline) = ('', '')
      continue

    lead, line = match.group(1), match.group(2)
    if (lead == llead):
      if (lline != ''):
        lline += ' ' + line
      else:
        lline = line
    else:
      check(lline)
      (llead, lline) = (lead, line)
  check(lline)

def main():
  for f in sys.argv[1:]:
    try:
      with open(f) as file:
        work(file)
    except:
      print("failed to process %s" % f)

main()