Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: tboegi@web.de
To: tboegi@web.de, git@vger.kernel.org, takimoto-j@kba.biglobe.ne.jp
Subject: [PATCH v1 2/2] strbuf_getcwd() needs precompse_strbuf_if_needed()
Date: Tue,  7 May 2024 10:44:31 +0200	[thread overview]
Message-ID: <20240507084431.19797-1-tboegi@web.de> (raw)
In-Reply-To: <20240430032717281.IXLP.121462.mail.biglobe.ne.jp@biglobe.ne.jp>

From: Torsten Bögershausen <tboegi@web.de>

When running under macOs a call to strbuf_getcwd() may return
decomposed unicode.
This could make `git ls-files` fail, see previous commit of t0050

The solution is to precompose the result of getcwd() if needed.
One possible implementation would be to re-define getcwd() similar
to opendir(), readdir() and closedir().
Since there is already a strbuf wrapper around getcwd(), and only this
wrapper is used inside the whole codebase, equip strbuf_getcwd() with
a call to the newly created function precompse_strbuf_if_needed().
Note that precompse_strbuf_if_needed() is a function under macOs,
and is a "nop" on all other systems.

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
 compat/precompose_utf8.c | 11 +++++++++++
 compat/precompose_utf8.h |  1 +
 git-compat-util.h        |  2 ++
 strbuf.c                 |  1 +
 4 files changed, 15 insertions(+)

diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c
index 0bd5c24250..82ec2a1c5b 100644
--- a/compat/precompose_utf8.c
+++ b/compat/precompose_utf8.c
@@ -94,6 +94,17 @@ const char *precompose_string_if_needed(const char *in)
 	return in;
 }

+void precompse_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;
diff --git a/compat/precompose_utf8.h b/compat/precompose_utf8.h
index fea06cf28a..fb17b1bd4a 100644
--- a/compat/precompose_utf8.h
+++ b/compat/precompose_utf8.h
@@ -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 precompse_strbuf_if_needed(struct strbuf *sb);
 void probe_utf8_pathname_composition(void);

 PREC_DIR *precompose_utf8_opendir(const char *dirname);
diff --git a/git-compat-util.h b/git-compat-util.h
index ca7678a379..80ae463410 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -344,6 +344,8 @@ static inline const char *precompose_string_if_needed(const char *in)
 	return in;
 }

+#define precompse_strbuf_if_needed(a)
+
 #define probe_utf8_pathname_composition()
 #endif

diff --git a/strbuf.c b/strbuf.c
index 0d929e4e19..cefea6b75f 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -591,6 +591,7 @@ int strbuf_getcwd(struct strbuf *sb)
 	for (;; guessed_len *= 2) {
 		strbuf_grow(sb, guessed_len);
 		if (getcwd(sb->buf, sb->alloc)) {
+			precompse_strbuf_if_needed(sb);
 			strbuf_setlen(sb, strlen(sb->buf));
 			return 0;
 		}
--
2.41.0.394.ge43f4fd0bd


  parent reply	other threads:[~2024-05-07  8:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240430032717281.IXLP.121462.mail.biglobe.ne.jp@biglobe.ne.jp>
2024-05-07  8:44 ` [PATCH v1 1/2] t0050: ls-files path fails if path of workdir is NFD tboegi
2024-05-07 17:30   ` Junio C Hamano
2024-05-07  8:44 ` tboegi [this message]
2024-05-07 17:22   ` [PATCH v1 2/2] strbuf_getcwd() needs precompse_strbuf_if_needed() Junio C Hamano
2024-05-09 15:24     ` Junio C Hamano
2024-05-09 15:29       ` Torsten Bögershausen
2024-05-07 17:47   ` Junio C Hamano
2024-05-08  0:32     ` brian m. carlson
2024-05-09 16:11 ` [PATCH v2 1/1] macOS: ls-files path fails if path of workdir is NFD tboegi
2024-05-09 16:37   ` Junio C Hamano
2024-05-19  7:03   ` Jun. T
2024-05-20 16:06     ` Torsten Bögershausen
2024-05-20 18:08       ` Junio C Hamano
2024-05-20 19:21         ` Torsten Bögershausen
2024-05-21 14:14 ` [PATCH v3 " tboegi
2024-05-21 17:50   ` Junio C Hamano
2024-05-21 20:57     ` Torsten Bögershausen
2024-05-21 22:15       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240507084431.19797-1-tboegi@web.de \
    --to=tboegi@web.de \
    --cc=git@vger.kernel.org \
    --cc=takimoto-j@kba.biglobe.ne.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).