##// END OF EJS Templates
branches: improve performance by removing redundant operations...
branches: improve performance by removing redundant operations This refactors the branches command so it collects all the information it needs about a branch in one pass over the branch map. In particular, it fixes an issue where the command called repo.branchtags() to get branch tips, and then used repo.branchheads() to get the closed/open status. Both repo methods read the changelog to determine if the branch is closed, resulting in extra, redundant I/O. For the PyPy repo with 744 branches and 843 branch heads, this brings hg branches over NFS from: CallCount Recursive Total(ms) Inline(ms) module:lineno(function) 2427 0 0.9057 0.9057 <open> 2424 0 0.4096 0.4096 <method 'close' of 'file' objects> 2424 0 0.0476 0.0476 <method 'read' of 'file' objects> 1 0 0.0468 0.0468 mercurial.revlog:637(headrevs) +1 0 0.0000 0.0000 +<len> 2422 0 0.0443 0.0443 <method 'seek' of 'file' objects> 2962 0 0.0337 0.0337 <zlib.decompress> 2491 0 1.8008 0.0322 mercurial.changelog:182(read) +2491 0 1.6982 0.0315 +mercurial.revlog:881(revision) +2488 0 0.0269 0.0134 +mercurial.changelog:28(decodeextra) +4982 0 0.0085 0.0085 +<method 'split' of 'str' objects> +4982 0 0.0274 0.0049 +mercurial.encoding:61(tolocal) +2491 0 0.0039 0.0039 +<method 'index' of 'str' objects> 2491 0 1.6982 0.0315 mercurial.revlog:881(revision) +2413 0 0.0112 0.0112 +mercurial.revlog:305(rev) +2491 0 1.5315 0.0068 +mercurial.revlog:847(_chunkraw) +2491 0 0.0414 0.0058 +mercurial.revlog:945(_checkhash) +2491 0 0.0028 0.0028 +mercurial.revlog:349(flags) +2491 0 0.0025 0.0025 +<mercurial.mpatch.patches> 2422 0 1.5089 0.0286 mercurial.revlog:818(_loadchunk) +2422 0 0.4093 0.4093 +<method 'close' of 'file' objects> +2422 0 0.0451 0.0451 +<method 'read' of 'file' objects> +2422 0 0.0443 0.0443 +<method 'seek' of 'file' objects> +2422 0 0.9703 0.0096 +mercurial.store:374(__call__) +2422 0 0.0079 0.0069 +mercurial.revlog:810(_addchunk) 5804 0 0.0204 0.0204 mercurial.revlog:305(rev) 2426 0 0.9552 0.0177 mercurial.scmutil:218(__call__) +2426 0 0.9057 0.9057 +<open> +2426 0 0.0120 0.0083 +os.path:80(split) +2426 0 0.0061 0.0049 +mercurial.scmutil:92(__call__) Time: real 1.950 secs (user 0.560+0.000 sys 0.220+0.000) down to: CallCount Recursive Total(ms) Inline(ms) module:lineno(function) 1545 0 0.6035 0.6035 <open> 1542 0 0.2697 0.2697 <method 'close' of 'file' objects> 1 0 0.0547 0.0547 mercurial.revlog:637(headrevs) +1 0 0.0000 0.0000 +<len> 1542 0 0.0389 0.0389 <method 'read' of 'file' objects> 1540 0 0.0316 0.0316 <method 'seek' of 'file' objects> 1853 0 0.0227 0.0227 <zlib.decompress> 1557 0 1.2131 0.0226 mercurial.changelog:182(read) +1557 0 1.1398 0.0221 +mercurial.revlog:881(revision) +1555 0 0.0199 0.0094 +mercurial.changelog:28(decodeextra) +3114 0 0.0058 0.0058 +<method 'split' of 'str' objects> +3114 0 0.0196 0.0035 +mercurial.encoding:61(tolocal) +1557 0 0.0026 0.0026 +<method 'index' of 'str' objects> 1557 0 1.1398 0.0221 mercurial.revlog:881(revision) +1557 0 1.0307 0.0047 +mercurial.revlog:847(_chunkraw) +1557 0 0.0287 0.0040 +mercurial.revlog:945(_checkhash) +1557 0 0.0018 0.0018 +<mercurial.mpatch.patches> +1557 0 0.0018 0.0018 +mercurial.revlog:326(node) +1557 0 0.0417 0.0013 +mercurial.revlog:857(_chunkbase) 1540 0 1.0147 0.0210 mercurial.revlog:818(_loadchunk) +1540 0 0.2693 0.2693 +<method 'close' of 'file' objects> +1540 0 0.0360 0.0360 +<method 'read' of 'file' objects> +1540 0 0.0316 0.0316 +<method 'seek' of 'file' objects> +1540 0 0.6487 0.0070 +mercurial.store:374(__call__) +1540 0 0.0059 0.0052 +mercurial.revlog:810(_addchunk) 3192 0 0.0173 0.0173 mercurial.revlog:305(rev) 8184 0 0.0300 0.0147 <method 'decode' of 'str' objects> +5204 0 0.0149 0.0048 +encodings.utf_8:15(decode) +1 0 0.0004 0.0000 +encodings:71(search_function) 43 26 0.0147 0.0129 <__import__> Time: real 1.390 secs (user 0.450+0.000 sys 0.170+0.000)

File last commit:

r16514:363e808d stable
r16721:3e6d59ae default
Show More
darcs.py
200 lines | 7.5 KiB | text/x-python | PythonLexer
# darcs.py - darcs support for the convert extension
#
# Copyright 2007-2009 Matt Mackall <mpm@selenic.com> 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.
from common import NoRepo, checktool, commandline, commit, converter_source
from mercurial.i18n import _
from mercurial import util
import os, shutil, tempfile, re
# The naming drift of ElementTree is fun!
try:
from xml.etree.cElementTree import ElementTree, XMLParser
except ImportError:
try:
from xml.etree.ElementTree import ElementTree, XMLParser
except ImportError:
try:
from elementtree.cElementTree import ElementTree, XMLParser
except ImportError:
try:
from elementtree.ElementTree import ElementTree, XMLParser
except ImportError:
pass
class darcs_source(converter_source, commandline):
def __init__(self, ui, path, rev=None):
converter_source.__init__(self, ui, path, rev=rev)
commandline.__init__(self, ui, 'darcs')
# check for _darcs, ElementTree so that we can easily skip
# test-convert-darcs if ElementTree is not around
if not os.path.exists(os.path.join(path, '_darcs')):
raise NoRepo(_("%s does not look like a darcs repository") % path)
checktool('darcs')
version = self.run0('--version').splitlines()[0].strip()
if version < '2.1':
raise util.Abort(_('darcs version 2.1 or newer needed (found %r)') %
version)
if "ElementTree" not in globals():
raise util.Abort(_("Python ElementTree module is not available"))
self.path = os.path.realpath(path)
self.lastrev = None
self.changes = {}
self.parents = {}
self.tags = {}
# Check darcs repository format
format = self.format()
if format:
if format in ('darcs-1.0', 'hashed'):
raise NoRepo(_("%s repository format is unsupported, "
"please upgrade") % format)
else:
self.ui.warn(_('failed to detect repository format!'))
def before(self):
self.tmppath = tempfile.mkdtemp(
prefix='convert-' + os.path.basename(self.path) + '-')
output, status = self.run('init', repodir=self.tmppath)
self.checkexit(status)
tree = self.xml('changes', xml_output=True, summary=True,
repodir=self.path)
tagname = None
child = None
for elt in tree.findall('patch'):
node = elt.get('hash')
name = elt.findtext('name', '')
if name.startswith('TAG '):
tagname = name[4:].strip()
elif tagname is not None:
self.tags[tagname] = node
tagname = None
self.changes[node] = elt
self.parents[child] = [node]
child = node
self.parents[child] = []
def after(self):
self.ui.debug('cleaning up %s\n' % self.tmppath)
shutil.rmtree(self.tmppath, ignore_errors=True)
def recode(self, s, encoding=None):
if isinstance(s, unicode):
# XMLParser returns unicode objects for anything it can't
# encode into ASCII. We convert them back to str to get
# recode's normal conversion behavior.
s = s.encode('latin-1')
return super(darcs_source, self).recode(s, encoding)
def xml(self, cmd, **kwargs):
# NOTE: darcs is currently encoding agnostic and will print
# patch metadata byte-for-byte, even in the XML changelog.
etree = ElementTree()
# While we are decoding the XML as latin-1 to be as liberal as
# possible, etree will still raise an exception if any
# non-printable characters are in the XML changelog.
parser = XMLParser(encoding='latin-1')
fp = self._run(cmd, **kwargs)
etree.parse(fp, parser=parser)
self.checkexit(fp.close())
return etree.getroot()
def format(self):
output, status = self.run('show', 'repo', no_files=True,
repodir=self.path)
self.checkexit(status)
m = re.search(r'^\s*Format:\s*(.*)$', output, re.MULTILINE)
if not m:
return None
return ','.join(sorted(f.strip() for f in m.group(1).split(',')))
def manifest(self):
man = []
output, status = self.run('show', 'files', no_directories=True,
repodir=self.tmppath)
self.checkexit(status)
for line in output.split('\n'):
path = line[2:]
if path:
man.append(path)
return man
def getheads(self):
return self.parents[None]
def getcommit(self, rev):
elt = self.changes[rev]
date = util.strdate(elt.get('local_date'), '%a %b %d %H:%M:%S %Z %Y')
desc = elt.findtext('name') + '\n' + elt.findtext('comment', '')
# etree can return unicode objects for name, comment, and author,
# so recode() is used to ensure str objects are emitted.
return commit(author=self.recode(elt.get('author')),
date=util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2'),
desc=self.recode(desc).strip(),
parents=self.parents[rev])
def pull(self, rev):
output, status = self.run('pull', self.path, all=True,
match='hash %s' % rev,
no_test=True, no_posthook=True,
external_merge='/bin/false',
repodir=self.tmppath)
if status:
if output.find('We have conflicts in') == -1:
self.checkexit(status, output)
output, status = self.run('revert', all=True, repodir=self.tmppath)
self.checkexit(status, output)
def getchanges(self, rev):
copies = {}
changes = []
man = None
for elt in self.changes[rev].find('summary').getchildren():
if elt.tag in ('add_directory', 'remove_directory'):
continue
if elt.tag == 'move':
if man is None:
man = self.manifest()
source, dest = elt.get('from'), elt.get('to')
if source in man:
# File move
changes.append((source, rev))
changes.append((dest, rev))
copies[dest] = source
else:
# Directory move, deduce file moves from manifest
source = source + '/'
for f in man:
if not f.startswith(source):
continue
fdest = dest + '/' + f[len(source):]
changes.append((f, rev))
changes.append((fdest, rev))
copies[fdest] = f
else:
changes.append((elt.text.strip(), rev))
self.pull(rev)
self.lastrev = rev
return sorted(changes), copies
def getfile(self, name, rev):
if rev != self.lastrev:
raise util.Abort(_('internal calling inconsistency'))
path = os.path.join(self.tmppath, name)
data = util.readfile(path)
mode = os.lstat(path).st_mode
mode = (mode & 0111) and 'x' or ''
return data, mode
def gettags(self):
return self.tags