From: Junio C Hamano <gitster@pobox.com>
To: Yannik Tausch <dev@ytausch.de>
Cc: git@vger.kernel.org
Subject: pathspec: match and original in pathspec_item are const
Date: Thu, 03 Sep 2026 11:13:29 -0700 [thread overview]
Message-ID: <xmqqy0dib3ue.fsf_-_@gitster.g> (raw)
In-Reply-To: <xmqq4ig6cihc.fsf@gitster.g> (Junio C. Hamano's message of "Thu, 03 Sep 2026 11:11:59 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> This unfortunately triggers
>
> t/unit-tests/u-dir.c: In function 'test_dir__common_prefix_skips_excluded_pathspec_items':
> t/unit-tests/u-dir.c:53:34: error: initialization discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
> 53 | .match = "unrelated/path",
> | ^~~~~~~~~~~~~~~~
>
> Other than that, looking good.
We may want a preparatory patch before this step.
----- >8 -----
Subject: pathspec: match and original in pathspec_item are const
No existing code modifies these two strings in pathspec elements
after they are created via these two pointers. Declare them as
"const char *" to stress on this fact and cast away constness from
the code that frees these two strings.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
pathspec.c | 4 ++--
pathspec.h | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git c/pathspec.c w/pathspec.c
index f78b22709c..06b7065372 100644
--- c/pathspec.c
+++ w/pathspec.c
@@ -749,8 +749,8 @@ void clear_pathspec(struct pathspec *pathspec)
int i, j;
for (i = 0; i < pathspec->nr; i++) {
- free(pathspec->items[i].match);
- free(pathspec->items[i].original);
+ free((void *)pathspec->items[i].match);
+ free((void *)pathspec->items[i].original);
for (j = 0; j < pathspec->items[i].attr_match_nr; j++)
free(pathspec->items[i].attr_match[j].value);
diff --git c/pathspec.h w/pathspec.h
index 5e3a6f1fe7..fc1b9465ad 100644
--- c/pathspec.h
+++ w/pathspec.h
@@ -35,8 +35,8 @@ struct pathspec {
unsigned magic;
int max_depth;
struct pathspec_item {
- char *match;
- char *original;
+ const char *match;
+ const char *original;
unsigned magic;
int len, prefix;
int nowildcard_len;
next prev parent reply other threads:[~2026-09-03 18:13 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 13:04 [PATCH] dir: find common prefix among positive pathspecs Yannik Tausch
2026-09-02 17:07 ` Junio C Hamano
2026-09-03 9:59 ` Yannik Tausch
2026-09-03 10:02 ` [PATCH v2 0/2] dir: fix pathspec prefixes with exclusions Yannik Tausch
2026-09-03 10:03 ` [PATCH v2 1/2] dir: do not apply prefix to negative pathspecs Yannik Tausch
2026-09-04 5:00 ` Elijah Newren
2026-09-04 14:21 ` Junio C Hamano
2026-09-03 10:04 ` [PATCH v2 2/2] dir: find common prefix among non-exclude pathspec items Yannik Tausch
[not found] ` <CY5PR17MB6144A1A7BF2E101FE26A6A85B1B62@CY5PR17MB6144.namprd17.prod.outlook.com>
2026-09-03 11:49 ` Yannik Tausch
2026-09-03 18:11 ` Junio C Hamano
2026-09-03 18:13 ` Junio C Hamano [this message]
2026-09-03 18:37 ` pathspec: match and original in pathspec_item are const Yannik Tausch
2026-09-03 18:51 ` Junio C Hamano
2026-09-03 18:57 ` Yannik Tausch
2026-09-03 21:05 ` Junio C Hamano
2026-09-03 21:13 ` Yannik Tausch
2026-09-04 5:02 ` [PATCH v2 2/2] dir: find common prefix among non-exclude pathspec items Elijah Newren
2026-09-04 16:43 ` Junio C Hamano
2026-09-04 19:19 ` Elijah Newren
2026-09-05 16:14 ` Junio C Hamano
2026-09-03 18:06 ` [PATCH v2 0/2] dir: fix pathspec prefixes with exclusions Yannik Tausch
2026-09-03 18:43 ` [PATCH v3 0/3] " Yannik Tausch
2026-09-03 18:44 ` [PATCH v3 1/3] pathspec: match and original in pathspec_item are const Yannik Tausch
2026-09-03 18:45 ` [PATCH v3 2/3] dir: do not apply prefix to negative pathspecs Yannik Tausch
2026-09-03 18:45 ` [PATCH v3 3/3] dir: find common prefix among non-exclude pathspec items Yannik Tausch
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=xmqqy0dib3ue.fsf_-_@gitster.g \
--to=gitster@pobox.com \
--cc=dev@ytausch.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.