diff options
| author | 2011-03-07 07:59:56 (JST) | |
|---|---|---|
| committer | 2011-03-07 07:59:56 (JST) | |
| commit | 962a24892feb9e3d69542bcf0a219dc14836e921 (patch) | |
| tree | 991b67cd914a708d83f08dd7f859a9cadbb74490 | |
| parent | 1a64fd2f83affda41fb9903b7c299d35170bfc05 (diff) | |
| download | cgit-962a24892feb9e3d69542bcf0a219dc14836e921.zip cgit-962a24892feb9e3d69542bcf0a219dc14836e921.tar.gz | |
ui-diff.c: create a control panel for diff options
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
| -rw-r--r-- | cgit.css | 27 | ||||
| -rw-r--r-- | cmd.c | 2 | ||||
| -rw-r--r-- | ui-commit.c | 10 | ||||
| -rw-r--r-- | ui-diff.c | 83 | ||||
| -rw-r--r-- | ui-diff.h | 4 |
5 files changed, 88 insertions, 38 deletions
| @@ -331,6 +331,33 @@ table.commit-info { | |||
| 331 | margin-top: 1.5em; | 331 | margin-top: 1.5em; |
| 332 | } | 332 | } |
| 333 | 333 | ||
| 334 | div.cgit-panel { | ||
| 335 | float: right; | ||
| 336 | margin-top: 1.5em; | ||
| 337 | } | ||
| 338 | |||
| 339 | div.cgit-panel table { | ||
| 340 | border-collapse: collapse; | ||
| 341 | border: solid 1px #aaa; | ||
| 342 | background-color: #eee; | ||
| 343 | } | ||
| 344 | |||
| 345 | div.cgit-panel th { | ||
| 346 | text-align: center; | ||
| 347 | } | ||
| 348 | |||
| 349 | div.cgit-panel td { | ||
| 350 | padding: 0.25em 0.5em; | ||
| 351 | } | ||
| 352 | |||
| 353 | div.cgit-panel td.label { | ||
| 354 | padding-right: 0.5em; | ||
| 355 | } | ||
| 356 | |||
| 357 | div.cgit-panel td.ctrl { | ||
| 358 | padding-left: 0.5em; | ||
| 359 | } | ||
| 360 | |||
| 334 | table.commit-info th { | 361 | table.commit-info th { |
| 335 | text-align: left; | 362 | text-align: left; |
| 336 | font-weight: normal; | 363 | font-weight: normal; |
| @@ -56,7 +56,7 @@ static void commit_fn(struct cgit_context *ctx) | |||
| 56 | 56 | ||
| 57 | static void diff_fn(struct cgit_context *ctx) | 57 | static void diff_fn(struct cgit_context *ctx) |
| 58 | { | 58 | { |
| 59 | cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); | 59 | cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path, 1); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | static void info_fn(struct cgit_context *ctx) | 62 | static void info_fn(struct cgit_context *ctx) |
diff --git a/ui-commit.c b/ui-commit.c index 2b4f677..536a8e8 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
| @@ -39,7 +39,8 @@ void cgit_print_commit(char *hex, const char *prefix) | |||
| 39 | format_note(NULL, sha1, ¬es, PAGE_ENCODING, 0); | 39 | format_note(NULL, sha1, ¬es, PAGE_ENCODING, 0); |
| 40 | 40 | ||
| 41 | load_ref_decorations(DECORATE_FULL_REFS); | 41 | load_ref_decorations(DECORATE_FULL_REFS); |
| 42 | 42 | ||
| 43 | cgit_print_diff_ctrls(); | ||
| 43 | html("<table summary='commit info' class='commit-info'>\n"); | 44 | html("<table summary='commit info' class='commit-info'>\n"); |
| 44 | html("<tr><th>author</th><td>"); | 45 | html("<tr><th>author</th><td>"); |
| 45 | html_txt(info->author); | 46 | html_txt(info->author); |
| @@ -64,11 +65,6 @@ void cgit_print_commit(char *hex, const char *prefix) | |||
| 64 | cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0); | 65 | cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix, 0); |
| 65 | html(" ("); | 66 | html(" ("); |
| 66 | cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix); | 67 | cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix); |
| 67 | html(") ("); | ||
| 68 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) | ||
| 69 | cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, prefix, 1); | ||
| 70 | else | ||
| 71 | cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, prefix, 1); | ||
| 72 | html(")</td></tr>\n"); | 68 | html(")</td></tr>\n"); |
| 73 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); | 69 | html("<tr><th>tree</th><td colspan='2' class='sha1'>"); |
| 74 | tmp = xstrdup(hex); | 70 | tmp = xstrdup(hex); |
| @@ -139,7 +135,7 @@ void cgit_print_commit(char *hex, const char *prefix) | |||
| 139 | tmp = sha1_to_hex(commit->parents->item->object.sha1); | 135 | tmp = sha1_to_hex(commit->parents->item->object.sha1); |
| 140 | else | 136 | else |
| 141 | tmp = NULL; | 137 | tmp = NULL; |
| 142 | cgit_print_diff(ctx.qry.sha1, tmp, prefix); | 138 | cgit_print_diff(ctx.qry.sha1, tmp, prefix, 0); |
| 143 | } | 139 | } |
| 144 | strbuf_release(¬es); | 140 | strbuf_release(¬es); |
| 145 | cgit_free_commitinfo(info); | 141 | cgit_free_commitinfo(info); |
| @@ -167,7 +167,7 @@ static void inspect_filepair(struct diff_filepair *pair) | |||
| 167 | void cgit_print_diffstat(const unsigned char *old_sha1, | 167 | void cgit_print_diffstat(const unsigned char *old_sha1, |
| 168 | const unsigned char *new_sha1, const char *prefix) | 168 | const unsigned char *new_sha1, const char *prefix) |
| 169 | { | 169 | { |
| 170 | int i, save_context = ctx.qry.context; | 170 | int i; |
| 171 | 171 | ||
| 172 | html("<div class='diffstat-header'>"); | 172 | html("<div class='diffstat-header'>"); |
| 173 | cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, | 173 | cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1, |
| @@ -177,19 +177,6 @@ void cgit_print_diffstat(const unsigned char *old_sha1, | |||
| 177 | html_txt(prefix); | 177 | html_txt(prefix); |
| 178 | html("')"); | 178 | html("')"); |
| 179 | } | 179 | } |
| 180 | html(" ("); | ||
| 181 | ctx.qry.context = (save_context > 0 ? save_context : 3) << 1; | ||
| 182 | cgit_self_link("more", NULL, NULL, &ctx); | ||
| 183 | html("/"); | ||
| 184 | ctx.qry.context = (save_context > 3 ? save_context : 3) >> 1; | ||
| 185 | cgit_self_link("less", NULL, NULL, &ctx); | ||
| 186 | ctx.qry.context = save_context; | ||
| 187 | html(" context)"); | ||
| 188 | html(" ("); | ||
| 189 | ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; | ||
| 190 | cgit_self_link(ctx.qry.ignorews ? "ignore" : "show", NULL, NULL, &ctx); | ||
| 191 | ctx.qry.ignorews = (ctx.qry.ignorews + 1) % 2; | ||
| 192 | html(" whitespace changes)"); | ||
| 193 | html("</div>"); | 180 | html("</div>"); |
| 194 | html("<table summary='diffstat' class='diffstat'>"); | 181 | html("<table summary='diffstat' class='diffstat'>"); |
| 195 | max_changes = 0; | 182 | max_changes = 0; |
| @@ -278,19 +265,6 @@ static void header(unsigned char *sha1, char *path1, int mode1, | |||
| 278 | html("</div>"); | 265 | html("</div>"); |
| 279 | } | 266 | } |
| 280 | 267 | ||
| 281 | static void print_ssdiff_link() | ||
| 282 | { | ||
| 283 | if (!strcmp(ctx.qry.page, "diff")) { | ||
| 284 | if (use_ssdiff) | ||
| 285 | cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head, | ||
| 286 | ctx.qry.sha1, ctx.qry.sha2, ctx.qry.path, 1); | ||
| 287 | else | ||
| 288 | cgit_diff_link("Side-by-side diff", NULL, NULL, | ||
| 289 | ctx.qry.head, ctx.qry.sha1, | ||
| 290 | ctx.qry.sha2, ctx.qry.path, 1); | ||
| 291 | } | ||
| 292 | } | ||
| 293 | |||
| 294 | static void filepair_cb(struct diff_filepair *pair) | 268 | static void filepair_cb(struct diff_filepair *pair) |
| 295 | { | 269 | { |
| 296 | unsigned long old_size = 0; | 270 | unsigned long old_size = 0; |
| @@ -330,7 +304,56 @@ static void filepair_cb(struct diff_filepair *pair) | |||
| 330 | cgit_ssdiff_footer(); | 304 | cgit_ssdiff_footer(); |
| 331 | } | 305 | } |
| 332 | 306 | ||
| 333 | void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix) | 307 | void cgit_print_diff_ctrls() |
| 308 | { | ||
| 309 | int i, curr; | ||
| 310 | |||
| 311 | html("<div class='cgit-panel'>"); | ||
| 312 | html("<b>diff options</b>"); | ||
| 313 | html("<form method='get' action='.'>"); | ||
| 314 | cgit_add_hidden_formfields(1, 0, ctx.qry.page); | ||
| 315 | html("<table>"); | ||
| 316 | html("<tr><td colspan='2'/></tr>"); | ||
| 317 | html("<tr>"); | ||
| 318 | html("<td class='label'>context:</td>"); | ||
| 319 | html("<td class='ctrl'>"); | ||
| 320 | html("<select name='context' onchange='this.form.submit();'>"); | ||
| 321 | curr = ctx.qry.context; | ||
| 322 | if (!curr) | ||
| 323 | curr = 3; | ||
| 324 | for (i = 1; i <= 10; i++) | ||
| 325 | html_intoption(i, fmt("%d", i), curr); | ||
| 326 | for (i = 15; i <= 40; i += 5) | ||
| 327 | html_intoption(i, fmt("%d", i), curr); | ||
| 328 | html("</select>"); | ||
| 329 | html("</td>"); | ||
| 330 | html("</tr><tr>"); | ||
| 331 | html("<td class='label'>space:</td>"); | ||
| 332 | html("<td class='ctrl'>"); | ||
| 333 | html("<select name='ignorews' onchange='this.form.submit();'>"); | ||
| 334 | html_intoption(0, "include", ctx.qry.ignorews); | ||
| 335 | html_intoption(1, "ignore", ctx.qry.ignorews); | ||
| 336 | html("</select>"); | ||
| 337 | html("</td>"); | ||
| 338 | html("</tr><tr>"); | ||
| 339 | html("<td class='label'>mode:</td>"); | ||
| 340 | html("<td class='ctrl'>"); | ||
| 341 | html("<select name='ss' onchange='this.form.submit();'>"); | ||
| 342 | curr = ctx.qry.ssdiff; | ||
| 343 | if (!curr && ctx.cfg.ssdiff) | ||
| 344 | curr = 1; | ||
| 345 | html_intoption(0, "unified", curr); | ||
| 346 | html_intoption(1, "ssdiff", curr); | ||
| 347 | html("</select></td></tr>"); | ||
| 348 | html("<tr><td/><td class='ctrl'>"); | ||
| 349 | html("<noscript><input type='submit' value='reload'/></noscript>"); | ||
| 350 | html("</td></tr></table>"); | ||
| 351 | html("</form>"); | ||
| 352 | html("</div>"); | ||
| 353 | } | ||
| 354 | |||
| 355 | void cgit_print_diff(const char *new_rev, const char *old_rev, | ||
| 356 | const char *prefix, int show_ctrls) | ||
| 334 | { | 357 | { |
| 335 | enum object_type type; | 358 | enum object_type type; |
| 336 | unsigned long size; | 359 | unsigned long size; |
| @@ -369,7 +392,9 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi | |||
| 369 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) | 392 | if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff)) |
| 370 | use_ssdiff = 1; | 393 | use_ssdiff = 1; |
| 371 | 394 | ||
| 372 | print_ssdiff_link(); | 395 | if (show_ctrls) |
| 396 | cgit_print_diff_ctrls(); | ||
| 397 | |||
| 373 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix); | 398 | cgit_print_diffstat(old_rev_sha1, new_rev_sha1, prefix); |
| 374 | 399 | ||
| 375 | if (use_ssdiff) { | 400 | if (use_ssdiff) { |
| @@ -1,11 +1,13 @@ | |||
| 1 | #ifndef UI_DIFF_H | 1 | #ifndef UI_DIFF_H |
| 2 | #define UI_DIFF_H | 2 | #define UI_DIFF_H |
| 3 | 3 | ||
| 4 | extern void cgit_print_diff_ctrls(); | ||
| 5 | |||
| 4 | extern void cgit_print_diffstat(const unsigned char *old_sha1, | 6 | extern void cgit_print_diffstat(const unsigned char *old_sha1, |
| 5 | const unsigned char *new_sha1); | 7 | const unsigned char *new_sha1); |
| 6 | 8 | ||
| 7 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, | 9 | extern void cgit_print_diff(const char *new_hex, const char *old_hex, |
| 8 | const char *prefix); | 10 | const char *prefix, int show_ctrls); |
| 9 | 11 | ||
| 10 | extern struct diff_filespec *cgit_get_current_old_file(void); | 12 | extern struct diff_filespec *cgit_get_current_old_file(void); |
| 11 | extern struct diff_filespec *cgit_get_current_new_file(void); | 13 | extern struct diff_filespec *cgit_get_current_new_file(void); |
