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

timeless timeless at gmail.com
Sun Aug 1 11:01:59 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".

timeless-mbp:tmp timeless$ hg init qr; cd qr; echo 1 > x; echo 2 >> x;
echo 4 >> x; echo 5 >> x; echo 6 >> x; echo 7 >> x;hg commit -Am init;
echo 1 > x; echo 2 >> x; echo 3 >> x; echo 4 >> x; echo 5 >> x; echo 7
>> x ; hg record
adding x
diff --git a/x b/x
2 hunks, 2 lines changed
examine changes to 'x'? [Ynsfdaq?]

@@ -1,4 +1,5 @@
 1
 2
+3
 4
 5
record change 1/2 to 'x'? [Ynsfdaq?]

@@ -3,4 +4,3 @@
 4
 5
-6
 7
record change 2/2 to 'x'? [Ynsfdaq?]

abort: empty commit message

timeless-mbp:qr timeless$ hg init qr; cd qr; echo 1 > x; echo 2 >> x;
echo 4 >> x; echo 6 >> x; echo 7 >> x;hg commit -Am init; echo 1 > x;
echo 2 >> x; echo 3 >> x; echo 4 >> x; echo 7 >> x ; hg record
adding x
diff --git a/x b/x
2 hunks, 2 lines changed
examine changes to 'x'? [Ynsfdaq?]

@@ -1,3 +1,4 @@
 1
 2
+3
 4
record change 1/2 to 'x'? [Ynsfdaq?]

@@ -3,3 +4,2 @@
 4
-6
 7
record change 2/2 to 'x'? [Ynsfdaq?]

abort: empty commit message


record manages to split just about everything into distinct hunks.

# HG changeset patch
# User timeless <timeless at gmail.com>
# Date 1279813666 -10800
# Node ID dcf4d221107df8a6b5228bdf47e6cbe63a1ea630
# Parent  aae1dd12fce6067cf6b7db8140c705789bcb5ea4
record: count lines changed as the number of lines added or removed
per "record" hunk
Record deals in hunks which are tighter than traditional patch hunks,
really only a single run of additions/removals. Another addition, even a
line after a fixed line is treated as a new hunk by record.

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