aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cgit.c1
-rw-r--r--cgit.h1
-rw-r--r--ui-diff.c3
-rw-r--r--ui-log.c3
-rw-r--r--ui-repolist.c6
-rw-r--r--ui-shared.c24
-rw-r--r--ui-shared.h2
-rw-r--r--ui-ssdiff.c33
-rw-r--r--ui-ssdiff.h12
9 files changed, 68 insertions, 17 deletions
diff --git a/cgit.c b/cgit.c
index b7807ad..1d50129 100644
--- a/cgit.c
+++ b/cgit.c
@@ -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")) {
diff --git a/cgit.h b/cgit.h
index bad66f0..c7ab5c6 100644
--- a/cgit.h
+++ b/cgit.h
@@ -137,6 +137,7 @@ struct reflist {
137struct cgit_query { 137struct 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;
diff --git a/ui-diff.c b/ui-diff.c
index d97a801..af24a6c 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -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();
diff --git a/ui-log.c b/ui-log.c
index 4a295bd..6b12ca2 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -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 }
93next:
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
121void print_pager(int items, int pagelen, char *search) 121void 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
136static void site_url(const char *page, const char *search, int ofs) 136static 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
163static void site_link(const char *page, const char *name, const char *title, 169static 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
184void cgit_index_link(const char *name, const char *title, const char *class, 190void 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
190static char *repolink(const char *title, const char *class, const char *page, 196static 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
13extern void cgit_index_link(const char *name, const char *title, 13extern 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);
15extern void cgit_summary_link(const char *name, const char *title, 15extern void cgit_summary_link(const char *name, const char *title,
16 const char *class, const char *head); 16 const char *class, const char *head);
17extern void cgit_tag_link(const char *name, const char *title, 17extern 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
6extern int use_ssdiff; 7extern int use_ssdiff;
7 8
8static int current_old_line, current_new_line; 9static int current_old_line, current_new_line;
10static int **L = NULL;
9 11
10struct deferred_lines { 12struct deferred_lines {
11 int line_no; 13 int line_no;
@@ -16,16 +18,42 @@ struct deferred_lines {
16static struct deferred_lines *deferred_old, *deferred_old_last; 18static struct deferred_lines *deferred_old, *deferred_old_last;
17static struct deferred_lines *deferred_new, *deferred_new_last; 19static struct deferred_lines *deferred_new, *deferred_new_last;
18 20
21static 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
19static char *longest_common_subsequence(char *A, char *B) 40static 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
4extern void cgit_ssdiff_print_deferred_lines(); 16extern void cgit_ssdiff_print_deferred_lines();
5 17
6extern void cgit_ssdiff_line_cb(char *line, int len); 18extern void cgit_ssdiff_line_cb(char *line, int len);