public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Collin Funk <collin.funk1@gmail•com>
To: git@vger•kernel.org
Cc: "Collin Funk" <collin.funk1@gmail•com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail•com>,
	"Junio C Hamano" <gitster@pobox•com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx•de>,
	"Phillip Wood" <phillip.wood@dunelm•org.uk>,
	"Matthew John Cheetham" <mjcheetham@outlook•com>,
	"Victoria Dye" <vdye@github•com>, "Jeff King" <peff@peff•net>,
	"Derrick Stolee" <stolee@gmail•com>
Subject: [PATCH] git-compat-util: make git_find_last_dir_sep return a const pointer
Date: Mon,  2 Feb 2026 21:19:01 -0800	[thread overview]
Message-ID: <e6f7e2eddbc9aef1c21f661420a4b8cb9cd8e2c1.1770095829.git.collin.funk1@gmail.com> (raw)

Unsure if this should be tagged [RFC], but this patch clears up lots
of warning spam with glibc 2.43 because of a change mentioned in the
commit message.

I plan to handle the rest of them and try to organize the changes by
subsystem, for lack of a better term. But I figured it was best to
submit just this one for review first.

-- 8< --

The recent glibc 2.43 release had the following change listed in its
NEWS file:

    For ISO C23, the functions bsearch, memchr, strchr, strpbrk, strrchr,
    strstr, wcschr, wcspbrk, wcsrchr, wcsstr and wmemchr that return
    pointers into their input arrays now have definitions as macros that
    return a pointer to a const-qualified type when the input argument is
    a pointer to a const-qualified type.

When compiling with GCC 15, which defaults to -std=gnu23, this causes
many warnings like this:

        CC abspath.o
    In file included from abspath.c:1:
    git-compat-util.h: In function ‘git_find_last_dir_sep’:
    git-compat-util.h:344:16: warning: return discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
      344 |         return strrchr(path, '/');
          |                ^~~~~~~

Most of the warnings are from git_find_last_dir_sep which calls strrchr
on a "const char *" but returns a "char *". This patch addresses them by
changing the return type to be const, since only one location needs the
qualifier casted away.

Signed-off-by: Collin Funk <collin.funk1@gmail•com>
---
 config.c          | 2 +-
 git-compat-util.h | 2 +-
 remote.c          | 2 +-
 scalar.c          | 8 ++++----
 strbuf.c          | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/config.c b/config.c
index 7f6d53b473..156f2a24fa 100644
--- a/config.c
+++ b/config.c
@@ -160,7 +160,7 @@ static int handle_path_include(const struct key_value_info *kvi,
 	 * based on the including config file.
 	 */
 	if (!is_absolute_path(path)) {
-		char *slash;
+		const char *slash;
 
 		if (!kvi || kvi->origin_type != CONFIG_ORIGIN_FILE) {
 			ret = error(_("relative config includes must come from files"));
diff --git a/git-compat-util.h b/git-compat-util.h
index bebcf9f698..fb4251564a 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -339,7 +339,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/remote.c b/remote.c
index b756ff6f15..8c1a0a0c15 100644
--- a/remote.c
+++ b/remote.c
@@ -2753,7 +2753,7 @@ void remote_state_clear(struct remote_state *remote_state)
  */
 static int chop_last_dir(char **remoteurl, int is_relative)
 {
-	char *rfind = find_last_dir_sep(*remoteurl);
+	char *rfind = (char *) find_last_dir_sep(*remoteurl);
 	if (rfind) {
 		*rfind = '\0';
 		return 0;
diff --git a/scalar.c b/scalar.c
index c9df9348ec..54a75ad971 100644
--- a/scalar.c
+++ b/scalar.c
@@ -393,7 +393,7 @@ static int delete_enlistment(struct strbuf *enlistment)
 {
 	struct strbuf parent = STRBUF_INIT;
 	size_t offset;
-	char *path_sep;
+	const char *path_sep;
 
 	if (unregister_dir())
 		return error(_("failed to unregister repository"));
@@ -479,11 +479,11 @@ 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);
-		if (!enlistment) {
+		const char *last = find_last_dir_sep(buf.buf);
+		if (!last) {
 			die(_("cannot deduce worktree name from '%s'"), url);
 		}
-		enlistment = xstrdup(enlistment + 1);
+		enlistment = xstrdup(last + 1);
 	} else {
 		usage_msg_opt(_("You must specify a repository to clone."),
 			      clone_usage, clone_options);
diff --git a/strbuf.c b/strbuf.c
index 59678bf5b0..3939863cf3 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1119,6 +1119,6 @@ void strbuf_stripspace(struct strbuf *sb, const char *comment_prefix)
 
 void strbuf_strip_file_from_path(struct strbuf *sb)
 {
-	char *path_sep = find_last_dir_sep(sb->buf);
+	const char *path_sep = find_last_dir_sep(sb->buf);
 	strbuf_setlen(sb, path_sep ? path_sep - sb->buf + 1 : 0);
 }
-- 
2.52.0


             reply	other threads:[~2026-02-03  5:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-03  5:19 Collin Funk [this message]
2026-02-03  6:25 ` [PATCH] git-compat-util: make git_find_last_dir_sep return a const pointer Jeff King
2026-02-04  3:15   ` Collin Funk
2026-02-04  5:32     ` Jeff King
2026-03-19 11:06       ` Toon Claes
2026-03-20  4:39         ` Jeff King
2026-03-20  5:20           ` Collin Funk

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=e6f7e2eddbc9aef1c21f661420a4b8cb9cd8e2c1.1770095829.git.collin.funk1@gmail.com \
    --to=collin.funk1@gmail$(echo .)com \
    --cc=Johannes.Schindelin@gmx$(echo .)de \
    --cc=avarab@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    --cc=mjcheetham@outlook$(echo .)com \
    --cc=peff@peff$(echo .)net \
    --cc=phillip.wood@dunelm$(echo .)org.uk \
    --cc=stolee@gmail$(echo .)com \
    --cc=vdye@github$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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