Mercurial > hg-stable
comparison mercurial/hg.py @ 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 | 649ed23e4661 |
children | e8eb427c6d71 |
comparison
equal
deleted
inserted
replaced
261:3dae0296551d | 262:3db700146536 |
---|---|
4 # | 4 # |
5 # This software may be used and distributed according to the terms | 5 # This software may be used and distributed according to the terms |
6 # of the GNU General Public License, incorporated herein by reference. | 6 # of the GNU General Public License, incorporated herein by reference. |
7 | 7 |
8 import sys, struct, os | 8 import sys, struct, os |
9 from mercurial import lock | 9 from revlog import * |
10 from mercurial.transaction import * | 10 from demandload import * |
11 from mercurial.revlog import * | 11 demandload(globals(), "re lock urllib urllib2 transaction time socket") |
12 from difflib import SequenceMatcher | 12 demandload(globals(), "tempfile byterange difflib") |
13 | 13 |
14 class filelog(revlog): | 14 class filelog(revlog): |
15 def __init__(self, opener, path): | 15 def __init__(self, opener, path): |
16 revlog.__init__(self, opener, | 16 revlog.__init__(self, opener, |
17 os.path.join("data", path + ".i"), | 17 os.path.join("data", path + ".i"), |
30 def strip(annotation): | 30 def strip(annotation): |
31 return [e[1] for e in annotation] | 31 return [e[1] for e in annotation] |
32 | 32 |
33 def pair(parent, child): | 33 def pair(parent, child): |
34 new = [] | 34 new = [] |
35 sm = SequenceMatcher(None, strip(parent), strip(child)) | 35 sm = difflib.SequenceMatcher(None, strip(parent), strip(child)) |
36 for o, m, n, s, t in sm.get_opcodes(): | 36 for o, m, n, s, t in sm.get_opcodes(): |
37 if o == 'equal': | 37 if o == 'equal': |
38 new += parent[m:n] | 38 new += parent[m:n] |
39 else: | 39 else: |
40 new += child[s:t] | 40 new += child[s:t] |
136 def read(self, node): | 136 def read(self, node): |
137 return self.extract(self.revision(node)) | 137 return self.extract(self.revision(node)) |
138 | 138 |
139 def add(self, manifest, list, desc, transaction, p1=None, p2=None, | 139 def add(self, manifest, list, desc, transaction, p1=None, p2=None, |
140 user=None, date=None): | 140 user=None, date=None): |
141 import socket, time | |
142 user = (user or | 141 user = (user or |
143 os.environ.get("HGUSER") or | 142 os.environ.get("HGUSER") or |
144 os.environ.get("EMAIL") or | 143 os.environ.get("EMAIL") or |
145 os.environ.get("LOGNAME", "unknown") + '@' + socket.getfqdn()) | 144 os.environ.get("LOGNAME", "unknown") + '@' + socket.getfqdn()) |
146 date = date or "%d %d" % (time.time(), time.timezone) | 145 date = date or "%d %d" % (time.time(), time.timezone) |
308 | 307 |
309 if not self.remote: | 308 if not self.remote: |
310 self.dirstate = dirstate(self.opener, ui, self.root) | 309 self.dirstate = dirstate(self.opener, ui, self.root) |
311 | 310 |
312 def ignore(self, f): | 311 def ignore(self, f): |
313 import re | |
314 if self.ignorelist is None: | 312 if self.ignorelist is None: |
315 self.ignorelist = [] | 313 self.ignorelist = [] |
316 try: | 314 try: |
317 l = open(os.path.join(self.root, ".hgignore")) | 315 l = open(os.path.join(self.root, ".hgignore")) |
318 for pat in l: | 316 for pat in l: |
356 | 354 |
357 def transaction(self): | 355 def transaction(self): |
358 # save dirstate for undo | 356 # save dirstate for undo |
359 ds = self.opener("dirstate").read() | 357 ds = self.opener("dirstate").read() |
360 self.opener("undo.dirstate", "w").write(ds) | 358 self.opener("undo.dirstate", "w").write(ds) |
361 return transaction(self.opener, self.join("journal"), | 359 |
362 self.join("undo")) | 360 return transaction.transaction(self.opener, self.join("journal"), |
361 self.join("undo")) | |
363 | 362 |
364 def recover(self): | 363 def recover(self): |
365 lock = self.lock() | 364 lock = self.lock() |
366 if os.path.exists(self.join("recover")): | 365 if os.path.exists(self.join("recover")): |
367 self.ui.status("attempting to rollback interrupted transaction\n") | 366 self.ui.status("attempting to rollback interrupted transaction\n") |
368 return rollback(self.opener, self.join("recover")) | 367 return transaction.rollback(self.opener, self.join("recover")) |
369 else: | 368 else: |
370 self.ui.warn("no interrupted transaction available\n") | 369 self.ui.warn("no interrupted transaction available\n") |
371 | 370 |
372 def undo(self): | 371 def undo(self): |
373 lock = self.lock() | 372 lock = self.lock() |
374 if os.path.exists(self.join("undo")): | 373 if os.path.exists(self.join("undo")): |
375 self.ui.status("attempting to rollback last transaction\n") | 374 self.ui.status("attempting to rollback last transaction\n") |
376 rollback(self.opener, self.join("undo")) | 375 transaction.rollback(self.opener, self.join("undo")) |
377 self.dirstate = None | 376 self.dirstate = None |
378 os.rename(self.join("undo.dirstate"), self.join("dirstate")) | 377 os.rename(self.join("undo.dirstate"), self.join("dirstate")) |
379 self.dirstate = dirstate(self.opener, self.ui, self.root) | 378 self.dirstate = dirstate(self.opener, self.ui, self.root) |
380 else: | 379 else: |
381 self.ui.warn("no undo information available\n") | 380 self.ui.warn("no undo information available\n") |
950 self.dirstate.update(remove, 'r') | 949 self.dirstate.update(remove, 'r') |
951 | 950 |
952 def merge3(self, fn, my, other): | 951 def merge3(self, fn, my, other): |
953 """perform a 3-way merge in the working directory""" | 952 """perform a 3-way merge in the working directory""" |
954 | 953 |
955 import tempfile | |
956 | |
957 def temp(prefix, node): | 954 def temp(prefix, node): |
958 pre = "%s~%s." % (os.path.basename(fn), prefix) | 955 pre = "%s~%s." % (os.path.basename(fn), prefix) |
959 (fd, name) = tempfile.mkstemp("", pre) | 956 (fd, name) = tempfile.mkstemp("", pre) |
960 f = os.fdopen(fd, "w") | 957 f = os.fdopen(fd, "w") |
961 f.write(fl.revision(node)) | 958 f.write(fl.revision(node)) |
1162 yield zd.decompress(d) | 1159 yield zd.decompress(d) |
1163 self.ui.note("%d bytes of data transfered\n" % bytes) | 1160 self.ui.note("%d bytes of data transfered\n" % bytes) |
1164 | 1161 |
1165 def repository(ui, path=None, create=0): | 1162 def repository(ui, path=None, create=0): |
1166 if path and path[:7] == "http://": | 1163 if path and path[:7] == "http://": |
1167 import urllib, urllib2 | |
1168 return remoterepository(ui, path) | 1164 return remoterepository(ui, path) |
1169 if path and path[:5] == "hg://": | 1165 if path and path[:5] == "hg://": |
1170 import urllib, urllib2 | |
1171 return remoterepository(ui, path.replace("hg://", "http://")) | 1166 return remoterepository(ui, path.replace("hg://", "http://")) |
1172 if path and path[:11] == "old-http://": | 1167 if path and path[:11] == "old-http://": |
1173 import urllib, urllib2 | |
1174 from mercurial import byterange | |
1175 return localrepository(ui, path.replace("old-http://", "http://")) | 1168 return localrepository(ui, path.replace("old-http://", "http://")) |
1176 else: | 1169 else: |
1177 return localrepository(ui, path, create) | 1170 return localrepository(ui, path, create) |
1178 | 1171 |
1179 class httprangereader: | 1172 class httprangereader: |