summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-05-15 22:58:35 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-05-15 22:58:35 (UTC)
commitf9ff7df613b4ee86fe5914c4ae3400650882c03d (patch) (side-by-side diff)
treec26fde3a4d3485943c275232f18359bebd133f1a
parenta2ddc10479ec463708e422ca5ce7ec02c22a7d02 (diff)
downloadcgit-f9ff7df613b4ee86fe5914c4ae3400650882c03d.zip
cgit-f9ff7df613b4ee86fe5914c4ae3400650882c03d.tar.gz
cgit-f9ff7df613b4ee86fe5914c4ae3400650882c03d.tar.bz2
Add support for commitdiff via h parameter
The commitdiff will be generated against the first parent, and the diff page also gets the benefit of repo.defbranch. Cleaned up some bad whitespace in cgit.h while at it. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c3
-rw-r--r--cgit.h11
-rw-r--r--ui-diff.c14
3 files changed, 21 insertions, 7 deletions
diff --git a/cgit.c b/cgit.c
index 9b4815d..3e7e595 100644
--- a/cgit.c
+++ b/cgit.c
@@ -111,25 +111,26 @@ static void cgit_print_repo_page(struct cacheitem *item)
if (!strcmp(cgit_query_page, "log")) {
cgit_print_log(cgit_query_head, cgit_query_ofs,
cgit_max_commit_count, cgit_query_search,
cgit_query_path);
} else if (!strcmp(cgit_query_page, "tree")) {
cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path);
} else if (!strcmp(cgit_query_page, "commit")) {
cgit_print_commit(cgit_query_head);
} else if (!strcmp(cgit_query_page, "view")) {
cgit_print_view(cgit_query_sha1, cgit_query_path);
} else if (!strcmp(cgit_query_page, "diff")) {
- cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path);
+ cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2,
+ cgit_query_path);
} else {
cgit_print_error("Invalid request");
}
cgit_print_docend();
}
static void cgit_fill_cache(struct cacheitem *item, int use_cache)
{
static char buf[PATH_MAX];
int stdout2;
getcwd(buf, sizeof(buf));
diff --git a/cgit.h b/cgit.h
index ac710a6..764225d 100644
--- a/cgit.h
+++ b/cgit.h
@@ -148,37 +148,38 @@ 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 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_pageurl(const char *reponame, const char *pagename,
+extern char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query);
extern void cgit_print_error(char *msg);
extern void cgit_print_date(unsigned long secs);
extern void cgit_print_docstart(char *title, struct cacheitem *item);
extern void cgit_print_docend();
extern void cgit_print_pageheader(char *title, int show_search);
-extern void cgit_print_snapshot_start(const char *mimetype,
- const char *filename,
+extern void cgit_print_snapshot_start(const char *mimetype,
+ const char *filename,
struct cacheitem *item);
extern void cgit_print_repolist(struct cacheitem *item);
extern void cgit_print_summary();
extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path);
extern void cgit_print_view(const char *hex, char *path);
extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
extern void cgit_print_tree(const char *rev, const char *hex, char *path);
extern void cgit_print_commit(const char *hex);
-extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path);
-extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
+extern void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex,
+ char *path);
+extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
const char *format, const char *prefix,
const char *filename);
#endif /* CGIT_H */
diff --git a/ui-diff.c b/ui-diff.c
index 999b6f3..afe1c90 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -57,29 +57,41 @@ static void header(unsigned char *sha1, char *path1,
html("</div>");
}
static void filepair_cb(struct diff_filepair *pair)
{
header(pair->one->sha1, pair->one->path,
pair->two->sha1, pair->two->path);
if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line))
cgit_print_error("Error running diff");
html("</tr></td>");
}
-void cgit_print_diff(const char *old_hex, const char *new_hex, char *path)
+void cgit_print_diff(const char *head, const char *old_hex, const char *new_hex, char *path)
{
unsigned char sha1[20], sha2[20];
enum object_type type;
unsigned long size;
+ struct commit *commit;
+
+ if (head && !old_hex && !new_hex) {
+ get_sha1(head, sha1);
+ commit = lookup_commit_reference(sha1);
+ if (commit && !parse_commit(commit)) {
+ html("<table class='diff'>");
+ cgit_diff_commit(commit, filepair_cb);
+ html("</td></tr></table>");
+ }
+ return;
+ }
get_sha1(old_hex, sha1);
get_sha1(new_hex, sha2);
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD) {
type = sha1_object_info(sha2, &size);
if (type == OBJ_BAD) {
cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex));
return;
}
}