Skip to content

Commit dbc2fb6

Browse files
mattmccutchengitster
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 3927bbe commit dbc2fb6

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
@@ -175,10 +175,8 @@ static int builtin_diff_combined(struct rev_info *revs,
175175
if (!revs->dense_combined_merges && !revs->combine_merges)
176176
revs->dense_combined_merges = revs->combine_merges = 1;
177177
parent = xmalloc(ents * sizeof(*parent));
178-
/* Again, the revs are all reverse */
179178
for (i = 0; i < ents; i++)
180-
hashcpy((unsigned char *)(parent + i),
181-
ent[ents - 1 - i].item->sha1);
179+
hashcpy((unsigned char *)(parent + i), ent[i].item->sha1);
182180
diff_tree_combined(parent[0], parent + 1, ents - 1,
183181
revs->dense_combined_merges, revs);
184182
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)