summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2006-12-11 15:55:07 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2006-12-11 15:55:33 (UTC)
commit1418034e642fee67c981b31e4c3eb6e8ae14e303 (patch) (unidiff)
tree3addc880197706f2ddd24f35c5d886f1e885b276
parent74620f12e4f7e91cb0a0b4ca731e07272d1b65f6 (diff)
downloadcgit-1418034e642fee67c981b31e4c3eb6e8ae14e303.zip
cgit-1418034e642fee67c981b31e4c3eb6e8ae14e303.tar.gz
cgit-1418034e642fee67c981b31e4c3eb6e8ae14e303.tar.bz2
Move repo summary functions into ui-summary.c
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile2
-rw-r--r--cgit.c46
-rw-r--r--cgit.h3
-rw-r--r--ui-summary.c55
4 files changed, 59 insertions, 47 deletions
diff --git a/Makefile b/Makefile
index 81ebb18..71ddc40 100644
--- a/Makefile
+++ b/Makefile
@@ -1,24 +1,24 @@
1CGIT_VERSION = 0.1-pre 1CGIT_VERSION = 0.1-pre
2 2
3INSTALL_BIN = /var/www/htdocs/cgit.cgi 3INSTALL_BIN = /var/www/htdocs/cgit.cgi
4INSTALL_CSS = /var/www/htdocs/cgit.css 4INSTALL_CSS = /var/www/htdocs/cgit.css
5CACHE_ROOT = /var/cache/cgit 5CACHE_ROOT = /var/cache/cgit
6 6
7EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto 7EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto
8OBJECTS = parsing.o html.o cache.o ui-shared.o ui-repolist.o 8OBJECTS = cache.o parsing.o html.o ui-shared.o ui-repolist.o ui-summary.o
9 9
10CFLAGS += -Wall 10CFLAGS += -Wall
11 11
12all: cgit 12all: cgit
13 13
14install: all 14install: all
15 install cgit $(INSTALL_BIN) 15 install cgit $(INSTALL_BIN)
16 install cgit.css $(INSTALL_CSS) 16 install cgit.css $(INSTALL_CSS)
17 rm -rf $(CACHE_ROOT)/* 17 rm -rf $(CACHE_ROOT)/*
18 18
19cgit: cgit.c cgit.h git.h $(OBJECTS) 19cgit: cgit.c cgit.h git.h $(OBJECTS)
20 $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit \ 20 $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit \
21 $(OBJECTS) $(EXTLIBS) 21 $(OBJECTS) $(EXTLIBS)
22 22
23$(OBJECTS): cgit.h git.h 23$(OBJECTS): cgit.h git.h
24 24
diff --git a/cgit.c b/cgit.c
index b3ff512..300fe46 100644
--- a/cgit.c
+++ b/cgit.c
@@ -71,70 +71,32 @@ void cgit_repo_config_cb(const char *name, const char *value)
71 71
72void cgit_querystring_cb(const char *name, const char *value) 72void cgit_querystring_cb(const char *name, const char *value)
73{ 73{
74 if (!strcmp(name,"r")) 74 if (!strcmp(name,"r"))
75 cgit_query_repo = xstrdup(value); 75 cgit_query_repo = xstrdup(value);
76 else if (!strcmp(name, "p")) 76 else if (!strcmp(name, "p"))
77 cgit_query_page = xstrdup(value); 77 cgit_query_page = xstrdup(value);
78 else if (!strcmp(name, "h")) { 78 else if (!strcmp(name, "h")) {
79 cgit_query_head = xstrdup(value); 79 cgit_query_head = xstrdup(value);
80 cgit_query_has_symref = 1; 80 cgit_query_has_symref = 1;
81 } else if (!strcmp(name, "id")) { 81 } else if (!strcmp(name, "id")) {
82 cgit_query_sha1 = xstrdup(value); 82 cgit_query_sha1 = xstrdup(value);
83 cgit_query_has_sha1 = 1; 83 cgit_query_has_sha1 = 1;
84 } 84 }
85} 85}
86 86
87static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
88 int flags, void *cb_data)
89{
90 struct commit *commit;
91 char buf[256], *url;
92
93 commit = lookup_commit(sha1);
94 if (commit && !parse_commit(commit)){
95 html("<tr><td>");
96 url = cgit_pageurl(cgit_query_repo, "log",
97 fmt("h=%s", refname));
98 html_link_open(url, NULL, NULL);
99 strncpy(buf, refname, sizeof(buf));
100 html_txt(buf);
101 html_link_close();
102 html("</td><td>");
103 pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0, buf,
104 sizeof(buf), 0, NULL, NULL, 0);
105 html_txt(buf);
106 html("</td></tr>\n");
107 } else {
108 html("<tr><td>");
109 html_txt(buf);
110 html("</td><td>");
111 htmlf("*** bad ref %s", sha1_to_hex(sha1));
112 html("</td></tr>\n");
113 }
114 return 0;
115}
116
117static void cgit_print_branches()
118{
119 html("<table class='list'>");
120 html("<tr><th>Branch name</th><th>Head commit</th></tr>\n");
121 for_each_branch_ref(cgit_print_branch_cb, NULL);
122 html("</table>");
123}
124
125static int get_one_line(char *txt) 87static int get_one_line(char *txt)
126{ 88{
127 char *t; 89 char *t;
128 90
129 for(t=txt; *t != '\n' && t != '\0'; t++) 91 for(t=txt; *t != '\n' && t != '\0'; t++)
130 ; 92 ;
131 *t = '\0'; 93 *t = '\0';
132 return t-txt-1; 94 return t-txt-1;
133} 95}
134 96
135static void cgit_print_commit_shortlog(struct commit *commit) 97static void cgit_print_commit_shortlog(struct commit *commit)
136{ 98{
137 char *h, *t, *p; 99 char *h, *t, *p;
138 char *tree = NULL, *author = NULL, *subject = NULL; 100 char *tree = NULL, *author = NULL, *subject = NULL;
139 int len; 101 int len;
140 time_t sec; 102 time_t sec;
@@ -214,40 +176,32 @@ static void cgit_print_log(const char *tip, int ofs, int cnt)
214 setup_revisions(2, argv, &rev, NULL); 176 setup_revisions(2, argv, &rev, NULL);
215 prepare_revision_walk(&rev); 177 prepare_revision_walk(&rev);
216 178
217 html("<h2>Log</h2>"); 179 html("<h2>Log</h2>");
218 html("<table class='list'>"); 180 html("<table class='list'>");
219 html("<tr><th>Date</th><th>Message</th><th>Author</th></tr>\n"); 181 html("<tr><th>Date</th><th>Message</th><th>Author</th></tr>\n");
220 while ((commit = get_revision(&rev)) != NULL && n++ < 100) { 182 while ((commit = get_revision(&rev)) != NULL && n++ < 100) {
221 cgit_print_commit_shortlog(commit); 183 cgit_print_commit_shortlog(commit);
222 free(commit->buffer); 184 free(commit->buffer);
223 commit->buffer = NULL; 185 commit->buffer = NULL;
224 free_commit_list(commit->parents); 186 free_commit_list(commit->parents);
225 commit->parents = NULL; 187 commit->parents = NULL;
226 } 188 }
227 html("</table>\n"); 189 html("</table>\n");
228} 190}
229 191
230static void cgit_print_repo_summary()
231{
232 html("<h2>");
233 html_txt("Repo summary page");
234 html("</h2>");
235 cgit_print_branches();
236}
237
238static void cgit_print_object(char *hex) 192static void cgit_print_object(char *hex)
239{ 193{
240 unsigned char sha1[20]; 194 unsigned char sha1[20];
241 //struct object *object; 195 //struct object *object;
242 char type[20]; 196 char type[20];
243 unsigned char *buf; 197 unsigned char *buf;
244 unsigned long size; 198 unsigned long size;
245 199
246 if (get_sha1_hex(hex, sha1)){ 200 if (get_sha1_hex(hex, sha1)){
247 cgit_print_error(fmt("Bad hex value: %s", hex)); 201 cgit_print_error(fmt("Bad hex value: %s", hex));
248 return; 202 return;
249 } 203 }
250 204
251 if (sha1_object_info(sha1, type, NULL)){ 205 if (sha1_object_info(sha1, type, NULL)){
252 cgit_print_error("Bad object name"); 206 cgit_print_error("Bad object name");
253 return; 207 return;
diff --git a/cgit.h b/cgit.h
index bf5bd8d..3a153a5 100644
--- a/cgit.h
+++ b/cgit.h
@@ -66,17 +66,20 @@ extern int cache_exist(struct cacheitem *item);
66extern int cache_expired(struct cacheitem *item); 66extern int cache_expired(struct cacheitem *item);
67 67
68extern char *cgit_repourl(const char *reponame); 68extern char *cgit_repourl(const char *reponame);
69extern char *cgit_pageurl(const char *reponame, const char *pagename, 69extern char *cgit_pageurl(const char *reponame, const char *pagename,
70 const char *query); 70 const char *query);
71 71
72extern void cgit_print_error(char *msg); 72extern void cgit_print_error(char *msg);
73extern void cgit_print_docstart(char *title, struct cacheitem *item); 73extern void cgit_print_docstart(char *title, struct cacheitem *item);
74extern void cgit_print_docend(); 74extern void cgit_print_docend();
75extern void cgit_print_pageheader(char *title); 75extern void cgit_print_pageheader(char *title);
76 76
77extern void cgit_print_repolist(struct cacheitem *item); 77extern void cgit_print_repolist(struct cacheitem *item);
78 78
79 79
80extern void cgit_repo_config_cb(const char *name, const char *value); 80extern void cgit_repo_config_cb(const char *name, const char *value);
81 81
82extern void cgit_print_repo_summary();
83
84
82#endif /* CGIT_H */ 85#endif /* CGIT_H */
diff --git a/ui-summary.c b/ui-summary.c
new file mode 100644
index 0000000..532ddbf
--- a/dev/null
+++ b/ui-summary.c
@@ -0,0 +1,55 @@
1/* ui-summary.c: functions for generating repo summary page
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
11static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
12 int flags, void *cb_data)
13{
14 struct commit *commit;
15 char buf[256], *url;
16
17 commit = lookup_commit(sha1);
18 if (commit && !parse_commit(commit)){
19 html("<tr><td>");
20 url = cgit_pageurl(cgit_query_repo, "log",
21 fmt("h=%s", refname));
22 html_link_open(url, NULL, NULL);
23 strncpy(buf, refname, sizeof(buf));
24 html_txt(buf);
25 html_link_close();
26 html("</td><td>");
27 pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0, buf,
28 sizeof(buf), 0, NULL, NULL, 0);
29 html_txt(buf);
30 html("</td></tr>\n");
31 } else {
32 html("<tr><td>");
33 html_txt(buf);
34 html("</td><td>");
35 htmlf("*** bad ref %s", sha1_to_hex(sha1));
36 html("</td></tr>\n");
37 }
38 return 0;
39}
40
41static void cgit_print_branches()
42{
43 html("<table class='list'>");
44 html("<tr><th>Branch name</th><th>Head commit</th></tr>\n");
45 for_each_branch_ref(cgit_print_branch_cb, NULL);
46 html("</table>");
47}
48
49void cgit_print_repo_summary()
50{
51 html("<h2>");
52 html_txt("Repo summary page");
53 html("</h2>");
54 cgit_print_branches();
55}