diff: run arguments through precompose_argv
authorAlexander Rinass <alex@fournova.com>
Fri, 13 May 2016 20:41:02 +0000 (22:41 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 13 May 2016 21:35:49 +0000 (14:35 -0700)
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 <alex@fournova.com>
Helped-by: Torsten Bòˆgershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/diff-files.c
builtin/diff-index.c
builtin/diff-tree.c
builtin/diff.c
t/t3910-mac-os-precompose.sh
index 8ed2eb8813a442b64c8f43ed23acbdbd1c0dd452..15c61fd8d1ef891b013404ea5e7cbe42befac7bd 100644 (file)
@@ -24,6 +24,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
        gitmodules_config();
        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
        rev.abbrev = 0;
+       precompose_argv(argc, argv);
 
        argc = setup_revisions(argc, argv, &rev, NULL);
        while (1 < argc && argv[1][0] == '-') {
index d979824f9395a0cbc8ffffa9cede524589710d43..1af373d0021f56f539a1d261e908a60d92ff5b4f 100644 (file)
@@ -21,6 +21,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
        gitmodules_config();
        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
        rev.abbrev = 0;
+       precompose_argv(argc, argv);
 
        argc = setup_revisions(argc, argv, &rev, NULL);
        for (i = 1; i < argc; i++) {
index 12b683d0217856a23cb4c3271a173ce1b7bfbe68..7969e22252468112ba8c355df7e1a6d56e9570df 100644 (file)
@@ -114,6 +114,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
        opt->disable_stdin = 1;
        memset(&s_r_opt, 0, sizeof(s_r_opt));
        s_r_opt.tweak = diff_tree_tweak_rev;
+
+       precompose_argv(argc, argv);
        argc = setup_revisions(argc, argv, opt, &s_r_opt);
 
        while (--argc > 0) {
index 4326fa56bfa2021c6518c225eaa3f89b8b852e11..5b8039cbc7d51a52f0a9bd3e7cc84e722e606555 100644 (file)
@@ -319,6 +319,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
        if (!no_index)
                gitmodules_config();
        git_config(git_diff_ui_config, NULL);
+       precompose_argv(argc, argv);
 
        init_revisions(&rev, prefix);
 
index 831935665e012c04bbe4c57feee92c0310df5c04..26dd5b7f78a7f7e65ddda24c4686d2ae26fc30de 100755 (executable)
@@ -49,12 +49,54 @@ test_expect_success "setup" '
 test_expect_success "setup case mac" '
        git checkout -b mac_os
 '
+# This will test nfd2nfc in git diff
+test_expect_success "git diff f.Adiar" '
+       touch f.$Adiarnfc &&
+       git add f.$Adiarnfc &&
+       echo f.Adiarnfc >f.$Adiarnfc &&
+       git diff f.$Adiarnfd >expect &&
+       git diff f.$Adiarnfc >actual &&
+       test_cmp expect actual &&
+       git reset HEAD f.Adiarnfc &&
+       rm f.$Adiarnfc expect actual
+'
+# This will test nfd2nfc in git diff-files
+test_expect_success "git diff-files f.Adiar" '
+       touch f.$Adiarnfc &&
+       git add f.$Adiarnfc &&
+       echo f.Adiarnfc >f.$Adiarnfc &&
+       git diff-files f.$Adiarnfd >expect &&
+       git diff-files f.$Adiarnfc >actual &&
+       test_cmp expect actual &&
+       git reset HEAD f.Adiarnfc &&
+       rm f.$Adiarnfc expect actual
+'
+# This will test nfd2nfc in git diff-index
+test_expect_success "git diff-index f.Adiar" '
+       touch f.$Adiarnfc &&
+       git add f.$Adiarnfc &&
+       echo f.Adiarnfc >f.$Adiarnfc &&
+       git diff-index HEAD f.$Adiarnfd >expect &&
+       git diff-index HEAD f.$Adiarnfc >actual &&
+       test_cmp expect actual &&
+       git reset HEAD f.Adiarnfc &&
+       rm f.$Adiarnfc expect actual
+'
 # This will test nfd2nfc in readdir()
 test_expect_success "add file Adiarnfc" '
        echo f.Adiarnfc >f.$Adiarnfc &&
        git add f.$Adiarnfc &&
        git commit -m "add f.$Adiarnfc"
 '
+# This will test nfd2nfc in git diff-tree
+test_expect_success "git diff-tree f.Adiar" '
+       echo f.Adiarnfc >>f.$Adiarnfc &&
+       git diff-tree HEAD f.$Adiarnfd >expect &&
+       git diff-tree HEAD f.$Adiarnfc >actual &&
+       test_cmp expect actual &&
+       git checkout f.$Adiarnfc &&
+       rm expect actual
+'
 # This will test nfd2nfc in git stage()
 test_expect_success "stage file d.Adiarnfd/f.Adiarnfd" '
        mkdir d.$Adiarnfd &&