comparison mercurial/hg.py @ 249:619e775aa7f9

import and startup cleanups -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 import and startup cleanups add commands:run() add copyright notice to commands eliminate/reorganize imports to speed up start time: 0.5b: $ time bash -c 'for i in `seq 100`; do ~/bin/hg > /dev/null; done' real 0m7.718s user 0m6.719s sys 0m0.794s new: $ time bash -c 'for i in `seq 100`; do hg > /dev/null; done' real 0m2.171s user 0m1.684s sys 0m0.444s just python: $ time bash -c 'for i in `seq 100`; do python -c pass; done' real 0m0.988s user 0m0.771s sys 0m0.207s Ignoring the fixed cost of loading the Python interpreter, we're 5.6 times faster. With the Python load time, we're still 3.5 times faster. manifest hash: acce5882a55c76eb165316f5741724c8ce4ef587 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCoihAywK+sNU5EO8RAqMdAJwMe6Ur0R9G6jjayNa5hH2C3c4k/gCeIYvc N178vaWWGciX9zq+g5qCAls= =buhv -----END PGP SIGNATURE-----
author mpm@selenic.com
date Sat, 04 Jun 2005 14:16:32 -0800
parents 863b508c5b36
children 3fd8fc14b12f
comparison
equal deleted inserted replaced
248:b7645b3c86ff 249:619e775aa7f9
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> 3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
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, sha, socket, os, time, re, urllib2, tempfile 8 import sys, struct, os
9 import urllib 9 from mercurial import lock
10 from mercurial import byterange, lock
11 from mercurial.transaction import * 10 from mercurial.transaction import *
12 from mercurial.revlog import * 11 from mercurial.revlog import *
13 from difflib import SequenceMatcher 12 from difflib import SequenceMatcher
14 13
15 class filelog(revlog): 14 class filelog(revlog):
137 def read(self, node): 136 def read(self, node):
138 return self.extract(self.revision(node)) 137 return self.extract(self.revision(node))
139 138
140 def add(self, manifest, list, desc, transaction, p1=None, p2=None, 139 def add(self, manifest, list, desc, transaction, p1=None, p2=None,
141 user=None, date=None): 140 user=None, date=None):
141 import socket, time
142 user = (user or 142 user = (user or
143 os.environ.get("HGUSER") or 143 os.environ.get("HGUSER") or
144 os.environ.get("EMAIL") or 144 os.environ.get("EMAIL") or
145 os.environ.get("LOGNAME", "unknown") + '@' + socket.getfqdn()) 145 os.environ.get("LOGNAME", "unknown") + '@' + socket.getfqdn())
146 date = date or "%d %d" % (time.time(), time.timezone) 146 date = date or "%d %d" % (time.time(), time.timezone)
313 313
314 if not self.remote: 314 if not self.remote:
315 self.dirstate = dirstate(self.opener, ui, self.root) 315 self.dirstate = dirstate(self.opener, ui, self.root)
316 316
317 def ignore(self, f): 317 def ignore(self, f):
318 import re
318 if self.ignorelist is None: 319 if self.ignorelist is None:
319 self.ignorelist = [] 320 self.ignorelist = []
320 try: 321 try:
321 l = open(os.path.join(self.root, ".hgignore")) 322 l = open(os.path.join(self.root, ".hgignore"))
322 for pat in l: 323 for pat in l:
964 #os.unlink(f) 965 #os.unlink(f)
965 self.dirstate.update(remove, 'r') 966 self.dirstate.update(remove, 'r')
966 967
967 def merge3(self, fn, my, other): 968 def merge3(self, fn, my, other):
968 """perform a 3-way merge in the working directory""" 969 """perform a 3-way merge in the working directory"""
970
971 import tempfile
969 972
970 def temp(prefix, node): 973 def temp(prefix, node):
971 pre = "%s~%s." % (os.path.basename(fn), prefix) 974 pre = "%s~%s." % (os.path.basename(fn), prefix)
972 (fd, name) = tempfile.mkstemp("", pre) 975 (fd, name) = tempfile.mkstemp("", pre)
973 f = os.fdopen(fd, "w") 976 f = os.fdopen(fd, "w")
1175 yield zd.decompress(d) 1178 yield zd.decompress(d)
1176 self.ui.note("%d bytes of data transfered\n" % bytes) 1179 self.ui.note("%d bytes of data transfered\n" % bytes)
1177 1180
1178 def repository(ui, path=None, create=0): 1181 def repository(ui, path=None, create=0):
1179 if path and path[:7] == "http://": 1182 if path and path[:7] == "http://":
1183 import urllib, urllib2
1180 return remoterepository(ui, path) 1184 return remoterepository(ui, path)
1181 if path and path[:5] == "hg://": 1185 if path and path[:5] == "hg://":
1186 import urllib, urllib2
1182 return remoterepository(ui, path.replace("hg://", "http://")) 1187 return remoterepository(ui, path.replace("hg://", "http://"))
1183 if path and path[:11] == "old-http://": 1188 if path and path[:11] == "old-http://":
1189 import urllib, urllib2
1190 from mercurial import byterange
1184 return localrepository(ui, path.replace("old-http://", "http://")) 1191 return localrepository(ui, path.replace("old-http://", "http://"))
1185 else: 1192 else:
1186 return localrepository(ui, path, create) 1193 return localrepository(ui, path, create)
1187 1194
1188 class httprangereader: 1195 class httprangereader: