Skip to content

Commit 8b25dee

Browse files
committed
Merge branch 'tb/precompose-prefix-too'
When commands are started from a subdirectory, they may have to compare the path to the subdirectory (called prefix and found out from $(pwd)) with the tracked paths. On macOS, $(pwd) and readdir() yield decomposed path, while the tracked paths are usually normalized to the precomposed form, causing mismatch. This has been fixed by taking the same approach used to normalize the command line arguments. * tb/precompose-prefix-too: MacOS: precompose_argv_prefix()
2 parents 006c5f7 + 5c32750 commit 8b25dee

File tree

11 files changed

+59
-29
lines changed

11 files changed

+59
-29
lines changed

builtin/diff-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
3636
*/
3737
rev.diffopt.ita_invisible_in_index = 1;
3838

39-
precompose_argv(argc, argv);
39+
prefix = precompose_argv_prefix(argc, argv, prefix);
4040

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

builtin/diff-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
2525
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2626
repo_init_revisions(the_repository, &rev, prefix);
2727
rev.abbrev = 0;
28-
precompose_argv(argc, argv);
28+
prefix = precompose_argv_prefix(argc, argv, prefix);
2929

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

builtin/diff-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
126126
memset(&s_r_opt, 0, sizeof(s_r_opt));
127127
s_r_opt.tweak = diff_tree_tweak_rev;
128128

129-
precompose_argv(argc, argv);
129+
prefix = precompose_argv_prefix(argc, argv, prefix);
130130
argc = setup_revisions(argc, argv, opt, &s_r_opt);
131131

132132
memset(&w, 0, sizeof(w));

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
453453

454454
init_diff_ui_defaults();
455455
git_config(git_diff_ui_config, NULL);
456-
precompose_argv(argc, argv);
456+
prefix = precompose_argv_prefix(argc, argv, prefix);
457457

458458
repo_init_revisions(the_repository, &rev, prefix);
459459

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ static int compute_summary_module_list(struct object_id *head_oid,
12571257
git_config(git_diff_basic_config, NULL);
12581258
init_revisions(&rev, info->prefix);
12591259
rev.abbrev = 0;
1260-
precompose_argv(diff_args.nr, diff_args.v);
1260+
precompose_argv_prefix(diff_args.nr, diff_args.v, NULL);
12611261
setup_revisions(diff_args.nr, diff_args.v, &rev, NULL);
12621262
rev.diffopt.output_format = DIFF_FORMAT_NO_OUTPUT | DIFF_FORMAT_CALLBACK;
12631263
rev.diffopt.format_callback = submodule_summary_callback;

compat/precompose_utf8.c

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,46 @@ void probe_utf8_pathname_composition(void)
6060
strbuf_release(&path);
6161
}
6262

63-
64-
void precompose_argv(int argc, const char **argv)
63+
static inline const char *precompose_string_if_needed(const char *in)
6564
{
66-
int i = 0;
67-
const char *oldarg;
68-
char *newarg;
69-
iconv_t ic_precompose;
65+
size_t inlen;
66+
size_t outlen;
67+
if (has_non_ascii(in, (size_t)-1, &inlen)) {
68+
iconv_t ic_prec;
69+
char *out;
70+
if (precomposed_unicode < 0)
71+
git_config_get_bool("core.precomposeunicode", &precomposed_unicode);
72+
if (precomposed_unicode != 1)
73+
return in;
74+
ic_prec = iconv_open(repo_encoding, path_encoding);
75+
if (ic_prec == (iconv_t) -1)
76+
return in;
77+
78+
out = reencode_string_iconv(in, inlen, ic_prec, 0, &outlen);
79+
if (out) {
80+
if (outlen == inlen && !memcmp(in, out, outlen))
81+
free(out); /* no need to return indentical */
82+
else
83+
in = out;
84+
}
85+
iconv_close(ic_prec);
7086

71-
if (precomposed_unicode != 1)
72-
return;
87+
}
88+
return in;
89+
}
7390

74-
ic_precompose = iconv_open(repo_encoding, path_encoding);
75-
if (ic_precompose == (iconv_t) -1)
76-
return;
91+
const char *precompose_argv_prefix(int argc, const char **argv, const char *prefix)
92+
{
93+
int i = 0;
7794

7895
while (i < argc) {
79-
size_t namelen;
80-
oldarg = argv[i];
81-
if (has_non_ascii(oldarg, (size_t)-1, &namelen)) {
82-
newarg = reencode_string_iconv(oldarg, namelen, ic_precompose, 0, NULL);
83-
if (newarg)
84-
argv[i] = newarg;
85-
}
96+
argv[i] = precompose_string_if_needed(argv[i]);
8697
i++;
8798
}
88-
iconv_close(ic_precompose);
99+
if (prefix) {
100+
prefix = precompose_string_if_needed(prefix);
101+
}
102+
return prefix;
89103
}
90104

91105

compat/precompose_utf8.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef struct {
2828
struct dirent_prec_psx *dirent_nfc;
2929
} PREC_DIR;
3030

31-
void precompose_argv(int argc, const char **argv);
31+
const char *precompose_argv_prefix(int argc, const char **argv, const char *prefix);
3232
void probe_utf8_pathname_composition(void);
3333

3434
PREC_DIR *precompose_utf8_opendir(const char *dirname);

git-compat-util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ typedef unsigned long uintptr_t;
252252
#ifdef PRECOMPOSE_UNICODE
253253
#include "compat/precompose_utf8.h"
254254
#else
255-
static inline void precompose_argv(int argc, const char **argv)
255+
static inline const char *precompose_argv_prefix(int argc, const char **argv, const char *prefix)
256256
{
257-
; /* nothing */
257+
return prefix;
258258
}
259259
#define probe_utf8_pathname_composition()
260260
#endif

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
423423
int nongit_ok;
424424
prefix = setup_git_directory_gently(&nongit_ok);
425425
}
426-
426+
prefix = precompose_argv_prefix(argc, argv, prefix);
427427
if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY) &&
428428
!(p->option & DELAY_PAGER_CONFIG))
429429
use_pager = check_pager_config(p->cmd);

parse-options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
869869
usage_with_options(usagestr, options);
870870
}
871871

872-
precompose_argv(argc, argv);
872+
precompose_argv_prefix(argc, argv, NULL);
873873
free(real_options);
874874
free(ctx.alias_groups);
875875
return parse_options_end(&ctx);

0 commit comments

Comments
 (0)