[PATCH 0 of 1] diffstat implementation in python

Alexander Solovyov piranha at piranha.org.ua
Sun Dec 21 12:47:59 CST 2008


On 2008-12-21, Alexander Solovyov wrote:

> On 2008-12-21, Dirkjan Ochtman wrote:

>> Not sure yet on whether this should just be a simple string-returning function
>> rather than a whole class, though.

> It's better as a class as you can use results of parsing in
> extensions. For example, churn can use diffstat to determine amount of
> changes instead of shipping with separate function.

I have changed diffstat:

diff --git a/hgext/churn.py b/hgext/churn.py
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -43,13 +43,9 @@
     return t
 
 def changedlines(ui, repo, ctx1, ctx2):
-    lines = 0
     diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node()))
-    for l in diff.split('\n'):
-        if (l.startswith("+") and not l.startswith("+++ ") or
-            l.startswith("-") and not l.startswith("--- ")):
-            lines += 1
-    return lines
+    diffstat = patch.diffstat(diff.splitlines())
+    return diffstat.adds + diffstat.removes
 
 def countrate(ui, repo, amap, *pats, **opts):
     """Calculate stats"""


Thereis comparison of performance of churn on a repo with 1100
revisions, before change:

piranha at gtv ~/dev/web/byteflow>time hg churn > /dev/null
hg churn > /dev/null  4.56s user 0.08s system 99% cpu 4.651 total
piranha at gtv ~/dev/web/byteflow>time hg churn > /dev/null
hg churn > /dev/null  4.52s user 0.11s system 99% cpu 4.632 total
piranha at gtv ~/dev/web/byteflow>time hg churn > /dev/null
hg churn > /dev/null  4.49s user 0.13s system 96% cpu 4.762 total


And after change:

piranha at gtv ~/dev/web/byteflow>time hg churn > /dev/null
hg churn > /dev/null  4.59s user 0.12s system 99% cpu 4.735 total
piranha at gtv ~/dev/web/byteflow>time hg churn > /dev/null
hg churn > /dev/null  4.59s user 0.12s system 99% cpu 4.713 total
piranha at gtv ~/dev/web/byteflow>time hg churn > /dev/null
hg churn > /dev/null  4.60s user 0.14s system 99% cpu 4.737 total


Looks like performance for simple function and for class, which counts
names of changed files, is almost the same.

-- 
Alexander


More information about the Mercurial-devel mailing list