-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cgit.c | 6 | ||||
-rw-r--r-- | cgit.css | 13 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | git.h | 13 | ||||
-rw-r--r-- | ui-log.c | 7 | ||||
-rw-r--r-- | ui-summary.c | 7 | ||||
-rw-r--r-- | ui-tree.c | 70 | ||||
-rw-r--r-- | ui-view.c | 2 |
9 files changed, 113 insertions, 8 deletions
@@ -3,13 +3,13 @@ CGIT_VERSION = 0.1-pre INSTALL_BIN = /var/www/htdocs/cgit.cgi INSTALL_CSS = /var/www/htdocs/cgit.css 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-summary.o ui-log.o ui-view.c ui-tree.c CFLAGS += -Wall all: cgit install: all @@ -23,16 +23,18 @@ static void cgit_print_repo_page(struct cacheitem *item) return; } setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); cgit_print_docstart(title, item); cgit_print_pageheader(title); - if (!cgit_query_page) + if (!cgit_query_page) { cgit_print_summary(); - else if (!strcmp(cgit_query_page, "log")) { + } else if (!strcmp(cgit_query_page, "log")) { cgit_print_log(cgit_query_head, 0, 100); + } else if (!strcmp(cgit_query_page, "tree")) { + cgit_print_tree(cgit_query_sha1); } else if (!strcmp(cgit_query_page, "view")) { cgit_print_view(cgit_query_sha1); } cgit_print_docend(); } @@ -27,13 +27,13 @@ table.list th { border-bottom: solid 1px #aaa; padding: 0.1em 0.5em 0.1em; vertical-align: baseline; } table.list td { border: none; - padding: 0.1em 0.5em; + padding: 0.1em 1em 0.1em 0.5em; background: white; } img { border: none; } @@ -57,7 +57,16 @@ div#content { } div.error { color: red; font-weight: bold; margin: 1em 2em; -}
\ No newline at end of file +} +div.ls-dir a { + font-weight: bold; +} +th.filesize, td.filesize { + text-align: right; +} +th.filemode, td.filemode { + text-align: center; +} @@ -80,8 +80,9 @@ extern void cgit_print_docend(); 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); #endif /* CGIT_H */ @@ -185,12 +185,25 @@ struct tree { struct object object; void *buffer; unsigned long size; }; +struct tree *lookup_tree(const unsigned char *sha1); +int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); +int parse_tree(struct tree *tree); +struct tree *parse_tree_indirect(const unsigned char *sha1); + +typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int); + +extern int read_tree_recursive(struct tree *tree, + const char *base, int baselen, + int stage, const char **match, + read_tree_fn_t fn); + +extern int read_tree(struct tree *tree, int stage, const char **paths); /* from git:commit.h */ struct commit_list { struct commit *item; @@ -79,12 +79,17 @@ static void cgit_print_commit_shortlog(struct commit *commit) char *url = cgit_pageurl(cgit_query_repo, "view", qry); html_link_open(url, NULL, NULL); html_txt(subject); html_link_close(); html("</td><td>"); html_txt(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"); } void cgit_print_log(const char *tip, int ofs, int cnt) { struct rev_info rev; @@ -99,13 +104,13 @@ void cgit_print_log(const char *tip, int ofs, int cnt) rev.show_root_diff = 0; setup_revisions(2, argv, &rev, NULL); prepare_revision_walk(&rev); html("<h2>Log</h2>"); html("<table class='list'>"); - html("<tr><th>Date</th><th>Message</th><th>Author</th></tr>\n"); + html("<tr><th>Date</th><th>Message</th><th>Author</th><th>Link</th></tr>\n"); while ((commit = get_revision(&rev)) != NULL && n++ < 100) { cgit_print_commit_shortlog(commit); free(commit->buffer); commit->buffer = NULL; free_commit_list(commit->parents); commit->parents = NULL; diff --git a/ui-summary.c b/ui-summary.c index cc918ad..29baa74 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -24,12 +24,17 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, html_txt(buf); html_link_close(); html("</td><td>"); pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0, buf, sizeof(buf), 0, NULL, NULL, 0); html_txt(buf); + 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"); } else { html("<tr><td>"); html_txt(buf); html("</td><td>"); htmlf("*** bad ref %s", sha1_to_hex(sha1)); @@ -38,13 +43,13 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, return 0; } static void cgit_print_branches() { html("<table class='list'>"); - html("<tr><th>Branch name</th><th>Head commit</th></tr>\n"); + html("<tr><th>Branch name</th><th>Latest</th><th>Link</th></tr>\n"); for_each_branch_ref(cgit_print_branch_cb, NULL); html("</table>"); } void cgit_print_summary() { diff --git a/ui-tree.c b/ui-tree.c new file mode 100644 index 0000000..84930cb --- a/dev/null +++ b/ui-tree.c @@ -0,0 +1,70 @@ +/* ui-tree.c: functions for tree output + * + * Copyright (C) 2006 Lars Hjemli + * + * Licensed under GNU General Public License v2 + * (see COPYING for full license text) + */ + +#include "cgit.h" + + +static int print_entry(const unsigned char *sha1, const char *base, + int baselen, const char *pathname, unsigned int mode, + int stage) +{ + char *name; + char type[20]; + unsigned long size; + + if (sha1_object_info(sha1, type, &size)) { + cgit_print_error(fmt("Bad object name: %s", + sha1_to_hex(sha1))); + return 0; + } + name = xstrdup(pathname); + html("<tr><td>"); + if (S_ISDIR(mode)) { + html("<div class='ls-dir'><a href='"); + html_attr(cgit_pageurl(cgit_query_repo, "tree", + fmt("id=%s", sha1_to_hex(sha1)))); + } else { + html("<div class='ls-blob'><a href='"); + html_attr(cgit_pageurl(cgit_query_repo, "view", + fmt("id=%s", sha1_to_hex(sha1)))); + } + html("'>"); + html_txt(name); + if (S_ISDIR(mode)) + html("/"); + html("</a></div></td>"); + htmlf("<td class='filesize'>%li</td>", size); + htmlf("<td class='filemode'>%06o</td>", mode); + html("</tr>\n"); + free(name); + return 0; +} + +void cgit_print_tree(const char *hex) +{ + struct tree *tree; + unsigned char sha1[20]; + + if (get_sha1_hex(hex, sha1)) { + cgit_print_error(fmt("Invalid object id: %s", hex)); + return; + } + tree = parse_tree_indirect(sha1); + if (!tree) { + cgit_print_error(fmt("Not a tree object: %s", hex)); + return; + } + + 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"); + read_tree_recursive(tree, "", 0, 1, NULL, print_entry); + html("</table>\n"); +} @@ -17,13 +17,13 @@ void cgit_print_view(char *hex) if (get_sha1_hex(hex, sha1)){ cgit_print_error(fmt("Bad hex value: %s", hex)); return; } - if (sha1_object_info(sha1, type, NULL)){ + if (sha1_object_info(sha1, type, &size)){ cgit_print_error("Bad object name"); return; } buf = read_sha1_file(sha1, type, &size); if (!buf) { |