Skip to content

Commit b75271d

Browse files
mattmccutchenspearce
authored andcommitted
"git diff <tree>{3,}": do not reverse order of arguments
According to the message of commit 0fe7c1d, "git diff" with three or more trees expects the merged tree first followed by the parents, in order. However, this command reversed the order of its arguments, resulting in confusing diffs. A comment /* Again, the revs are all reverse */ suggested there was a reason for this, but I can't figure out the reason, so I removed the reversal of the arguments. Test case included. Signed-off-by: Matt McCutchen <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent f285a2d commit b75271d

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

builtin-diff.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,8 @@ static int builtin_diff_combined(struct rev_info *revs,
177177
if (!revs->dense_combined_merges && !revs->combine_merges)
178178
revs->dense_combined_merges = revs->combine_merges = 1;
179179
parent = xmalloc(ents * sizeof(*parent));
180-
/* Again, the revs are all reverse */
181180
for (i = 0; i < ents; i++)
182-
hashcpy((unsigned char *)(parent + i),
183-
ent[ents - 1 - i].item->sha1);
181+
hashcpy((unsigned char *)(parent + i), ent[i].item->sha1);
184182
diff_tree_combined(parent[0], parent + 1, ents - 1,
185183
revs->dense_combined_merges, revs);
186184
return 0;

t/t4013-diff-various.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ diff --patch-with-stat -r initial..side
258258
diff --patch-with-raw -r initial..side
259259
diff --name-status dir2 dir
260260
diff --no-index --name-status dir2 dir
261+
diff master master^ side
261262
EOF
262263

263264
test_done

t/t4013/diff.diff_master_master^_side

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$ git diff master master^ side
2+
diff --cc dir/sub
3+
index cead32e,7289e35..992913c
4+
--- a/dir/sub
5+
+++ b/dir/sub
6+
@@@ -1,6 -1,4 +1,8 @@@
7+
A
8+
B
9+
+C
10+
+D
11+
+E
12+
+F
13+
+ 1
14+
+ 2
15+
diff --cc file0
16+
index b414108,f4615da..10a8a9f
17+
--- a/file0
18+
+++ b/file0
19+
@@@ -1,6 -1,6 +1,9 @@@
20+
1
21+
2
22+
3
23+
+4
24+
+5
25+
+6
26+
+ A
27+
+ B
28+
+ C
29+
$

0 commit comments

Comments
 (0)