Honor core.precomposeUnicode in more places

On Mac's HFS where git sets core.precomposeUnicode to true automatically by git init/clone, when a user creates a simple unicode refname (in NFC format) such as españa: $ git branch españa different commands would display the branch name differently. For example, git branch, git log --decorate, and git fast-export all used 65 73 70 61 c3 b1 61 (or "espa\xc3\xb1a") (NFC form) while show-ref would use 65 73 70 61 6e cc 83 61 (or "espan\xcc\x83a") (NFD form). A stress test for git filter-repo was tripped up by this inconsistency, though digging in I found that the problems could compound; for example, if the user ran $ git pack-refs --all and then tried to check out the branch, they would be met with: $ git checkout españa error: pathspec 'españa' did not match any file(s) known to git $ git checkout españa -- fatal: invalid reference: españa $ git branch españa * master Note that the user could run the `git branch` command first and copy and paste the `españa` portion of the output and still see the same two errors. Also, if the user added --no-prune to the pack-refs command, then they would see three branches: master, españa, and españa (those last two are NFC vs. NFD forms, even if they render the same). Further, if the user had the `españa` branch checked out before running `git pack-refs --all`, the user would be greeted with (note that I'm trimming trailing output with an ellipsis): $ git rev-parse HEAD fatal: ambiguous argument 'HEAD': unknown revision or path... $ git status On branch españa No commits yet... Or worse, if the user didn't check this stuff first, running `git commit` will create a new commit with all changes of all of history being squashed into it. In addition to pack-refs, one could also get into this state with upload-pack or anything that calls either pack-refs or upload-pack (e.g. gc or clone). Add code in a few places (pack-refs, show-ref, upload-pack) to check and honor the setting of core.precomposeUnicode to avoid these bugs. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Apr 25, 2019 at 07:58 UTC 8e712ef6fc9742a9bf6f1826d81327f8da488041
3 files changed +7
builtin/pack-refs.c
+2
@@ -1,4 +1,5 @@
1 #include "builtin.h"
2 +#include "config.h"
3 #include "parse-options.h"
4 #include "refs.h"
5 #include "repository.h"
@@ -16,6 +17,7 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
17 OPT_BIT(0, "prune", &flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
18 OPT_END(),
19 };
20 + git_config(git_default_config, NULL);
21 if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
22 usage_with_options(pack_refs_usage, opts);
23 return refs_pack_refs(get_main_ref_store(the_repository), flags);
builtin/show-ref.c
+3
@@ -1,5 +1,6 @@
1 #include "builtin.h"
2 #include "cache.h"
3 +#include "config.h"
4 #include "refs.h"
5 #include "object-store.h"
6 #include "object.h"
@@ -182,6 +183,8 @@ static const struct option show_ref_options[] = {
183
184 int cmd_show_ref(int argc, const char **argv, const char *prefix)
185 {
186 + git_config(git_default_config, NULL);
187 +
188 argc = parse_options(argc, argv, prefix, show_ref_options,
189 show_ref_usage, 0);
190
upload-pack.c
+2
@@ -1041,6 +1041,8 @@ static int upload_pack_config(const char *var, const char *value, void *unused)
1041 allow_filter = git_config_bool(var, value);
1042 } else if (!strcmp("uploadpack.allowrefinwant", var)) {
1043 allow_ref_in_want = git_config_bool(var, value);
1044 + } else if (!strcmp("core.precomposeunicode", var)) {
1045 + precomposed_unicode = git_config_bool(var, value);
1046 }
1047
1048 if (current_config_scope() != CONFIG_SCOPE_REPO) {