comparison mercurial/commands.py @ 837:a95c9b3fc3bf

Fix performance of hg diff. commands.walk has been refactored. commands.walk's behaviour remains as it was, but there is a new function, commands.makewalk. This returns results that can be passed along to other internal code, in our case dodiff.
author Bryan O'Sullivan <bos@serpentine.com>
date Wed, 03 Aug 2005 09:10:48 -0800
parents f0446f6963d2
children 0fc4b1ab57e3
comparison
equal deleted inserted replaced
823:f0446f6963d2 837:a95c9b3fc3bf
51 while a and b and a[-1] == b[-1]: 51 while a and b and a[-1] == b[-1]:
52 a.pop(), b.pop() 52 a.pop(), b.pop()
53 b.reverse() 53 b.reverse()
54 return os.sep.join((['..'] * len(a)) + b) 54 return os.sep.join((['..'] * len(a)) + b)
55 55
56 def walk(repo, pats, opts, head = ''): 56 def makewalk(repo, pats, opts, head = ''):
57 cwd = repo.getcwd() 57 cwd = repo.getcwd()
58 files, matchfn = matchpats(cwd, pats, opts, head) 58 files, matchfn = matchpats(cwd, pats, opts, head)
59 for src, fn in repo.walk(files = files, match = matchfn): 59 def walk():
60 yield src, fn, pathto(cwd, fn) 60 for src, fn in repo.walk(files = files, match = matchfn):
61 yield src, fn, pathto(cwd, fn)
62 return files, matchfn, walk()
63
64 def walk(repo, pats, opts, head = ''):
65 files, matchfn, results = makewalk(repo, pats, opts, head)
66 for r in results: yield r
61 67
62 revrangesep = ':' 68 revrangesep = ':'
63 69
64 def revrange(ui, repo, revs, revlog=None): 70 def revrange(ui, repo, revs, revlog=None):
65 if revlog is None: 71 if revlog is None:
151 if hasattr(pat, 'read') and 'r' in mode: 157 if hasattr(pat, 'read') and 'r' in mode:
152 return pat 158 return pat
153 return open(make_filename(repo, r, pat, node, total, seqno, revwidth), 159 return open(make_filename(repo, r, pat, node, total, seqno, revwidth),
154 mode) 160 mode)
155 161
156 def dodiff(fp, ui, repo, files=None, node1=None, node2=None): 162 def dodiff(fp, ui, repo, files=None, node1=None, node2=None, match=util.always):
157 def date(c): 163 def date(c):
158 return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) 164 return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
159 165
160 (c, a, d, u) = repo.changes(node1, node2, files) 166 (c, a, d, u) = repo.changes(node1, node2, files, match = match)
161 if files: 167 if files:
162 c, a, d = map(lambda x: filterfiles(files, x), (c, a, d)) 168 c, a, d = map(lambda x: filterfiles(files, x), (c, a, d))
163 169
164 if not c and not a and not d: 170 if not c and not a and not d:
165 return 171 return
586 592
587 if len(revs) > 2: 593 if len(revs) > 2:
588 raise Abort("too many revisions to diff") 594 raise Abort("too many revisions to diff")
589 595
590 files = [] 596 files = []
591 for src, abs, rel in walk(repo, pats, opts): 597 roots, match, results = makewalk(repo, pats, opts)
598 for src, abs, rel in results:
592 files.append(abs) 599 files.append(abs)
593 dodiff(sys.stdout, ui, repo, files, *revs) 600 dodiff(sys.stdout, ui, repo, files, *revs, **{'match': match})
594 601
595 def doexport(ui, repo, changeset, seqno, total, revwidth, opts): 602 def doexport(ui, repo, changeset, seqno, total, revwidth, opts):
596 node = repo.lookup(changeset) 603 node = repo.lookup(changeset)
597 prev, other = repo.changelog.parents(node) 604 prev, other = repo.changelog.parents(node)
598 change = repo.changelog.read(node) 605 change = repo.changelog.read(node)