summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c5
-rw-r--r--cgit.h2
-rw-r--r--cgitrc.5.txt4
-rw-r--r--ui-commit.c11
-rw-r--r--ui-diff.c22
-rw-r--r--ui-log.c4
-rw-r--r--ui-refs.c2
-rw-r--r--ui-shared.c34
-rw-r--r--ui-shared.h5
9 files changed, 73 insertions, 16 deletions
diff --git a/cgit.c b/cgit.c
index bd37788..ff678fb 100644
--- a/cgit.c
+++ b/cgit.c
@@ -179,12 +179,14 @@ void config_cb(const char *name, const char *value)
else if (!strcmp(name, "summary-log"))
ctx.cfg.summary_log = atoi(value);
else if (!strcmp(name, "summary-branches"))
ctx.cfg.summary_branches = atoi(value);
else if (!strcmp(name, "summary-tags"))
ctx.cfg.summary_tags = atoi(value);
+ else if (!strcmp(name, "side-by-side-diffs"))
+ ctx.cfg.ssdiff = atoi(value);
else if (!strcmp(name, "agefile"))
ctx.cfg.agefile = xstrdup(value);
else if (!strcmp(name, "renamelimit"))
ctx.cfg.renamelimit = atoi(value);
else if (!strcmp(name, "robots"))
ctx.cfg.robots = xstrdup(value);
@@ -235,12 +237,14 @@ static void querystring_cb(const char *name, const char *value)
} else if (!strcmp(name, "s")){
ctx.qry.sort = xstrdup(value);
} else if (!strcmp(name, "showmsg")) {
ctx.qry.showmsg = atoi(value);
} else if (!strcmp(name, "period")) {
ctx.qry.period = xstrdup(value);
+ } else if (!strcmp(name, "ss")) {
+ ctx.qry.ssdiff = atoi(value);
}
}
char *xstrdupn(const char *str)
{
return (str ? xstrdup(str) : NULL);
@@ -276,12 +280,13 @@ static void prepare_context(struct cgit_context *ctx)
ctx->cfg.root_desc = "a fast webinterface for the git dscm";
ctx->cfg.script_name = CGIT_SCRIPT_NAME;
ctx->cfg.section = "";
ctx->cfg.summary_branches = 10;
ctx->cfg.summary_log = 10;
ctx->cfg.summary_tags = 10;
+ ctx->cfg.ssdiff = 0;
ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG"));
ctx->env.http_host = xstrdupn(getenv("HTTP_HOST"));
ctx->env.https = xstrdupn(getenv("HTTPS"));
ctx->env.no_http = xstrdupn(getenv("NO_HTTP"));
ctx->env.path_info = xstrdupn(getenv("PATH_INFO"));
ctx->env.query_string = xstrdupn(getenv("QUERY_STRING"));
diff --git a/cgit.h b/cgit.h
index 6c6c460..b7b0adb 100644
--- a/cgit.h
+++ b/cgit.h
@@ -140,12 +140,13 @@ struct cgit_query {
char *url;
char *period;
int ofs;
int nohead;
char *sort;
int showmsg;
+ int ssdiff;
};
struct cgit_config {
char *agefile;
char *cache_root;
char *clone_prefix;
@@ -191,12 +192,13 @@ struct cgit_config {
int noheader;
int renamelimit;
int snapshots;
int summary_branches;
int summary_log;
int summary_tags;
+ int ssdiff;
struct string_list mimetypes;
struct cgit_filter *about_filter;
struct cgit_filter *commit_filter;
struct cgit_filter *source_filter;
};
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 4dc383d..252d546 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -235,12 +235,16 @@ scan-path::
section::
The name of the current repository section - all repositories defined
after this option will inherit the current section name. Default value:
none.
+side-by-side-diffs::
+ If set to "1" shows side-by-side diffs instead of unidiffs per
+ default. Default value: "0".
+
snapshots::
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
values "tar", "tar.gz", "tar.bz2" and "zip". Default value: none.
source-filter::
diff --git a/ui-commit.c b/ui-commit.c
index f5b0ae5..b5e3c01 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -55,15 +55,20 @@ void cgit_print_commit(char *hex)
}
html("</td><td class='right'>");
cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
html("</td></tr>\n");
html("<tr><th>commit</th><td colspan='2' class='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(" (");
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("<tr><th>tree</th><td colspan='2' class='sha1'>");
tmp = xstrdup(hex);
cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
ctx.qry.head, tmp, NULL);
html("</td></tr>\n");
@@ -75,16 +80,16 @@ void cgit_print_commit(char *hex)
html("</td></tr>");
continue;
}
html("<tr><th>parent</th>"
"<td colspan='2' class='sha1'>");
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(" (");
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>");
parents++;
}
if (ctx.repo->snapshots) {
html("<tr><th>download</th><td colspan='2' class='sha1'>");
cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
diff --git a/ui-diff.c b/ui-diff.c
index 0c6f8d7..42e81ac 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -82,13 +82,13 @@ static void print_fileinfo(struct fileinfo *info)
html("<span class='modechange'>[");
cgit_print_filemode(info->old_mode);
html("]</span>");
}
htmlf("</td><td class='%s'>", class);
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)
htmlf(" (%s from %s)",
info->status == DIFF_STATUS_COPIED ? "copied" : "renamed",
info->old_path);
html("</td><td class='right'>");
if (info->binary) {
@@ -157,13 +157,13 @@ void cgit_print_diffstat(const unsigned char *old_sha1,
const unsigned char *new_sha1)
{
int i;
html("<div class='diffstat-header'>");
cgit_diff_link("Diffstat", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
- ctx.qry.sha2, NULL);
+ ctx.qry.sha2, NULL, 0);
html("</div>");
html("<table summary='diffstat' class='diffstat'>");
max_changes = 0;
cgit_diff_tree(old_sha1, new_sha1, inspect_filepair, NULL);
for(i = 0; i<files; i++)
print_fileinfo(&items[i]);
@@ -247,12 +247,25 @@ static void header(unsigned char *sha1, char *path1, int mode1,
}
html("</div>");
if (use_ssdiff)
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)
{
unsigned long old_size = 0;
unsigned long new_size = 0;
int binary = 0;
linediff_fn print_line_fn = print_line;
@@ -311,12 +324,17 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi
return;
}
commit2 = lookup_commit_reference(old_rev_sha1);
if (!commit2 || parse_commit(commit2))
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);
html("<table summary='diff' class='diff'>");
html("<tr><td>");
cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix);
html("</td></tr>");
diff --git a/ui-log.c b/ui-log.c
index f3132c9..0947604 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -63,13 +63,13 @@ void show_commit_decorations(struct commit *commit)
sha1_to_hex(commit->object.sha1), NULL,
0, NULL, NULL, ctx.qry.showmsg);
}
else {
strncpy(buf, deco->name, sizeof(buf) - 1);
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;
}
}
void print_commit(struct commit *commit)
@@ -86,13 +86,13 @@ void print_commit(struct commit *commit)
html_link_open(tmp, NULL, NULL);
cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
html_link_close();
htmlf("</td><td%s>",
ctx.qry.showmsg ? " class='logsubject'" : "");
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);
html("</td><td>");
html_txt(info->author);
if (ctx.repo->enable_log_filecount) {
files = 0;
add_lines = 0;
diff --git a/ui-refs.c b/ui-refs.c
index d3b4f6e..33d9bec 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -71,13 +71,13 @@ static int print_branch(struct refinfo *ref)
html("<tr><td>");
cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL,
ctx.qry.showmsg);
html("</td><td>");
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_txt(info->author);
html("</td><td colspan='2'>");
cgit_print_age(info->commit->date, -1, NULL);
} else {
html("</td><td></td><td>");
diff --git a/ui-shared.c b/ui-shared.c
index 07d5dd4..de55eff 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -314,21 +314,37 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
html("'>");
html_txt(name);
html("</a>");
}
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) {
name[ctx.cfg.max_msg_len] = '\0';
name[ctx.cfg.max_msg_len - 1] = '.';
name[ctx.cfg.max_msg_len - 2] = '.';
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 = "&amp;";
+ }
+ 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,
char *rev, char *path)
{
reporevlink("refs", name, title, class, head, rev, path);
@@ -338,13 +354,14 @@ void cgit_snapshot_link(char *name, char *title, char *class, char *head,
char *rev, char *archivename)
{
reporevlink("snapshot", name, title, class, head, rev, archivename);
}
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;
delim = repolink(title, class, "diff", head, path);
if (new_rev && strcmp(new_rev, ctx.qry.head)) {
html(delim);
@@ -353,12 +370,17 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
delim = "&amp;";
}
if (old_rev) {
html(delim);
html("id2=");
html_url_arg(old_rev);
+ delim = "&amp;";
+ }
+ if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
+ html(delim);
+ html("ss=1");
}
html("'>");
html_txt(name);
html("</a>");
}
@@ -380,13 +402,13 @@ void cgit_object_link(struct object *obj)
fullrev = sha1_to_hex(obj->sha1);
shortrev = xstrdup(fullrev);
shortrev[10] = '\0';
if (obj->type == OBJ_COMMIT) {
cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
- ctx.qry.head, fullrev);
+ ctx.qry.head, fullrev, 0);
return;
} else if (obj->type == OBJ_TREE)
page = "tree";
else if (obj->type == OBJ_TAG)
page = "tag";
else
@@ -692,15 +714,15 @@ void cgit_print_pageheader(struct cgit_context *ctx)
ctx->qry.sha1, NULL);
cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg);
cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
ctx->qry.sha1, NULL);
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,
- ctx->qry.sha1, ctx->qry.sha2, NULL);
+ ctx->qry.sha1, ctx->qry.sha2, NULL, 0);
if (ctx->repo->max_stats)
cgit_stats_link("stats", NULL, hc(cmd, "stats"),
ctx->qry.head, NULL);
if (ctx->repo->readme)
reporevlink("about", "about", NULL,
hc(cmd, "about"), ctx->qry.head, NULL,
diff --git a/ui-shared.h b/ui-shared.h
index bff4826..166246d 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -19,21 +19,22 @@ extern void cgit_tree_link(char *name, char *title, char *class, char *head,
extern void cgit_plain_link(char *name, char *title, char *class, char *head,
char *rev, char *path);
extern void cgit_log_link(char *name, char *title, char *class, char *head,
char *rev, char *path, int ofs, char *grep,
char *pattern, int showmsg);
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,
char *rev);
extern void cgit_refs_link(char *name, char *title, char *class, char *head,
char *rev, char *path);
extern void cgit_snapshot_link(char *name, char *title, char *class,
char *head, char *rev, char *archivename);
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,
char *path);
extern void cgit_object_link(struct object *obj);
extern void cgit_print_error(char *msg);
extern void cgit_print_date(time_t secs, char *format, int local_time);