summaryrefslogtreecommitdiffabout
path: root/ui-log.c
authorLars Hjemli <hjemli@gmail.com>2009-01-31 09:40:40 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-01-31 09:40:40 (UTC)
commitc495cf02bac16e459f7c9e1740798646f12c00c5 (patch) (unidiff)
treea36ba3904edd96ffc79fdf420fb10d33117a469f /ui-log.c
parentd6174b7aab476c2b6a86e59d98cf978d603045f4 (diff)
downloadcgit-c495cf02bac16e459f7c9e1740798646f12c00c5.zip
cgit-c495cf02bac16e459f7c9e1740798646f12c00c5.tar.gz
cgit-c495cf02bac16e459f7c9e1740798646f12c00c5.tar.bz2
Handle binary files in diffs
This teaches all diff-related operations (i.e. ui-log, ui-diff and ui-patch) how to handle binary files. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-log.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-log.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/ui-log.c b/ui-log.c
index 3202848..ba2ab03 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,79 +1,84 @@
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
13int files, add_lines, rem_lines; 13int files, add_lines, rem_lines;
14 14
15void count_lines(char *line, int size) 15void 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
27void inspect_files(struct diff_filepair *pair) 27void 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
34void show_commit_decorations(struct commit *commit) 39void 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
66void print_commit(struct commit *commit) 71void 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();