view doc/docchecker @ 27784:432242f41d9f

obsolete: make _computeobsoleteset much faster This patch makes _computeobsoleteset much faster by looping over the draft and secrets as opposed to looping over the successors. This works because "number of draft and secret" is typically way smaller(<100) than the number of successor in the repo (~90k in my checkout of core mercurial as of today). And also because it is very fast to compute "not public()". I timed the code with the following setup: """ from mercurial import hg, ui, obsolete ui = ui.ui() repo = hg.repository(ui, "~/hg") l = repo.obsstore.successors # This caches the result """ With about 90k successors. k=obsolete._computeobsoleteset(repo) before this patch: 10 loops, best of 3: 33.9 ms per loop k=obsolete._computeobsoleteset(repo) after this patch: 10000 loops, best of 3: 83.3 µs per loop
author Laurent Charignon <lc2817@columbia.edu>
date Wed, 13 Jan 2016 21:52:26 -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()