tests/blackbox-readonly-dispatch.py
author Gregory Szorc <gregory.szorc@gmail.com>
Thu, 23 Mar 2017 19:54:59 -0700
branchstable
changeset 31587 ed5b25874d99
parent 28406 0767c2f624c6
child 35724 853bf7d90804
permissions -rw-r--r--
changegroup: store old heads as a set Previously, the "oldheads" variable was a list. On a repository at Mozilla with 46,492 heads, profiling revealed that list membership testing was dominating execution time of applying small changegroups. This patch converts the list of old heads to a set. This makes membership testing significantly faster. On the aforementioned repository with 46,492 heads: $ hg unbundle <file with 1 changeset> before: 18.535s wall after: 1.303s Consumers of this variable only check for truthiness (`if oldheads`), length (`len(oldheads)`), and (most importantly) item membership (`h not in oldheads` - which occurs twice). So, the change to a set should be safe and suitable for stable. The practical effect of this change is that changegroup application and related operations (like `hg push`) no longer exhibit an O(n^2) CPU explosion as the number of heads grows.

from __future__ import absolute_import, print_function
import os
from mercurial import (
    dispatch,
)

def testdispatch(cmd):
    """Simple wrapper around dispatch.dispatch()

    Prints command and result value, but does not handle quoting.
    """
    print("running: %s" % (cmd,))
    req = dispatch.request(cmd.split())
    result = dispatch.dispatch(req)
    print("result: %r" % (result,))

# create file 'foo', add and commit
f = open('foo', 'wb')
f.write('foo\n')
f.close()
testdispatch("add foo")
testdispatch("commit -m commit1 -d 2000-01-01 foo")

# append to file 'foo' and commit
f = open('foo', 'ab')
f.write('bar\n')
f.close()
# remove blackbox.log directory (proxy for readonly log file)
os.rmdir(".hg/blackbox.log")
# replace it with the real blackbox.log file
os.rename(".hg/blackbox.log-", ".hg/blackbox.log")
testdispatch("commit -m commit2 -d 2000-01-02 foo")

# check 88803a69b24 (fancyopts modified command table)
testdispatch("log -r 0")
testdispatch("log -r tip")