-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
@@ -1,28 +1,28 @@ | |||
1 | CGIT_VERSION = 0.1-pre | 1 | CGIT_VERSION = 0.1-pre |
2 | 2 | ||
3 | INSTALL_BIN = /var/www/htdocs/cgit.cgi | 3 | INSTALL_BIN = /var/www/htdocs/cgit.cgi |
4 | INSTALL_CSS = /var/www/htdocs/cgit.css | 4 | INSTALL_CSS = /var/www/htdocs/cgit.css |
5 | CACHE_ROOT = /var/cache/cgit | 5 | CACHE_ROOT = /var/cache/cgit |
6 | 6 | ||
7 | EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto | 7 | EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto |
8 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 8 | OBJECTS = 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 | ||
11 | CFLAGS += -Wall | 11 | CFLAGS += -Wall |
12 | 12 | ||
13 | all: cgit | 13 | all: cgit |
14 | 14 | ||
15 | install: all | 15 | install: all |
16 | install cgit $(INSTALL_BIN) | 16 | install cgit $(INSTALL_BIN) |
17 | install cgit.css $(INSTALL_CSS) | 17 | install cgit.css $(INSTALL_CSS) |
18 | rm -rf $(CACHE_ROOT)/* | 18 | rm -rf $(CACHE_ROOT)/* |
19 | 19 | ||
20 | cgit: cgit.c cgit.h git.h $(OBJECTS) | 20 | cgit: cgit.c cgit.h git.h $(OBJECTS) |
21 | $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit \ | 21 | $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit \ |
22 | $(OBJECTS) $(EXTLIBS) | 22 | $(OBJECTS) $(EXTLIBS) |
23 | 23 | ||
24 | $(OBJECTS): cgit.h git.h | 24 | $(OBJECTS): cgit.h git.h |
25 | 25 | ||
26 | .PHONY: clean | 26 | .PHONY: clean |
27 | clean: | 27 | clean: |
28 | rm -f cgit *.o | 28 | rm -f cgit *.o |
@@ -1,106 +1,108 @@ | |||
1 | /* cgit.c: cgi for the git scm | 1 | /* cgit.c: cgi for the git scm |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | const char cgit_version[] = CGIT_VERSION; | 11 | const char cgit_version[] = CGIT_VERSION; |
12 | 12 | ||
13 | static void cgit_print_repo_page(struct cacheitem *item) | 13 | static void cgit_print_repo_page(struct cacheitem *item) |
14 | { | 14 | { |
15 | if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) || | 15 | if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) || |
16 | cgit_read_config("info/cgit", cgit_repo_config_cb)) { | 16 | cgit_read_config("info/cgit", cgit_repo_config_cb)) { |
17 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 17 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); |
18 | cgit_print_docstart(title, item); | 18 | cgit_print_docstart(title, item); |
19 | cgit_print_pageheader(title); | 19 | cgit_print_pageheader(title); |
20 | cgit_print_error(fmt("Unable to scan repository: %s", | 20 | cgit_print_error(fmt("Unable to scan repository: %s", |
21 | strerror(errno))); | 21 | strerror(errno))); |
22 | cgit_print_docend(); | 22 | cgit_print_docend(); |
23 | return; | 23 | return; |
24 | } | 24 | } |
25 | setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); | 25 | setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); |
26 | char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); | 26 | char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); |
27 | cgit_print_docstart(title, item); | 27 | cgit_print_docstart(title, 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")) { |
34 | cgit_print_view(cgit_query_sha1); | 36 | cgit_print_view(cgit_query_sha1); |
35 | } | 37 | } |
36 | cgit_print_docend(); | 38 | cgit_print_docend(); |
37 | } | 39 | } |
38 | 40 | ||
39 | static void cgit_fill_cache(struct cacheitem *item) | 41 | static void cgit_fill_cache(struct cacheitem *item) |
40 | { | 42 | { |
41 | htmlfd = item->fd; | 43 | htmlfd = item->fd; |
42 | item->st.st_mtime = time(NULL); | 44 | item->st.st_mtime = time(NULL); |
43 | if (cgit_query_repo) | 45 | if (cgit_query_repo) |
44 | cgit_print_repo_page(item); | 46 | cgit_print_repo_page(item); |
45 | else | 47 | else |
46 | cgit_print_repolist(item); | 48 | cgit_print_repolist(item); |
47 | } | 49 | } |
48 | 50 | ||
49 | static void cgit_check_cache(struct cacheitem *item) | 51 | static void cgit_check_cache(struct cacheitem *item) |
50 | { | 52 | { |
51 | int i = 0; | 53 | int i = 0; |
52 | 54 | ||
53 | cache_prepare(item); | 55 | cache_prepare(item); |
54 | top: | 56 | top: |
55 | if (++i > cgit_max_lock_attempts) { | 57 | if (++i > cgit_max_lock_attempts) { |
56 | die("cgit_refresh_cache: unable to lock %s: %s", | 58 | die("cgit_refresh_cache: unable to lock %s: %s", |
57 | item->name, strerror(errno)); | 59 | item->name, strerror(errno)); |
58 | } | 60 | } |
59 | if (!cache_exist(item)) { | 61 | if (!cache_exist(item)) { |
60 | if (!cache_lock(item)) { | 62 | if (!cache_lock(item)) { |
61 | sleep(1); | 63 | sleep(1); |
62 | goto top; | 64 | goto top; |
63 | } | 65 | } |
64 | if (!cache_exist(item)) { | 66 | if (!cache_exist(item)) { |
65 | cgit_fill_cache(item); | 67 | cgit_fill_cache(item); |
66 | cache_unlock(item); | 68 | cache_unlock(item); |
67 | } else { | 69 | } else { |
68 | cache_cancel_lock(item); | 70 | cache_cancel_lock(item); |
69 | } | 71 | } |
70 | } else if (cache_expired(item) && cache_lock(item)) { | 72 | } else if (cache_expired(item) && cache_lock(item)) { |
71 | if (cache_expired(item)) { | 73 | if (cache_expired(item)) { |
72 | cgit_fill_cache(item); | 74 | cgit_fill_cache(item); |
73 | cache_unlock(item); | 75 | cache_unlock(item); |
74 | } else { | 76 | } else { |
75 | cache_cancel_lock(item); | 77 | cache_cancel_lock(item); |
76 | } | 78 | } |
77 | } | 79 | } |
78 | } | 80 | } |
79 | 81 | ||
80 | static void cgit_print_cache(struct cacheitem *item) | 82 | static void cgit_print_cache(struct cacheitem *item) |
81 | { | 83 | { |
82 | static char buf[4096]; | 84 | static char buf[4096]; |
83 | ssize_t i; | 85 | ssize_t i; |
84 | 86 | ||
85 | int fd = open(item->name, O_RDONLY); | 87 | int fd = open(item->name, O_RDONLY); |
86 | if (fd<0) | 88 | if (fd<0) |
87 | die("Unable to open cached file %s", item->name); | 89 | die("Unable to open cached file %s", item->name); |
88 | 90 | ||
89 | while((i=read(fd, buf, sizeof(buf))) > 0) | 91 | while((i=read(fd, buf, sizeof(buf))) > 0) |
90 | write(STDOUT_FILENO, buf, i); | 92 | write(STDOUT_FILENO, buf, i); |
91 | 93 | ||
92 | close(fd); | 94 | close(fd); |
93 | } | 95 | } |
94 | 96 | ||
95 | int main(int argc, const char **argv) | 97 | int main(int argc, const char **argv) |
96 | { | 98 | { |
97 | struct cacheitem item; | 99 | struct cacheitem item; |
98 | 100 | ||
99 | cgit_read_config("/etc/cgitrc", cgit_global_config_cb); | 101 | cgit_read_config("/etc/cgitrc", cgit_global_config_cb); |
100 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); | 102 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); |
101 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); | 103 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); |
102 | 104 | ||
103 | cgit_check_cache(&item); | 105 | cgit_check_cache(&item); |
104 | cgit_print_cache(&item); | 106 | cgit_print_cache(&item); |
105 | return 0; | 107 | return 0; |
106 | } | 108 | } |
@@ -1,63 +1,72 @@ | |||
1 | body { | 1 | body { |
2 | font-family: arial; | 2 | font-family: arial; |
3 | font-size: normal; | 3 | font-size: normal; |
4 | background: white; | 4 | background: white; |
5 | padding: 0em; | 5 | padding: 0em; |
6 | margin: 0.5em; | 6 | margin: 0.5em; |
7 | } | 7 | } |
8 | 8 | ||
9 | 9 | ||
10 | h2 { | 10 | h2 { |
11 | font-size: normal; | 11 | font-size: normal; |
12 | font-weight: bold; | 12 | font-weight: bold; |
13 | margin-bottom: 0.1em; | 13 | margin-bottom: 0.1em; |
14 | } | 14 | } |
15 | 15 | ||
16 | 16 | ||
17 | table.list { | 17 | table.list { |
18 | border: solid 1px black; | 18 | border: solid 1px black; |
19 | border-collapse: collapse; | 19 | border-collapse: collapse; |
20 | border: solid 1px #aaa; | 20 | border: solid 1px #aaa; |
21 | } | 21 | } |
22 | 22 | ||
23 | table.list th { | 23 | table.list th { |
24 | text-align: left; | 24 | text-align: left; |
25 | font-weight: bold; | 25 | font-weight: bold; |
26 | background: #ddd; | 26 | background: #ddd; |
27 | border-bottom: solid 1px #aaa; | 27 | border-bottom: solid 1px #aaa; |
28 | padding: 0.1em 0.5em 0.1em; | 28 | padding: 0.1em 0.5em 0.1em; |
29 | vertical-align: baseline; | 29 | vertical-align: baseline; |
30 | } | 30 | } |
31 | table.list td { | 31 | 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; |
35 | } | 35 | } |
36 | 36 | ||
37 | img { | 37 | img { |
38 | border: none; | 38 | border: none; |
39 | } | 39 | } |
40 | 40 | ||
41 | 41 | ||
42 | div#header { | 42 | div#header { |
43 | background-color: #ddd; | 43 | background-color: #ddd; |
44 | padding: 0.25em 0.25em 0.25em 0.5em; | 44 | padding: 0.25em 0.25em 0.25em 0.5em; |
45 | font-size: 150%; | 45 | font-size: 150%; |
46 | font-weight: bold; | 46 | font-weight: bold; |
47 | border: solid 1px #aaa; | 47 | border: solid 1px #aaa; |
48 | vertical-align: middle; | 48 | vertical-align: middle; |
49 | } | 49 | } |
50 | 50 | ||
51 | div#header img#logo { | 51 | div#header img#logo { |
52 | float: right; | 52 | float: right; |
53 | } | 53 | } |
54 | 54 | ||
55 | div#content { | 55 | div#content { |
56 | margin: 0.5em 0.5em; | 56 | margin: 0.5em 0.5em; |
57 | } | 57 | } |
58 | 58 | ||
59 | div.error { | 59 | div.error { |
60 | color: red; | 60 | color: red; |
61 | font-weight: bold; | 61 | font-weight: bold; |
62 | margin: 1em 2em; | 62 | margin: 1em 2em; |
63 | } \ No newline at end of file | 63 | } |
64 | div.ls-dir a { | ||
65 | font-weight: bold; | ||
66 | } | ||
67 | th.filesize, td.filesize { | ||
68 | text-align: right; | ||
69 | } | ||
70 | th.filemode, td.filemode { | ||
71 | text-align: center; | ||
72 | } | ||
@@ -1,87 +1,88 @@ | |||
1 | #ifndef CGIT_H | 1 | #ifndef CGIT_H |
2 | #define CGIT_H | 2 | #define CGIT_H |
3 | 3 | ||
4 | #include "git.h" | 4 | #include "git.h" |
5 | #include <openssl/sha.h> | 5 | #include <openssl/sha.h> |
6 | #include <ctype.h> | 6 | #include <ctype.h> |
7 | #include <sched.h> | 7 | #include <sched.h> |
8 | 8 | ||
9 | typedef void (*configfn)(const char *name, const char *value); | 9 | typedef void (*configfn)(const char *name, const char *value); |
10 | 10 | ||
11 | struct cacheitem { | 11 | struct cacheitem { |
12 | char *name; | 12 | char *name; |
13 | struct stat st; | 13 | struct stat st; |
14 | int ttl; | 14 | int ttl; |
15 | int fd; | 15 | int fd; |
16 | }; | 16 | }; |
17 | 17 | ||
18 | extern const char cgit_version[]; | 18 | extern const char cgit_version[]; |
19 | 19 | ||
20 | extern char *cgit_root; | 20 | extern char *cgit_root; |
21 | extern char *cgit_root_title; | 21 | extern char *cgit_root_title; |
22 | extern char *cgit_css; | 22 | extern char *cgit_css; |
23 | extern char *cgit_logo; | 23 | extern char *cgit_logo; |
24 | extern char *cgit_logo_link; | 24 | extern char *cgit_logo_link; |
25 | extern char *cgit_virtual_root; | 25 | extern char *cgit_virtual_root; |
26 | extern char *cgit_cache_root; | 26 | extern char *cgit_cache_root; |
27 | 27 | ||
28 | extern int cgit_max_lock_attempts; | 28 | extern int cgit_max_lock_attempts; |
29 | extern int cgit_cache_root_ttl; | 29 | extern int cgit_cache_root_ttl; |
30 | extern int cgit_cache_repo_ttl; | 30 | extern int cgit_cache_repo_ttl; |
31 | extern int cgit_cache_dynamic_ttl; | 31 | extern int cgit_cache_dynamic_ttl; |
32 | extern int cgit_cache_static_ttl; | 32 | extern int cgit_cache_static_ttl; |
33 | extern int cgit_cache_max_create_time; | 33 | extern int cgit_cache_max_create_time; |
34 | 34 | ||
35 | extern char *cgit_repo_name; | 35 | extern char *cgit_repo_name; |
36 | extern char *cgit_repo_desc; | 36 | extern char *cgit_repo_desc; |
37 | extern char *cgit_repo_owner; | 37 | extern char *cgit_repo_owner; |
38 | 38 | ||
39 | extern int cgit_query_has_symref; | 39 | extern int cgit_query_has_symref; |
40 | extern int cgit_query_has_sha1; | 40 | extern int cgit_query_has_sha1; |
41 | 41 | ||
42 | extern char *cgit_querystring; | 42 | extern char *cgit_querystring; |
43 | extern char *cgit_query_repo; | 43 | extern char *cgit_query_repo; |
44 | extern char *cgit_query_page; | 44 | extern char *cgit_query_page; |
45 | extern char *cgit_query_head; | 45 | extern char *cgit_query_head; |
46 | extern char *cgit_query_sha1; | 46 | extern char *cgit_query_sha1; |
47 | 47 | ||
48 | extern int htmlfd; | 48 | extern int htmlfd; |
49 | 49 | ||
50 | extern void cgit_global_config_cb(const char *name, const char *value); | 50 | extern void cgit_global_config_cb(const char *name, const char *value); |
51 | extern void cgit_repo_config_cb(const char *name, const char *value); | 51 | extern void cgit_repo_config_cb(const char *name, const char *value); |
52 | extern void cgit_querystring_cb(const char *name, const char *value); | 52 | extern void cgit_querystring_cb(const char *name, const char *value); |
53 | 53 | ||
54 | extern char *fmt(const char *format,...); | 54 | extern char *fmt(const char *format,...); |
55 | 55 | ||
56 | extern void html(const char *txt); | 56 | extern void html(const char *txt); |
57 | extern void htmlf(const char *format,...); | 57 | extern void htmlf(const char *format,...); |
58 | extern void html_txt(char *txt); | 58 | extern void html_txt(char *txt); |
59 | extern void html_attr(char *txt); | 59 | extern void html_attr(char *txt); |
60 | extern void html_link_open(char *url, char *title, char *class); | 60 | extern void html_link_open(char *url, char *title, char *class); |
61 | extern void html_link_close(void); | 61 | extern void html_link_close(void); |
62 | 62 | ||
63 | extern int cgit_read_config(const char *filename, configfn fn); | 63 | extern int cgit_read_config(const char *filename, configfn fn); |
64 | extern int cgit_parse_query(char *txt, configfn fn); | 64 | extern int cgit_parse_query(char *txt, configfn fn); |
65 | 65 | ||
66 | extern void cache_prepare(struct cacheitem *item); | 66 | extern void cache_prepare(struct cacheitem *item); |
67 | extern int cache_lock(struct cacheitem *item); | 67 | extern int cache_lock(struct cacheitem *item); |
68 | extern int cache_unlock(struct cacheitem *item); | 68 | extern int cache_unlock(struct cacheitem *item); |
69 | extern int cache_cancel_lock(struct cacheitem *item); | 69 | extern int cache_cancel_lock(struct cacheitem *item); |
70 | extern int cache_exist(struct cacheitem *item); | 70 | extern int cache_exist(struct cacheitem *item); |
71 | extern int cache_expired(struct cacheitem *item); | 71 | extern int cache_expired(struct cacheitem *item); |
72 | 72 | ||
73 | extern char *cgit_repourl(const char *reponame); | 73 | extern char *cgit_repourl(const char *reponame); |
74 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 74 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
75 | const char *query); | 75 | const char *query); |
76 | 76 | ||
77 | extern void cgit_print_error(char *msg); | 77 | extern void cgit_print_error(char *msg); |
78 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 78 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
79 | extern void cgit_print_docend(); | 79 | extern void cgit_print_docend(); |
80 | extern void cgit_print_pageheader(char *title); | 80 | extern void cgit_print_pageheader(char *title); |
81 | 81 | ||
82 | extern void cgit_print_repolist(struct cacheitem *item); | 82 | extern void cgit_print_repolist(struct cacheitem *item); |
83 | extern void cgit_print_summary(); | 83 | extern void cgit_print_summary(); |
84 | extern void cgit_print_log(const char *tip, int ofs, int cnt); | 84 | extern void cgit_print_log(const char *tip, int ofs, int cnt); |
85 | extern void cgit_print_view(char *hex); | 85 | extern void cgit_print_view(char *hex); |
86 | extern void cgit_print_tree(const char *sha1); | ||
86 | 87 | ||
87 | #endif /* CGIT_H */ | 88 | #endif /* CGIT_H */ |
@@ -95,192 +95,205 @@ static inline void *xcalloc(size_t nmemb, size_t size) | |||
95 | } | 95 | } |
96 | 96 | ||
97 | static inline ssize_t xread(int fd, void *buf, size_t len) | 97 | static inline ssize_t xread(int fd, void *buf, size_t len) |
98 | { | 98 | { |
99 | ssize_t nr; | 99 | ssize_t nr; |
100 | while (1) { | 100 | while (1) { |
101 | nr = read(fd, buf, len); | 101 | nr = read(fd, buf, len); |
102 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | 102 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) |
103 | continue; | 103 | continue; |
104 | return nr; | 104 | return nr; |
105 | } | 105 | } |
106 | } | 106 | } |
107 | 107 | ||
108 | static inline ssize_t xwrite(int fd, const void *buf, size_t len) | 108 | static inline ssize_t xwrite(int fd, const void *buf, size_t len) |
109 | { | 109 | { |
110 | ssize_t nr; | 110 | ssize_t nr; |
111 | while (1) { | 111 | while (1) { |
112 | nr = write(fd, buf, len); | 112 | nr = write(fd, buf, len); |
113 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | 113 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) |
114 | continue; | 114 | continue; |
115 | return nr; | 115 | return nr; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | 120 | ||
121 | 121 | ||
122 | /* | 122 | /* |
123 | * from git:cache.h | 123 | * from git:cache.h |
124 | */ | 124 | */ |
125 | 125 | ||
126 | 126 | ||
127 | /* Convert to/from hex/sha1 representation */ | 127 | /* Convert to/from hex/sha1 representation */ |
128 | #define MINIMUM_ABBREV 4 | 128 | #define MINIMUM_ABBREV 4 |
129 | #define DEFAULT_ABBREV 7 | 129 | #define DEFAULT_ABBREV 7 |
130 | 130 | ||
131 | extern int sha1_object_info(const unsigned char *, char *, unsigned long *); | 131 | extern int sha1_object_info(const unsigned char *, char *, unsigned long *); |
132 | 132 | ||
133 | extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); | 133 | extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); |
134 | 134 | ||
135 | extern int get_sha1(const char *str, unsigned char *sha1); | 135 | extern int get_sha1(const char *str, unsigned char *sha1); |
136 | extern int get_sha1_hex(const char *hex, unsigned char *sha1); | 136 | extern int get_sha1_hex(const char *hex, unsigned char *sha1); |
137 | extern char *sha1_to_hex(const unsigned char *sha1);/* static buffer result! */ | 137 | extern char *sha1_to_hex(const unsigned char *sha1);/* static buffer result! */ |
138 | 138 | ||
139 | 139 | ||
140 | 140 | ||
141 | /* | 141 | /* |
142 | * from git:object.h | 142 | * from git:object.h |
143 | */ | 143 | */ |
144 | 144 | ||
145 | struct object_list { | 145 | struct object_list { |
146 | struct object *item; | 146 | struct object *item; |
147 | struct object_list *next; | 147 | struct object_list *next; |
148 | }; | 148 | }; |
149 | 149 | ||
150 | struct object_refs { | 150 | struct object_refs { |
151 | unsigned count; | 151 | unsigned count; |
152 | struct object *base; | 152 | struct object *base; |
153 | struct object *ref[FLEX_ARRAY]; /* more */ | 153 | struct object *ref[FLEX_ARRAY]; /* more */ |
154 | }; | 154 | }; |
155 | 155 | ||
156 | struct object_array { | 156 | struct object_array { |
157 | unsigned int nr; | 157 | unsigned int nr; |
158 | unsigned int alloc; | 158 | unsigned int alloc; |
159 | struct object_array_entry { | 159 | struct object_array_entry { |
160 | struct object *item; | 160 | struct object *item; |
161 | const char *name; | 161 | const char *name; |
162 | } *objects; | 162 | } *objects; |
163 | }; | 163 | }; |
164 | 164 | ||
165 | #define TYPE_BITS 3 | 165 | #define TYPE_BITS 3 |
166 | #define FLAG_BITS 27 | 166 | #define FLAG_BITS 27 |
167 | 167 | ||
168 | /* | 168 | /* |
169 | * The object type is stored in 3 bits. | 169 | * The object type is stored in 3 bits. |
170 | */ | 170 | */ |
171 | struct object { | 171 | struct object { |
172 | unsigned parsed : 1; | 172 | unsigned parsed : 1; |
173 | unsigned used : 1; | 173 | unsigned used : 1; |
174 | unsigned type : TYPE_BITS; | 174 | unsigned type : TYPE_BITS; |
175 | unsigned flags : FLAG_BITS; | 175 | unsigned flags : FLAG_BITS; |
176 | unsigned char sha1[20]; | 176 | unsigned char sha1[20]; |
177 | }; | 177 | }; |
178 | 178 | ||
179 | 179 | ||
180 | /* | 180 | /* |
181 | * from git:tree.h | 181 | * from git:tree.h |
182 | */ | 182 | */ |
183 | 183 | ||
184 | struct tree { | 184 | struct tree { |
185 | struct object object; | 185 | struct object object; |
186 | void *buffer; | 186 | void *buffer; |
187 | unsigned long size; | 187 | unsigned long size; |
188 | }; | 188 | }; |
189 | 189 | ||
190 | 190 | ||
191 | struct tree *lookup_tree(const unsigned char *sha1); | ||
192 | int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); | ||
193 | int parse_tree(struct tree *tree); | ||
194 | struct tree *parse_tree_indirect(const unsigned char *sha1); | ||
195 | |||
196 | typedef int (*read_tree_fn_t)(const unsigned char *, const char *, int, const char *, unsigned int, int); | ||
197 | |||
198 | extern 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 | |||
203 | extern int read_tree(struct tree *tree, int stage, const char **paths); | ||
191 | 204 | ||
192 | 205 | ||
193 | /* from git:commit.h */ | 206 | /* from git:commit.h */ |
194 | 207 | ||
195 | struct commit_list { | 208 | struct commit_list { |
196 | struct commit *item; | 209 | struct commit *item; |
197 | struct commit_list *next; | 210 | struct commit_list *next; |
198 | }; | 211 | }; |
199 | 212 | ||
200 | struct commit { | 213 | struct commit { |
201 | struct object object; | 214 | struct object object; |
202 | void *util; | 215 | void *util; |
203 | unsigned long date; | 216 | unsigned long date; |
204 | struct commit_list *parents; | 217 | struct commit_list *parents; |
205 | struct tree *tree; | 218 | struct tree *tree; |
206 | char *buffer; | 219 | char *buffer; |
207 | }; | 220 | }; |
208 | 221 | ||
209 | 222 | ||
210 | struct commit *lookup_commit(const unsigned char *sha1); | 223 | struct commit *lookup_commit(const unsigned char *sha1); |
211 | struct commit *lookup_commit_reference(const unsigned char *sha1); | 224 | struct commit *lookup_commit_reference(const unsigned char *sha1); |
212 | struct commit *lookup_commit_reference_gently(const unsigned char *sha1, | 225 | struct commit *lookup_commit_reference_gently(const unsigned char *sha1, |
213 | int quiet); | 226 | int quiet); |
214 | 227 | ||
215 | int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); | 228 | int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); |
216 | int parse_commit(struct commit *item); | 229 | int parse_commit(struct commit *item); |
217 | 230 | ||
218 | struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); | 231 | struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); |
219 | struct commit_list * insert_by_date(struct commit *item, struct commit_list **list); | 232 | struct commit_list * insert_by_date(struct commit *item, struct commit_list **list); |
220 | 233 | ||
221 | void free_commit_list(struct commit_list *list); | 234 | void free_commit_list(struct commit_list *list); |
222 | 235 | ||
223 | void sort_by_date(struct commit_list **list); | 236 | void sort_by_date(struct commit_list **list); |
224 | 237 | ||
225 | /* Commit formats */ | 238 | /* Commit formats */ |
226 | enum cmit_fmt { | 239 | enum cmit_fmt { |
227 | CMIT_FMT_RAW, | 240 | CMIT_FMT_RAW, |
228 | CMIT_FMT_MEDIUM, | 241 | CMIT_FMT_MEDIUM, |
229 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, | 242 | CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM, |
230 | CMIT_FMT_SHORT, | 243 | CMIT_FMT_SHORT, |
231 | CMIT_FMT_FULL, | 244 | CMIT_FMT_FULL, |
232 | CMIT_FMT_FULLER, | 245 | CMIT_FMT_FULLER, |
233 | CMIT_FMT_ONELINE, | 246 | CMIT_FMT_ONELINE, |
234 | CMIT_FMT_EMAIL, | 247 | CMIT_FMT_EMAIL, |
235 | 248 | ||
236 | CMIT_FMT_UNSPECIFIED, | 249 | CMIT_FMT_UNSPECIFIED, |
237 | }; | 250 | }; |
238 | 251 | ||
239 | extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject, int relative_date); | 252 | extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject, int relative_date); |
240 | 253 | ||
241 | 254 | ||
242 | typedef void (*topo_sort_set_fn_t)(struct commit*, void *data); | 255 | typedef void (*topo_sort_set_fn_t)(struct commit*, void *data); |
243 | typedef void* (*topo_sort_get_fn_t)(struct commit*); | 256 | typedef void* (*topo_sort_get_fn_t)(struct commit*); |
244 | 257 | ||
245 | 258 | ||
246 | 259 | ||
247 | 260 | ||
248 | /* | 261 | /* |
249 | * from git:diff.h | 262 | * from git:diff.h |
250 | */ | 263 | */ |
251 | 264 | ||
252 | 265 | ||
253 | struct rev_info; | 266 | struct rev_info; |
254 | struct diff_options; | 267 | struct diff_options; |
255 | struct diff_queue_struct; | 268 | struct diff_queue_struct; |
256 | 269 | ||
257 | typedef void (*change_fn_t)(struct diff_options *options, | 270 | typedef void (*change_fn_t)(struct diff_options *options, |
258 | unsigned old_mode, unsigned new_mode, | 271 | unsigned old_mode, unsigned new_mode, |
259 | const unsigned char *old_sha1, | 272 | const unsigned char *old_sha1, |
260 | const unsigned char *new_sha1, | 273 | const unsigned char *new_sha1, |
261 | const char *base, const char *path); | 274 | const char *base, const char *path); |
262 | 275 | ||
263 | typedef void (*add_remove_fn_t)(struct diff_options *options, | 276 | typedef void (*add_remove_fn_t)(struct diff_options *options, |
264 | int addremove, unsigned mode, | 277 | int addremove, unsigned mode, |
265 | const unsigned char *sha1, | 278 | const unsigned char *sha1, |
266 | const char *base, const char *path); | 279 | const char *base, const char *path); |
267 | 280 | ||
268 | typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, | 281 | typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, |
269 | struct diff_options *options, void *data); | 282 | struct diff_options *options, void *data); |
270 | 283 | ||
271 | #define DIFF_FORMAT_RAW 0x0001 | 284 | #define DIFF_FORMAT_RAW 0x0001 |
272 | #define DIFF_FORMAT_DIFFSTAT0x0002 | 285 | #define DIFF_FORMAT_DIFFSTAT0x0002 |
273 | #define DIFF_FORMAT_NUMSTAT0x0004 | 286 | #define DIFF_FORMAT_NUMSTAT0x0004 |
274 | #define DIFF_FORMAT_SUMMARY0x0008 | 287 | #define DIFF_FORMAT_SUMMARY0x0008 |
275 | #define DIFF_FORMAT_PATCH0x0010 | 288 | #define DIFF_FORMAT_PATCH0x0010 |
276 | 289 | ||
277 | /* These override all above */ | 290 | /* These override all above */ |
278 | #define DIFF_FORMAT_NAME0x0100 | 291 | #define DIFF_FORMAT_NAME0x0100 |
279 | #define DIFF_FORMAT_NAME_STATUS0x0200 | 292 | #define DIFF_FORMAT_NAME_STATUS0x0200 |
280 | #define DIFF_FORMAT_CHECKDIFF0x0400 | 293 | #define DIFF_FORMAT_CHECKDIFF0x0400 |
281 | 294 | ||
282 | /* Same as output_format = 0 but we know that -s flag was given | 295 | /* Same as output_format = 0 but we know that -s flag was given |
283 | * and we should not give default value to output_format. | 296 | * and we should not give default value to output_format. |
284 | */ | 297 | */ |
285 | #define DIFF_FORMAT_NO_OUTPUT0x0800 | 298 | #define DIFF_FORMAT_NO_OUTPUT0x0800 |
286 | 299 | ||
@@ -1,115 +1,120 @@ | |||
1 | /* ui-log.c: functions for log output | 1 | /* ui-log.c: functions for log output |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | static int get_one_line(char *txt) | 11 | static int get_one_line(char *txt) |
12 | { | 12 | { |
13 | char *t; | 13 | char *t; |
14 | 14 | ||
15 | for(t=txt; *t != '\n' && t != '\0'; t++) | 15 | for(t=txt; *t != '\n' && t != '\0'; t++) |
16 | ; | 16 | ; |
17 | *t = '\0'; | 17 | *t = '\0'; |
18 | return t-txt-1; | 18 | return t-txt-1; |
19 | } | 19 | } |
20 | 20 | ||
21 | static void cgit_print_commit_shortlog(struct commit *commit) | 21 | static void cgit_print_commit_shortlog(struct commit *commit) |
22 | { | 22 | { |
23 | char *h, *t, *p; | 23 | char *h, *t, *p; |
24 | char *tree = NULL, *author = NULL, *subject = NULL; | 24 | char *tree = NULL, *author = NULL, *subject = NULL; |
25 | int len; | 25 | int len; |
26 | time_t sec; | 26 | time_t sec; |
27 | struct tm *time; | 27 | struct tm *time; |
28 | char buf[32]; | 28 | char buf[32]; |
29 | 29 | ||
30 | h = t = commit->buffer; | 30 | h = t = commit->buffer; |
31 | 31 | ||
32 | if (strncmp(h, "tree ", 5)) | 32 | if (strncmp(h, "tree ", 5)) |
33 | die("Bad commit format: %s", | 33 | die("Bad commit format: %s", |
34 | sha1_to_hex(commit->object.sha1)); | 34 | sha1_to_hex(commit->object.sha1)); |
35 | 35 | ||
36 | len = get_one_line(h); | 36 | len = get_one_line(h); |
37 | tree = h+5; | 37 | tree = h+5; |
38 | h += len + 2; | 38 | h += len + 2; |
39 | 39 | ||
40 | while (!strncmp(h, "parent ", 7)) | 40 | while (!strncmp(h, "parent ", 7)) |
41 | h += get_one_line(h) + 2; | 41 | h += get_one_line(h) + 2; |
42 | 42 | ||
43 | if (!strncmp(h, "author ", 7)) { | 43 | if (!strncmp(h, "author ", 7)) { |
44 | author = h+7; | 44 | author = h+7; |
45 | h += get_one_line(h) + 2; | 45 | h += get_one_line(h) + 2; |
46 | t = author; | 46 | t = author; |
47 | while(t!=h && *t!='<') | 47 | while(t!=h && *t!='<') |
48 | t++; | 48 | t++; |
49 | *t='\0'; | 49 | *t='\0'; |
50 | p = t; | 50 | p = t; |
51 | while(--t!=author && *t==' ') | 51 | while(--t!=author && *t==' ') |
52 | *t='\0'; | 52 | *t='\0'; |
53 | while(++p!=h && *p!='>') | 53 | while(++p!=h && *p!='>') |
54 | ; | 54 | ; |
55 | while(++p!=h && !isdigit(*p)) | 55 | while(++p!=h && !isdigit(*p)) |
56 | ; | 56 | ; |
57 | 57 | ||
58 | t = p; | 58 | t = p; |
59 | while(++p && isdigit(*p)) | 59 | while(++p && isdigit(*p)) |
60 | ; | 60 | ; |
61 | *p = '\0'; | 61 | *p = '\0'; |
62 | sec = atoi(t); | 62 | sec = atoi(t); |
63 | time = gmtime(&sec); | 63 | time = gmtime(&sec); |
64 | } | 64 | } |
65 | 65 | ||
66 | while((len = get_one_line(h)) > 0) | 66 | while((len = get_one_line(h)) > 0) |
67 | h += len+2; | 67 | h += len+2; |
68 | 68 | ||
69 | h++; | 69 | h++; |
70 | len = get_one_line(h); | 70 | len = get_one_line(h); |
71 | 71 | ||
72 | subject = h; | 72 | subject = h; |
73 | 73 | ||
74 | html("<tr><td>"); | 74 | html("<tr><td>"); |
75 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); | 75 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); |
76 | html_txt(buf); | 76 | html_txt(buf); |
77 | html("</td><td>"); | 77 | html("</td><td>"); |
78 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | 78 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); |
79 | char *url = cgit_pageurl(cgit_query_repo, "view", qry); | 79 | char *url = cgit_pageurl(cgit_query_repo, "view", qry); |
80 | html_link_open(url, NULL, NULL); | 80 | html_link_open(url, NULL, NULL); |
81 | html_txt(subject); | 81 | html_txt(subject); |
82 | html_link_close(); | 82 | html_link_close(); |
83 | html("</td><td>"); | 83 | html("</td><td>"); |
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"); |
86 | } | 91 | } |
87 | 92 | ||
88 | void cgit_print_log(const char *tip, int ofs, int cnt) | 93 | void cgit_print_log(const char *tip, int ofs, int cnt) |
89 | { | 94 | { |
90 | struct rev_info rev; | 95 | struct rev_info rev; |
91 | struct commit *commit; | 96 | struct commit *commit; |
92 | const char *argv[2] = {NULL, tip}; | 97 | const char *argv[2] = {NULL, tip}; |
93 | int n = 0; | 98 | int n = 0; |
94 | 99 | ||
95 | init_revisions(&rev, NULL); | 100 | init_revisions(&rev, NULL); |
96 | rev.abbrev = DEFAULT_ABBREV; | 101 | rev.abbrev = DEFAULT_ABBREV; |
97 | rev.commit_format = CMIT_FMT_DEFAULT; | 102 | rev.commit_format = CMIT_FMT_DEFAULT; |
98 | rev.verbose_header = 1; | 103 | rev.verbose_header = 1; |
99 | rev.show_root_diff = 0; | 104 | rev.show_root_diff = 0; |
100 | setup_revisions(2, argv, &rev, NULL); | 105 | setup_revisions(2, argv, &rev, NULL); |
101 | prepare_revision_walk(&rev); | 106 | prepare_revision_walk(&rev); |
102 | 107 | ||
103 | html("<h2>Log</h2>"); | 108 | html("<h2>Log</h2>"); |
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) { |
107 | cgit_print_commit_shortlog(commit); | 112 | cgit_print_commit_shortlog(commit); |
108 | free(commit->buffer); | 113 | free(commit->buffer); |
109 | commit->buffer = NULL; | 114 | commit->buffer = NULL; |
110 | free_commit_list(commit->parents); | 115 | free_commit_list(commit->parents); |
111 | commit->parents = NULL; | 116 | commit->parents = NULL; |
112 | } | 117 | } |
113 | html("</table>\n"); | 118 | html("</table>\n"); |
114 | } | 119 | } |
115 | 120 | ||
diff --git a/ui-summary.c b/ui-summary.c index cc918ad..29baa74 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -1,55 +1,60 @@ | |||
1 | /* ui-summary.c: functions for generating repo summary page | 1 | /* ui-summary.c: functions for generating repo summary page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | 11 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, |
12 | int flags, void *cb_data) | 12 | int flags, void *cb_data) |
13 | { | 13 | { |
14 | struct commit *commit; | 14 | struct commit *commit; |
15 | char buf[256], *url; | 15 | char buf[256], *url; |
16 | 16 | ||
17 | commit = lookup_commit(sha1); | 17 | commit = lookup_commit(sha1); |
18 | if (commit && !parse_commit(commit)){ | 18 | if (commit && !parse_commit(commit)){ |
19 | html("<tr><td>"); | 19 | html("<tr><td>"); |
20 | url = cgit_pageurl(cgit_query_repo, "log", | 20 | url = cgit_pageurl(cgit_query_repo, "log", |
21 | fmt("h=%s", refname)); | 21 | fmt("h=%s", refname)); |
22 | html_link_open(url, NULL, NULL); | 22 | html_link_open(url, NULL, NULL); |
23 | strncpy(buf, refname, sizeof(buf)); | 23 | strncpy(buf, refname, sizeof(buf)); |
24 | html_txt(buf); | 24 | html_txt(buf); |
25 | html_link_close(); | 25 | html_link_close(); |
26 | html("</td><td>"); | 26 | html("</td><td>"); |
27 | pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0, buf, | 27 | pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0, buf, |
28 | sizeof(buf), 0, NULL, NULL, 0); | 28 | sizeof(buf), 0, NULL, NULL, 0); |
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"); |
31 | } else { | 36 | } else { |
32 | html("<tr><td>"); | 37 | html("<tr><td>"); |
33 | html_txt(buf); | 38 | html_txt(buf); |
34 | html("</td><td>"); | 39 | html("</td><td>"); |
35 | htmlf("*** bad ref %s", sha1_to_hex(sha1)); | 40 | htmlf("*** bad ref %s", sha1_to_hex(sha1)); |
36 | html("</td></tr>\n"); | 41 | html("</td></tr>\n"); |
37 | } | 42 | } |
38 | return 0; | 43 | return 0; |
39 | } | 44 | } |
40 | 45 | ||
41 | static void cgit_print_branches() | 46 | static void cgit_print_branches() |
42 | { | 47 | { |
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); |
46 | html("</table>"); | 51 | html("</table>"); |
47 | } | 52 | } |
48 | 53 | ||
49 | void cgit_print_summary() | 54 | void cgit_print_summary() |
50 | { | 55 | { |
51 | html("<h2>"); | 56 | html("<h2>"); |
52 | html_txt("Repo summary page"); | 57 | html_txt("Repo summary page"); |
53 | html("</h2>"); | 58 | html("</h2>"); |
54 | cgit_print_branches(); | 59 | cgit_print_branches(); |
55 | } | 60 | } |
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 | |||
12 | static 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 | |||
48 | void 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 | } | ||
@@ -1,40 +1,40 @@ | |||
1 | /* ui-view.c: functions to output _any_ object, given it's sha1 | 1 | /* ui-view.c: functions to output _any_ object, given it's sha1 |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | void cgit_print_view(char *hex) | 11 | void cgit_print_view(char *hex) |
12 | { | 12 | { |
13 | unsigned char sha1[20]; | 13 | unsigned char sha1[20]; |
14 | char type[20]; | 14 | char type[20]; |
15 | unsigned char *buf; | 15 | unsigned char *buf; |
16 | unsigned long size; | 16 | unsigned long size; |
17 | 17 | ||
18 | if (get_sha1_hex(hex, sha1)){ | 18 | if (get_sha1_hex(hex, sha1)){ |
19 | cgit_print_error(fmt("Bad hex value: %s", hex)); | 19 | cgit_print_error(fmt("Bad hex value: %s", hex)); |
20 | return; | 20 | return; |
21 | } | 21 | } |
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"); |
25 | return; | 25 | return; |
26 | } | 26 | } |
27 | 27 | ||
28 | buf = read_sha1_file(sha1, type, &size); | 28 | buf = read_sha1_file(sha1, type, &size); |
29 | if (!buf) { | 29 | if (!buf) { |
30 | cgit_print_error("Error reading object"); | 30 | cgit_print_error("Error reading object"); |
31 | return; | 31 | return; |
32 | } | 32 | } |
33 | 33 | ||
34 | buf[size] = '\0'; | 34 | buf[size] = '\0'; |
35 | html("<h2>Object view</h2>"); | 35 | html("<h2>Object view</h2>"); |
36 | htmlf("sha1=%s<br/>type=%s<br/>size=%i<br/>", hex, type, size); | 36 | htmlf("sha1=%s<br/>type=%s<br/>size=%i<br/>", hex, type, size); |
37 | html("<pre>"); | 37 | html("<pre>"); |
38 | html_txt(buf); | 38 | html_txt(buf); |
39 | html("</pre>"); | 39 | html("</pre>"); |
40 | } | 40 | } |