2 cehtehs git web frontend
5 2007, 2008 Christian Thaeter <ct@pipapo.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 webgit_object_commit_tree_parse (struct commit* commit)
28 char* tree = strstr (commit->buffer, "tree ");
35 webgit_object_commit_author_date_parse (struct commit* commit, struct tm* tm)
41 char* author = strstr (commit->buffer, "author ");
45 char* beg = strchr (author, '>');
49 if (!strptime (beg + 2, "%s %Z", tm))
56 webgit_object_commit_author_name_parse (struct commit* commit)
58 char* author = strstr (commit->buffer, "author ");
62 char* end = strchr (author, '<');
66 return html_fmt ("%.*s", end-author-8, author+7);
70 webgit_object_commit_author_email_parse (struct commit* commit)
72 char* author = strstr (commit->buffer, "author ");
76 char* beg = strchr (author, '<');
80 char* end = strchr (beg, '>');
85 return html_fmt ("%.*s", end-beg-1, beg+1);
89 webgit_object_commit_committer_date_parse (struct commit* commit, struct tm* tm)
95 char* committer = strstr (commit->buffer, "committer ");
99 char* beg = strchr (committer, '>');
103 if (!strptime (beg + 2, "%s %Z", tm))
110 webgit_object_commit_committer_name_parse (struct commit* commit)
112 char* committer = strstr (commit->buffer, "committer ");
116 char* end = strchr (committer, '<');
120 return html_fmt ("%.*s", end-committer-11, committer+10);
124 webgit_object_commit_committer_email_parse (struct commit* commit)
126 char* committer = strstr (commit->buffer, "committer ");
130 char* beg = strchr (committer, '<');
134 char* end = strchr (beg, '>');
139 return html_fmt ("%.*s", end-beg-1, beg+1);
143 webgit_object_commit_header_parse (struct commit* commit)
145 char* header = strstr (commit->buffer, "\n\n");
149 char* end = strchr (header+2, '\n');
151 end = header + strlen (header+2);
155 return html_fmt ("%.*s", end-header, header+2);
159 webgit_object_commit_message_parse (struct commit* commit)
161 char* header = strstr (commit->buffer, "\n\n");
165 header = strchr (header+2, '\n');
171 return html_fmt ("%.*s", strlen (header), header);
180 webgit_object_commit_menu_action (struct webgit_repo_info* repo, unsigned char* sha1, void* buf, unsigned long size)
187 return html ("TODO: commit-object sidebar");
191 webgit_object_commit_content_action (struct webgit_repo_info* repo, unsigned char* sha1, void* buf, unsigned long size)
194 TODO pass commit objects instead buf/size, use parsers from above
198 Html tree = html_list ();
199 Html parents = html_list ();
200 Html author_text = html_list ();
201 Html author = html_list ();
202 Html committer = html_list ();
204 const char* author_beg = NULL;
205 const char* author_end = NULL;
208 while (i && (void*)i < buf+size)
216 if (!strncmp (i, "tree ", 5))
218 html_list_append (tree,
220 webgit_object_link (repo->query,
221 repo->name, strlen (repo->name),
225 html_fmt ("%.40s", i+5))
227 if ((i = strchr (i, '\n')))
231 else if (!strncmp (i, "parent ", 7))
233 html_list_append (parents, html (
235 webgit_object_link (repo->query,
236 repo->name, strlen (repo->name),
240 html_fmt ("%.40s", i+7))
243 if ((i = strchr (i, '\n')))
247 else if (!strncmp (i, "author ", 7))
249 char* email_beg = strchr (i, '<');
250 char* email_end = strchr (email_beg, '>');
253 author_end = strchr (author_beg, '\n');
255 Html name = html_strndup (i+7, email_beg - i - 8);
256 Html email = html_strndup (email_beg + 1, email_end - email_beg - 1);
259 strptime (email_end + 2, "%s %Z", &tm);
260 char pretty_date[256];
261 strftime (pretty_date, 255, "%c", &tm);
263 html_list_append (author_text, "Author");
265 html_list_append (author, html (
266 html ( author_text ), /*BUG: libcwa bug, must be wraped in html()*/
267 webgit_email_link (name, email),
268 html_strndup (pretty_date, 255)
271 if ((i = strchr (i, '\n')))
275 else if (!strncmp (i, "committer ", 10))
277 char* email_beg = strchr (i, '<');
278 char* email_end = strchr (email_beg, '>');
280 if (author_beg && author_end && strncmp (i + 10, author_beg, author_end - author_beg))
282 Html name = html_strndup (i+10, email_beg - i - 11);
283 Html email = html_strndup (email_beg + 1, email_end - email_beg - 1);
286 strptime (email_end + 2, "%s %Z", &tm);
287 char pretty_date[256];
288 strftime (pretty_date, 255, "%c", &tm);
290 html_list_append (committer, html ("Committer: ",
291 webgit_email_link (name, email),
292 html_strndup (pretty_date, 255)
297 html_list_append (author_text, " and Committer");
299 if ((i = strchr (i, '\n')))
306 html_list_append (author_text, ": ");
308 Html headline = html_list ();
309 Html message = html_list ();
313 const char* message_beg = strchr (i, '\n');
317 html_list_append (headline,
318 html_strndup (i, message_beg - i)
321 while (*message_beg == '\n')
324 html_list_append (message,
325 html_strndup (message_beg, SIZE_MAX)
330 html_list_append (headline,
331 html_strndup (i, SIZE_MAX)
333 html_list_append (message,
334 html_strndup (i, SIZE_MAX)
343 html (html_tag ("h3"), headline),
344 html (html_tag ("div"), tree), html_nl (),
345 html (html_tag ("div"), parents), html_nl (),
346 html (html_tag ("div"), author), html_nl (),
347 html (html_tag ("div"), committer), html_nl (),
348 html (html_tag ("pre"), message)
353 webgit_object_commit_action (struct webgit_repo_info* repo, unsigned char* sha1)
358 buf = read_object_with_reference (sha1, "commit", &size, NULL);
361 html(html_tag("div", html_attr ("id", "object-commit")),
362 html(html_tag("div"), webgit_object_commit_menu_action (repo, sha1, buf, size)), html_nl (),
363 html(html_tag("div"), webgit_object_commit_content_action (repo, sha1, buf, size)), html_nl ()