Mercurial > hg
changeset 262:3db700146536
implement demand loading hack
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
implement demand loading hack
This attempts to speed up start-up times without pushing imports down
into local scopes.
manifest hash: f9c18897e67f7872b44f5c89bdde00edfc3628ce
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCo0kHywK+sNU5EO8RAg5HAKCxRKAz3FXDyv4wScq1ZbwTgfPa2gCfW9K+
dg5nC3Uvp4FilP8waF6liAY=
=dolF
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Sun, 05 Jun 2005 10:48:39 -0800 |
parents | 3dae0296551d |
children | e8eb427c6d71 |
files | mercurial/commands.py mercurial/demandload.py mercurial/hg.py |
diffstat | 3 files changed, 29 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Sun Jun 05 10:42:52 2005 -0800 +++ b/mercurial/commands.py Sun Jun 05 10:48:39 2005 -0800 @@ -5,8 +5,10 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os, re, sys, signal, time, mdiff -from mercurial import fancyopts, ui, hg +import os, re, sys, signal +import fancyopts, ui, hg +from demandload import * +demandload(globals(), "mdiff time hgweb traceback") class UnknownCommand(Exception): pass @@ -397,7 +399,6 @@ def serve(ui, repo, **opts): """export the repository via HTTP""" - from mercurial import hgweb hgweb.server(repo.root, opts["name"], opts["templates"], opts["address"], opts["port"]) @@ -594,7 +595,6 @@ else: raise except TypeError, inst: - import traceback # was this an argument error? tb = traceback.extract_tb(sys.exc_info()[2]) if len(tb) > 2: # no
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/demandload.py Sun Jun 05 10:48:39 2005 -0800 @@ -0,0 +1,15 @@ +def demandload(scope, modules): + class d: + def __getattr__(self, name): + mod = self.__dict__["mod"] + scope = self.__dict__["scope"] + scope[mod] = __import__(mod, scope, scope, []) + return getattr(scope[mod], name) + + for m in modules.split(): + dl = d() + dl.mod = m + dl.scope = scope + scope[m] = dl + +
--- a/mercurial/hg.py Sun Jun 05 10:42:52 2005 -0800 +++ b/mercurial/hg.py Sun Jun 05 10:48:39 2005 -0800 @@ -6,10 +6,10 @@ # of the GNU General Public License, incorporated herein by reference. import sys, struct, os -from mercurial import lock -from mercurial.transaction import * -from mercurial.revlog import * -from difflib import SequenceMatcher +from revlog import * +from demandload import * +demandload(globals(), "re lock urllib urllib2 transaction time socket") +demandload(globals(), "tempfile byterange difflib") class filelog(revlog): def __init__(self, opener, path): @@ -32,7 +32,7 @@ def pair(parent, child): new = [] - sm = SequenceMatcher(None, strip(parent), strip(child)) + sm = difflib.SequenceMatcher(None, strip(parent), strip(child)) for o, m, n, s, t in sm.get_opcodes(): if o == 'equal': new += parent[m:n] @@ -138,7 +138,6 @@ def add(self, manifest, list, desc, transaction, p1=None, p2=None, user=None, date=None): - import socket, time user = (user or os.environ.get("HGUSER") or os.environ.get("EMAIL") or @@ -310,7 +309,6 @@ self.dirstate = dirstate(self.opener, ui, self.root) def ignore(self, f): - import re if self.ignorelist is None: self.ignorelist = [] try: @@ -358,14 +356,15 @@ # save dirstate for undo ds = self.opener("dirstate").read() self.opener("undo.dirstate", "w").write(ds) - return transaction(self.opener, self.join("journal"), - self.join("undo")) + + return transaction.transaction(self.opener, self.join("journal"), + self.join("undo")) def recover(self): lock = self.lock() if os.path.exists(self.join("recover")): self.ui.status("attempting to rollback interrupted transaction\n") - return rollback(self.opener, self.join("recover")) + return transaction.rollback(self.opener, self.join("recover")) else: self.ui.warn("no interrupted transaction available\n") @@ -373,7 +372,7 @@ lock = self.lock() if os.path.exists(self.join("undo")): self.ui.status("attempting to rollback last transaction\n") - rollback(self.opener, self.join("undo")) + transaction.rollback(self.opener, self.join("undo")) self.dirstate = None os.rename(self.join("undo.dirstate"), self.join("dirstate")) self.dirstate = dirstate(self.opener, self.ui, self.root) @@ -952,8 +951,6 @@ def merge3(self, fn, my, other): """perform a 3-way merge in the working directory""" - import tempfile - def temp(prefix, node): pre = "%s~%s." % (os.path.basename(fn), prefix) (fd, name) = tempfile.mkstemp("", pre) @@ -1164,14 +1161,10 @@ def repository(ui, path=None, create=0): if path and path[:7] == "http://": - import urllib, urllib2 return remoterepository(ui, path) if path and path[:5] == "hg://": - import urllib, urllib2 return remoterepository(ui, path.replace("hg://", "http://")) if path and path[:11] == "old-http://": - import urllib, urllib2 - from mercurial import byterange return localrepository(ui, path.replace("old-http://", "http://")) else: return localrepository(ui, path, create)