Skip to content

Commit 90a78b8

Browse files
alexrinassgitster
authored andcommitted
diff: run arguments through precompose_argv
When running diff commands, a pathspec containing decomposed unicode code points is not converted to precomposed unicode form under Mac OS X, but we normalize the paths in the index and the history to precomposed form on that platform. As a result, the pathspec would not match and no diff is shown. Unlike many builtin commands, the "diff" family of commands do not use parse_options(), which is how other builtin commands indirectly call precompose_argv() to normalize argv[] into precomposed form on Mac OSX. Teach these commands to call precompose_argv() themselves. Note that precomopose_argv() normalizes not just paths but all command line arguments, so things like "git diff -G $string" when $string has the decomposed form would first be normalized into the precomposed form and would stop hitting the same string in the decomposed form in the diff output with this change. It is not a problem per-se, as "log" family of commands already use parse_options() and call precompose_argv()--we can think of this change as making the "diff" family of commands behave in a similar way as the commands in the "log" family. Signed-off-by: Alexander Rinass <[email protected]> Helped-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7654286 commit 90a78b8

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

builtin/diff-files.c

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
2424
gitmodules_config();
2525
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2626
rev.abbrev = 0;
27+
precompose_argv(argc, argv);
2728

2829
argc = setup_revisions(argc, argv, &rev, NULL);
2930
while (1 < argc && argv[1][0] == '-') {

builtin/diff-index.c

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
2121
gitmodules_config();
2222
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2323
rev.abbrev = 0;
24+
precompose_argv(argc, argv);
2425

2526
argc = setup_revisions(argc, argv, &rev, NULL);
2627
for (i = 1; i < argc; i++) {

builtin/diff-tree.c

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
114114
opt->disable_stdin = 1;
115115
memset(&s_r_opt, 0, sizeof(s_r_opt));
116116
s_r_opt.tweak = diff_tree_tweak_rev;
117+
118+
precompose_argv(argc, argv);
117119
argc = setup_revisions(argc, argv, opt, &s_r_opt);
118120

119121
while (--argc > 0) {

builtin/diff.c

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
319319
if (!no_index)
320320
gitmodules_config();
321321
git_config(git_diff_ui_config, NULL);
322+
precompose_argv(argc, argv);
322323

323324
init_revisions(&rev, prefix);
324325

t/t3910-mac-os-precompose.sh

+42
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,54 @@ test_expect_success "setup" '
4949
test_expect_success "setup case mac" '
5050
git checkout -b mac_os
5151
'
52+
# This will test nfd2nfc in git diff
53+
test_expect_success "git diff f.Adiar" '
54+
touch f.$Adiarnfc &&
55+
git add f.$Adiarnfc &&
56+
echo f.Adiarnfc >f.$Adiarnfc &&
57+
git diff f.$Adiarnfd >expect &&
58+
git diff f.$Adiarnfc >actual &&
59+
test_cmp expect actual &&
60+
git reset HEAD f.Adiarnfc &&
61+
rm f.$Adiarnfc expect actual
62+
'
63+
# This will test nfd2nfc in git diff-files
64+
test_expect_success "git diff-files f.Adiar" '
65+
touch f.$Adiarnfc &&
66+
git add f.$Adiarnfc &&
67+
echo f.Adiarnfc >f.$Adiarnfc &&
68+
git diff-files f.$Adiarnfd >expect &&
69+
git diff-files f.$Adiarnfc >actual &&
70+
test_cmp expect actual &&
71+
git reset HEAD f.Adiarnfc &&
72+
rm f.$Adiarnfc expect actual
73+
'
74+
# This will test nfd2nfc in git diff-index
75+
test_expect_success "git diff-index f.Adiar" '
76+
touch f.$Adiarnfc &&
77+
git add f.$Adiarnfc &&
78+
echo f.Adiarnfc >f.$Adiarnfc &&
79+
git diff-index HEAD f.$Adiarnfd >expect &&
80+
git diff-index HEAD f.$Adiarnfc >actual &&
81+
test_cmp expect actual &&
82+
git reset HEAD f.Adiarnfc &&
83+
rm f.$Adiarnfc expect actual
84+
'
5285
# This will test nfd2nfc in readdir()
5386
test_expect_success "add file Adiarnfc" '
5487
echo f.Adiarnfc >f.$Adiarnfc &&
5588
git add f.$Adiarnfc &&
5689
git commit -m "add f.$Adiarnfc"
5790
'
91+
# This will test nfd2nfc in git diff-tree
92+
test_expect_success "git diff-tree f.Adiar" '
93+
echo f.Adiarnfc >>f.$Adiarnfc &&
94+
git diff-tree HEAD f.$Adiarnfd >expect &&
95+
git diff-tree HEAD f.$Adiarnfc >actual &&
96+
test_cmp expect actual &&
97+
git checkout f.$Adiarnfc &&
98+
rm expect actual
99+
'
58100
# This will test nfd2nfc in git stage()
59101
test_expect_success "stage file d.Adiarnfd/f.Adiarnfd" '
60102
mkdir d.$Adiarnfd &&

0 commit comments

Comments
 (0)