author | Ragnar Ouchterlony <ragnar@lysator.liu.se> | 2009-09-14 18:19:02 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-09-16 18:17:56 (UTC) |
commit | c358aa3dfebf4fc1f3005dd960aa5c1c020eed76 (patch) (unidiff) | |
tree | 475fa421d673b270c7d1bde872b96425abfafce8 | |
parent | 40e174d5364910750413d94b5417e57d108190ef (diff) | |
download | cgit-c358aa3dfebf4fc1f3005dd960aa5c1c020eed76.zip cgit-c358aa3dfebf4fc1f3005dd960aa5c1c020eed76.tar.gz cgit-c358aa3dfebf4fc1f3005dd960aa5c1c020eed76.tar.bz2 |
Add possibility to switch between unidiff and side-by-side-diff.
A new config option side-by-side-diffs added, defaulting to 0,
meaning unidiff. Also a query option (ss) is used toggle this.
In the commit page you can switch between the two diff formats by
clicking on the link on the "commit"-row, to the right of (patch).
In the diff page you can switch by using the link at the start
of the page.
All commit-links and diff-links will remember the choice.
Signed-off-by: Ragnar Ouchterlony <ragnar@lysator.liu.se>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 5 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | cgitrc.5.txt | 4 | ||||
-rw-r--r-- | ui-commit.c | 11 | ||||
-rw-r--r-- | ui-diff.c | 22 | ||||
-rw-r--r-- | ui-log.c | 4 | ||||
-rw-r--r-- | ui-refs.c | 2 | ||||
-rw-r--r-- | ui-shared.c | 34 | ||||
-rw-r--r-- | ui-shared.h | 5 |
9 files changed, 73 insertions, 16 deletions
@@ -184,2 +184,4 @@ void config_cb(const char *name, const char *value) | |||
184 | ctx.cfg.summary_tags = atoi(value); | 184 | ctx.cfg.summary_tags = atoi(value); |
185 | else if (!strcmp(name, "side-by-side-diffs")) | ||
186 | ctx.cfg.ssdiff = atoi(value); | ||
185 | else if (!strcmp(name, "agefile")) | 187 | else if (!strcmp(name, "agefile")) |
@@ -240,2 +242,4 @@ static void querystring_cb(const char *name, const char *value) | |||
240 | ctx.qry.period = xstrdup(value); | 242 | ctx.qry.period = xstrdup(value); |
243 | } else if (!strcmp(name, "ss")) { | ||
244 | ctx.qry.ssdiff = atoi(value); | ||
241 | } | 245 | } |
@@ -281,2 +285,3 @@ static void prepare_context(struct cgit_context *ctx) | |||
281 | ctx->cfg.summary_tags = 10; | 285 | ctx->cfg.summary_tags = 10; |
286 | ctx->cfg.ssdiff = 0; | ||
282 | ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); | 287 | ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); |
@@ -145,2 +145,3 @@ struct cgit_query { | |||
145 | int showmsg; | 145 | int showmsg; |
146 | int ssdiff; | ||
146 | }; | 147 | }; |
@@ -196,2 +197,3 @@ struct cgit_config { | |||
196 | int summary_tags; | 197 | int summary_tags; |
198 | int ssdiff; | ||
197 | struct string_list mimetypes; | 199 | struct string_list mimetypes; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 4dc383d..252d546 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -240,2 +240,6 @@ section:: | |||
240 | 240 | ||
241 | side-by-side-diffs:: | ||
242 | If set to "1" shows side-by-side diffs instead of unidiffs per | ||
243 | default. Default value: "0". | ||
244 | |||
241 | snapshots:: | 245 | snapshots:: |
diff --git a/ui-commit.c b/ui-commit.c index f5b0ae5..b5e3c01 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -60,5 +60,10 @@ void cgit_print_commit(char *hex) | |||
60 | tmp = sha1_to_hex(commit->object.sha1); | 60 | tmp = sha1_to_hex(commit->object.sha1); |
61 | cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp); | 61 | cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, 0); |
62 | html(" ("); | 62 | html(" ("); |
63 | cgit_patch_link("patch", NULL, NULL, NULL, tmp); | 63 | cgit_patch_link("patch", NULL, NULL, NULL, tmp); |
64 | html(") ("); | ||
65 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) | ||
66 | cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, 1); | ||
67 | else | ||
68 | cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, 1); | ||
64 | html(")</td></tr>\n"); | 69 | html(")</td></tr>\n"); |
@@ -80,6 +85,6 @@ void cgit_print_commit(char *hex) | |||
80 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, | 85 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, |
81 | ctx.qry.head, sha1_to_hex(p->item->object.sha1)); | 86 | ctx.qry.head, sha1_to_hex(p->item->object.sha1), 0); |
82 | html(" ("); | 87 | html(" ("); |
83 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, | 88 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, |
84 | sha1_to_hex(p->item->object.sha1), NULL); | 89 | sha1_to_hex(p->item->object.sha1), NULL, 0); |
85 | html(")</td></tr>"); | 90 | html(")</td></tr>"); |
@@ -87,3 +87,3 @@ static void print_fileinfo(struct fileinfo *info) | |||
87 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, | 87 | cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
88 | ctx.qry.sha2, info->new_path); | 88 | ctx.qry.sha2, info->new_path, 0); |
89 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) | 89 | if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED) |
@@ -162,3 +162,3 @@ void cgit_print_diffstat(const unsigned char *old_sha1, | |||
162 | cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, | 162 | cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
163 | ctx.qry.sha2, NULL); | 163 | ctx.qry.sha2, NULL, 0); |
164 | html("</div>"); | 164 | html("</div>"); |
@@ -252,2 +252,15 @@ static void header(unsigned char *sha1, char *path1, int mode1, | |||
252 | 252 | ||
253 | static void print_ssdiff_link() | ||
254 | { | ||
255 | if (!strcmp(ctx.qry.page, "diff")) { | ||
256 | if (use_ssdiff) | ||
257 | cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head, | ||
258 | ctx.qry.sha1, ctx.qry.sha2, NULL, 1); | ||
259 | else | ||
260 | cgit_diff_link("Side-by-side diff", NULL, NULL, | ||
261 | ctx.qry.head, ctx.qry.sha1, | ||
262 | ctx.qry.sha2, NULL, 1); | ||
263 | } | ||
264 | } | ||
265 | |||
253 | static void filepair_cb(struct diff_filepair *pair) | 266 | static void filepair_cb(struct diff_filepair *pair) |
@@ -316,2 +329,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi | |||
316 | } | 329 | } |
330 | |||
331 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) | ||
332 | use_ssdiff = 1; | ||
333 | |||
334 | print_ssdiff_link(); | ||
317 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1); | 335 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1); |
@@ -68,3 +68,3 @@ void show_commit_decorations(struct commit *commit) | |||
68 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, | 68 | cgit_commit_link(buf, NULL, "deco", ctx.qry.head, |
69 | sha1_to_hex(commit->object.sha1)); | 69 | sha1_to_hex(commit->object.sha1), 0); |
70 | } | 70 | } |
@@ -91,3 +91,3 @@ void print_commit(struct commit *commit) | |||
91 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, | 91 | cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, |
92 | sha1_to_hex(commit->object.sha1)); | 92 | sha1_to_hex(commit->object.sha1), 0); |
93 | show_commit_decorations(commit); | 93 | show_commit_decorations(commit); |
@@ -76,3 +76,3 @@ static int print_branch(struct refinfo *ref) | |||
76 | if (ref->object->type == OBJ_COMMIT) { | 76 | if (ref->object->type == OBJ_COMMIT) { |
77 | cgit_commit_link(info->subject, NULL, NULL, name, NULL); | 77 | cgit_commit_link(info->subject, NULL, NULL, name, NULL, 0); |
78 | html("</td><td>"); | 78 | html("</td><td>"); |
diff --git a/ui-shared.c b/ui-shared.c index 07d5dd4..de55eff 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -319,3 +319,3 @@ void cgit_log_link(char *name, char *title, char *class, char *head, | |||
319 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 319 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
320 | char *rev) | 320 | char *rev, int toggle_ssdiff) |
321 | { | 321 | { |
@@ -327,3 +327,19 @@ void cgit_commit_link(char *name, char *title, char *class, char *head, | |||
327 | } | 327 | } |
328 | reporevlink("commit", name, title, class, head, rev, NULL); | 328 | |
329 | char *delim; | ||
330 | |||
331 | delim = repolink(title, class, "commit", head, NULL); | ||
332 | if (rev && strcmp(rev, ctx.qry.head)) { | ||
333 | html(delim); | ||
334 | html("id="); | ||
335 | html_url_arg(rev); | ||
336 | delim = "&"; | ||
337 | } | ||
338 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | ||
339 | html(delim); | ||
340 | html("ss=1"); | ||
341 | } | ||
342 | html("'>"); | ||
343 | html_txt(name); | ||
344 | html("</a>"); | ||
329 | } | 345 | } |
@@ -343,3 +359,4 @@ void cgit_snapshot_link(char *name, char *title, char *class, char *head, | |||
343 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 359 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
344 | char *new_rev, char *old_rev, char *path) | 360 | char *new_rev, char *old_rev, char *path, |
361 | int toggle_ssdiff) | ||
345 | { | 362 | { |
@@ -358,2 +375,7 @@ void cgit_diff_link(char *name, char *title, char *class, char *head, | |||
358 | html_url_arg(old_rev); | 375 | html_url_arg(old_rev); |
376 | delim = "&"; | ||
377 | } | ||
378 | if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { | ||
379 | html(delim); | ||
380 | html("ss=1"); | ||
359 | } | 381 | } |
@@ -385,3 +407,3 @@ void cgit_object_link(struct object *obj) | |||
385 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, | 407 | cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, |
386 | ctx.qry.head, fullrev); | 408 | ctx.qry.head, fullrev, 0); |
387 | return; | 409 | return; |
@@ -697,5 +719,5 @@ void cgit_print_pageheader(struct cgit_context *ctx) | |||
697 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), | 719 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), |
698 | ctx->qry.head, ctx->qry.sha1); | 720 | ctx->qry.head, ctx->qry.sha1, 0); |
699 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, | 721 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, |
700 | ctx->qry.sha1, ctx->qry.sha2, NULL); | 722 | ctx->qry.sha1, ctx->qry.sha2, NULL, 0); |
701 | if (ctx->repo->max_stats) | 723 | if (ctx->repo->max_stats) |
diff --git a/ui-shared.h b/ui-shared.h index bff4826..166246d 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -24,3 +24,3 @@ extern void cgit_log_link(char *name, char *title, char *class, char *head, | |||
24 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | 24 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, |
25 | char *rev); | 25 | char *rev, int toggle_ssdiff); |
26 | extern void cgit_patch_link(char *name, char *title, char *class, char *head, | 26 | extern void cgit_patch_link(char *name, char *title, char *class, char *head, |
@@ -32,3 +32,4 @@ extern void cgit_snapshot_link(char *name, char *title, char *class, | |||
32 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 32 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
33 | char *new_rev, char *old_rev, char *path); | 33 | char *new_rev, char *old_rev, char *path, |
34 | int toggle_ssdiff); | ||
34 | extern void cgit_stats_link(char *name, char *title, char *class, char *head, | 35 | extern void cgit_stats_link(char *name, char *title, char *class, char *head, |