summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-10-01 09:42:19 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-10-01 09:42:19 (UTC)
commitf527a57c8a55f5fd315e1bc1cb338f5f4a9b20ae (patch) (side-by-side diff)
tree086e1afad5762c5b6bb09672b58f2c491ffbbc20
parent98fcf7227c8dda520c864ea8a51012934115258f (diff)
downloadcgit-f527a57c8a55f5fd315e1bc1cb338f5f4a9b20ae.zip
cgit-f527a57c8a55f5fd315e1bc1cb338f5f4a9b20ae.tar.gz
cgit-f527a57c8a55f5fd315e1bc1cb338f5f4a9b20ae.tar.bz2
Add prefix parameter to cgit_diff_tree()
This paramter can be used to restrict a diff to the specified path prefix. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (show 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
@@ -149,49 +149,49 @@ extern int cgit_query_ofs;
extern int htmlfd;
extern int cgit_get_cmd_index(const char *cmd);
extern struct repoinfo *cgit_get_repoinfo(const char *url);
extern void cgit_global_config_cb(const char *name, const char *value);
extern void cgit_repo_config_cb(const char *name, const char *value);
extern void cgit_querystring_cb(const char *name, const char *value);
extern int chk_zero(int result, char *msg);
extern int chk_positive(int result, char *msg);
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);
extern void html_link_close(void);
extern void html_filemode(unsigned short mode);
extern int html_include(const char *filename);
extern int cgit_read_config(const char *filename, configfn fn);
extern int cgit_parse_query(char *txt, configfn fn);
extern struct commitinfo *cgit_parse_commit(struct commit *commit);
extern struct taginfo *cgit_parse_tag(struct tag *tag);
extern void cgit_parse_url(const char *url);
extern char *cache_safe_filename(const char *unsafe);
extern int cache_lock(struct cacheitem *item);
diff --git a/shared.c b/shared.c
index 0a6a5ed..3d4feea 100644
--- a/shared.c
+++ b/shared.c
@@ -365,54 +365,61 @@ int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf)
int cgit_diff_files(const unsigned char *old_sha1,
const unsigned char *new_sha1,
linediff_fn fn)
{
mmfile_t file1, file2;
xpparam_t diff_params;
xdemitconf_t emit_params;
xdemitcb_t emit_cb;
if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1))
return 1;
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
@@ -110,31 +110,30 @@ void cgit_print_diff(const char *new_rev, const char *old_rev)
return;
}
commit = lookup_commit_reference(sha1);
if (!commit || parse_commit(commit))
cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(sha1)));
if (old_rev)
get_sha1(old_rev, sha2);
else if (commit->parents && commit->parents->item)
hashcpy(sha2, commit->parents->item->object.sha1);
else
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>");
}