Skip to content

Commit

Permalink
Merge branch 'tb/precompose-getcwd' into jch
Browse files Browse the repository at this point in the history
We forgot to normalize the result of getcwd() to NFC on macOS where
all other paths are normalized, which has been corrected.

Reverted out of 'next' to be replaced with an updated version (this one).
Expectign a reroll to clarify the proposed log message.
cf. <20240520160601.GA29154@tb-raspi4>
cf. <20240521205749.GA8165@tb-raspi4>

* tb/precompose-getcwd:
  macOS: ls-files path fails if path of workdir is NFD
  • Loading branch information
gitster committed May 23, 2024
2 parents d77a9d2 + bbb2076 commit 519f2d5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
10 changes: 10 additions & 0 deletions compat/precompose_utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ const char *precompose_string_if_needed(const char *in)
return in;
}

void precompose_strbuf_if_needed(struct strbuf *sb)
{
char *buf_prec = (char *)precompose_string_if_needed(sb->buf);
if (buf_prec != sb->buf) {
size_t buf_prec_len = strlen(buf_prec);
free(strbuf_detach(sb, NULL));
strbuf_attach(sb, buf_prec, buf_prec_len, buf_prec_len + 1);
}
}

const char *precompose_argv_prefix(int argc, const char **argv, const char *prefix)
{
int i = 0;
Expand Down
1 change: 1 addition & 0 deletions compat/precompose_utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef struct {

const char *precompose_argv_prefix(int argc, const char **argv, const char *prefix);
const char *precompose_string_if_needed(const char *in);
void precompose_strbuf_if_needed(struct strbuf *sb);
void probe_utf8_pathname_composition(void);

PREC_DIR *precompose_utf8_opendir(const char *dirname);
Expand Down
1 change: 1 addition & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ static inline const char *precompose_string_if_needed(const char *in)
return in;
}

#define precompose_strbuf_if_needed(a)
#define probe_utf8_pathname_composition()
#endif

Expand Down
2 changes: 1 addition & 1 deletion setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static int abspath_part_inside_repo(char *path)
size_t wtlen;
char *path0;
int off;
const char *work_tree = get_git_work_tree();
const char *work_tree = precompose_string_if_needed(get_git_work_tree());
struct strbuf realpath = STRBUF_INIT;

if (!work_tree)
Expand Down
1 change: 1 addition & 0 deletions strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ int strbuf_getcwd(struct strbuf *sb)
strbuf_grow(sb, guessed_len);
if (getcwd(sb->buf, sb->alloc)) {
strbuf_setlen(sb, strlen(sb->buf));
precompose_strbuf_if_needed(sb);
return 0;
}

Expand Down
26 changes: 26 additions & 0 deletions t/t0050-filesystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,30 @@ test_expect_success CASE_INSENSITIVE_FS 'checkout with no pathspec and a case in
)
'

test_expect_success 'git ls-files under NFD' '
(
mkdir -p "somewhere/$aumlcdiar" &&
mypwd=$PWD &&
cd "somewhere/$aumlcdiar" &&
git init &&
git --literal-pathspecs ls-files "$mypwd/somewhere/$aumlcdiar" 2>err &&
>expected &&
test_cmp expected err
)
'

# Re-do the same test. Note: global core.precomposeunicode is changed
test_expect_success 'git ls-files under NFD. global precompose false' '
test_when_finished "git config --global --unset core.precomposeunicode" &&
(
mypwd=$PWD &&
cd "somewhere/$aumlcdiar" &&
git config --global core.precomposeunicode false &&
git config core.precomposeunicode true &&
git --literal-pathspecs ls-files "$mypwd/somewhere/$aumlcdiar" 2>err &&
>expected &&
test_cmp expected err
)
'

test_done

0 comments on commit 519f2d5

Please sign in to comment.