@matheusbsbs / matheus-bagliano / commits / 095ce9538b
Fork 0

diff-files: show unmerged entries correctly

Earlier, e9c8409 (diff-index --cached --raw: show tree entry on the LHS for unmerged entries., 2007-01-05) taught the command to show the object name and the mode from the entry coming from the tree side when comparing a tree with an unmerged index. This is a belated companion patch that teaches diff-files to show the mode from the entry coming from the working tree side, when comparing an unmerged index and the working tree. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 22, 2011 at 16:19 UTC 095ce9538b738db28d5e9a6e05d94c7e3f55f39d
2 files changed +95 -2
diff-lib.c
+8 -2
@@ -111,6 +111,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
111
112 if (ce_stage(ce)) {
113 struct combine_diff_path *dpath;
114 + struct diff_filepair *pair;
115 + unsigned int wt_mode = 0;
116 int num_compare_stages = 0;
117 size_t path_len;
118
@@ -129,7 +131,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
131
132 changed = check_removed(ce, &st);
133 if (!changed)
132 - dpath->mode = ce_mode_from_stat(ce, st.st_mode);
134 + wt_mode = ce_mode_from_stat(ce, st.st_mode);
135 else {
136 if (changed < 0) {
137 perror(ce->name);
@@ -137,7 +139,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
139 }
140 if (silent_on_removed)
141 continue;
142 + wt_mode = 0;
143 }
144 + dpath->mode = wt_mode;
145
146 while (i < entries) {
147 struct cache_entry *nce = active_cache[i];
@@ -183,7 +187,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
187 * Show the diff for the 'ce' if we found the one
188 * from the desired stage.
189 */
186 - diff_unmerge(&revs->diffopt, ce->name);
190 + pair = diff_unmerge(&revs->diffopt, ce->name);
191 + if (wt_mode)
192 + pair->two->mode = wt_mode;
193 if (ce_stage(ce) != diff_unmerged_stage)
194 continue;
195 }
t/t4046-diff-unmerged.sh new
+87
@@ -0,0 +1,87 @@
1 +#!/bin/sh
2 +
3 +test_description='diff with unmerged index entries'
4 +. ./test-lib.sh
5 +
6 +test_expect_success setup '
7 + for i in 0 1 2 3
8 + do
9 + blob=$(echo $i | git hash-object --stdin) &&
10 + eval "blob$i=$blob" &&
11 + eval "m$i=\"100644 \$blob$i $i\"" || break
12 + done &&
13 + paths= &&
14 + for b in o x
15 + do
16 + for o in o x
17 + do
18 + for t in o x
19 + do
20 + path="$b$o$t" &&
21 + case "$path" in ooo) continue ;; esac
22 + paths="$paths$path " &&
23 + p=" $path" &&
24 + case "$b" in x) echo "$m1$p" ;; esac &&
25 + case "$o" in x) echo "$m2$p" ;; esac &&
26 + case "$t" in x) echo "$m3$p" ;; esac ||
27 + break
28 + done || break
29 + done || break
30 + done >ls-files-s.expect &&
31 + git update-index --index-info <ls-files-s.expect &&
32 + git ls-files -s >ls-files-s.actual &&
33 + test_cmp ls-files-s.expect ls-files-s.actual
34 +'
35 +
36 +test_expect_success 'diff-files -0' '
37 + for path in $paths
38 + do
39 + >"$path" &&
40 + echo ":000000 100644 $_z40 $_z40 U $path"
41 + done >diff-files-0.expect &&
42 + git diff-files -0 >diff-files-0.actual &&
43 + test_cmp diff-files-0.expect diff-files-0.actual
44 +'
45 +
46 +test_expect_success 'diff-files -1' '
47 + for path in $paths
48 + do
49 + >"$path" &&
50 + echo ":000000 100644 $_z40 $_z40 U $path" &&
51 + case "$path" in
52 + x??) echo ":100644 100644 $blob1 $_z40 M $path"
53 + esac
54 + done >diff-files-1.expect &&
55 + git diff-files -1 >diff-files-1.actual &&
56 + test_cmp diff-files-1.expect diff-files-1.actual
57 +'
58 +
59 +test_expect_success 'diff-files -2' '
60 + for path in $paths
61 + do
62 + >"$path" &&
63 + echo ":000000 100644 $_z40 $_z40 U $path" &&
64 + case "$path" in
65 + ?x?) echo ":100644 100644 $blob2 $_z40 M $path"
66 + esac
67 + done >diff-files-2.expect &&
68 + git diff-files -2 >diff-files-2.actual &&
69 + test_cmp diff-files-2.expect diff-files-2.actual &&
70 + git diff-files >diff-files-default-2.actual &&
71 + test_cmp diff-files-2.expect diff-files-default-2.actual
72 +'
73 +
74 +test_expect_success 'diff-files -3' '
75 + for path in $paths
76 + do
77 + >"$path" &&
78 + echo ":000000 100644 $_z40 $_z40 U $path" &&
79 + case "$path" in
80 + ??x) echo ":100644 100644 $blob3 $_z40 M $path"
81 + esac
82 + done >diff-files-3.expect &&
83 + git diff-files -3 >diff-files-3.actual &&
84 + test_cmp diff-files-3.expect diff-files-3.actual
85 +'
86 +
87 +test_done