[PATCH] Reduce amount of stat traffic generated by dodiff

Bryan O'Sullivan bos at serpentine.com
Wed Aug 3 12:13:34 CDT 2005


On Wed, 2005-08-03 at 10:50 -0400, Chris Mason wrote:

> Thanks a lot for working on this.  It looks like we're still doing the stats 
> with the code in hg tip though:
> 
> strace hg diff Makefile

Ah, right.  The problem was that we were not passing a match function to
dodiff, so its call to repo.changes was doing an os.stat on everything.

I've refactored the code a little, and now all is well.

Change pullable from http://www.serpentine.com/hg

	<b

# HG changeset patch
# User Bryan O'Sullivan <bos at serpentine.com>
# Node ID a95c9b3fc3bfcd468d54cd1a9b28add0fd7dcc0f
# Parent  f0446f6963d25bd78c8d9b6e4b7c13cd7c1ec36d
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.

diff -r f0446f6963d2 -r a95c9b3fc3bf mercurial/commands.py
--- a/mercurial/commands.py	Mon Aug  1 16:58:13 2005
+++ b/mercurial/commands.py	Wed Aug  3 17:10:48 2005
@@ -53,11 +53,17 @@
     b.reverse()
     return os.sep.join((['..'] * len(a)) + b)
 
-def walk(repo, pats, opts, head = ''):
+def makewalk(repo, pats, opts, head = ''):
     cwd = repo.getcwd()
     files, matchfn = matchpats(cwd, pats, opts, head)
-    for src, fn in repo.walk(files = files, match = matchfn):
-        yield src, fn, pathto(cwd, fn)
+    def walk():
+        for src, fn in repo.walk(files = files, match = matchfn):
+            yield src, fn, pathto(cwd, fn)
+    return files, matchfn, walk()
+
+def walk(repo, pats, opts, head = ''):
+    files, matchfn, results = makewalk(repo, pats, opts, head)
+    for r in results: yield r
 
 revrangesep = ':'
 
@@ -153,11 +159,11 @@
     return open(make_filename(repo, r, pat, node, total, seqno, revwidth),
                 mode)
 
-def dodiff(fp, ui, repo, files=None, node1=None, node2=None):
+def dodiff(fp, ui, repo, files=None, node1=None, node2=None, match=util.always):
     def date(c):
         return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
 
-    (c, a, d, u) = repo.changes(node1, node2, files)
+    (c, a, d, u) = repo.changes(node1, node2, files, match = match)
     if files:
         c, a, d = map(lambda x: filterfiles(files, x), (c, a, d))
 
@@ -588,9 +594,10 @@
         raise Abort("too many revisions to diff")
 
     files = []
-    for src, abs, rel in walk(repo, pats, opts):
+    roots, match, results = makewalk(repo, pats, opts)
+    for src, abs, rel in results:
         files.append(abs)
-    dodiff(sys.stdout, ui, repo, files, *revs)
+    dodiff(sys.stdout, ui, repo, files, *revs, **{'match': match})
 
 def doexport(ui, repo, changeset, seqno, total, revwidth, opts):
     node = repo.lookup(changeset)




More information about the Mercurial mailing list