From 9a8f88658d51aeb86a79ac1121de13562ad2601f Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 16 Dec 2006 00:19:56 +0100 Subject: Add ui-commit.c + misc ui cleanups Signed-off-by: Lars Hjemli --- Makefile | 2 +- cgit.c | 2 ++ cgit.css | 50 ++++++++++++++++++++++++++++++++++---- cgit.h | 5 ++-- parsing.c | 1 + ui-commit.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ui-log.c | 11 +++------ ui-tree.c | 6 ++--- ui-view.c | 2 +- 9 files changed, 140 insertions(+), 19 deletions(-) create mode 100644 ui-commit.c diff --git a/Makefile b/Makefile index 2a4d62a..58a583b 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ CACHE_ROOT = /var/cache/cgit EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ - ui-summary.o ui-log.o ui-view.c ui-tree.c + ui-summary.o ui-log.o ui-view.c ui-tree.c ui-commit.c CFLAGS += -Wall diff --git a/cgit.c b/cgit.c index d7e586d..37cdb83 100644 --- a/cgit.c +++ b/cgit.c @@ -32,6 +32,8 @@ static void cgit_print_repo_page(struct cacheitem *item) cgit_print_log(cgit_query_head, cgit_query_ofs, 100); } else if (!strcmp(cgit_query_page, "tree")) { cgit_print_tree(cgit_query_sha1); + } else if (!strcmp(cgit_query_page, "commit")) { + cgit_print_commit(cgit_query_sha1); } else if (!strcmp(cgit_query_page, "view")) { cgit_print_view(cgit_query_sha1); } diff --git a/cgit.css b/cgit.css index 97b4e27..3579598 100644 --- a/cgit.css +++ b/cgit.css @@ -21,16 +21,15 @@ table.list { } table.list th { - text-align: left; font-weight: bold; background: #ddd; border-bottom: solid 1px #aaa; - padding: 0.1em 0.5em 0.1em; + padding: 0.1em 0.5em 0.1em 0.5em; vertical-align: baseline; } table.list td { border: none; - padding: 0.1em 1em 0.1em 0.5em; + padding: 0.1em 0.5em 0.1em 0.5em; background: white; } @@ -56,6 +55,10 @@ div#content { margin: 0.5em 0.5em; } +div#blob { + border: solid 1px black; +} + div.error { color: red; font-weight: bold; @@ -75,4 +78,43 @@ td.blob { white-space: pre; font-family: courier; font-size: 100%; -} \ No newline at end of file +} + +table.log td { + white-space: nowrap; +} + +table.commit-info { + border-collapse: collapse; + margin-top: 1em; + +} +table.commit-info th { + text-align: left; + font-weight: normal; + padding: 0.1em 1em 0.1em 0.1em; +} +table.commit-info td { + font-weight: normal; + padding: 0.1em 1em 0.1em 0.1em; +} +div.commit-subject { + font-weight: bold; + font-size: 110%; + margin: 1em 0em 1em; +} +div.commit-msg { + white-space: pre; + font-family: courier; + font-size: 100%; +} +.sha1 { + font-family: courier; + font-size: 90%; +} +.left { + text-align: left; +} +.right { + text-align: right; +} diff --git a/cgit.h b/cgit.h index 268db53..a905e47 100644 --- a/cgit.h +++ b/cgit.h @@ -92,7 +92,8 @@ extern void cgit_print_pageheader(char *title); 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); -extern void cgit_print_view(char *hex); -extern void cgit_print_tree(const char *sha1); +extern void cgit_print_view(const char *hex); +extern void cgit_print_tree(const char *hex); +extern void cgit_print_commit(const char *hex); #endif /* CGIT_H */ diff --git a/parsing.c b/parsing.c index 6cab0e9..be471b5 100644 --- a/parsing.c +++ b/parsing.c @@ -150,6 +150,7 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) t = strchr(p, '\n'); ret->subject = substr(p, t); + p = t + 1; while (*p == '\n') p = strchr(p, '\n') + 1; diff --git a/ui-commit.c b/ui-commit.c new file mode 100644 index 0000000..1c0e7e5 --- /dev/null +++ b/ui-commit.c @@ -0,0 +1,80 @@ +#include "cgit.h" + +void cgit_print_date(unsigned long secs) +{ + char buf[32]; + struct tm *time; + + time = gmtime(&secs); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); + html_txt(buf); + +} + +void cgit_print_commit(const char *hex) +{ + struct commit *commit; + struct commitinfo *info; + struct commit_list *p; + unsigned long size; + char type[20]; + char *buf; + + unsigned char sha1[20]; + + if (get_sha1(hex, sha1)) { + cgit_print_error(fmt("Bad object id: %s", hex)); + return; + } + + buf = read_sha1_file(sha1, type, &size); + if (!buf) { + cgit_print_error(fmt("Bad object reference: %s", hex)); + return; + } + + commit = lookup_commit(sha1); + if (!commit) { + cgit_print_error(fmt("Bad commit reference: %s", hex)); + return; + } + + commit->buffer = buf; + if (parse_commit_buffer(commit, buf, size)) { + cgit_print_error(fmt("Malformed commit buffer: %s", hex)); + return; + } + + info = cgit_parse_commit(commit); + + html("\n"); + html("\n"); + html("\n"); + html("\n", sha1_to_hex(commit->tree->object.sha1)); + + for (p = commit->parents; p ; p = p->next) { + html("\n", + sha1_to_hex(p->item->object.sha1)); + } + html("
author"); + html_txt(info->author); + html("
committer"); + html_txt(info->committer); + html(""); + cgit_print_date(commit->date); + html("
tree%s
parent%s
\n"); + html("
"); + html_txt(info->subject); + html("
"); + html("
"); + html_txt(info->msg); + html("
"); + free(info->author); + free(info->committer); + free(info->subject); + free(info); +} diff --git a/ui-log.c b/ui-log.c index 31331ef..c52af79 100644 --- a/ui-log.c +++ b/ui-log.c @@ -21,17 +21,12 @@ void print_commit(struct commit *commit) html_txt(buf); html(""); char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); - char *url = cgit_pageurl(cgit_query_repo, "view", qry); + char *url = cgit_pageurl(cgit_query_repo, "commit", qry); html_link_open(url, NULL, NULL); html_txt(info->subject); html_link_close(); html(""); html_txt(info->author); - html("tree"); html("\n"); free(info->author); free(info->committer); @@ -56,8 +51,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt) prepare_revision_walk(&rev); html("

Log

"); - html(""); - html("\n"); + html("
DateMessageAuthorLink
"); + html("\n"); if (ofs<0) ofs = 0; diff --git a/ui-tree.c b/ui-tree.c index 84930cb..c4d75ab 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -62,9 +62,9 @@ void cgit_print_tree(const char *hex) html("

Tree content

\n"); html("
DateMessageAuthor
\n"); - html(""); - html(""); - html("\n"); + html(""); + html(""); + html("\n"); read_tree_recursive(tree, "", 0, 1, NULL, print_entry); html("
NameSizeMode
NameSizeMode
\n"); } diff --git a/ui-view.c b/ui-view.c index 9d13be1..b75ce9a 100644 --- a/ui-view.c +++ b/ui-view.c @@ -8,7 +8,7 @@ #include "cgit.h" -void cgit_print_view(char *hex) +void cgit_print_view(const char *hex) { unsigned char sha1[20]; char type[20]; -- cgit