From b275e66df0ad3f000d1e0fa964c58b04711066e5 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Wed, 23 Sep 2026 19:13:47 -1000 Subject: Limit rawdiff to the requested path The diff and patch pages honour the path in the url, which the parameter table documents for every page, but rawdiff never handed it to git and answered with the whole diff. --- source/shared.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'source/shared.c') diff --git a/source/shared.c b/source/shared.c index 1b610a0..78dc3f4 100644 --- a/source/shared.c +++ b/source/shared.c @@ -451,11 +451,24 @@ int cgit_diff_files(const struct object_id *old_oid, const struct object_id *new return 0; } +void cgit_diff_limit_path(struct diff_options *opt, const char *prefix) +{ + struct pathspec_item *item; + + 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; +} + void cgit_diff_tree(const struct object_id *old_oid, const struct object_id *new_oid, filepair_fn fn, const char *prefix, int ignorews) { struct diff_options opt; - struct pathspec_item *item; repo_diff_setup(the_repository, &opt); opt.output_format = DIFF_FORMAT_CALLBACK; @@ -466,16 +479,8 @@ void cgit_diff_tree(const struct object_id *old_oid, const struct object_id *new DIFF_XDL_SET(&opt, IGNORE_WHITESPACE); opt.format_callback = cgit_diff_tree_cb; opt.format_callback_data = fn; - if (prefix) { - 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; - } + if (prefix) + cgit_diff_limit_path(&opt, prefix); diff_setup_done(&opt); if (old_oid && !is_null_oid(old_oid)) -- cgit 2.12.1