author | Lars Hjemli <hjemli@gmail.com> | 2006-12-15 17:17:36 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2006-12-15 17:17:36 (UTC) |
commit | 2101e26fd68f816e77de62b93df4c32fd1110d0c (patch) (unidiff) | |
tree | d70d28734c4fbfd0a4e4a40bcfd445eb50dc1666 /ui-log.c | |
parent | 420712ac2531f65a2b94d5ec6d8e03de6942331e (diff) | |
download | cgit-2101e26fd68f816e77de62b93df4c32fd1110d0c.zip cgit-2101e26fd68f816e77de62b93df4c32fd1110d0c.tar.gz cgit-2101e26fd68f816e77de62b93df4c32fd1110d0c.tar.bz2 |
Add a common commit parser
Make a better commit parser, replacing the ugly one in ui-log.c
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-log.c | 76 |
1 files changed, 13 insertions, 63 deletions
@@ -9,67 +9,12 @@ | |||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | static int get_one_line(char *txt) | 11 | void print_commit(struct commit *commit) |
12 | { | 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]; | 13 | char buf[32]; |
14 | struct commitinfo *info; | ||
15 | struct tm *time; | ||
29 | 16 | ||
30 | h = t = commit->buffer; | 17 | info = cgit_parse_commit(commit); |
31 | 18 | time = gmtime(&commit->date); | |
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>"); | 19 | html("<tr><td>"); |
75 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); | 20 | strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); |
@@ -79,8 +24,8 @@ static void cgit_print_commit_shortlog(struct commit *commit) | |||
79 | char *url = cgit_pageurl(cgit_query_repo, "view", qry); | 24 | char *url = cgit_pageurl(cgit_query_repo, "view", qry); |
80 | html_link_open(url, NULL, NULL); | 25 | html_link_open(url, NULL, NULL); |
81 | html_txt(subject); | 26 | html_txt(info->subject); |
82 | html_link_close(); | 27 | html_link_close(); |
83 | html("</td><td>"); | 28 | html("</td><td>"); |
84 | html_txt(author); | 29 | html_txt(info->author); |
85 | html("</td><td><a href='"); | 30 | html("</td><td><a href='"); |
86 | html_attr(cgit_pageurl(cgit_query_repo, "tree", | 31 | html_attr(cgit_pageurl(cgit_query_repo, "tree", |
@@ -89,6 +34,11 @@ static void cgit_print_commit_shortlog(struct commit *commit) | |||
89 | html("'>tree</a>"); | 34 | html("'>tree</a>"); |
90 | html("</td></tr>\n"); | 35 | html("</td></tr>\n"); |
36 | free(info->author); | ||
37 | free(info->committer); | ||
38 | free(info->subject); | ||
39 | free(info); | ||
91 | } | 40 | } |
92 | 41 | ||
42 | |||
93 | void cgit_print_log(const char *tip, int ofs, int cnt) | 43 | void cgit_print_log(const char *tip, int ofs, int cnt) |
94 | { | 44 | { |
@@ -121,5 +71,5 @@ void cgit_print_log(const char *tip, int ofs, int cnt) | |||
121 | 71 | ||
122 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 72 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
123 | cgit_print_commit_shortlog(commit); | 73 | print_commit(commit); |
124 | free(commit->buffer); | 74 | free(commit->buffer); |
125 | commit->buffer = NULL; | 75 | commit->buffer = NULL; |