mirror of
https://git.zx2c4.com/cgit
synced 2024-11-26 02:18:42 +00:00
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>
This commit is contained in:
parent
40e174d536
commit
c358aa3dfe
5
cgit.c
5
cgit.c
@ -182,6 +182,8 @@ void config_cb(const char *name, const char *value)
|
|||||||
ctx.cfg.summary_branches = atoi(value);
|
ctx.cfg.summary_branches = atoi(value);
|
||||||
else if (!strcmp(name, "summary-tags"))
|
else if (!strcmp(name, "summary-tags"))
|
||||||
ctx.cfg.summary_tags = atoi(value);
|
ctx.cfg.summary_tags = atoi(value);
|
||||||
|
else if (!strcmp(name, "side-by-side-diffs"))
|
||||||
|
ctx.cfg.ssdiff = atoi(value);
|
||||||
else if (!strcmp(name, "agefile"))
|
else if (!strcmp(name, "agefile"))
|
||||||
ctx.cfg.agefile = xstrdup(value);
|
ctx.cfg.agefile = xstrdup(value);
|
||||||
else if (!strcmp(name, "renamelimit"))
|
else if (!strcmp(name, "renamelimit"))
|
||||||
@ -238,6 +240,8 @@ static void querystring_cb(const char *name, const char *value)
|
|||||||
ctx.qry.showmsg = atoi(value);
|
ctx.qry.showmsg = atoi(value);
|
||||||
} else if (!strcmp(name, "period")) {
|
} else if (!strcmp(name, "period")) {
|
||||||
ctx.qry.period = xstrdup(value);
|
ctx.qry.period = xstrdup(value);
|
||||||
|
} else if (!strcmp(name, "ss")) {
|
||||||
|
ctx.qry.ssdiff = atoi(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,6 +283,7 @@ static void prepare_context(struct cgit_context *ctx)
|
|||||||
ctx->cfg.summary_branches = 10;
|
ctx->cfg.summary_branches = 10;
|
||||||
ctx->cfg.summary_log = 10;
|
ctx->cfg.summary_log = 10;
|
||||||
ctx->cfg.summary_tags = 10;
|
ctx->cfg.summary_tags = 10;
|
||||||
|
ctx->cfg.ssdiff = 0;
|
||||||
ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG"));
|
ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG"));
|
||||||
ctx->env.http_host = xstrdupn(getenv("HTTP_HOST"));
|
ctx->env.http_host = xstrdupn(getenv("HTTP_HOST"));
|
||||||
ctx->env.https = xstrdupn(getenv("HTTPS"));
|
ctx->env.https = xstrdupn(getenv("HTTPS"));
|
||||||
|
2
cgit.h
2
cgit.h
@ -143,6 +143,7 @@ struct cgit_query {
|
|||||||
int nohead;
|
int nohead;
|
||||||
char *sort;
|
char *sort;
|
||||||
int showmsg;
|
int showmsg;
|
||||||
|
int ssdiff;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cgit_config {
|
struct cgit_config {
|
||||||
@ -194,6 +195,7 @@ struct cgit_config {
|
|||||||
int summary_branches;
|
int summary_branches;
|
||||||
int summary_log;
|
int summary_log;
|
||||||
int summary_tags;
|
int summary_tags;
|
||||||
|
int ssdiff;
|
||||||
struct string_list mimetypes;
|
struct string_list mimetypes;
|
||||||
struct cgit_filter *about_filter;
|
struct cgit_filter *about_filter;
|
||||||
struct cgit_filter *commit_filter;
|
struct cgit_filter *commit_filter;
|
||||||
|
@ -238,6 +238,10 @@ section::
|
|||||||
after this option will inherit the current section name. Default value:
|
after this option will inherit the current section name. Default value:
|
||||||
none.
|
none.
|
||||||
|
|
||||||
|
side-by-side-diffs::
|
||||||
|
If set to "1" shows side-by-side diffs instead of unidiffs per
|
||||||
|
default. Default value: "0".
|
||||||
|
|
||||||
snapshots::
|
snapshots::
|
||||||
Text which specifies the default set of snapshot formats generated by
|
Text which specifies the default set of snapshot formats generated by
|
||||||
cgit. The value is a space-separated list of zero or more of the
|
cgit. The value is a space-separated list of zero or more of the
|
||||||
|
11
ui-commit.c
11
ui-commit.c
@ -58,9 +58,14 @@ void cgit_print_commit(char *hex)
|
|||||||
html("</td></tr>\n");
|
html("</td></tr>\n");
|
||||||
html("<tr><th>commit</th><td colspan='2' class='sha1'>");
|
html("<tr><th>commit</th><td colspan='2' class='sha1'>");
|
||||||
tmp = sha1_to_hex(commit->object.sha1);
|
tmp = sha1_to_hex(commit->object.sha1);
|
||||||
cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp);
|
cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, 0);
|
||||||
html(" (");
|
html(" (");
|
||||||
cgit_patch_link("patch", NULL, NULL, NULL, tmp);
|
cgit_patch_link("patch", NULL, NULL, NULL, tmp);
|
||||||
|
html(") (");
|
||||||
|
if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
|
||||||
|
cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, 1);
|
||||||
|
else
|
||||||
|
cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, 1);
|
||||||
html(")</td></tr>\n");
|
html(")</td></tr>\n");
|
||||||
html("<tr><th>tree</th><td colspan='2' class='sha1'>");
|
html("<tr><th>tree</th><td colspan='2' class='sha1'>");
|
||||||
tmp = xstrdup(hex);
|
tmp = xstrdup(hex);
|
||||||
@ -78,10 +83,10 @@ void cgit_print_commit(char *hex)
|
|||||||
html("<tr><th>parent</th>"
|
html("<tr><th>parent</th>"
|
||||||
"<td colspan='2' class='sha1'>");
|
"<td colspan='2' class='sha1'>");
|
||||||
cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
|
cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL,
|
||||||
ctx.qry.head, sha1_to_hex(p->item->object.sha1));
|
ctx.qry.head, sha1_to_hex(p->item->object.sha1), 0);
|
||||||
html(" (");
|
html(" (");
|
||||||
cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
|
cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
|
||||||
sha1_to_hex(p->item->object.sha1), NULL);
|
sha1_to_hex(p->item->object.sha1), NULL, 0);
|
||||||
html(")</td></tr>");
|
html(")</td></tr>");
|
||||||
parents++;
|
parents++;
|
||||||
}
|
}
|
||||||
|
22
ui-diff.c
22
ui-diff.c
@ -85,7 +85,7 @@ static void print_fileinfo(struct fileinfo *info)
|
|||||||
}
|
}
|
||||||
htmlf("</td><td class='%s'>", class);
|
htmlf("</td><td class='%s'>", class);
|
||||||
cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
|
cgit_diff_link(info->new_path, NULL, NULL, ctx.qry.head, ctx.qry.sha1,
|
||||||
ctx.qry.sha2, info->new_path);
|
ctx.qry.sha2, info->new_path, 0);
|
||||||
if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED)
|
if (info->status == DIFF_STATUS_COPIED || info->status == DIFF_STATUS_RENAMED)
|
||||||
htmlf(" (%s from %s)",
|
htmlf(" (%s from %s)",
|
||||||
info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
|
info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
|
||||||
@ -160,7 +160,7 @@ void cgit_print_diffstat(const unsigned char *old_sha1,
|
|||||||
|
|
||||||
html("<div class='diffstat-header'>");
|
html("<div class='diffstat-header'>");
|
||||||
cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
|
cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
|
||||||
ctx.qry.sha2, NULL);
|
ctx.qry.sha2, NULL, 0);
|
||||||
html("</div>");
|
html("</div>");
|
||||||
html("<table summary='diffstat' class='diffstat'>");
|
html("<table summary='diffstat' class='diffstat'>");
|
||||||
max_changes = 0;
|
max_changes = 0;
|
||||||
@ -250,6 +250,19 @@ static void header(unsigned char *sha1, char *path1, int mode1,
|
|||||||
cgit_ssdiff_header();
|
cgit_ssdiff_header();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_ssdiff_link()
|
||||||
|
{
|
||||||
|
if (!strcmp(ctx.qry.page, "diff")) {
|
||||||
|
if (use_ssdiff)
|
||||||
|
cgit_diff_link("Unidiff", NULL, NULL, ctx.qry.head,
|
||||||
|
ctx.qry.sha1, ctx.qry.sha2, NULL, 1);
|
||||||
|
else
|
||||||
|
cgit_diff_link("Side-by-side diff", NULL, NULL,
|
||||||
|
ctx.qry.head, ctx.qry.sha1,
|
||||||
|
ctx.qry.sha2, NULL, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void filepair_cb(struct diff_filepair *pair)
|
static void filepair_cb(struct diff_filepair *pair)
|
||||||
{
|
{
|
||||||
unsigned long old_size = 0;
|
unsigned long old_size = 0;
|
||||||
@ -314,6 +327,11 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
|
|||||||
if (!commit2 || parse_commit(commit2))
|
if (!commit2 || parse_commit(commit2))
|
||||||
cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
|
cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(old_rev_sha1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
|
||||||
|
use_ssdiff = 1;
|
||||||
|
|
||||||
|
print_ssdiff_link();
|
||||||
cgit_print_diffstat(old_rev_sha1, new_rev_sha1);
|
cgit_print_diffstat(old_rev_sha1, new_rev_sha1);
|
||||||
|
|
||||||
html("<table summary='diff' class='diff'>");
|
html("<table summary='diff' class='diff'>");
|
||||||
|
4
ui-log.c
4
ui-log.c
@ -66,7 +66,7 @@ void show_commit_decorations(struct commit *commit)
|
|||||||
else {
|
else {
|
||||||
strncpy(buf, deco->name, sizeof(buf) - 1);
|
strncpy(buf, deco->name, sizeof(buf) - 1);
|
||||||
cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
|
cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
|
||||||
sha1_to_hex(commit->object.sha1));
|
sha1_to_hex(commit->object.sha1), 0);
|
||||||
}
|
}
|
||||||
deco = deco->next;
|
deco = deco->next;
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ void print_commit(struct commit *commit)
|
|||||||
htmlf("</td><td%s>",
|
htmlf("</td><td%s>",
|
||||||
ctx.qry.showmsg ? " class='logsubject'" : "");
|
ctx.qry.showmsg ? " class='logsubject'" : "");
|
||||||
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
|
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
|
||||||
sha1_to_hex(commit->object.sha1));
|
sha1_to_hex(commit->object.sha1), 0);
|
||||||
show_commit_decorations(commit);
|
show_commit_decorations(commit);
|
||||||
html("</td><td>");
|
html("</td><td>");
|
||||||
html_txt(info->author);
|
html_txt(info->author);
|
||||||
|
@ -74,7 +74,7 @@ static int print_branch(struct refinfo *ref)
|
|||||||
html("</td><td>");
|
html("</td><td>");
|
||||||
|
|
||||||
if (ref->object->type == OBJ_COMMIT) {
|
if (ref->object->type == OBJ_COMMIT) {
|
||||||
cgit_commit_link(info->subject, NULL, NULL, name, NULL);
|
cgit_commit_link(info->subject, NULL, NULL, name, NULL, 0);
|
||||||
html("</td><td>");
|
html("</td><td>");
|
||||||
html_txt(info->author);
|
html_txt(info->author);
|
||||||
html("</td><td colspan='2'>");
|
html("</td><td colspan='2'>");
|
||||||
|
34
ui-shared.c
34
ui-shared.c
@ -317,7 +317,7 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cgit_commit_link(char *name, char *title, char *class, char *head,
|
void cgit_commit_link(char *name, char *title, char *class, char *head,
|
||||||
char *rev)
|
char *rev, int toggle_ssdiff)
|
||||||
{
|
{
|
||||||
if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
|
if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
|
||||||
name[ctx.cfg.max_msg_len] = '\0';
|
name[ctx.cfg.max_msg_len] = '\0';
|
||||||
@ -325,7 +325,23 @@ void cgit_commit_link(char *name, char *title, char *class, char *head,
|
|||||||
name[ctx.cfg.max_msg_len - 2] = '.';
|
name[ctx.cfg.max_msg_len - 2] = '.';
|
||||||
name[ctx.cfg.max_msg_len - 3] = '.';
|
name[ctx.cfg.max_msg_len - 3] = '.';
|
||||||
}
|
}
|
||||||
reporevlink("commit", name, title, class, head, rev, NULL);
|
|
||||||
|
char *delim;
|
||||||
|
|
||||||
|
delim = repolink(title, class, "commit", head, NULL);
|
||||||
|
if (rev && strcmp(rev, ctx.qry.head)) {
|
||||||
|
html(delim);
|
||||||
|
html("id=");
|
||||||
|
html_url_arg(rev);
|
||||||
|
delim = "&";
|
||||||
|
}
|
||||||
|
if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
|
||||||
|
html(delim);
|
||||||
|
html("ss=1");
|
||||||
|
}
|
||||||
|
html("'>");
|
||||||
|
html_txt(name);
|
||||||
|
html("</a>");
|
||||||
}
|
}
|
||||||
|
|
||||||
void cgit_refs_link(char *name, char *title, char *class, char *head,
|
void cgit_refs_link(char *name, char *title, char *class, char *head,
|
||||||
@ -341,7 +357,8 @@ void cgit_snapshot_link(char *name, char *title, char *class, char *head,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cgit_diff_link(char *name, char *title, char *class, char *head,
|
void cgit_diff_link(char *name, char *title, char *class, char *head,
|
||||||
char *new_rev, char *old_rev, char *path)
|
char *new_rev, char *old_rev, char *path,
|
||||||
|
int toggle_ssdiff)
|
||||||
{
|
{
|
||||||
char *delim;
|
char *delim;
|
||||||
|
|
||||||
@ -356,6 +373,11 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
|
|||||||
html(delim);
|
html(delim);
|
||||||
html("id2=");
|
html("id2=");
|
||||||
html_url_arg(old_rev);
|
html_url_arg(old_rev);
|
||||||
|
delim = "&";
|
||||||
|
}
|
||||||
|
if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
|
||||||
|
html(delim);
|
||||||
|
html("ss=1");
|
||||||
}
|
}
|
||||||
html("'>");
|
html("'>");
|
||||||
html_txt(name);
|
html_txt(name);
|
||||||
@ -383,7 +405,7 @@ void cgit_object_link(struct object *obj)
|
|||||||
shortrev[10] = '\0';
|
shortrev[10] = '\0';
|
||||||
if (obj->type == OBJ_COMMIT) {
|
if (obj->type == OBJ_COMMIT) {
|
||||||
cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
|
cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
|
||||||
ctx.qry.head, fullrev);
|
ctx.qry.head, fullrev, 0);
|
||||||
return;
|
return;
|
||||||
} else if (obj->type == OBJ_TREE)
|
} else if (obj->type == OBJ_TREE)
|
||||||
page = "tree";
|
page = "tree";
|
||||||
@ -695,9 +717,9 @@ void cgit_print_pageheader(struct cgit_context *ctx)
|
|||||||
cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
|
cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
|
||||||
ctx->qry.sha1, NULL);
|
ctx->qry.sha1, NULL);
|
||||||
cgit_commit_link("commit", NULL, hc(cmd, "commit"),
|
cgit_commit_link("commit", NULL, hc(cmd, "commit"),
|
||||||
ctx->qry.head, ctx->qry.sha1);
|
ctx->qry.head, ctx->qry.sha1, 0);
|
||||||
cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
|
cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
|
||||||
ctx->qry.sha1, ctx->qry.sha2, NULL);
|
ctx->qry.sha1, ctx->qry.sha2, NULL, 0);
|
||||||
if (ctx->repo->max_stats)
|
if (ctx->repo->max_stats)
|
||||||
cgit_stats_link("stats", NULL, hc(cmd, "stats"),
|
cgit_stats_link("stats", NULL, hc(cmd, "stats"),
|
||||||
ctx->qry.head, NULL);
|
ctx->qry.head, NULL);
|
||||||
|
@ -22,7 +22,7 @@ extern void cgit_log_link(char *name, char *title, char *class, char *head,
|
|||||||
char *rev, char *path, int ofs, char *grep,
|
char *rev, char *path, int ofs, char *grep,
|
||||||
char *pattern, int showmsg);
|
char *pattern, int showmsg);
|
||||||
extern void cgit_commit_link(char *name, char *title, char *class, char *head,
|
extern void cgit_commit_link(char *name, char *title, char *class, char *head,
|
||||||
char *rev);
|
char *rev, int toggle_ssdiff);
|
||||||
extern void cgit_patch_link(char *name, char *title, char *class, char *head,
|
extern void cgit_patch_link(char *name, char *title, char *class, char *head,
|
||||||
char *rev);
|
char *rev);
|
||||||
extern void cgit_refs_link(char *name, char *title, char *class, char *head,
|
extern void cgit_refs_link(char *name, char *title, char *class, char *head,
|
||||||
@ -30,7 +30,8 @@ extern void cgit_refs_link(char *name, char *title, char *class, char *head,
|
|||||||
extern void cgit_snapshot_link(char *name, char *title, char *class,
|
extern void cgit_snapshot_link(char *name, char *title, char *class,
|
||||||
char *head, char *rev, char *archivename);
|
char *head, char *rev, char *archivename);
|
||||||
extern void cgit_diff_link(char *name, char *title, char *class, char *head,
|
extern void cgit_diff_link(char *name, char *title, char *class, char *head,
|
||||||
char *new_rev, char *old_rev, char *path);
|
char *new_rev, char *old_rev, char *path,
|
||||||
|
int toggle_ssdiff);
|
||||||
extern void cgit_stats_link(char *name, char *title, char *class, char *head,
|
extern void cgit_stats_link(char *name, char *title, char *class, char *head,
|
||||||
char *path);
|
char *path);
|
||||||
extern void cgit_object_link(struct object *obj);
|
extern void cgit_object_link(struct object *obj);
|
||||||
|
Loading…
Reference in New Issue
Block a user