t4211: fix broken test when one -L range is subset of another

t4211 attempts to test multiple git-log -L ranges where one range is a superset of the other, and falsely succeeds because its "expected" output is incorrect. Overlapping -L ranges handed to git-log are coalesced by line-log.c:sort_and_merge_range_set() into a set of non-overlapping, disjoint ranges. When one range is a subset of another, sort_and_merge_range_set() should coalesce both ranges to the superset range, but instead the coalesced range often is incorrectly truncated to the end of the subset range. For example, ranges 2-8 and 3-4 are coalesced incorrectly to 2-4. One can observe this incorrect behavior with git-log -L using the test repository created by t4211. The superset/subset ranges t4211 employs are 4-$ and 8-12 (where $ represents end-of-file). The coalesced range should be 4-$. Manually invoking git-log with the same ranges the test employs, we see: % git log -L 4:a.c simple | awk '/^commit [0-9a-f]{40}/ { print substr($2,1,7) }' 4659538 100b61a 39b6eb2 a6eb826 f04fb20 de4c48a % git log -L 8,12:a.c simple | awk ... f04fb20 de4c48a % git log -L 4:a.c -L 8,12:a.c simple | awk ... a6eb826 f04fb20 de4c48a This last output is incorrect. 8-12 is a subset of 4-$, hence the output of the coalesced range should be the same as the 4-$ output shown first. In fact, the above incorrect output is the truncated bogus range 4-12: % git log -L 4,12:a.c simple | awk ... a6eb826 f04fb20 de4c48a Fix the test to correctly fail in the presence of the sort_and_merge_range_set() coalescing bug. Do so by changing the "expected" output to the commits mentioned in the 4-$ output above. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 9, 2013 at 01:55 UTC 18d472db6fe3909537ceb7e0c54cf01fa3466b8f
2 files changed +133 -5
t/t4211-line-log.sh
+2 -2
@@ -50,8 +50,8 @@ canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main
50 canned_test "-L 4,12:a.c -L :main:a.c simple" multiple
51 canned_test "-L 4,18:a.c -L :main:a.c simple" multiple-overlapping
52 canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping
53 -canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset
54 -canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset
53 +canned_test_failure "-L 4:a.c -L 8,12:a.c simple" multiple-superset
54 +canned_test_failure "-L 8,12:a.c -L 4:a.c simple" multiple-superset
55
56 test_bad_opts "-L" "switch.*requires a value"
57 test_bad_opts "-L b.c" "argument.*not of the form"
t/t4211/expect.multiple-superset
+131 -3
@@ -1,3 +1,100 @@
1 +commit 4659538844daa2849b1a9e7d6fadb96fcd26fc83
2 +Author: Thomas Rast <trast@student.ethz.ch>
3 +Date: Thu Feb 28 10:48:43 2013 +0100
4 +
5 + change back to complete line
6 +
7 +diff --git a/a.c b/a.c
8 +--- a/a.c
9 ++++ b/a.c
10 +@@ -4,19 +4,21 @@
11 + long f(long x)
12 + {
13 + int s = 0;
14 + while (x) {
15 + x >>= 1;
16 + s++;
17 + }
18 + return s;
19 + }
20 +
21 + /*
22 + * This is only an example!
23 + */
24 +
25 + int main ()
26 + {
27 + printf("%ld\n", f(15));
28 + return 0;
29 +-}
30 +\ No newline at end of file
31 ++}
32 ++
33 ++/* incomplete lines are bad! */
34 +
35 +commit 100b61a6f2f720f812620a9d10afb3a960ccb73c
36 +Author: Thomas Rast <trast@student.ethz.ch>
37 +Date: Thu Feb 28 10:48:10 2013 +0100
38 +
39 + change to an incomplete line at end
40 +
41 +diff --git a/a.c b/a.c
42 +--- a/a.c
43 ++++ b/a.c
44 +@@ -4,19 +4,19 @@
45 + long f(long x)
46 + {
47 + int s = 0;
48 + while (x) {
49 + x >>= 1;
50 + s++;
51 + }
52 + return s;
53 + }
54 +
55 + /*
56 + * This is only an example!
57 + */
58 +
59 + int main ()
60 + {
61 + printf("%ld\n", f(15));
62 + return 0;
63 +-}
64 ++}
65 +\ No newline at end of file
66 +
67 +commit 39b6eb2d5b706d3322184a169f666f25ed3fbd00
68 +Author: Thomas Rast <trast@student.ethz.ch>
69 +Date: Thu Feb 28 10:45:41 2013 +0100
70 +
71 + touch comment
72 +
73 +diff --git a/a.c b/a.c
74 +--- a/a.c
75 ++++ b/a.c
76 +@@ -3,19 +3,19 @@
77 + long f(long x)
78 + {
79 + int s = 0;
80 + while (x) {
81 + x >>= 1;
82 + s++;
83 + }
84 + return s;
85 + }
86 +
87 + /*
88 +- * A comment.
89 ++ * This is only an example!
90 + */
91 +
92 + int main ()
93 + {
94 + printf("%ld\n", f(15));
95 + return 0;
96 + }
97 +
98 commit a6eb82647d5d67f893da442f8f9375fd89a3b1e2
99 Author: Thomas Rast <trast@student.ethz.ch>
100 Date: Thu Feb 28 10:45:16 2013 +0100
@@ -7,7 +104,7 @@ Date: Thu Feb 28 10:45:16 2013 +0100
104 diff --git a/a.c b/a.c
105 --- a/a.c
106 +++ b/a.c
10 -@@ -3,9 +3,9 @@
107 +@@ -3,19 +3,19 @@
108 -int f(int x)
109 +long f(long x)
110 {
@@ -18,6 +115,17 @@ diff --git a/a.c b/a.c
115 }
116 return s;
117 }
118 +
119 + /*
120 + * A comment.
121 + */
122 +
123 + int main ()
124 + {
125 +- printf("%d\n", f(15));
126 ++ printf("%ld\n", f(15));
127 + return 0;
128 + }
129
130 commit f04fb20f2c77850996cba739709acc6faecc58f7
131 Author: Thomas Rast <trast@student.ethz.ch>
@@ -28,7 +136,7 @@ Date: Thu Feb 28 10:44:55 2013 +0100
136 diff --git a/a.c b/a.c
137 --- a/a.c
138 +++ b/a.c
31 -@@ -3,8 +3,9 @@
139 +@@ -3,18 +3,19 @@
140 int f(int x)
141 {
142 int s = 0;
@@ -38,6 +146,16 @@ diff --git a/a.c b/a.c
146 }
147 + return s;
148 }
149 +
150 + /*
151 + * A comment.
152 + */
153 +
154 + int main ()
155 + {
156 + printf("%d\n", f(15));
157 + return 0;
158 + }
159
160 commit de4c48ae814792c02a49c4c3c0c757ae69c55f6a
161 Author: Thomas Rast <trast@student.ethz.ch>
@@ -48,7 +166,7 @@ Date: Thu Feb 28 10:44:48 2013 +0100
166 diff --git a/a.c b/a.c
167 --- /dev/null
168 +++ b/a.c
51 -@@ -0,0 +3,8 @@
169 +@@ -0,0 +3,18 @@
170 +int f(int x)
171 +{
172 + int s = 0;
@@ -57,3 +175,13 @@ diff --git a/a.c b/a.c
175 + s++;
176 + }
177 +}
178 ++
179 ++/*
180 ++ * A comment.
181 ++ */
182 ++
183 ++int main ()
184 ++{
185 ++ printf("%d\n", f(15));
186 ++ return 0;
187 ++}