author | Lars Hjemli <hjemli@gmail.com> | 2008-12-06 10:37:37 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-12-06 10:37:37 (UTC) |
commit | 3c32fe07717f27fc891b66ccd06057fb810d03ad (patch) (unidiff) | |
tree | 04897b3eac6432c43284e7da79161e47856d078b /ui-log.c | |
parent | 9c8be943f72b6f1bda5a31ce401899c3dd734e98 (diff) | |
parent | ab67164d6217fcda5ef3e07aefa3dd6eee6b65a3 (diff) | |
download | cgit-3c32fe07717f27fc891b66ccd06057fb810d03ad.zip cgit-3c32fe07717f27fc891b66ccd06057fb810d03ad.tar.gz cgit-3c32fe07717f27fc891b66ccd06057fb810d03ad.tar.bz2 |
Merge branch 'full-log'
Conflicts:
cgit.c
cgit.h
-rw-r--r-- | ui-log.c | 35 |
1 files changed, 28 insertions, 7 deletions
@@ -1,168 +1,189 @@ | |||
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 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | int files, add_lines, rem_lines; | 13 | int files, add_lines, rem_lines; |
14 | 14 | ||
15 | void count_lines(char *line, int size) | 15 | void count_lines(char *line, int size) |
16 | { | 16 | { |
17 | if (size <= 0) | 17 | if (size <= 0) |
18 | return; | 18 | return; |
19 | 19 | ||
20 | if (line[0] == '+') | 20 | if (line[0] == '+') |
21 | add_lines++; | 21 | add_lines++; |
22 | 22 | ||
23 | else if (line[0] == '-') | 23 | else if (line[0] == '-') |
24 | rem_lines++; | 24 | rem_lines++; |
25 | } | 25 | } |
26 | 26 | ||
27 | void inspect_files(struct diff_filepair *pair) | 27 | void inspect_files(struct diff_filepair *pair) |
28 | { | 28 | { |
29 | files++; | 29 | files++; |
30 | if (ctx.repo->enable_log_linecount) | 30 | if (ctx.repo->enable_log_linecount) |
31 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); | 31 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); |
32 | } | 32 | } |
33 | 33 | ||
34 | void print_commit(struct commit *commit) | 34 | void print_commit(struct commit *commit) |
35 | { | 35 | { |
36 | struct commitinfo *info; | 36 | struct commitinfo *info; |
37 | char *tmp; | 37 | char *tmp; |
38 | int cols = 2; | ||
38 | 39 | ||
39 | info = cgit_parse_commit(commit); | 40 | info = cgit_parse_commit(commit); |
40 | html("<tr><td>"); | 41 | htmlf("<tr%s><td>", |
42 | ctx.qry.showmsg ? " class='logheader'" : ""); | ||
41 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | 43 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); |
42 | tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); | 44 | tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); |
43 | html_link_open(tmp, NULL, NULL); | 45 | html_link_open(tmp, NULL, NULL); |
44 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 46 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
45 | html_link_close(); | 47 | html_link_close(); |
46 | html("</td><td>"); | 48 | htmlf("</td><td%s>", |
49 | ctx.qry.showmsg ? " class='logsubject'" : ""); | ||
47 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, | 50 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
48 | sha1_to_hex(commit->object.sha1)); | 51 | sha1_to_hex(commit->object.sha1)); |
49 | html("</td><td>"); | 52 | html("</td><td>"); |
50 | html_txt(info->author); | 53 | html_txt(info->author); |
51 | if (ctx.repo->enable_log_filecount) { | 54 | if (ctx.repo->enable_log_filecount) { |
52 | files = 0; | 55 | files = 0; |
53 | add_lines = 0; | 56 | add_lines = 0; |
54 | rem_lines = 0; | 57 | rem_lines = 0; |
55 | cgit_diff_commit(commit, inspect_files); | 58 | cgit_diff_commit(commit, inspect_files); |
56 | html("</td><td>"); | 59 | html("</td><td>"); |
57 | htmlf("%d", files); | 60 | htmlf("%d", files); |
58 | if (ctx.repo->enable_log_linecount) { | 61 | if (ctx.repo->enable_log_linecount) { |
59 | html("</td><td>"); | 62 | html("</td><td>"); |
60 | htmlf("-%d/+%d", rem_lines, add_lines); | 63 | htmlf("-%d/+%d", rem_lines, add_lines); |
61 | } | 64 | } |
62 | } | 65 | } |
63 | html("</td></tr>\n"); | 66 | html("</td></tr>\n"); |
67 | if (ctx.qry.showmsg) { | ||
68 | if (ctx.repo->enable_log_filecount) { | ||
69 | cols++; | ||
70 | if (ctx.repo->enable_log_linecount) | ||
71 | cols++; | ||
72 | } | ||
73 | htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", | ||
74 | cols); | ||
75 | html_txt(info->msg); | ||
76 | html("</td></tr>\n"); | ||
77 | } | ||
64 | cgit_free_commitinfo(info); | 78 | cgit_free_commitinfo(info); |
65 | } | 79 | } |
66 | 80 | ||
67 | static const char *disambiguate_ref(const char *ref) | 81 | static const char *disambiguate_ref(const char *ref) |
68 | { | 82 | { |
69 | unsigned char sha1[20]; | 83 | unsigned char sha1[20]; |
70 | const char *longref; | 84 | const char *longref; |
71 | 85 | ||
72 | longref = fmt("refs/heads/%s", ref); | 86 | longref = fmt("refs/heads/%s", ref); |
73 | if (get_sha1(longref, sha1) == 0) | 87 | if (get_sha1(longref, sha1) == 0) |
74 | return longref; | 88 | return longref; |
75 | 89 | ||
76 | return ref; | 90 | return ref; |
77 | } | 91 | } |
78 | 92 | ||
79 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, | 93 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, |
80 | char *path, int pager) | 94 | char *path, int pager) |
81 | { | 95 | { |
82 | struct rev_info rev; | 96 | struct rev_info rev; |
83 | struct commit *commit; | 97 | struct commit *commit; |
84 | const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; | 98 | const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; |
85 | int argc = 2; | 99 | int argc = 2; |
86 | int i, columns = 3; | 100 | int i, columns = 3; |
87 | 101 | ||
88 | if (!tip) | 102 | if (!tip) |
89 | tip = ctx.qry.head; | 103 | tip = ctx.qry.head; |
90 | 104 | ||
91 | argv[1] = disambiguate_ref(tip); | 105 | argv[1] = disambiguate_ref(tip); |
92 | 106 | ||
93 | if (grep && pattern && (!strcmp(grep, "grep") || | 107 | if (grep && pattern && (!strcmp(grep, "grep") || |
94 | !strcmp(grep, "author") || | 108 | !strcmp(grep, "author") || |
95 | !strcmp(grep, "committer"))) | 109 | !strcmp(grep, "committer"))) |
96 | argv[argc++] = fmt("--%s=%s", grep, pattern); | 110 | argv[argc++] = fmt("--%s=%s", grep, pattern); |
97 | 111 | ||
98 | if (path) { | 112 | if (path) { |
99 | argv[argc++] = "--"; | 113 | argv[argc++] = "--"; |
100 | argv[argc++] = path; | 114 | argv[argc++] = path; |
101 | } | 115 | } |
102 | init_revisions(&rev, NULL); | 116 | init_revisions(&rev, NULL); |
103 | rev.abbrev = DEFAULT_ABBREV; | 117 | rev.abbrev = DEFAULT_ABBREV; |
104 | rev.commit_format = CMIT_FMT_DEFAULT; | 118 | rev.commit_format = CMIT_FMT_DEFAULT; |
105 | rev.verbose_header = 1; | 119 | rev.verbose_header = 1; |
106 | rev.show_root_diff = 0; | 120 | rev.show_root_diff = 0; |
107 | setup_revisions(argc, argv, &rev, NULL); | 121 | setup_revisions(argc, argv, &rev, NULL); |
108 | rev.grep_filter.regflags |= REG_ICASE; | 122 | rev.grep_filter.regflags |= REG_ICASE; |
109 | compile_grep_patterns(&rev.grep_filter); | 123 | compile_grep_patterns(&rev.grep_filter); |
110 | prepare_revision_walk(&rev); | 124 | prepare_revision_walk(&rev); |
111 | 125 | ||
112 | if (pager) | 126 | if (pager) |
113 | html("<table class='list nowrap'>"); | 127 | html("<table class='list nowrap'>"); |
114 | 128 | ||
115 | html("<tr class='nohover'><th class='left'>Age</th>" | 129 | html("<tr class='nohover'><th class='left'>Age</th>" |
116 | "<th class='left'>Commit message</th>" | 130 | "<th class='left'>Commit message"); |
117 | "<th class='left'>Author</th>"); | 131 | if (pager) { |
132 | html(" ("); | ||
133 | cgit_log_link("toggle", NULL, NULL, ctx.qry.head, ctx.qry.sha1, | ||
134 | ctx.qry.path, ctx.qry.ofs, ctx.qry.grep, | ||
135 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1); | ||
136 | html(")"); | ||
137 | } | ||
138 | html("</th><th class='left'>Author</th>"); | ||
118 | if (ctx.repo->enable_log_filecount) { | 139 | if (ctx.repo->enable_log_filecount) { |
119 | html("<th class='left'>Files</th>"); | 140 | html("<th class='left'>Files</th>"); |
120 | columns++; | 141 | columns++; |
121 | if (ctx.repo->enable_log_linecount) { | 142 | if (ctx.repo->enable_log_linecount) { |
122 | html("<th class='left'>Lines</th>"); | 143 | html("<th class='left'>Lines</th>"); |
123 | columns++; | 144 | columns++; |
124 | } | 145 | } |
125 | } | 146 | } |
126 | html("</tr>\n"); | 147 | html("</tr>\n"); |
127 | 148 | ||
128 | if (ofs<0) | 149 | if (ofs<0) |
129 | ofs = 0; | 150 | ofs = 0; |
130 | 151 | ||
131 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 152 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
132 | free(commit->buffer); | 153 | free(commit->buffer); |
133 | commit->buffer = NULL; | 154 | commit->buffer = NULL; |
134 | free_commit_list(commit->parents); | 155 | free_commit_list(commit->parents); |
135 | commit->parents = NULL; | 156 | commit->parents = NULL; |
136 | } | 157 | } |
137 | 158 | ||
138 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 159 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
139 | print_commit(commit); | 160 | print_commit(commit); |
140 | free(commit->buffer); | 161 | free(commit->buffer); |
141 | commit->buffer = NULL; | 162 | commit->buffer = NULL; |
142 | free_commit_list(commit->parents); | 163 | free_commit_list(commit->parents); |
143 | commit->parents = NULL; | 164 | commit->parents = NULL; |
144 | } | 165 | } |
145 | if (pager) { | 166 | if (pager) { |
146 | htmlf("</table><div class='pager'>", | 167 | htmlf("</table><div class='pager'>", |
147 | columns); | 168 | columns); |
148 | if (ofs > 0) { | 169 | if (ofs > 0) { |
149 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, | 170 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, |
150 | ctx.qry.sha1, ctx.qry.path, | 171 | ctx.qry.sha1, ctx.qry.path, |
151 | ofs - cnt, ctx.qry.grep, | 172 | ofs - cnt, ctx.qry.grep, |
152 | ctx.qry.search); | 173 | ctx.qry.search, ctx.qry.showmsg); |
153 | html(" "); | 174 | html(" "); |
154 | } | 175 | } |
155 | if ((commit = get_revision(&rev)) != NULL) { | 176 | if ((commit = get_revision(&rev)) != NULL) { |
156 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, | 177 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, |
157 | ctx.qry.sha1, ctx.qry.path, | 178 | ctx.qry.sha1, ctx.qry.path, |
158 | ofs + cnt, ctx.qry.grep, | 179 | ofs + cnt, ctx.qry.grep, |
159 | ctx.qry.search); | 180 | ctx.qry.search, ctx.qry.showmsg); |
160 | } | 181 | } |
161 | html("</div>"); | 182 | html("</div>"); |
162 | } else if ((commit = get_revision(&rev)) != NULL) { | 183 | } else if ((commit = get_revision(&rev)) != NULL) { |
163 | html("<tr class='nohover'><td colspan='3'>"); | 184 | html("<tr class='nohover'><td colspan='3'>"); |
164 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0, | 185 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0, |
165 | NULL, NULL); | 186 | NULL, NULL, ctx.qry.showmsg); |
166 | html("</td></tr>\n"); | 187 | html("</td></tr>\n"); |
167 | } | 188 | } |
168 | } | 189 | } |