Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
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.
Diffstat (limited to 'source/shared.c')
| -rw-r--r-- | source/shared.c | 18 |
1 file changed, 10 insertions, 8 deletions
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, |
