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

[PATCH 2/6] do not discard const: make git-compat-util ISOC23-like

From
Michael J Gruber <git@grubix.eu>
Date
Mar 26, 2026, 15:22 UTC
Message-ID
<cfea3c6f006f926319da79bb7d97d57fb3b580e9.1774537954.git.git@grubix.eu>
In-Reply-To
<cover.1774537954.git.git@grubix.eu>
find_last_dir() should and can return a const pointer. This change fixes
the warnings with ISOC23 for git-compat-util and - via explicit casts -
makes it clear where we mutate the returned memory.
---
 git-compat-util.h | 2 +-
 scalar.c          | 2 +-
 submodule.c       | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 4b4ea2498f..3c3dbe298c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -335,7 +335,7 @@ static inline int is_path_owned_by_current_uid(const char *path,
 #endif
 
 #ifndef find_last_dir_sep
-static inline char *git_find_last_dir_sep(const char *path)
+static inline const char *git_find_last_dir_sep(const char *path)
 {
 	return strrchr(path, '/');
 }
diff --git a/scalar.c b/scalar.c
index 4efb6ac36d..44f432d7f0 100644
--- a/scalar.c
+++ b/scalar.c
@@ -479,7 +479,7 @@ static int cmd_clone(int argc, const char **argv)
 		/* Strip suffix `.git`, if any */
 		strbuf_strip_suffix(&buf, ".git");
 
-		enlistment = find_last_dir_sep(buf.buf);
+		enlistment = (char *) find_last_dir_sep(buf.buf);
 		if (!enlistment) {
 			die(_("cannot deduce worktree name from '%s'"), url);
 		}
diff --git a/submodule.c b/submodule.c
index b1a0363f9d..57933386bc 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2268,7 +2268,7 @@ static int check_casefolding_conflict(const char *git_dir,
 	DIR *dir = NULL;
 	int ret = 0;
 
-	if ((p = find_last_dir_sep(modules_dir)))
+	if ((p = (char *) find_last_dir_sep(modules_dir)))
 		*p = '\0';
 
 	/* No conflict is possible if modules_dir doesn't exist (first clone) */
-- 
2.53.0.1195.g771ffcb452
Previous: Michael J GruberNext: Michael J Gruber
Message 20 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.