summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.h2
-rw-r--r--shared.c11
-rw-r--r--ui-diff.c3
3 files changed, 11 insertions, 5 deletions
diff --git a/cgit.h b/cgit.h
index e3d9cb8..5ef0bc5 100644
--- a/cgit.h
+++ b/cgit.h
@@ -161,25 +161,25 @@ extern int chk_non_negative(int result, char *msg);
extern int hextoint(char c);
extern char *trim_end(const char *str, char c);
extern void *cgit_free_commitinfo(struct commitinfo *info);
extern int cgit_diff_files(const unsigned char *old_sha1,
const unsigned char *new_sha1,
linediff_fn fn);
extern void cgit_diff_tree(const unsigned char *old_sha1,
const unsigned char *new_sha1,
- filepair_fn fn);
+ filepair_fn fn, const char *prefix);
extern void cgit_diff_commit(struct commit *commit, filepair_fn fn);
extern char *fmt(const char *format,...);
extern void html(const char *txt);
extern void htmlf(const char *format,...);
extern void html_txt(char *txt);
extern void html_ntxt(int len, char *txt);
extern void html_attr(char *txt);
extern void html_hidden(char *name, char *value);
extern void html_link_open(char *url, char *title, char *class);
diff --git a/shared.c b/shared.c
index 0a6a5ed..3d4feea 100644
--- a/shared.c
+++ b/shared.c
@@ -377,42 +377,49 @@ int cgit_diff_files(const unsigned char *old_sha1,
diff_params.flags = XDF_NEED_MINIMAL;
emit_params.ctxlen = 3;
emit_params.flags = XDL_EMIT_FUNCNAMES;
emit_params.find_func = NULL;
emit_cb.outf = filediff_cb;
emit_cb.priv = fn;
xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb);
return 0;
}
void cgit_diff_tree(const unsigned char *old_sha1,
const unsigned char *new_sha1,
- filepair_fn fn)
+ filepair_fn fn, const char *prefix)
{
struct diff_options opt;
int ret;
+ int prefixlen;
diff_setup(&opt);
opt.output_format = DIFF_FORMAT_CALLBACK;
opt.detect_rename = 1;
opt.rename_limit = cgit_renamelimit;
opt.recursive = 1;
opt.format_callback = cgit_diff_tree_cb;
opt.format_callback_data = fn;
+ if (prefix) {
+ opt.nr_paths = 1;
+ opt.paths = &prefix;
+ prefixlen = strlen(prefix);
+ opt.pathlens = &prefixlen;
+ }
diff_setup_done(&opt);
if (old_sha1 && !is_null_sha1(old_sha1))
ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt);
else
ret = diff_root_tree_sha1(new_sha1, "", &opt);
diffcore_std(&opt);
diff_flush(&opt);
}
void cgit_diff_commit(struct commit *commit, filepair_fn fn)
{
unsigned char *old_sha1 = NULL;
if (commit->parents)
old_sha1 = commit->parents->item->object.sha1;
- cgit_diff_tree(old_sha1, commit->object.sha1, fn);
+ cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL);
}
diff --git a/ui-diff.c b/ui-diff.c
index 0be845f..11a2ff8 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -122,19 +122,18 @@ void cgit_print_diff(const char *new_rev, const char *old_rev)
hashclr(sha2);
if (!is_null_sha1(sha2)) {
type = sha1_object_info(sha2, &size);
if (type == OBJ_BAD) {
cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(sha2)));
return;
}
commit2 = lookup_commit_reference(sha2);
if (!commit2 || parse_commit(commit2))
cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(sha2)));
}
-
html("<table class='diff'>");
html("<tr><td>");
- cgit_diff_tree(sha2, sha1, filepair_cb);
+ cgit_diff_tree(sha2, sha1, filepair_cb, NULL);
html("</td></tr>");
html("</table>");
}