author | Lars Hjemli <hjemli@gmail.com> | 2007-10-01 09:42:19 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-10-01 09:42:19 (UTC) |
commit | f527a57c8a55f5fd315e1bc1cb338f5f4a9b20ae (patch) (side-by-side diff) | |
tree | 086e1afad5762c5b6bb09672b58f2c491ffbbc20 | |
parent | 98fcf7227c8dda520c864ea8a51012934115258f (diff) | |
download | cgit-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>
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | shared.c | 11 | ||||
-rw-r--r-- | ui-diff.c | 3 |
3 files changed, 11 insertions, 5 deletions
@@ -125,97 +125,97 @@ extern int cgit_max_lock_attempts; extern int cgit_cache_root_ttl; extern int cgit_cache_repo_ttl; extern int cgit_cache_dynamic_ttl; extern int cgit_cache_static_ttl; extern int cgit_cache_max_create_time; extern int cgit_summary_log; extern int cgit_max_msg_len; extern int cgit_max_repodesc_len; extern int cgit_max_commit_count; extern int cgit_query_has_symref; extern int cgit_query_has_sha1; extern char *cgit_querystring; extern char *cgit_query_repo; extern char *cgit_query_page; extern char *cgit_query_search; extern char *cgit_query_head; extern char *cgit_query_sha1; extern char *cgit_query_sha2; extern char *cgit_query_path; extern char *cgit_query_name; 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); extern int cache_unlock(struct cacheitem *item); extern int cache_cancel_lock(struct cacheitem *item); extern int cache_exist(struct cacheitem *item); extern int cache_expired(struct cacheitem *item); extern char *cgit_repourl(const char *reponame); extern char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename, const char *query); extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query); extern const char *cgit_repobasename(const char *reponame); extern void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path); extern void cgit_log_link(char *name, char *title, char *class, char *head, char *rev, char *path, int ofs); extern void cgit_commit_link(char *name, char *title, char *class, char *head, char *rev); extern void cgit_snapshot_link(char *name, char *title, char *class, char *head, char *rev, char *archivename); extern void cgit_diff_link(char *name, char *title, char *class, char *head, char *new_rev, char *old_rev, char *path); @@ -341,78 +341,85 @@ int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) continue; } /* we have a complete line */ if (!diffbuf) { ((linediff_fn)priv)(mb[i].ptr, mb[i].size); continue; } diffbuf = xrealloc(diffbuf, buflen + mb[i].size); memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); free(diffbuf); diffbuf = NULL; buflen = 0; } if (diffbuf) { ((linediff_fn)priv)(diffbuf, buflen); free(diffbuf); diffbuf = NULL; buflen = 0; } return 0; } 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); } @@ -86,55 +86,54 @@ static void filepair_cb(struct diff_filepair *pair) return; } if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) cgit_print_error("Error running diff"); } void cgit_print_diff(const char *new_rev, const char *old_rev) { unsigned char sha1[20], sha2[20]; enum object_type type; unsigned long size; struct commit *commit, *commit2; if (!new_rev) new_rev = cgit_query_head; get_sha1(new_rev, sha1); type = sha1_object_info(sha1, &size); if (type == OBJ_BAD) { cgit_print_error(fmt("Bad object name: %s", new_rev)); return; } if (type != OBJ_COMMIT) { cgit_print_error(fmt("Unhandled object type: %s", typename(type))); 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>"); } |