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

Re: [PATCH 3/6] do not discard const: adjust to non-const data types

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 26, 2026, 17:28 UTC
Message-ID
<xmqq5x6iqz3d.fsf@gitster.g>
In-Reply-To
<8a65ada967b6b1308ea4cffca82102d4de8e9dd9.1774537954.git.git@grubix.eu>
Michael J Gruber <git@grubix.eu> writes:
Show 36 quoted lines
> We use data types (such as string_list's util member) which are not
> necessarily "non-const in practice" (such as the list of environment
> variables in run-command.c) but are not declared "const". Rather than
> duplicating data types (e.g. with a new constr_string_list), discard the
> const explicitly for now to quell ISOC23 warnings.
> ---
>  http-push.c   | 2 +-
>  run-command.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/http-push.c b/http-push.c
> index 9ae6062198..acc7f1d8fa 100644
> --- a/http-push.c
> +++ b/http-push.c
> @@ -1772,7 +1772,7 @@ int cmd_main(int argc, const char **argv)
>  			str_end_url_with_slash(arg, &repo->url);
>  			repo->path_len = strlen(repo->url);
>  			if (path) {
> -				repo->path = strchr(path+2, '/');
> +				repo->path = (char *) strchr(path+2, '/');
>  				if (repo->path)
>  					repo->path_len = strlen(repo->path);
>  			}
> diff --git a/run-command.c b/run-command.c
> index 32c290ee6a..1db02ef030 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -604,7 +604,7 @@ static void trace_add_env(struct strbuf *dst, const char *const *deltaenv)
>  	/* Last one wins, see run-command.c:prep_childenv() for context */
>  	for (e = deltaenv; e && *e; e++) {
>  		struct strbuf key = STRBUF_INIT;
> -		char *equals = strchr(*e, '=');
> +		char *equals = (char *) strchr(*e, '=');
>  
>  		if (equals) {
>  			strbuf_add(&key, *e, equals - *e);

I didn't look at the other http-push.c one, but this part with a bit wider context reads like this:

	for (e = deltaenv; e && *e; e++) {
		struct strbuf key = STRBUF_INIT;
		char *equals = strchr(*e, '=');
		if (equals) {
			strbuf_add(&key, *e, equals - *e);
			string_list_insert(&envs, key.buf)->util = equals + 1;
		} else {
			string_list_insert(&envs, *e)->util = NULL;
		}
		strbuf_release(&key);
	}

I wonder if the cast to strip away constness wants to go near the assignment to ->util.

Previous: Michael J GruberNext: D. Ben Knoble
Message 22 of 24 in “ISOC23: quell warnings on discarding const”
  1. 0/6 ISOC23: quell warnings on discarding constMichael J Gruber, Mar 26, 2026
  2. 5/6 do not discard const: keep signatureMichael J Gruber, Mar 26, 2026
  3. Junio C HamanoMar 26, 2026
  4. 6/6 do not discard const: the ugly truthMichael J Gruber, Mar 26, 2026
  5. Junio C HamanoMar 26, 2026
  6. Jeff KingMar 26, 2026
  7. 0/4 fix const issues in revision parserJeff King, Mar 26, 2026
  8. 1/4 revision: make handle_dotdot() interface less confusingJeff King, Mar 26, 2026
  9. Junio C HamanoMar 26, 2026
  10. Jeff KingMar 26, 2026
  11. Junio C HamanoMar 27, 2026
  12. 2/4 rev-parse: simplify dotdot parsingJeff King, Mar 26, 2026
  13. 3/4 revision: avoid writing to const string for parent marksJeff King, Mar 26, 2026
  14. 4/4 rev-parse: avoid writing to const string for parent marksJeff King, Mar 26, 2026
  15. 1/6 do not discard const: the simple casesMichael J Gruber, Mar 26, 2026
  16. Jeff KingMar 26, 2026
  17. Junio C HamanoMar 26, 2026
  18. config: store allocated string in non-const pointerJeff King, Mar 26, 2026
  19. 4/6 do not discard const: declare const where we stay constMichael J Gruber, Mar 26, 2026
  20. 2/6 do not discard const: make git-compat-util ISOC23-likeMichael J Gruber, Mar 26, 2026
  21. 3/6 do not discard const: adjust to non-const data typesMichael J Gruber, Mar 26, 2026
  22. Junio C HamanoMar 26, 2026
  23. D. Ben KnobleMar 26, 2026
  24. Michael J GruberMar 27, 2026

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.