From 06fe0c2f47eaf467db8ab1443e61dfa1c280f30a Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Wed, 13 Dec 2006 00:13:27 +0100 Subject: Add display of tree content w/ui-tree.c Signed-off-by: Lars Hjemli --- Makefile | 2 +- cgit.c | 6 ++++-- cgit.css | 13 +++++++++-- cgit.h | 1 + git.h | 13 +++++++++++ ui-log.c | 7 +++++- ui-summary.c | 7 +++++- ui-tree.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ui-view.c | 2 +- 9 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 ui-tree.c diff --git a/Makefile b/Makefile index c029637..4d2ede3 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-summary.o ui-log.o ui-view.c ui-tree.c CFLAGS += -Wall diff --git a/cgit.c b/cgit.c index 0f72f2d..ada488b 100644 --- a/cgit.c +++ b/cgit.c @@ -26,10 +26,12 @@ static void cgit_print_repo_page(struct cacheitem *item) 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); } diff --git a/cgit.css b/cgit.css index 3ed0c22..c16f3f2 100644 --- a/cgit.css +++ b/cgit.css @@ -30,7 +30,7 @@ table.list th { } table.list td { border: none; - padding: 0.1em 0.5em; + padding: 0.1em 1em 0.1em 0.5em; background: white; } @@ -60,4 +60,13 @@ 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; +} diff --git a/cgit.h b/cgit.h index c9554a7..2fdfab3 100644 --- a/cgit.h +++ b/cgit.h @@ -83,5 +83,6 @@ 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 */ diff --git a/git.h b/git.h index dfa3542..a3f977c 100644 --- a/git.h +++ b/git.h @@ -188,6 +188,19 @@ struct tree { }; +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 */ diff --git a/ui-log.c b/ui-log.c index 701c392..4d2c2e0 100644 --- a/ui-log.c +++ b/ui-log.c @@ -82,6 +82,11 @@ static void cgit_print_commit_shortlog(struct commit *commit) html_link_close(); html(""); html_txt(author); + html("tree"); html("\n"); } @@ -102,7 +107,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt) html("

Log

"); html(""); - html("\n"); + html("\n"); while ((commit = get_revision(&rev)) != NULL && n++ < 100) { cgit_print_commit_shortlog(commit); free(commit->buffer); diff --git a/ui-summary.c b/ui-summary.c index cc918ad..29baa74 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -27,6 +27,11 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0, buf, sizeof(buf), 0, NULL, NULL, 0); html_txt(buf); + html("\n"); } else { html(""); + htmlf("", size); + htmlf("", mode); + html("\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("

Tree content

\n"); + html("
DateMessageAuthor
DateMessageAuthorLink
tree"); html("
"); @@ -41,7 +46,7 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, static void cgit_print_branches() { html(""); - html("\n"); + html("\n"); for_each_branch_ref(cgit_print_branch_cb, NULL); html("
Branch nameHead commit
Branch nameLatestLink
"); } diff --git a/ui-tree.c b/ui-tree.c new file mode 100644 index 0000000..84930cb --- /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("
"); + if (S_ISDIR(mode)) { + html("%li%06o
\n"); + html(""); + html(""); + html("\n"); + read_tree_recursive(tree, "", 0, 1, NULL, print_entry); + html("
NameSizeMode
\n"); +} diff --git a/ui-view.c b/ui-view.c index 193c685..1bf8472 100644 --- a/ui-view.c +++ b/ui-view.c @@ -20,7 +20,7 @@ void cgit_print_view(char *hex) return; } - if (sha1_object_info(sha1, type, NULL)){ + if (sha1_object_info(sha1, type, &size)){ cgit_print_error("Bad object name"); return; } -- cgit