[PATCH] record: count lines changed as the number of lines added or removed per hunk

timeless timeless at gmail.com
Thu Jul 22 10:51:45 CDT 2010


I'm doing a lot of recording for transifex and hg qrecord tells me:

diff --git a/transifex/templates/projects/component_lang_detail.html
b/transifex/templates/projects/component_lang_detail.html
1 hunks, 2 lines changed
-  <h3>{{ language.name }} {% trans "translation files" %}</h3>
+  <h3>{{ language.name }} {% trans "Translation Files" %}</h3>

but anyone can see that there's only one line that's changed, it has
an old version and a new version, but it's collectively only one line.

I claim that the following simple patch which accounts for the number
of additions or removals per hunk correctly matches the concept of
"number of lines changed".

# HG changeset patch
# User timeless <timeless at gmail.com>
# Date 1279813666 -10800
# Node ID 8255d70ae096520a77789bc82050ce2f36313f7b
# Parent  898a5305f34200ee592db69a1a323da373488f3f
record: count lines changed as the number of lines added or removed per hunk

diff --git a/hgext/record.py b/hgext/record.py
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -97,7 +97,7 @@ class header(object):
             if h.startswith('---'):
                 fp.write(_('%d hunks, %d lines changed\n') %
                          (len(self.hunks),
-                          sum([h.added + h.removed for h in self.hunks])))
+                          sum([max(h.added, h.removed) for h in self.hunks])))
                 break
             fp.write(h)

diff --git a/tests/test-qrecord.out b/tests/test-qrecord.out
--- a/tests/test-qrecord.out
+++ b/tests/test-qrecord.out
@@ -81,7 +81,7 @@ diff -r 1057167b20ef dir/a.txt
  up
 % qrecord a.patch
 diff --git a/1.txt b/1.txt
-2 hunks, 4 lines changed
+2 hunks, 2 lines changed
 examine changes to '1.txt'? [Ynsfdaq?]
 @@ -1,3 +1,3 @@
  1
@@ -96,7 +96,7 @@ record change 1/6 to '1.txt'? [Ynsfdaq?]
  5
 record change 2/6 to '1.txt'? [Ynsfdaq?]
 diff --git a/2.txt b/2.txt
-1 hunks, 2 lines changed
+1 hunks, 1 lines changed
 examine changes to '2.txt'? [Ynsfdaq?]
 @@ -1,5 +1,5 @@
  a
@@ -107,7 +107,7 @@ examine changes to '2.txt'? [Ynsfdaq?]
  e
 record change 4/6 to '2.txt'? [Ynsfdaq?]
 diff --git a/dir/a.txt b/dir/a.txt
-1 hunks, 2 lines changed
+1 hunks, 1 lines changed
 examine changes to 'dir/a.txt'? [Ynsfdaq?]

 % after qrecord a.patch 'tip'
@@ -164,7 +164,7 @@ diff -r 5d1ca63427ee dir/a.txt
  up
 % qrecord b.patch
 diff --git a/1.txt b/1.txt
-1 hunks, 2 lines changed
+1 hunks, 1 lines changed
 examine changes to '1.txt'? [Ynsfdaq?]
 @@ -1,5 +1,5 @@
  1
@@ -175,7 +175,7 @@ examine changes to '1.txt'? [Ynsfdaq?]
  5
 record change 1/3 to '1.txt'? [Ynsfdaq?]
 diff --git a/dir/a.txt b/dir/a.txt
-1 hunks, 2 lines changed
+1 hunks, 1 lines changed
 examine changes to 'dir/a.txt'? [Ynsfdaq?]
 @@ -1,4 +1,4 @@
 -hello world
diff --git a/tests/test-record.out b/tests/test-record.out
--- a/tests/test-record.out
+++ b/tests/test-record.out
@@ -222,7 +222,7 @@ examine changes to 'plain'? [Ynsfdaq?]
 record this change to 'plain'? [Ynsfdaq?]
 % modify end of plain file, add EOL
 diff --git a/plain b/plain
-1 hunks, 2 lines changed
+1 hunks, 1 lines changed
 examine changes to 'plain'? [Ynsfdaq?]
 @@ -9,4 +9,4 @@
  9
@@ -234,7 +234,7 @@ examine changes to 'plain'? [Ynsfdaq?]
 record this change to 'plain'? [Ynsfdaq?]
 % modify beginning, trim end, record both
 diff --git a/plain b/plain
-2 hunks, 4 lines changed
+2 hunks, 3 lines changed
 examine changes to 'plain'? [Ynsfdaq?]
 @@ -1,4 +1,4 @@
 -1
@@ -276,7 +276,7 @@ diff -r cd07d48e8cbe -r efca65c9b09e pla
 % trim beginning, modify end
 % record end
 diff --git a/plain b/plain
-2 hunks, 5 lines changed
+2 hunks, 4 lines changed
 examine changes to 'plain'? [Ynsfdaq?]
 @@ -1,9 +1,6 @@
 -2


More information about the Mercurial-devel mailing list