]> git.cameronkatri.com Git - cgit.git/commitdiff
Add ui-commit.c + misc ui cleanups
authorLars Hjemli <hjemli@gmail.com>
Fri, 15 Dec 2006 23:19:56 +0000 (00:19 +0100)
committerLars Hjemli <hjemli@gmail.com>
Fri, 15 Dec 2006 23:19:56 +0000 (00:19 +0100)
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Makefile
cgit.c
cgit.css
cgit.h
parsing.c
ui-commit.c [new file with mode: 0644]
ui-log.c
ui-tree.c
ui-view.c

index 2a4d62a4b1d9463b500be3b9c3d263479efd476c..58a583b339463db275ec54b402c8092a5b8ff62c 100644 (file)
--- 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 d7e586d0962d9f7a9c43c89c8ee50bd933c09662..37cdb8331495a54820a9f67f01f86484b3a847f2 100644 (file)
--- 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);
        }
index 97b4e27b5d93ec0f3000cc6bbcbd06c73ece123b..3579598c7dfc105745211d8f2bbd0c20b85b9268 100644 (file)
--- 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 268db53164ac176150f0d9d9a128c99df55dabbf..a905e479b703d1873f75c01d39eddabb0c6a47cc 100644 (file)
--- 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 */
index 6cab0e94701fe12f8e0fd6e48d05004d761f113f..be471b5fd57ef6451fbab7ff0402df0fad47a844 100644 (file)
--- 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 (file)
index 0000000..1c0e7e5
--- /dev/null
@@ -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("<table class='commit-info'>\n");
+       html("<tr><th>author</th><td colspan='2'>");
+       html_txt(info->author);
+       html("</td></tr>\n");
+       html("<tr><th>committer</th><td>");
+       html_txt(info->committer);
+       html("</td><td class='right'>");
+       cgit_print_date(commit->date);
+       html("</td></tr>\n");
+       html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='");
+       html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("id=%s", sha1_to_hex(commit->tree->object.sha1))));
+       htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1));
+       
+       for (p = commit->parents; p ; p = p->next) {
+               html("<tr><th>parent</th><td colspan='2' class='sha1'><a href='");
+               html_attr(cgit_pageurl(cgit_query_repo, "commit", fmt("id=%s", sha1_to_hex(p->item->object.sha1))));
+               htmlf("'>%s</a></td></tr>\n", 
+                     sha1_to_hex(p->item->object.sha1));
+       }
+       html("</table>\n");
+       html("<div class='commit-subject'>");
+       html_txt(info->subject);
+       html("</div>");
+       html("<div class='commit-msg'>");
+       html_txt(info->msg);
+       html("</div>");
+       free(info->author);
+       free(info->committer);
+       free(info->subject);
+       free(info);
+}
index 31331ef4c35028ab6fbcfe7cf5cf8cb49c875cad..c52af79ac5ffb876bd4e41211fda907baa0f629b 100644 (file)
--- a/ui-log.c
+++ b/ui-log.c
@@ -21,17 +21,12 @@ void print_commit(struct commit *commit)
        html_txt(buf);
        html("</td><td>");
        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("</td><td>");
        html_txt(info->author);
-       html("</td><td><a href='");
-       html_attr(cgit_pageurl(cgit_query_repo, "tree", 
-                              fmt("id=%s", 
-                                  sha1_to_hex(commit->tree->object.sha1))));
-       html("'>tree</a>");
        html("</td></tr>\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("<h2>Log</h2>");
-       html("<table class='list'>");
-       html("<tr><th>Date</th><th>Message</th><th>Author</th><th>Link</th></tr>\n");
+       html("<table class='list log'>");
+       html("<tr><th class='left'>Date</th><th class='left'>Message</th><th class='left'>Author</th></tr>\n");
 
        if (ofs<0)
                ofs = 0;
index 84930cb50df30988a7930f44cb8ea64edd31f851..c4d75ab3f3b3b564c0da4decf80b8ed7a54b9954 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -62,9 +62,9 @@ void cgit_print_tree(const char *hex)
 
        html("<h2>Tree content</h2>\n");
        html("<table class='list'>\n");
-       html("<tr><th>Name</th>");
-       html("<th class='filesize'>Size</th>");
-       html("<th class='filemode'>Mode</th></tr>\n");
+       html("<tr><th class='left'>Name</th>");
+       html("<th class='right'>Size</th>");
+       html("<th class='right'>Mode</th></tr>\n");
        read_tree_recursive(tree, "", 0, 1, NULL, print_entry);
        html("</table>\n");
 }
index 9d13be19c717b626c953f5814d84117d8e28fc91..b75ce9a4c619e25f5ee79395c556a84235cc6f12 100644 (file)
--- 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];