[PATCH] churn: Fixes issue 1569, handles subdirectories correctly and adds a test case.

Madhusudan C.S madhusudancs at gmail.com
Tue Mar 24 12:41:38 CDT 2009


# HG changeset patch
# User madhusudancs at gmail.com
# Date 1237915643 -19800
# Node ID 206d1dd65862d2fa6d6765ae3706e89b0430d76a
# Parent  b2c18c7956221df0f961ac697a01effa1233978f
Returns lines changed for paths specified as arguments correctly.

This fixes issue 1569. hg churn path now returns only the number
of lines changed in the path, if the path is specified. A test
case is also included.

diff --git a/hgext/churn.py b/hgext/churn.py
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -21,9 +21,10 @@
     t.use_template(tmpl)
     return t

-def changedlines(ui, repo, ctx1, ctx2):
+def changedlines(ui, repo, ctx1, ctx2, fns):
     lines = 0
-    diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node()))
+    fmatch = cmdutil.match(repo, pats=fns)
+    diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node(), fmatch))
     for l in diff.split('\n'):
         if (l.startswith("+") and not l.startswith("+++ ") or
             l.startswith("-") and not l.startswith("--- ")):
@@ -71,7 +72,7 @@
                 continue

             ctx1 = parents[0]
-            lines = changedlines(ui, repo, ctx1, ctx)
+            lines = changedlines(ui, repo, ctx1, ctx, fns)
             rate[key] = rate.get(key, 0) + lines

         if opts.get('progress'):
diff --git a/tests/test-issue1569 b/tests/test-issue1569
new file mode 100755
--- /dev/null
+++ b/tests/test-issue1569
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+echo "[extensions]" >> $HGRCPATH
+echo "churn=" >> $HGRCPATH
+
+mkdir t
+cd t
+hg init
+mkdir -p a/b
+mkdir -p a/c
+echo "abc" > a/b/file.txt
+echo "def" > a/c/file2.txt
+hg commit -A -m "first commit" -u testuser -d '1 0'
+hg churn a/b
+
+echo expected output is 1
+echo done
diff --git a/tests/test-issue1569.out b/tests/test-issue1569.out
new file mode 100644
--- /dev/null
+++ b/tests/test-issue1569.out
@@ -0,0 +1,5 @@
+adding a/b/file.txt
+adding a/c/file2.txt
+testuser      1
************************************************************
+expected output is 1
+done


-- 
Thanks and regards,
 Madhusudan.C.S

Blogs at: www.madhusudancs.info
Official Email ID: madhusudan at madhusudancs.info
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://selenic.com/pipermail/mercurial-devel/attachments/20090324/042826b3/attachment.htm 


More information about the Mercurial-devel mailing list