pager: explicitly cast away strchr() constness

When we do: char *cp = strchr(argv[i], '='); it implicitly removes the constness from argv[i]. We need "cp" to remain writable (since we overwrite it with a NUL). In theory we should be able to drop the const from argv[i], because it is a sub-pointer into our duplicated pager_env variable. But we get it from split_cmdline(), which uses the traditional "const char **" type for argv. This is overly limiting, but changing it would be awkward for all the other callers of split_cmdline(). Let's do an explicit cast with a note about why it is OK. This is enough to silence compiler warnings about the implicit const problems. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 2, 2026 at 00:14 UTC 031d29d6fbf12284d391c23f04d15970c3bac11c
1 file changed +3 -2
pager.c
+3 -2
@@ -108,10 +108,11 @@ const char *git_pager(struct repository *r, int stdout_is_tty)
108
109 static void setup_pager_env(struct strvec *env)
110 {
111 - const char **argv;
111 + char **argv;
112 int i;
113 char *pager_env = xstrdup(PAGER_ENV);
114 - int n = split_cmdline(pager_env, &argv);
114 + /* split_cmdline splits in place, so we know the result is writable */
115 + int n = split_cmdline(pager_env, (const char ***)&argv);
116
117 if (n < 0)
118 die("malformed build-time PAGER_ENV: %s",