diff options
-rw-r--r-- | cgit.c | 1 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | ui-diff.c | 3 | ||||
-rw-r--r-- | ui-log.c | 3 | ||||
-rw-r--r-- | ui-repolist.c | 6 | ||||
-rw-r--r-- | ui-shared.c | 24 | ||||
-rw-r--r-- | ui-shared.h | 2 | ||||
-rw-r--r-- | ui-ssdiff.c | 33 | ||||
-rw-r--r-- | ui-ssdiff.h | 12 |
9 files changed, 68 insertions, 17 deletions
@@ -298,6 +298,7 @@ static void querystring_cb(const char *name, const char *value) | |||
298 | ctx.qry.period = xstrdup(value); | 298 | ctx.qry.period = xstrdup(value); |
299 | } else if (!strcmp(name, "ss")) { | 299 | } else if (!strcmp(name, "ss")) { |
300 | ctx.qry.ssdiff = atoi(value); | 300 | ctx.qry.ssdiff = atoi(value); |
301 | ctx.qry.has_ssdiff = 1; | ||
301 | } else if (!strcmp(name, "all")) { | 302 | } else if (!strcmp(name, "all")) { |
302 | ctx.qry.show_all = atoi(value); | 303 | ctx.qry.show_all = atoi(value); |
303 | } else if (!strcmp(name, "context")) { | 304 | } else if (!strcmp(name, "context")) { |
@@ -137,6 +137,7 @@ struct reflist { | |||
137 | struct cgit_query { | 137 | struct cgit_query { |
138 | int has_symref; | 138 | int has_symref; |
139 | int has_sha1; | 139 | int has_sha1; |
140 | int has_ssdiff; | ||
140 | char *raw; | 141 | char *raw; |
141 | char *repo; | 142 | char *repo; |
142 | char *page; | 143 | char *page; |
@@ -395,8 +395,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, | |||
395 | } | 395 | } |
396 | } | 396 | } |
397 | 397 | ||
398 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) | 398 | use_ssdiff = ctx.qry.has_ssdiff ? ctx.qry.ssdiff : ctx.cfg.ssdiff; |
399 | use_ssdiff = 1; | ||
400 | 399 | ||
401 | if (show_ctrls) | 400 | if (show_ctrls) |
402 | cgit_print_diff_ctrls(); | 401 | cgit_print_diff_ctrls(); |
@@ -76,6 +76,8 @@ void show_commit_decorations(struct commit *commit) | |||
76 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); | 76 | cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf); |
77 | } | 77 | } |
78 | else if (!prefixcmp(deco->name, "refs/remotes/")) { | 78 | else if (!prefixcmp(deco->name, "refs/remotes/")) { |
79 | if (!ctx.repo->enable_remote_branches) | ||
80 | goto next; | ||
79 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); | 81 | strncpy(buf, deco->name + 13, sizeof(buf) - 1); |
80 | cgit_log_link(buf, NULL, "remote-deco", NULL, | 82 | cgit_log_link(buf, NULL, "remote-deco", NULL, |
81 | sha1_to_hex(commit->object.sha1), | 83 | sha1_to_hex(commit->object.sha1), |
@@ -88,6 +90,7 @@ void show_commit_decorations(struct commit *commit) | |||
88 | sha1_to_hex(commit->object.sha1), | 90 | sha1_to_hex(commit->object.sha1), |
89 | ctx.qry.vpath, 0); | 91 | ctx.qry.vpath, 0); |
90 | } | 92 | } |
93 | next: | ||
91 | deco = deco->next; | 94 | deco = deco->next; |
92 | } | 95 | } |
93 | } | 96 | } |
diff --git a/ui-repolist.c b/ui-repolist.c index 25c36ce..a09a689 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -118,13 +118,13 @@ void print_header(int columns) | |||
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | void print_pager(int items, int pagelen, char *search) | 121 | void print_pager(int items, int pagelen, char *search, char *sort) |
122 | { | 122 | { |
123 | int i; | 123 | int i; |
124 | html("<div class='pager'>"); | 124 | html("<div class='pager'>"); |
125 | for(i = 0; i * pagelen < items; i++) | 125 | for(i = 0; i * pagelen < items; i++) |
126 | cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL, | 126 | cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL, |
127 | search, i * pagelen); | 127 | search, sort, i * pagelen); |
128 | html("</div>"); | 128 | html("</div>"); |
129 | } | 129 | } |
130 | 130 | ||
@@ -291,7 +291,7 @@ void cgit_print_repolist() | |||
291 | if (!hits) | 291 | if (!hits) |
292 | cgit_print_error("No repositories found"); | 292 | cgit_print_error("No repositories found"); |
293 | else if (hits > ctx.cfg.max_repo_count) | 293 | else if (hits > ctx.cfg.max_repo_count) |
294 | print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search); | 294 | print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort); |
295 | cgit_print_docend(); | 295 | cgit_print_docend(); |
296 | } | 296 | } |
297 | 297 | ||
diff --git a/ui-shared.c b/ui-shared.c index 5aa9119..85c2096 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -133,7 +133,7 @@ char *cgit_currurl() | |||
133 | return fmt("%s/", ctx.cfg.virtual_root); | 133 | return fmt("%s/", ctx.cfg.virtual_root); |
134 | } | 134 | } |
135 | 135 | ||
136 | static void site_url(const char *page, const char *search, int ofs) | 136 | static void site_url(const char *page, const char *search, const char *sort, int ofs) |
137 | { | 137 | { |
138 | char *delim = "?"; | 138 | char *delim = "?"; |
139 | 139 | ||
@@ -154,6 +154,12 @@ static void site_url(const char *page, const char *search, int ofs) | |||
154 | html_attr(search); | 154 | html_attr(search); |
155 | delim = "&"; | 155 | delim = "&"; |
156 | } | 156 | } |
157 | if (sort) { | ||
158 | html(delim); | ||
159 | html("s="); | ||
160 | html_attr(sort); | ||
161 | delim = "&"; | ||
162 | } | ||
157 | if (ofs) { | 163 | if (ofs) { |
158 | html(delim); | 164 | html(delim); |
159 | htmlf("ofs=%d", ofs); | 165 | htmlf("ofs=%d", ofs); |
@@ -161,7 +167,7 @@ static void site_url(const char *page, const char *search, int ofs) | |||
161 | } | 167 | } |
162 | 168 | ||
163 | static void site_link(const char *page, const char *name, const char *title, | 169 | static void site_link(const char *page, const char *name, const char *title, |
164 | const char *class, const char *search, int ofs) | 170 | const char *class, const char *search, const char *sort, int ofs) |
165 | { | 171 | { |
166 | html("<a"); | 172 | html("<a"); |
167 | if (title) { | 173 | if (title) { |
@@ -175,16 +181,16 @@ static void site_link(const char *page, const char *name, const char *title, | |||
175 | html("'"); | 181 | html("'"); |
176 | } | 182 | } |
177 | html(" href='"); | 183 | html(" href='"); |
178 | site_url(page, search, ofs); | 184 | site_url(page, search, sort, ofs); |
179 | html("'>"); | 185 | html("'>"); |
180 | html_txt(name); | 186 | html_txt(name); |
181 | html("</a>"); | 187 | html("</a>"); |
182 | } | 188 | } |
183 | 189 | ||
184 | void cgit_index_link(const char *name, const char *title, const char *class, | 190 | void cgit_index_link(const char *name, const char *title, const char *class, |
185 | const char *pattern, int ofs) | 191 | const char *pattern, const char *sort, int ofs) |
186 | { | 192 | { |
187 | site_link(NULL, name, title, class, pattern, ofs); | 193 | site_link(NULL, name, title, class, pattern, sort, ofs); |
188 | } | 194 | } |
189 | 195 | ||
190 | static char *repolink(const char *title, const char *class, const char *page, | 196 | static char *repolink(const char *title, const char *class, const char *page, |
@@ -428,7 +434,7 @@ void cgit_self_link(char *name, const char *title, const char *class, | |||
428 | struct cgit_context *ctx) | 434 | struct cgit_context *ctx) |
429 | { | 435 | { |
430 | if (!strcmp(ctx->qry.page, "repolist")) | 436 | if (!strcmp(ctx->qry.page, "repolist")) |
431 | return cgit_index_link(name, title, class, ctx->qry.search, | 437 | return cgit_index_link(name, title, class, ctx->qry.search, ctx->qry.sort, |
432 | ctx->qry.ofs); | 438 | ctx->qry.ofs); |
433 | else if (!strcmp(ctx->qry.page, "summary")) | 439 | else if (!strcmp(ctx->qry.page, "summary")) |
434 | return cgit_summary_link(name, title, class, ctx->qry.head); | 440 | return cgit_summary_link(name, title, class, ctx->qry.head); |
@@ -782,7 +788,7 @@ static void print_header(struct cgit_context *ctx) | |||
782 | 788 | ||
783 | html("<td class='main'>"); | 789 | html("<td class='main'>"); |
784 | if (ctx->repo) { | 790 | if (ctx->repo) { |
785 | cgit_index_link("index", NULL, NULL, NULL, 0); | 791 | cgit_index_link("index", NULL, NULL, NULL, NULL, 0); |
786 | html(" : "); | 792 | html(" : "); |
787 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); | 793 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); |
788 | html("</td><td class='form'>"); | 794 | html("</td><td class='form'>"); |
@@ -858,10 +864,10 @@ void cgit_print_pageheader(struct cgit_context *ctx) | |||
858 | html("<input type='submit' value='search'/>\n"); | 864 | html("<input type='submit' value='search'/>\n"); |
859 | html("</form>\n"); | 865 | html("</form>\n"); |
860 | } else { | 866 | } else { |
861 | site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, 0); | 867 | site_link(NULL, "index", NULL, hc(ctx, "repolist"), NULL, NULL, 0); |
862 | if (ctx->cfg.root_readme) | 868 | if (ctx->cfg.root_readme) |
863 | site_link("about", "about", NULL, hc(ctx, "about"), | 869 | site_link("about", "about", NULL, hc(ctx, "about"), |
864 | NULL, 0); | 870 | NULL, NULL, 0); |
865 | html("</td><td class='form'>"); | 871 | html("</td><td class='form'>"); |
866 | html("<form method='get' action='"); | 872 | html("<form method='get' action='"); |
867 | html_attr(cgit_rooturl()); | 873 | html_attr(cgit_rooturl()); |
diff --git a/ui-shared.h b/ui-shared.h index 3cc1258..865bd45 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -11,7 +11,7 @@ extern char *cgit_pageurl(const char *reponame, const char *pagename, | |||
11 | const char *query); | 11 | const char *query); |
12 | 12 | ||
13 | extern void cgit_index_link(const char *name, const char *title, | 13 | extern void cgit_index_link(const char *name, const char *title, |
14 | const char *class, const char *pattern, int ofs); | 14 | const char *class, const char *pattern, const char *sort, int ofs); |
15 | extern void cgit_summary_link(const char *name, const char *title, | 15 | extern void cgit_summary_link(const char *name, const char *title, |
16 | const char *class, const char *head); | 16 | const char *class, const char *head); |
17 | extern void cgit_tag_link(const char *name, const char *title, | 17 | extern void cgit_tag_link(const char *name, const char *title, |
diff --git a/ui-ssdiff.c b/ui-ssdiff.c index 2481585..9fb5b11 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c | |||
@@ -2,10 +2,12 @@ | |||
2 | #include "html.h" | 2 | #include "html.h" |
3 | #include "ui-shared.h" | 3 | #include "ui-shared.h" |
4 | #include "ui-diff.h" | 4 | #include "ui-diff.h" |
5 | #include "ui-ssdiff.h" | ||
5 | 6 | ||
6 | extern int use_ssdiff; | 7 | extern int use_ssdiff; |
7 | 8 | ||
8 | static int current_old_line, current_new_line; | 9 | static int current_old_line, current_new_line; |
10 | static int **L = NULL; | ||
9 | 11 | ||
10 | struct deferred_lines { | 12 | struct deferred_lines { |
11 | int line_no; | 13 | int line_no; |
@@ -16,16 +18,42 @@ struct deferred_lines { | |||
16 | static struct deferred_lines *deferred_old, *deferred_old_last; | 18 | static struct deferred_lines *deferred_old, *deferred_old_last; |
17 | static struct deferred_lines *deferred_new, *deferred_new_last; | 19 | static struct deferred_lines *deferred_new, *deferred_new_last; |
18 | 20 | ||
21 | static void create_or_reset_lcs_table() | ||
22 | { | ||
23 | int i; | ||
24 | |||
25 | if (L != NULL) { | ||
26 | memset(*L, 0, sizeof(*L) * MAX_SSDIFF_SIZE); | ||
27 | return; | ||
28 | } | ||
29 | |||
30 | // xcalloc will die if we ran out of memory; | ||
31 | // not very helpful for debugging | ||
32 | L = (int**)xcalloc(MAX_SSDIFF_M, sizeof(int *)); | ||
33 | *L = (int*)xcalloc(MAX_SSDIFF_SIZE, sizeof(int)); | ||
34 | |||
35 | for (i = 1; i < MAX_SSDIFF_M; i++) { | ||
36 | L[i] = *L + i * MAX_SSDIFF_N; | ||
37 | } | ||
38 | } | ||
39 | |||
19 | static char *longest_common_subsequence(char *A, char *B) | 40 | static char *longest_common_subsequence(char *A, char *B) |
20 | { | 41 | { |
21 | int i, j, ri; | 42 | int i, j, ri; |
22 | int m = strlen(A); | 43 | int m = strlen(A); |
23 | int n = strlen(B); | 44 | int n = strlen(B); |
24 | int L[m + 1][n + 1]; | 45 | int tmp1, tmp2, length; |
25 | int tmp1, tmp2; | ||
26 | int lcs_length; | 46 | int lcs_length; |
27 | char *result; | 47 | char *result; |
28 | 48 | ||
49 | length = (m + 1) * (n + 1); | ||
50 | |||
51 | // We bail if the lines are too long | ||
52 | if (length > MAX_SSDIFF_SIZE) | ||
53 | return NULL; | ||
54 | |||
55 | create_or_reset_lcs_table(); | ||
56 | |||
29 | for (i = m; i >= 0; i--) { | 57 | for (i = m; i >= 0; i--) { |
30 | for (j = n; j >= 0; j--) { | 58 | for (j = n; j >= 0; j--) { |
31 | if (A[i] == '\0' || B[j] == '\0') { | 59 | if (A[i] == '\0' || B[j] == '\0') { |
@@ -59,6 +87,7 @@ static char *longest_common_subsequence(char *A, char *B) | |||
59 | j += 1; | 87 | j += 1; |
60 | } | 88 | } |
61 | } | 89 | } |
90 | |||
62 | return result; | 91 | return result; |
63 | } | 92 | } |
64 | 93 | ||
diff --git a/ui-ssdiff.h b/ui-ssdiff.h index 64b4b12..88627e2 100644 --- a/ui-ssdiff.h +++ b/ui-ssdiff.h | |||
@@ -1,6 +1,18 @@ | |||
1 | #ifndef UI_SSDIFF_H | 1 | #ifndef UI_SSDIFF_H |
2 | #define UI_SSDIFF_H | 2 | #define UI_SSDIFF_H |
3 | 3 | ||
4 | /* | ||
5 | * ssdiff line limits | ||
6 | */ | ||
7 | #ifndef MAX_SSDIFF_M | ||
8 | #define MAX_SSDIFF_M 128 | ||
9 | #endif | ||
10 | |||
11 | #ifndef MAX_SSDIFF_N | ||
12 | #define MAX_SSDIFF_N 128 | ||
13 | #endif | ||
14 | #define MAX_SSDIFF_SIZE ((MAX_SSDIFF_M) * (MAX_SSDIFF_N)) | ||
15 | |||
4 | extern void cgit_ssdiff_print_deferred_lines(); | 16 | extern void cgit_ssdiff_print_deferred_lines(); |
5 | 17 | ||
6 | extern void cgit_ssdiff_line_cb(char *line, int len); | 18 | extern void cgit_ssdiff_line_cb(char *line, int len); |