From cbadaccdf6b8a87f962a9230b977cd6b28d7bada Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 14:14:32 -0700 Subject: Build a literal pathspec in one place Git's pathspec item holds a const string now, so a path needs no writable copy to be matched. --- source/shared.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'source/shared.c') diff --git a/source/shared.c b/source/shared.c index e075b8a..183d085 100644 --- a/source/shared.c +++ b/source/shared.c @@ -394,18 +394,20 @@ int cgit_blob_too_large(size_t size) return ctx.cfg.max_blob_size && size / 1024 > (size_t)ctx.cfg.max_blob_size; } -void cgit_diff_limit_path(struct diff_options *opt, const char *prefix) +void cgit_literal_pathspec(struct pathspec *ps, struct pathspec_item *item, const char *path) { - struct pathspec_item *item; + int len = path ? strlen(path) : 0; - item = xcalloc(1, sizeof(*item)); - item->match = xstrdup(prefix); - item->len = strlen(prefix); // nowildcard_len matching len makes git treat the path as literal // rather than as a glob. - item->nowildcard_len = item->len; - opt->pathspec.nr = 1; - opt->pathspec.items = item; + *item = (struct pathspec_item){ .match = path, .len = len, .nowildcard_len = len }; + ps->nr = path ? 1 : 0; + ps->items = item; +} + +void cgit_diff_limit_path(struct diff_options *opt, const char *prefix) +{ + cgit_literal_pathspec(&opt->pathspec, xmalloc(sizeof(struct pathspec_item)), xstrdup(prefix)); } void cgit_diff_tree(const struct object_id *old_oid, const struct object_id *new_oid, -- cgit