summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--Makefile2
-rw-r--r--cgit.c6
-rw-r--r--cgit.css11
-rw-r--r--cgit.h1
-rw-r--r--git.h13
-rw-r--r--ui-log.c7
-rw-r--r--ui-summary.c7
-rw-r--r--ui-tree.c70
-rw-r--r--ui-view.c2
9 files changed, 112 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index c029637..4d2ede3 100644
--- a/Makefile
+++ b/Makefile
@@ -8,3 +8,3 @@ EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto
8OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ 8OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \
9 ui-summary.o ui-log.o ui-view.c 9 ui-summary.o ui-log.o ui-view.c ui-tree.c
10 10
diff --git a/cgit.c b/cgit.c
index 0f72f2d..ada488b 100644
--- a/cgit.c
+++ b/cgit.c
@@ -28,6 +28,8 @@ static void cgit_print_repo_page(struct cacheitem *item)
28 cgit_print_pageheader(title); 28 cgit_print_pageheader(title);
29 if (!cgit_query_page) 29 if (!cgit_query_page) {
30 cgit_print_summary(); 30 cgit_print_summary();
31 else if (!strcmp(cgit_query_page, "log")) { 31 } else if (!strcmp(cgit_query_page, "log")) {
32 cgit_print_log(cgit_query_head, 0, 100); 32 cgit_print_log(cgit_query_head, 0, 100);
33 } else if (!strcmp(cgit_query_page, "tree")) {
34 cgit_print_tree(cgit_query_sha1);
33 } else if (!strcmp(cgit_query_page, "view")) { 35 } else if (!strcmp(cgit_query_page, "view")) {
diff --git a/cgit.css b/cgit.css
index 3ed0c22..c16f3f2 100644
--- a/cgit.css
+++ b/cgit.css
@@ -32,3 +32,3 @@ table.list td {
32 border: none; 32 border: none;
33 padding: 0.1em 0.5em; 33 padding: 0.1em 1em 0.1em 0.5em;
34 background: white; 34 background: white;
@@ -63 +63,10 @@ div.error {
63} \ No newline at end of file 63} \ No newline at end of file
64div.ls-dir a {
65 font-weight: bold;
66}
67th.filesize, td.filesize {
68 text-align: right;
69}
70th.filemode, td.filemode {
71 text-align: center;
72}
diff --git a/cgit.h b/cgit.h
index c9554a7..2fdfab3 100644
--- a/cgit.h
+++ b/cgit.h
@@ -85,2 +85,3 @@ extern void cgit_print_log(const char *tip, int ofs, int cnt);
85extern void cgit_print_view(char *hex); 85extern void cgit_print_view(char *hex);
86extern void cgit_print_tree(const char *sha1);
86 87
diff --git a/git.h b/git.h
index dfa3542..a3f977c 100644
--- a/git.h
+++ b/git.h
@@ -190,2 +190,15 @@ struct tree {
190 190
191struct tree *lookup_tree(const unsigned char *sha1);
192int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
193int parse_tree(struct tree *tree);
194struct tree *parse_tree_indirect(const unsigned char *sha1);
195
196typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int);
197
198extern int read_tree_recursive(struct tree *tree,
199 const char *base, int baselen,
200 int stage, const char **match,
201 read_tree_fn_t fn);
202
203extern int read_tree(struct tree *tree, int stage, const char **paths);
191 204
diff --git a/ui-log.c b/ui-log.c
index 701c392..4d2c2e0 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -84,2 +84,7 @@ static void cgit_print_commit_shortlog(struct commit *commit)
84 html_txt(author); 84 html_txt(author);
85 html("</td><td><a href='");
86 html_attr(cgit_pageurl(cgit_query_repo, "tree",
87 fmt("id=%s",
88 sha1_to_hex(commit->tree->object.sha1))));
89 html("'>tree</a>");
85 html("</td></tr>\n"); 90 html("</td></tr>\n");
@@ -104,3 +109,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt)
104 html("<table class='list'>"); 109 html("<table class='list'>");
105 html("<tr><th>Date</th><th>Message</th><th>Author</th></tr>\n"); 110 html("<tr><th>Date</th><th>Message</th><th>Author</th><th>Link</th></tr>\n");
106 while ((commit = get_revision(&rev)) != NULL && n++ < 100) { 111 while ((commit = get_revision(&rev)) != NULL && n++ < 100) {
diff --git a/ui-summary.c b/ui-summary.c
index cc918ad..29baa74 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -29,2 +29,7 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
29 html_txt(buf); 29 html_txt(buf);
30 html("</td><td><a href='");
31 html_attr(cgit_pageurl(cgit_query_repo, "tree",
32 fmt("id=%s",
33 sha1_to_hex(commit->tree->object.sha1))));
34 html("'>tree</a>");
30 html("</td></tr>\n"); 35 html("</td></tr>\n");
@@ -43,3 +48,3 @@ static void cgit_print_branches()
43 html("<table class='list'>"); 48 html("<table class='list'>");
44 html("<tr><th>Branch name</th><th>Head commit</th></tr>\n"); 49 html("<tr><th>Branch name</th><th>Latest</th><th>Link</th></tr>\n");
45 for_each_branch_ref(cgit_print_branch_cb, NULL); 50 for_each_branch_ref(cgit_print_branch_cb, NULL);
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 @@
1/* ui-tree.c: functions for tree output
2 *
3 * Copyright (C) 2006 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9#include "cgit.h"
10
11
12static int print_entry(const unsigned char *sha1, const char *base,
13 int baselen, const char *pathname, unsigned int mode,
14 int stage)
15{
16 char *name;
17 char type[20];
18 unsigned long size;
19
20 if (sha1_object_info(sha1, type, &size)) {
21 cgit_print_error(fmt("Bad object name: %s",
22 sha1_to_hex(sha1)));
23 return 0;
24 }
25 name = xstrdup(pathname);
26 html("<tr><td>");
27 if (S_ISDIR(mode)) {
28 html("<div class='ls-dir'><a href='");
29 html_attr(cgit_pageurl(cgit_query_repo, "tree",
30 fmt("id=%s", sha1_to_hex(sha1))));
31 } else {
32 html("<div class='ls-blob'><a href='");
33 html_attr(cgit_pageurl(cgit_query_repo, "view",
34 fmt("id=%s", sha1_to_hex(sha1))));
35 }
36 html("'>");
37 html_txt(name);
38 if (S_ISDIR(mode))
39 html("/");
40 html("</a></div></td>");
41 htmlf("<td class='filesize'>%li</td>", size);
42 htmlf("<td class='filemode'>%06o</td>", mode);
43 html("</tr>\n");
44 free(name);
45 return 0;
46}
47
48void cgit_print_tree(const char *hex)
49{
50 struct tree *tree;
51 unsigned char sha1[20];
52
53 if (get_sha1_hex(hex, sha1)) {
54 cgit_print_error(fmt("Invalid object id: %s", hex));
55 return;
56 }
57 tree = parse_tree_indirect(sha1);
58 if (!tree) {
59 cgit_print_error(fmt("Not a tree object: %s", hex));
60 return;
61 }
62
63 html("<h2>Tree content</h2>\n");
64 html("<table class='list'>\n");
65 html("<tr><th>Name</th>");
66 html("<th class='filesize'>Size</th>");
67 html("<th class='filemode'>Mode</th></tr>\n");
68 read_tree_recursive(tree, "", 0, 1, NULL, print_entry);
69 html("</table>\n");
70}
diff --git a/ui-view.c b/ui-view.c
index 193c685..1bf8472 100644
--- a/ui-view.c
+++ b/ui-view.c
@@ -22,3 +22,3 @@ void cgit_print_view(char *hex)
22 22
23 if (sha1_object_info(sha1, type, NULL)){ 23 if (sha1_object_info(sha1, type, &size)){
24 cgit_print_error("Bad object name"); 24 cgit_print_error("Bad object name");