diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | cgit.c | 2 | ||||
| -rw-r--r-- | cgit.css | 25 | ||||
| -rw-r--r-- | cgit.h | 2 | ||||
| -rw-r--r-- | shared.c | 4 | ||||
| -rw-r--r-- | ui-diff.c | 131 | ||||
| -rw-r--r-- | xdiff.h | 105 |
7 files changed, 270 insertions, 1 deletions
| @@ -6,7 +6,7 @@ CACHE_ROOT = /var/cache/cgit | |||
| 6 | 6 | ||
| 7 | EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto | 7 | EXTLIBS = ../git/libgit.a ../git/xdiff/lib.a -lz -lcrypto |
| 8 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 8 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
| 9 | ui-summary.o ui-log.o ui-view.c ui-tree.c ui-commit.c | 9 | ui-summary.o ui-log.o ui-view.c ui-tree.c ui-commit.c ui-diff.o |
| 10 | 10 | ||
| 11 | CFLAGS += -Wall | 11 | CFLAGS += -Wall |
| 12 | 12 | ||
| @@ -36,6 +36,8 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
| 36 | cgit_print_commit(cgit_query_sha1); | 36 | cgit_print_commit(cgit_query_sha1); |
| 37 | } else if (!strcmp(cgit_query_page, "view")) { | 37 | } else if (!strcmp(cgit_query_page, "view")) { |
| 38 | cgit_print_view(cgit_query_sha1); | 38 | cgit_print_view(cgit_query_sha1); |
| 39 | } else if (!strcmp(cgit_query_page, "diff")) { | ||
| 40 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); | ||
| 39 | } | 41 | } |
| 40 | cgit_print_docend(); | 42 | cgit_print_docend(); |
| 41 | } | 43 | } |
| @@ -77,12 +77,18 @@ div.error { | |||
| 77 | font-weight: bold; | 77 | font-weight: bold; |
| 78 | margin: 1em 2em; | 78 | margin: 1em 2em; |
| 79 | } | 79 | } |
| 80 | div.ls-blob, div.ls-dir { | ||
| 81 | font-family: monospace; | ||
| 82 | } | ||
| 80 | div.ls-dir a { | 83 | div.ls-dir a { |
| 81 | font-weight: bold; | 84 | font-weight: bold; |
| 82 | } | 85 | } |
| 83 | th.filesize, td.filesize { | 86 | th.filesize, td.filesize { |
| 84 | text-align: right; | 87 | text-align: right; |
| 85 | } | 88 | } |
| 89 | td.filesize { | ||
| 90 | font-family: monospace; | ||
| 91 | } | ||
| 86 | td.filemode { | 92 | td.filemode { |
| 87 | font-family: monospace; | 93 | font-family: monospace; |
| 88 | } | 94 | } |
| @@ -154,6 +160,25 @@ table.diffstat td.summary { | |||
| 154 | color: #888; | 160 | color: #888; |
| 155 | padding-top: 0.5em; | 161 | padding-top: 0.5em; |
| 156 | } | 162 | } |
| 163 | |||
| 164 | table.diff td { | ||
| 165 | border: solid 1px black; | ||
| 166 | font-family: monospace; | ||
| 167 | white-space: pre; | ||
| 168 | } | ||
| 169 | |||
| 170 | table.diff td div.hunk { | ||
| 171 | background: #ccc; | ||
| 172 | } | ||
| 173 | |||
| 174 | table.diff td div.add { | ||
| 175 | color: green; | ||
| 176 | } | ||
| 177 | |||
| 178 | table.diff td div.del { | ||
| 179 | color: red; | ||
| 180 | } | ||
| 181 | |||
| 157 | .sha1 { | 182 | .sha1 { |
| 158 | font-family: courier; | 183 | font-family: courier; |
| 159 | font-size: 90%; | 184 | font-size: 90%; |
| @@ -57,6 +57,7 @@ extern char *cgit_query_repo; | |||
| 57 | extern char *cgit_query_page; | 57 | extern char *cgit_query_page; |
| 58 | extern char *cgit_query_head; | 58 | extern char *cgit_query_head; |
| 59 | extern char *cgit_query_sha1; | 59 | extern char *cgit_query_sha1; |
| 60 | extern char *cgit_query_sha2; | ||
| 60 | extern int cgit_query_ofs; | 61 | extern int cgit_query_ofs; |
| 61 | 62 | ||
| 62 | extern int htmlfd; | 63 | extern int htmlfd; |
| @@ -104,5 +105,6 @@ extern void cgit_print_log(const char *tip, int ofs, int cnt); | |||
| 104 | extern void cgit_print_view(const char *hex); | 105 | extern void cgit_print_view(const char *hex); |
| 105 | extern void cgit_print_tree(const char *hex); | 106 | extern void cgit_print_tree(const char *hex); |
| 106 | extern void cgit_print_commit(const char *hex); | 107 | extern void cgit_print_commit(const char *hex); |
| 108 | extern void cgit_print_diff(const char *old_hex, const char *new_hex); | ||
| 107 | 109 | ||
| 108 | #endif /* CGIT_H */ | 110 | #endif /* CGIT_H */ |
| @@ -37,6 +37,7 @@ char *cgit_query_repo = NULL; | |||
| 37 | char *cgit_query_page = NULL; | 37 | char *cgit_query_page = NULL; |
| 38 | char *cgit_query_head = NULL; | 38 | char *cgit_query_head = NULL; |
| 39 | char *cgit_query_sha1 = NULL; | 39 | char *cgit_query_sha1 = NULL; |
| 40 | char *cgit_query_sha2 = NULL; | ||
| 40 | int cgit_query_ofs = 0; | 41 | int cgit_query_ofs = 0; |
| 41 | 42 | ||
| 42 | int htmlfd = 0; | 43 | int htmlfd = 0; |
| @@ -83,6 +84,9 @@ void cgit_querystring_cb(const char *name, const char *value) | |||
| 83 | } else if (!strcmp(name, "id")) { | 84 | } else if (!strcmp(name, "id")) { |
| 84 | cgit_query_sha1 = xstrdup(value); | 85 | cgit_query_sha1 = xstrdup(value); |
| 85 | cgit_query_has_sha1 = 1; | 86 | cgit_query_has_sha1 = 1; |
| 87 | } else if (!strcmp(name, "id2")) { | ||
| 88 | cgit_query_sha2 = xstrdup(value); | ||
| 89 | cgit_query_has_sha1 = 1; | ||
| 86 | } else if (!strcmp(name, "ofs")) { | 90 | } else if (!strcmp(name, "ofs")) { |
| 87 | cgit_query_ofs = atoi(value); | 91 | cgit_query_ofs = atoi(value); |
| 88 | } | 92 | } |
diff --git a/ui-diff.c b/ui-diff.c new file mode 100644 index 0000000..0bd9ade --- /dev/null +++ b/ui-diff.c | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* ui-diff.c: show diff between two blobs | ||
| 2 | * | ||
| 3 | * Copyright (C) 2006 Lars Hjemli | ||
| 4 | * | ||
| 5 | * Licensed under GNU General Public License v2 | ||
| 6 | * (see COPYING for full license text) | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "cgit.h" | ||
| 10 | #include "xdiff.h" | ||
| 11 | |||
| 12 | char *diff_buffer; | ||
| 13 | int diff_buffer_size; | ||
| 14 | |||
| 15 | |||
| 16 | /* | ||
| 17 | * print a single line returned from xdiff | ||
| 18 | */ | ||
| 19 | static void print_line(char *line, int len) | ||
| 20 | { | ||
| 21 | char *class = "ctx"; | ||
| 22 | char c = line[len-1]; | ||
| 23 | |||
| 24 | if (line[0] == '+') | ||
| 25 | class = "add"; | ||
| 26 | else if (line[0] == '-') | ||
| 27 | class = "del"; | ||
| 28 | else if (line[0] == '@') | ||
| 29 | class = "hunk"; | ||
| 30 | |||
| 31 | htmlf("<div class='%s'>", class); | ||
| 32 | line[len-1] = '\0'; | ||
| 33 | html_txt(line); | ||
| 34 | html("</div>"); | ||
| 35 | line[len-1] = c; | ||
| 36 | } | ||
| 37 | |||
| 38 | /* | ||
| 39 | * Receive diff-buffers from xdiff and concatenate them as | ||
| 40 | * needed across multiple callbacks. | ||
| 41 | * | ||
| 42 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), | ||
| 43 | * ripped from git and modified to use globals instead of | ||
| 44 | * a special callback-struct. | ||
| 45 | */ | ||
| 46 | int diff_cb(void *priv_, mmbuffer_t *mb, int nbuf) | ||
| 47 | { | ||
| 48 | int i; | ||
