diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
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.
Diffstat (limited to 'source/shared.c')
-rw-r--r--source/shared.c27
1 file changed, 16 insertions, 11 deletions
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))