author | Lars Hjemli <hjemli@gmail.com> | 2009-02-01 18:29:47 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-02-01 18:29:47 (UTC) |
commit | 5e447b1ed1aa751e8ec93dccf4df6fa4a7ffddb6 (patch) (unidiff) | |
tree | 823678b1c4a907cf0df50067c27fb5b752114df5 /ui-log.c | |
parent | 0b3c746ba80738dbe0885a21406409390936537c (diff) | |
parent | 481ce5e298e2dcd7edc1d4a30e523dda2ce58b01 (diff) | |
download | cgit-5e447b1ed1aa751e8ec93dccf4df6fa4a7ffddb6.zip cgit-5e447b1ed1aa751e8ec93dccf4df6fa4a7ffddb6.tar.gz cgit-5e447b1ed1aa751e8ec93dccf4df6fa4a7ffddb6.tar.bz2 |
Merge branch 'lh/binary'
-rw-r--r-- | ui-log.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -1,223 +1,228 @@ | |||
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 | unsigned long old_size = 0; | ||
30 | unsigned long new_size = 0; | ||
31 | int binary = 0; | ||
32 | |||
29 | files++; | 33 | files++; |
30 | if (ctx.repo->enable_log_linecount) | 34 | if (ctx.repo->enable_log_linecount) |
31 | cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); | 35 | cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, |
36 | &new_size, &binary, count_lines); | ||
32 | } | 37 | } |
33 | 38 | ||
34 | void show_commit_decorations(struct commit *commit) | 39 | void show_commit_decorations(struct commit *commit) |
35 | { | 40 | { |
36 | struct name_decoration *deco; | 41 | struct name_decoration *deco; |
37 | static char buf[1024]; | 42 | static char buf[1024]; |
38 | 43 | ||
39 | buf[sizeof(buf) - 1] = 0; | 44 | buf[sizeof(buf) - 1] = 0; |
40 | deco = lookup_decoration(&name_decoration, &commit->object); | 45 | deco = lookup_decoration(&name_decoration, &commit->object); |
41 | while (deco) { | 46 | while (deco) { |
42 | if (!prefixcmp(deco->name, "refs/heads/")) { | 47 | if (!prefixcmp(deco->name, "refs/heads/")) { |
43 | strncpy(buf, deco->name + 11, sizeof(buf) - 1); | 48 | strncpy(buf, deco->name + 11, sizeof(buf) - 1); |
44 | cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL, | 49 | cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL, |
45 | 0, NULL, NULL, ctx.qry.showmsg); | 50 | 0, NULL, NULL, ctx.qry.showmsg); |
46 | } | 51 | } |
47 | else if (!prefixcmp(deco->name, "tag: refs/tags/")) { | 52 | else if (!prefixcmp(deco->name, "tag: refs/tags/")) { |
48 | strncpy(buf, deco->name + 15, sizeof(buf) - 1); | 53 | strncpy(buf, deco->name + 15, sizeof(buf) - 1); |
49 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); | 54 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); |
50 | } | 55 | } |
51 | else if (!prefixcmp(deco->name, "refs/remotes/")) { | 56 | else if (!prefixcmp(deco->name, "refs/remotes/")) { |
52 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); | 57 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); |
53 | cgit_log_link(buf, NULL, "remote-deco", NULL, | 58 | cgit_log_link(buf, NULL, "remote-deco", NULL, |
54 | sha1_to_hex(commit->object.sha1), NULL, | 59 | sha1_to_hex(commit->object.sha1), NULL, |
55 | 0, NULL, NULL, ctx.qry.showmsg); | 60 | 0, NULL, NULL, ctx.qry.showmsg); |
56 | } | 61 | } |
57 | else { | 62 | else { |
58 | strncpy(buf, deco->name, sizeof(buf) - 1); | 63 | strncpy(buf, deco->name, sizeof(buf) - 1); |
59 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, | 64 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, |
60 | sha1_to_hex(commit->object.sha1)); | 65 | sha1_to_hex(commit->object.sha1)); |
61 | } | 66 | } |
62 | deco = deco->next; | 67 | deco = deco->next; |
63 | } | 68 | } |
64 | } | 69 | } |
65 | 70 | ||
66 | void print_commit(struct commit *commit) | 71 | void print_commit(struct commit *commit) |
67 | { | 72 | { |
68 | struct commitinfo *info; | 73 | struct commitinfo *info; |
69 | char *tmp; | 74 | char *tmp; |
70 | int cols = 2; | 75 | int cols = 2; |
71 | 76 | ||
72 | info = cgit_parse_commit(commit); | 77 | info = cgit_parse_commit(commit); |
73 | htmlf("<tr%s><td>", | 78 | htmlf("<tr%s><td>", |
74 | ctx.qry.showmsg ? " class='logheader'" : ""); | 79 | ctx.qry.showmsg ? " class='logheader'" : ""); |
75 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); | 80 | tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); |
76 | tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); | 81 | tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); |
77 | html_link_open(tmp, NULL, NULL); | 82 | html_link_open(tmp, NULL, NULL); |
78 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 83 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
79 | html_link_close(); | 84 | html_link_close(); |
80 | htmlf("</td><td%s>", | 85 | htmlf("</td><td%s>", |
81 | ctx.qry.showmsg ? " class='logsubject'" : ""); | 86 | ctx.qry.showmsg ? " class='logsubject'" : ""); |
82 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, | 87 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
83 | sha1_to_hex(commit->object.sha1)); | 88 | sha1_to_hex(commit->object.sha1)); |
84 | show_commit_decorations(commit); | 89 | show_commit_decorations(commit); |
85 | html("</td><td>"); | 90 | html("</td><td>"); |
86 | html_txt(info->author); | 91 | html_txt(info->author); |
87 | if (ctx.repo->enable_log_filecount) { | 92 | if (ctx.repo->enable_log_filecount) { |
88 | files = 0; | 93 | files = 0; |
89 | add_lines = 0; | 94 | add_lines = 0; |
90 | rem_lines = 0; | 95 | rem_lines = 0; |
91 | cgit_diff_commit(commit, inspect_files); | 96 | cgit_diff_commit(commit, inspect_files); |
92 | html("</td><td>"); | 97 | html("</td><td>"); |
93 | htmlf("%d", files); | 98 | htmlf("%d", files); |
94 | if (ctx.repo->enable_log_linecount) { | 99 | if (ctx.repo->enable_log_linecount) { |
95 | html("</td><td>"); | 100 | html("</td><td>"); |
96 | htmlf("-%d/+%d", rem_lines, add_lines); | 101 | htmlf("-%d/+%d", rem_lines, add_lines); |
97 | } | 102 | } |
98 | } | 103 | } |
99 | html("</td></tr>\n"); | 104 | html("</td></tr>\n"); |
100 | if (ctx.qry.showmsg) { | 105 | if (ctx.qry.showmsg) { |
101 | if (ctx.repo->enable_log_filecount) { | 106 | if (ctx.repo->enable_log_filecount) { |
102 | cols++; | 107 | cols++; |
103 | if (ctx.repo->enable_log_linecount) | 108 | if (ctx.repo->enable_log_linecount) |
104 | cols++; | 109 | cols++; |
105 | } | 110 | } |
106 | htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", | 111 | htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", |
107 | cols); | 112 | cols); |
108 | html_txt(info->msg); | 113 | html_txt(info->msg); |
109 | html("</td></tr>\n"); | 114 | html("</td></tr>\n"); |
110 | } | 115 | } |
111 | cgit_free_commitinfo(info); | 116 | cgit_free_commitinfo(info); |
112 | } | 117 | } |
113 | 118 | ||
114 | static const char *disambiguate_ref(const char *ref) | 119 | static const char *disambiguate_ref(const char *ref) |
115 | { | 120 | { |
116 | unsigned char sha1[20]; | 121 | unsigned char sha1[20]; |
117 | const char *longref; | 122 | const char *longref; |
118 | 123 | ||
119 | longref = fmt("refs/heads/%s", ref); | 124 | longref = fmt("refs/heads/%s", ref); |
120 | if (get_sha1(longref, sha1) == 0) | 125 | if (get_sha1(longref, sha1) == 0) |
121 | return longref; | 126 | return longref; |
122 | 127 | ||
123 | return ref; | 128 | return ref; |
124 | } | 129 | } |
125 | 130 | ||
126 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, | 131 | void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, |
127 | char *path, int pager) | 132 | char *path, int pager) |
128 | { | 133 | { |
129 | struct rev_info rev; | 134 | struct rev_info rev; |
130 | struct commit *commit; | 135 | struct commit *commit; |
131 | const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; | 136 | const char *argv[] = {NULL, NULL, NULL, NULL, NULL}; |
132 | int argc = 2; | 137 | int argc = 2; |
133 | int i, columns = 3; | 138 | int i, columns = 3; |
134 | 139 | ||
135 | if (!tip) | 140 | if (!tip) |
136 | tip = ctx.qry.head; | 141 | tip = ctx.qry.head; |
137 | 142 | ||
138 | argv[1] = disambiguate_ref(tip); | 143 | argv[1] = disambiguate_ref(tip); |
139 | 144 | ||
140 | if (grep && pattern && (!strcmp(grep, "grep") || | 145 | if (grep && pattern && (!strcmp(grep, "grep") || |
141 | !strcmp(grep, "author") || | 146 | !strcmp(grep, "author") || |
142 | !strcmp(grep, "committer"))) | 147 | !strcmp(grep, "committer"))) |
143 | argv[argc++] = fmt("--%s=%s", grep, pattern); | 148 | argv[argc++] = fmt("--%s=%s", grep, pattern); |
144 | 149 | ||
145 | if (path) { | 150 | if (path) { |
146 | argv[argc++] = "--"; | 151 | argv[argc++] = "--"; |
147 | argv[argc++] = path; | 152 | argv[argc++] = path; |
148 | } | 153 | } |
149 | init_revisions(&rev, NULL); | 154 | init_revisions(&rev, NULL); |
150 | rev.abbrev = DEFAULT_ABBREV; | 155 | rev.abbrev = DEFAULT_ABBREV; |
151 | rev.commit_format = CMIT_FMT_DEFAULT; | 156 | rev.commit_format = CMIT_FMT_DEFAULT; |
152 | rev.verbose_header = 1; | 157 | rev.verbose_header = 1; |
153 | rev.show_root_diff = 0; | 158 | rev.show_root_diff = 0; |
154 | setup_revisions(argc, argv, &rev, NULL); | 159 | setup_revisions(argc, argv, &rev, NULL); |
155 | load_ref_decorations(); | 160 | load_ref_decorations(); |
156 | rev.show_decorations = 1; | 161 | rev.show_decorations = 1; |
157 | rev.grep_filter.regflags |= REG_ICASE; | 162 | rev.grep_filter.regflags |= REG_ICASE; |
158 | compile_grep_patterns(&rev.grep_filter); | 163 | compile_grep_patterns(&rev.grep_filter); |
159 | prepare_revision_walk(&rev); | 164 | prepare_revision_walk(&rev); |
160 | 165 | ||
161 | if (pager) | 166 | if (pager) |
162 | html("<table class='list nowrap'>"); | 167 | html("<table class='list nowrap'>"); |
163 | 168 | ||
164 | html("<tr class='nohover'><th class='left'>Age</th>" | 169 | html("<tr class='nohover'><th class='left'>Age</th>" |
165 | "<th class='left'>Commit message"); | 170 | "<th class='left'>Commit message"); |
166 | if (pager) { | 171 | if (pager) { |
167 | html(" ("); | 172 | html(" ("); |
168 | cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, | 173 | cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL, |
169 | NULL, ctx.qry.head, ctx.qry.sha1, | 174 | NULL, ctx.qry.head, ctx.qry.sha1, |
170 | ctx.qry.path, ctx.qry.ofs, ctx.qry.grep, | 175 | ctx.qry.path, ctx.qry.ofs, ctx.qry.grep, |
171 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1); | 176 | ctx.qry.search, ctx.qry.showmsg ? 0 : 1); |
172 | html(")"); | 177 | html(")"); |
173 | } | 178 | } |
174 | html("</th><th class='left'>Author</th>"); | 179 | html("</th><th class='left'>Author</th>"); |
175 | if (ctx.repo->enable_log_filecount) { | 180 | if (ctx.repo->enable_log_filecount) { |
176 | html("<th class='left'>Files</th>"); | 181 | html("<th class='left'>Files</th>"); |
177 | columns++; | 182 | columns++; |
178 | if (ctx.repo->enable_log_linecount) { | 183 | if (ctx.repo->enable_log_linecount) { |
179 | html("<th class='left'>Lines</th>"); | 184 | html("<th class='left'>Lines</th>"); |
180 | columns++; | 185 | columns++; |
181 | } | 186 | } |
182 | } | 187 | } |
183 | html("</tr>\n"); | 188 | html("</tr>\n"); |
184 | 189 | ||
185 | if (ofs<0) | 190 | if (ofs<0) |
186 | ofs = 0; | 191 | ofs = 0; |
187 | 192 | ||
188 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { | 193 | for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { |
189 | free(commit->buffer); | 194 | free(commit->buffer); |
190 | commit->buffer = NULL; | 195 | commit->buffer = NULL; |
191 | free_commit_list(commit->parents); | 196 | free_commit_list(commit->parents); |
192 | commit->parents = NULL; | 197 | commit->parents = NULL; |
193 | } | 198 | } |
194 | 199 | ||
195 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { | 200 | for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { |
196 | print_commit(commit); | 201 | print_commit(commit); |
197 | free(commit->buffer); | 202 | free(commit->buffer); |
198 | commit->buffer = NULL; | 203 | commit->buffer = NULL; |
199 | free_commit_list(commit->parents); | 204 | free_commit_list(commit->parents); |
200 | commit->parents = NULL; | 205 | commit->parents = NULL; |
201 | } | 206 | } |
202 | if (pager) { | 207 | if (pager) { |
203 | htmlf("</table><div class='pager'>", | 208 | htmlf("</table><div class='pager'>", |
204 | columns); | 209 | columns); |
205 | if (ofs > 0) { | 210 | if (ofs > 0) { |
206 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, | 211 | cgit_log_link("[prev]", NULL, NULL, ctx.qry.head, |
207 | ctx.qry.sha1, ctx.qry.path, | 212 | ctx.qry.sha1, ctx.qry.path, |
208 | ofs - cnt, ctx.qry.grep, | 213 | ofs - cnt, ctx.qry.grep, |
209 | ctx.qry.search, ctx.qry.showmsg); | 214 | ctx.qry.search, ctx.qry.showmsg); |
210 | html(" "); | 215 | html(" "); |
211 | } | 216 | } |
212 | if ((commit = get_revision(&rev)) != NULL) { | 217 | if ((commit = get_revision(&rev)) != NULL) { |
213 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, | 218 | cgit_log_link("[next]", NULL, NULL, ctx.qry.head, |
214 | ctx.qry.sha1, ctx.qry.path, | 219 | ctx.qry.sha1, ctx.qry.path, |
215 | ofs + cnt, ctx.qry.grep, | 220 | ofs + cnt, ctx.qry.grep, |
216 | ctx.qry.search, ctx.qry.showmsg); | 221 | ctx.qry.search, ctx.qry.showmsg); |
217 | } | 222 | } |
218 | html("</div>"); | 223 | html("</div>"); |
219 | } else if ((commit = get_revision(&rev)) != NULL) { | 224 | } else if ((commit = get_revision(&rev)) != NULL) { |
220 | html("<tr class='nohover'><td colspan='3'>"); | 225 | html("<tr class='nohover'><td colspan='3'>"); |
221 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0, | 226 | cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0, |
222 | NULL, NULL, ctx.qry.showmsg); | 227 | NULL, NULL, ctx.qry.showmsg); |
223 | html("</td></tr>\n"); | 228 | html("</td></tr>\n"); |