author | Lars Hjemli <hjemli@gmail.com> | 2006-12-11 16:04:19 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2006-12-11 16:04:19 (UTC) |
commit | d14c5f6d3ac827e7b46831c4151638ab4b638ae1 (patch) (unidiff) | |
tree | d6592747d098d2fb2ca7a0e653984256ac9ac1a5 | |
parent | 1418034e642fee67c981b31e4c3eb6e8ae14e303 (diff) | |
download | cgit-d14c5f6d3ac827e7b46831c4151638ab4b638ae1.zip cgit-d14c5f6d3ac827e7b46831c4151638ab4b638ae1.tar.gz cgit-d14c5f6d3ac827e7b46831c4151638ab4b638ae1.tar.bz2 |
Move log-functions into ui-log.c
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | cgit.c | 107 | ||||
-rw-r--r-- | cgit.h | 5 | ||||
-rw-r--r-- | ui-log.c | 115 | ||||
-rw-r--r-- | ui-summary.c | 2 |
5 files changed, 121 insertions, 111 deletions
@@ -1,24 +1,25 @@ | |||
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 = cache.o parsing.o html.o ui-shared.o ui-repolist.o ui-summary.o | 8 | OBJECTS = cache.o parsing.o html.o ui-shared.o ui-repolist.o ui-summary.o \ |
9 | ui-log.o | ||
9 | 10 | ||
10 | CFLAGS += -Wall | 11 | CFLAGS += -Wall |
11 | 12 | ||
12 | all: cgit | 13 | all: cgit |
13 | 14 | ||
14 | install: all | 15 | install: all |
15 | install cgit $(INSTALL_BIN) | 16 | install cgit $(INSTALL_BIN) |
16 | install cgit.css $(INSTALL_CSS) | 17 | install cgit.css $(INSTALL_CSS) |
17 | rm -rf $(CACHE_ROOT)/* | 18 | rm -rf $(CACHE_ROOT)/* |
18 | 19 | ||
19 | cgit: cgit.c cgit.h git.h $(OBJECTS) | 20 | cgit: cgit.c cgit.h git.h $(OBJECTS) |
20 | $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit \ | 21 | $(CC) $(CFLAGS) -DCGIT_VERSION='"$(CGIT_VERSION)"' cgit.c -o cgit \ |
21 | $(OBJECTS) $(EXTLIBS) | 22 | $(OBJECTS) $(EXTLIBS) |
22 | 23 | ||
23 | $(OBJECTS): cgit.h git.h | 24 | $(OBJECTS): cgit.h git.h |
24 | 25 | ||
@@ -71,137 +71,32 @@ void cgit_repo_config_cb(const char *name, const char *value) | |||
71 | 71 | ||
72 | void cgit_querystring_cb(const char *name, const char *value) | 72 | void 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 | ||
87 | static int get_one_line(char *txt) | ||
88 | { | ||
89 | char *t; | ||
90 | |||
91 | for(t=txt; *t != '\n' && t != '\0'; t++) | ||
92 | ; | ||
93 | *t = '\0'; | ||
94 | return t-txt-1; | ||
95 | } | ||
96 | |||
97 | static void cgit_print_commit_shortlog(struct commit *commit) | ||
98 | { | ||
99 | char *h, *t, *p; | ||
100 | char *tree = NULL, *author = NULL, *subject = NULL; | ||
101 | int len; | ||
102 | time_t sec; | ||
103 | struct tm *time; | ||
104 | char buf[32]; | ||
105 | |||
106 | h = t = commit->buffer; | ||
107 | |||
108 | if (strncmp(h, "tree ", 5)) | ||
109 | die("Bad commit format: %s", | ||
110 | sha1_to_hex(commit->object.sha1)); | ||
111 | |||
112 | len = get_one_line(h); | ||
113 | tree = h+5; | ||
114 | h += len + 2; | ||
115 | |||
116 | while (!strncmp(h, "parent ", 7)) | ||
117 | h += get_one_line(h) + 2; | ||
118 | |||
119 | if (!strncmp(h, "author ", 7)) { | ||
120 | author = h+7; | ||
121 | h += get_one_line(h) + 2; | ||
122 | t = author; | ||
123 | while(t!=h && *t!='<') | ||
124 | t++; | ||
125 | *t='\0'; | ||
126 | p = t; | ||
127 | while(--t!=author && *t==' ') | ||
128 | *t='\0'; | ||
129 | while(++p!=h && *p!='>') | ||
130 | ; | ||
131 | while(++p!=h && !isdigit(*p)) | ||
132 | ; | ||
133 | |||
134 | t = p; | ||
135 | while(++p && isdigit(*p)) | ||
136 | ; | ||
137 | *p = '\0'; | ||
138 | sec = atoi(t); | ||
139 | time = gmtime(&sec); | ||
140 | } | ||
141 | |||
142 | while((len = get_one_line(h)) > 0) | ||
143 | h += len+2; | ||
144 | |||
145 | h++; | ||
146 | len = get_one_line(h); | ||
147 | |||
148 | subject = h; | ||
149 | |||
150 | html("<tr><td>"); | ||
151 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); | ||
152 | html_txt(buf); | ||
153 | html("</td><td>"); | ||
154 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | ||
155 | char *url = cgit_pageurl(cgit_query_repo, "view", qry); | ||
156 | html_link_open(url, NULL, NULL); | ||
157 | html_txt(subject); | ||
158 | html_link_close(); | ||
159 | html("</td><td>"); | ||
160 | html_txt(author); | ||
161 | html("</td></tr>\n"); | ||
162 | } | ||
163 | |||
164 | static void cgit_print_log(const char *tip, int ofs, int cnt) | ||
165 | { | ||
166 | struct rev_info rev; | ||
167 | struct commit *commit; | ||
168 | const char *argv[2] = {NULL, tip}; | ||
169 | int n = 0; | ||
170 | |||
171 | init_revisions(&rev, NULL); | ||
172 | rev.abbrev = DEFAULT_ABBREV; | ||
173 | rev.commit_format = CMIT_FMT_DEFAULT; | ||
174 | rev.verbose_header = 1; | ||
175 | rev.show_root_diff = 0; | ||
176 | setup_revisions(2, argv, &rev, NULL); | ||
177 | prepare_revision_walk(&rev); | ||
178 | |||
179 | html("<h2>Log</h2>"); | ||
180 | html("<table class='list'>"); | ||
181 | html("<tr><th>Date</th><th>Message</th><th>Author</th></tr>\n"); | ||
182 | while ((commit = get_revision(&rev)) != NULL && n++ < 100) { | ||
183 | cgit_print_commit_shortlog(commit); | ||
184 | free(commit->buffer); | ||
185 | commit->buffer = NULL; | ||
186 | free_commit_list(commit->parents); | ||
187 | commit->parents = NULL; | ||
188 | } | ||
189 | html("</table>\n"); | ||
190 | } | ||
191 | |||
192 | static void cgit_print_object(char *hex) | 87 | static void cgit_print_object(char *hex) |
193 | { | 88 | { |
194 | unsigned char sha1[20]; | 89 | unsigned char sha1[20]; |
195 | //struct object *object; | 90 | //struct object *object; |
196 | char type[20]; | 91 | char type[20]; |
197 | unsigned char *buf; | 92 | unsigned char *buf; |
198 | unsigned long size; | 93 | unsigned long size; |
199 | 94 | ||
200 | if (get_sha1_hex(hex, sha1)){ | 95 | if (get_sha1_hex(hex, sha1)){ |
201 | cgit_print_error(fmt("Bad hex value: %s", hex)); | 96 | cgit_print_error(fmt("Bad hex value: %s", hex)); |
202 | return; | 97 | return; |
203 | } | 98 | } |
204 | 99 | ||
205 | if (sha1_object_info(sha1, type, NULL)){ | 100 | if (sha1_object_info(sha1, type, NULL)){ |
206 | cgit_print_error("Bad object name"); | 101 | cgit_print_error("Bad object name"); |
207 | return; | 102 | return; |
@@ -225,33 +120,33 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
225 | { | 120 | { |
226 | if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) || | 121 | if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) || |
227 | cgit_read_config("info/cgit", cgit_repo_config_cb)) { | 122 | cgit_read_config("info/cgit", cgit_repo_config_cb)) { |
228 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 123 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); |
229 | cgit_print_docstart(title, item); | 124 | cgit_print_docstart(title, item); |
230 | cgit_print_pageheader(title); | 125 | cgit_print_pageheader(title); |
231 | cgit_print_error(fmt("Unable to scan repository: %s", | 126 | cgit_print_error(fmt("Unable to scan repository: %s", |
232 | strerror(errno))); | 127 | strerror(errno))); |
233 | cgit_print_docend(); | 128 | cgit_print_docend(); |
234 | return; | 129 | return; |
235 | } | 130 | } |
236 | setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); | 131 | setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); |
237 | char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); | 132 | char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); |
238 | cgit_print_docstart(title, item); | 133 | cgit_print_docstart(title, item); |
239 | cgit_print_pageheader(title); | 134 | cgit_print_pageheader(title); |
240 | if (!cgit_query_page) | 135 | if (!cgit_query_page) |
241 | cgit_print_repo_summary(); | 136 | cgit_print_summary(); |
242 | else if (!strcmp(cgit_query_page, "log")) { | 137 | else if (!strcmp(cgit_query_page, "log")) { |
243 | cgit_print_log(cgit_query_head, 0, 100); | 138 | cgit_print_log(cgit_query_head, 0, 100); |
244 | } else if (!strcmp(cgit_query_page, "view")) { | 139 | } else if (!strcmp(cgit_query_page, "view")) { |
245 | cgit_print_object(cgit_query_sha1); | 140 | cgit_print_object(cgit_query_sha1); |
246 | } | 141 | } |
247 | cgit_print_docend(); | 142 | cgit_print_docend(); |
248 | } | 143 | } |
249 | 144 | ||
250 | static void cgit_fill_cache(struct cacheitem *item) | 145 | static void cgit_fill_cache(struct cacheitem *item) |
251 | { | 146 | { |
252 | htmlfd = item->fd; | 147 | htmlfd = item->fd; |
253 | item->st.st_mtime = time(NULL); | 148 | item->st.st_mtime = time(NULL); |
254 | if (cgit_query_repo) | 149 | if (cgit_query_repo) |
255 | cgit_print_repo_page(item); | 150 | cgit_print_repo_page(item); |
256 | else | 151 | else |
257 | cgit_print_repolist(item); | 152 | cgit_print_repolist(item); |
@@ -62,24 +62,23 @@ extern int cgit_parse_query(char *txt, configfn fn); | |||
62 | extern void cache_prepare(struct cacheitem *item); | 62 | extern void cache_prepare(struct cacheitem *item); |
63 | extern int cache_lock(struct cacheitem *item); | 63 | extern int cache_lock(struct cacheitem *item); |
64 | extern int cache_unlock(struct cacheitem *item); | 64 | extern int cache_unlock(struct cacheitem *item); |
65 | extern int cache_exist(struct cacheitem *item); | 65 | extern int cache_exist(struct cacheitem *item); |
66 | extern int cache_expired(struct cacheitem *item); | 66 | extern int cache_expired(struct cacheitem *item); |
67 | 67 | ||
68 | extern char *cgit_repourl(const char *reponame); | 68 | extern char *cgit_repourl(const char *reponame); |
69 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 69 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
70 | const char *query); | 70 | const char *query); |
71 | 71 | ||
72 | extern void cgit_print_error(char *msg); | 72 | extern void cgit_print_error(char *msg); |
73 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 73 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
74 | extern void cgit_print_docend(); | 74 | extern void cgit_print_docend(); |
75 | extern void cgit_print_pageheader(char *title); | 75 | extern void cgit_print_pageheader(char *title); |
76 | 76 | ||
77 | extern void cgit_print_repolist(struct cacheitem *item); | 77 | extern void cgit_print_repolist(struct cacheitem *item); |
78 | 78 | extern void cgit_print_summary(); | |
79 | extern void cgit_print_log(const char *tip, int ofs, int cnt); | ||
79 | 80 | ||
80 | extern void cgit_repo_config_cb(const char *name, const char *value); | 81 | extern void cgit_repo_config_cb(const char *name, const char *value); |
81 | 82 | ||
82 | extern void cgit_print_repo_summary(); | ||
83 | |||
84 | 83 | ||
85 | #endif /* CGIT_H */ | 84 | #endif /* CGIT_H */ |
diff --git a/ui-log.c b/ui-log.c new file mode 100644 index 0000000..701c392 --- a/dev/null +++ b/ui-log.c | |||
@@ -0,0 +1,115 @@ | |||
1 | /* ui-log.c: functions for log 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 | static int get_one_line(char *txt) | ||
12 | { | ||
13 | char *t; | ||
14 | |||
15 | for(t=txt; *t != '\n' && t != '\0'; t++) | ||
16 | ; | ||
17 | *t = '\0'; | ||
18 | return t-txt-1; | ||
19 | } | ||
20 | |||
21 | static void cgit_print_commit_shortlog(struct commit *commit) | ||
22 | { | ||
23 | char *h, *t, *p; | ||
24 | char *tree = NULL, *author = NULL, *subject = NULL; | ||
25 | int len; | ||
26 | time_t sec; | ||
27 | struct tm *time; | ||
28 | char buf[32]; | ||
29 | |||
30 | h = t = commit->buffer; | ||
31 | |||
32 | if (strncmp(h, "tree ", 5)) | ||
33 | die("Bad commit format: %s", | ||
34 | sha1_to_hex(commit->object.sha1)); | ||
35 | |||
36 | len = get_one_line(h); | ||
37 | tree = h+5; | ||
38 | h += len + 2; | ||
39 | |||
40 | while (!strncmp(h, "parent ", 7)) | ||
41 | h += get_one_line(h) + 2; | ||
42 | |||
43 | if (!strncmp(h, "author ", 7)) { | ||
44 | author = h+7; | ||
45 | h += get_one_line(h) + 2; | ||
46 | t = author; | ||
47 | while(t!=h && *t!='<') | ||
48 | t++; | ||
49 | *t='\0'; | ||
50 | p = t; | ||
51 | while(--t!=author && *t==' ') | ||
52 | *t='\0'; | ||
53 | while(++p!=h && *p!='>') | ||
54 | ; | ||
55 | while(++p!=h && !isdigit(*p)) | ||
56 | ; | ||
57 | |||
58 | t = p; | ||
59 | while(++p && isdigit(*p)) | ||
60 | ; | ||
61 | *p = '\0'; | ||
62 | sec = atoi(t); | ||
63 | time = gmtime(&sec); | ||
64 | } | ||
65 | |||
66 | while((len = get_one_line(h)) > 0) | ||
67 | h += len+2; | ||
68 | |||
69 | h++; | ||
70 | len = get_one_line(h); | ||
71 | |||
72 | subject = h; | ||
73 | |||
74 | html("<tr><td>"); | ||
75 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); | ||
76 | html_txt(buf); | ||
77 | html("</td><td>"); | ||
78 | char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | ||
79 | char *url = cgit_pageurl(cgit_query_repo, "view", qry); | ||
80 | html_link_open(url, NULL, NULL); | ||
81 | html_txt(subject); | ||
82 | html_link_close(); | ||
83 | html("</td><td>"); | ||
84 | html_txt(author); | ||
85 | html("</td></tr>\n"); | ||
86 | } | ||
87 | |||
88 | void cgit_print_log(const char *tip, int ofs, int cnt) | ||
89 | { | ||
90 | struct rev_info rev; | ||
91 | struct commit *commit; | ||
92 | const char *argv[2] = {NULL, tip}; | ||
93 | int n = 0; | ||
94 | |||
95 | init_revisions(&rev, NULL); | ||
96 | rev.abbrev = DEFAULT_ABBREV; | ||
97 | rev.commit_format = CMIT_FMT_DEFAULT; | ||
98 | rev.verbose_header = 1; | ||
99 | rev.show_root_diff = 0; | ||
100 | setup_revisions(2, argv, &rev, NULL); | ||
101 | prepare_revision_walk(&rev); | ||
102 | |||
103 | html("<h2>Log</h2>"); | ||
104 | html("<table class='list'>"); | ||
105 | html("<tr><th>Date</th><th>Message</th><th>Author</th></tr>\n"); | ||
106 | while ((commit = get_revision(&rev)) != NULL && n++ < 100) { | ||
107 | cgit_print_commit_shortlog(commit); | ||
108 | free(commit->buffer); | ||
109 | commit->buffer = NULL; | ||
110 | free_commit_list(commit->parents); | ||
111 | commit->parents = NULL; | ||
112 | } | ||
113 | html("</table>\n"); | ||
114 | } | ||
115 | |||
diff --git a/ui-summary.c b/ui-summary.c index 532ddbf..cc918ad 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -33,23 +33,23 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | |||
33 | html_txt(buf); | 33 | html_txt(buf); |
34 | html("</td><td>"); | 34 | html("</td><td>"); |
35 | htmlf("*** bad ref %s", sha1_to_hex(sha1)); | 35 | htmlf("*** bad ref %s", sha1_to_hex(sha1)); |
36 | html("</td></tr>\n"); | 36 | html("</td></tr>\n"); |
37 | } | 37 | } |
38 | return 0; | 38 | return 0; |
39 | } | 39 | } |
40 | 40 | ||
41 | static void cgit_print_branches() | 41 | static void cgit_print_branches() |
42 | { | 42 | { |
43 | html("<table class='list'>"); | 43 | html("<table class='list'>"); |
44 | html("<tr><th>Branch name</th><th>Head commit</th></tr>\n"); | 44 | html("<tr><th>Branch name</th><th>Head commit</th></tr>\n"); |
45 | for_each_branch_ref(cgit_print_branch_cb, NULL); | 45 | for_each_branch_ref(cgit_print_branch_cb, NULL); |
46 | html("</table>"); | 46 | html("</table>"); |
47 | } | 47 | } |
48 | 48 | ||
49 | void cgit_print_repo_summary() | 49 | void cgit_print_summary() |
50 | { | 50 | { |
51 | html("<h2>"); | 51 | html("<h2>"); |
52 | html_txt("Repo summary page"); | 52 | html_txt("Repo summary page"); |
53 | html("</h2>"); | 53 | html("</h2>"); |
54 | cgit_print_branches(); | 54 | cgit_print_branches(); |
55 | } | 55 | } |