git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v1 2/2] strbuf_getcwd() needs precompse_strbuf_if_needed()

From
Junio C Hamano <gitster@pobox.com>
Date
May 7, 2024, 17:22 UTC
Message-ID
<xmqqa5l1pmf9.fsf@gitster.g>
In-Reply-To
<20240507084431.19797-1-tboegi@web.de>
tboegi@web.de writes:
> +void precompse_strbuf_if_needed(struct strbuf *sb)
> +{
> +	char *buf_prec = (char *)precompose_string_if_needed(sb->buf);
> +	if (buf_prec != sb->buf) {

Cute. This matches with the !PRECOMPSE_UNICODE case in git-compat-util.h where we do

    static inline const char *precompose_string_if_needed(const char *in)
    {
            return in;
    }

to make it a no-op. I was wondering how you are avoiding an inevitable crash from trying to free an unfreeable piece of memory, but this should do just fine.

You'd want to fix the typo in the name of the new function, I presume? "precompse" -> "precompose"

Show 6 quoted lines
> +		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);
> +	}
> +
> +}
Show 10 quoted lines
> 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));

The need for strbuf_setlen() stems from the use of getcwd() that may and will place a string that is much shorter than sb->alloc, so they logically belong together. It will make more sense to call the precompose _after_ arranging the members of strbuf in a consistent state with the call to strbuf_setlen().

>  			return 0;
>  		}
> --
> 2.41.0.394.ge43f4fd0bd
Previous: tboegi@web.deNext: Junio C Hamano
Message 2 of 24 in “strbuf_getcwd() needs precompse_strbuf_if_needed()”
  1. 2/2 strbuf_getcwd() needs precompse_strbuf_if_needed()tboegi@web.de, May 7, 2024
  2. Junio C HamanoMay 7, 2024
  3. Junio C HamanoMay 9, 2024
  4. Torsten BögershausenMay 9, 2024
  5. Junio C HamanoMay 7, 2024
  6. brian m. carlsonMay 8, 2024
  7. 1/2 t0050: ls-files path fails if path of workdir is NFDtboegi@web.de, May 7, 2024
  8. Junio C HamanoMay 7, 2024
  9. 1/1 macOS: ls-files path fails if path of workdir is NFDtboegi@web.de, May 9, 2024
  10. Junio C HamanoMay 9, 2024
  11. Jun. TMay 19, 2024
  12. Torsten BögershausenMay 20, 2024
  13. Junio C HamanoMay 20, 2024
  14. Torsten BögershausenMay 20, 2024
  15. 1/1 macOS: ls-files path fails if path of workdir is NFDtboegi@web.de, May 21, 2024
  16. Junio C HamanoMay 21, 2024
  17. Torsten BögershausenMay 21, 2024
  18. Junio C HamanoMay 21, 2024
  19. Jun. TMay 23, 2024
  20. Torsten BögershausenMay 25, 2024
  21. 1/1 macOS: ls-files path fails if path of workdir is NFDtboegi@web.de, May 31, 2024
  22. Junio C HamanoJun 1, 2024
  23. Torsten BögershausenJun 2, 2024
  24. Jun TJun 4, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.