summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile16
-rw-r--r--cgit.c14
-rw-r--r--cgit.css104
-rw-r--r--cgit.h5
-rw-r--r--cgitrc.5.txt17
-rwxr-xr-xfilters/syntax-highlighting.sh29
-rw-r--r--shared.c1
-rw-r--r--ui-commit.c11
-rw-r--r--ui-diff.c62
-rw-r--r--ui-log.c4
-rw-r--r--ui-refs.c4
-rw-r--r--ui-shared.c43
-rw-r--r--ui-shared.h5
-rw-r--r--ui-snapshot.c14
-rw-r--r--ui-ssdiff.c369
-rw-r--r--ui-ssdiff.h13
-rw-r--r--ui-tag.c24
-rw-r--r--ui-tree.c6
18 files changed, 684 insertions, 57 deletions
diff --git a/Makefile b/Makefile
index 7b9ac5f..d39a30e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,171 +1,181 @@
CGIT_VERSION = v0.8.3.1
CGIT_SCRIPT_NAME = cgit.cgi
CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
CGIT_CONFIG = /etc/cgitrc
CACHE_ROOT = /var/cache/cgit
SHA1_HEADER = <openssl/sha.h>
GIT_VER = 1.6.4.3
GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
INSTALL = install
# Define NO_STRCASESTR if you don't have strcasestr.
#
+# Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1
+# implementation (slower).
+#
# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin).
#
#-include config.mak
#
# Platform specific tweaks
#
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
ifeq ($(uname_O),Cygwin)
NO_STRCASESTR = YesPlease
NEEDS_LIBICONV = YesPlease
endif
#
# Let the user override the above settings.
#
-include cgit.conf
#
# Define a way to invoke make in subdirs quietly, shamelessly ripped
# from git.git
#
QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
QUIET_SUBDIR1 =
ifneq ($(findstring $(MAKEFLAGS),w),w)
PRINT_DIR = --no-print-directory
else # "make -w"
NO_SUBDIR = :
endif
ifndef V
QUIET_CC = @echo ' ' CC $@;
QUIET_MM = @echo ' ' MM $@;
QUIET_SUBDIR0 = +@subdir=
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
$(MAKE) $(PRINT_DIR) -C $$subdir
endif
#
# Define a pattern rule for automatic dependency building
#
%.d: %.c
$(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@
#
# Define a pattern rule for silent object building
#
%.o: %.c
$(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $<
-EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
+EXTLIBS = git/libgit.a git/xdiff/lib.a -lz
OBJECTS =
OBJECTS += cache.o
OBJECTS += cgit.o
OBJECTS += cmd.o
OBJECTS += configfile.o
OBJECTS += html.o
OBJECTS += parsing.o
OBJECTS += scan-tree.o
OBJECTS += shared.o
OBJECTS += ui-atom.o
OBJECTS += ui-blob.o
OBJECTS += ui-clone.o
OBJECTS += ui-commit.o
OBJECTS += ui-diff.o
OBJECTS += ui-log.o
OBJECTS += ui-patch.o
OBJECTS += ui-plain.o
OBJECTS += ui-refs.o
OBJECTS += ui-repolist.o
OBJECTS += ui-shared.o
OBJECTS += ui-snapshot.o
+OBJECTS += ui-ssdiff.o
OBJECTS += ui-stats.o
OBJECTS += ui-summary.o
OBJECTS += ui-tag.o
OBJECTS += ui-tree.o
ifdef NEEDS_LIBICONV
EXTLIBS += -liconv
endif
.PHONY: all libgit test install uninstall clean force-version get-git \
doc man-doc html-doc clean-doc
all: cgit
VERSION: force-version
@./gen-version.sh "$(CGIT_VERSION)"
-include VERSION
CFLAGS += -g -Wall -Igit
CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)'
CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"'
CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"'
CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"'
CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"'
ifdef NO_ICONV
CFLAGS += -DNO_ICONV
endif
ifdef NO_STRCASESTR
CFLAGS += -DNO_STRCASESTR
endif
+ifdef NO_OPENSSL
+ CFLAGS += -DNO_OPENSSL
+ GIT_OPTIONS += NO_OPENSSL=1
+else
+ EXTLIBS += -lcrypto
+endif
cgit: $(OBJECTS) libgit
$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o cgit $(OBJECTS) $(EXTLIBS)
cgit.o: VERSION
-include $(OBJECTS:.o=.d)
libgit:
- $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 libgit.a
- $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 xdiff/lib.a
+ $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) libgit.a
+ $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 $(GIT_OPTIONS) xdiff/lib.a
test: all
$(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) all
install: all
$(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_SCRIPT_PATH)
$(INSTALL) -m 0755 cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
$(INSTALL) -m 0755 -d $(DESTDIR)$(CGIT_DATA_PATH)
$(INSTALL) -m 0644 cgit.css $(DESTDIR)$(CGIT_DATA_PATH)/cgit.css
$(INSTALL) -m 0644 cgit.png $(DESTDIR)$(CGIT_DATA_PATH)/cgit.png
uninstall:
rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
rm -f $(CGIT_DATA_PATH)/cgit.css
rm -f $(CGIT_DATA_PATH)/cgit.png
doc: man-doc html-doc pdf-doc
man-doc: cgitrc.5.txt
a2x -f manpage cgitrc.5.txt
html-doc: cgitrc.5.txt
a2x -f xhtml --stylesheet=cgit-doc.css cgitrc.5.txt
pdf-doc: cgitrc.5.txt
a2x -f pdf cgitrc.5.txt
clean: clean-doc
rm -f cgit VERSION *.o *.d
clean-doc:
rm -f cgitrc.5 cgitrc.5.html cgitrc.5.pdf cgitrc.5.xml cgitrc.5.fo
get-git:
curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git
diff --git a/cgit.c b/cgit.c
index 6bb712d..e46c00a 100644
--- a/cgit.c
+++ b/cgit.c
@@ -15,315 +15,329 @@
#include "ui-stats.h"
#include "scan-tree.h"
const char *cgit_version = CGIT_VERSION;
void add_mimetype(const char *name, const char *value)
{
struct string_list_item *item;
item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes);
item->util = xstrdup(value);
}
struct cgit_filter *new_filter(const char *cmd, int extra_args)
{
struct cgit_filter *f;
if (!cmd || !cmd[0])
return NULL;
f = xmalloc(sizeof(struct cgit_filter));
f->cmd = xstrdup(cmd);
f->argv = xmalloc((2 + extra_args) * sizeof(char *));
f->argv[0] = f->cmd;
f->argv[1] = NULL;
return f;
}
static void process_cached_repolist(const char *path);
void repo_config(struct cgit_repo *repo, const char *name, const char *value)
{
if (!strcmp(name, "name"))
repo->name = xstrdup(value);
else if (!strcmp(name, "clone-url"))
repo->clone_url = xstrdup(value);
else if (!strcmp(name, "desc"))
repo->desc = xstrdup(value);
else if (!strcmp(name, "owner"))
repo->owner = xstrdup(value);
else if (!strcmp(name, "defbranch"))
repo->defbranch = xstrdup(value);
else if (!strcmp(name, "snapshots"))
repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value);
else if (!strcmp(name, "enable-log-filecount"))
repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value);
else if (!strcmp(name, "enable-log-linecount"))
repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value);
+ else if (!strcmp(name, "enable-remote-branches"))
+ repo->enable_remote_branches = atoi(value);
else if (!strcmp(name, "max-stats"))
repo->max_stats = cgit_find_stats_period(value, NULL);
else if (!strcmp(name, "module-link"))
repo->module_link= xstrdup(value);
else if (!strcmp(name, "section"))
repo->section = xstrdup(value);
else if (!strcmp(name, "readme") && value != NULL) {
if (*value == '/')
repo->readme = xstrdup(value);
else
repo->readme = xstrdup(fmt("%s/%s", repo->path, value));
} else if (ctx.cfg.enable_filter_overrides) {
if (!strcmp(name, "about-filter"))
repo->about_filter = new_filter(value, 0);
else if (!strcmp(name, "commit-filter"))
repo->commit_filter = new_filter(value, 0);
else if (!strcmp(name, "source-filter"))
repo->source_filter = new_filter(value, 1);
}
}
void config_cb(const char *name, const char *value)
{
if (!strcmp(name, "section") || !strcmp(name, "repo.group"))
ctx.cfg.section = xstrdup(value);
else if (!strcmp(name, "repo.url"))
ctx.repo = cgit_add_repo(value);
else if (ctx.repo && !strcmp(name, "repo.path"))
ctx.repo->path = trim_end(value, '/');
else if (ctx.repo && !prefixcmp(name, "repo."))
repo_config(ctx.repo, name + 5, value);
else if (!strcmp(name, "root-title"))
ctx.cfg.root_title = xstrdup(value);
else if (!strcmp(name, "root-desc"))
ctx.cfg.root_desc = xstrdup(value);
else if (!strcmp(name, "root-readme"))
ctx.cfg.root_readme = xstrdup(value);
else if (!strcmp(name, "css"))
ctx.cfg.css = xstrdup(value);
else if (!strcmp(name, "favicon"))
ctx.cfg.favicon = xstrdup(value);
else if (!strcmp(name, "footer"))
ctx.cfg.footer = xstrdup(value);
else if (!strcmp(name, "head-include"))
ctx.cfg.head_include = xstrdup(value);
else if (!strcmp(name, "header"))
ctx.cfg.header = xstrdup(value);
else if (!strcmp(name, "logo"))
ctx.cfg.logo = xstrdup(value);
else if (!strcmp(name, "index-header"))
ctx.cfg.index_header = xstrdup(value);
else if (!strcmp(name, "index-info"))
ctx.cfg.index_info = xstrdup(value);
else if (!strcmp(name, "logo-link"))
ctx.cfg.logo_link = xstrdup(value);
else if (!strcmp(name, "module-link"))
ctx.cfg.module_link = xstrdup(value);
else if (!strcmp(name, "virtual-root")) {
ctx.cfg.virtual_root = trim_end(value, '/');
if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
ctx.cfg.virtual_root = "";
} else if (!strcmp(name, "nocache"))
ctx.cfg.nocache = atoi(value);
else if (!strcmp(name, "noplainemail"))
ctx.cfg.noplainemail = atoi(value);
else if (!strcmp(name, "noheader"))
ctx.cfg.noheader = atoi(value);
else if (!strcmp(name, "snapshots"))
ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
else if (!strcmp(name, "enable-filter-overrides"))
ctx.cfg.enable_filter_overrides = atoi(value);
else if (!strcmp(name, "enable-index-links"))
ctx.cfg.enable_index_links = atoi(value);
else if (!strcmp(name, "enable-log-filecount"))
ctx.cfg.enable_log_filecount = atoi(value);
else if (!strcmp(name, "enable-log-linecount"))
ctx.cfg.enable_log_linecount = atoi(value);
+ else if (!strcmp(name, "enable-remote-branches"))
+ ctx.cfg.enable_remote_branches = atoi(value);
else if (!strcmp(name, "enable-tree-linenumbers"))
ctx.cfg.enable_tree_linenumbers = atoi(value);
else if (!strcmp(name, "max-stats"))
ctx.cfg.max_stats = cgit_find_stats_period(value, NULL);
else if (!strcmp(name, "cache-size"))
ctx.cfg.cache_size = atoi(value);
else if (!strcmp(name, "cache-root"))
ctx.cfg.cache_root = xstrdup(value);
else if (!strcmp(name, "cache-root-ttl"))
ctx.cfg.cache_root_ttl = atoi(value);
else if (!strcmp(name, "cache-repo-ttl"))
ctx.cfg.cache_repo_ttl = atoi(value);
else if (!strcmp(name, "cache-scanrc-ttl"))
ctx.cfg.cache_scanrc_ttl = atoi(value);
else if (!strcmp(name, "cache-static-ttl"))
ctx.cfg.cache_static_ttl = atoi(value);
else if (!strcmp(name, "cache-dynamic-ttl"))
ctx.cfg.cache_dynamic_ttl = atoi(value);
else if (!strcmp(name, "about-filter"))
ctx.cfg.about_filter = new_filter(value, 0);
else if (!strcmp(name, "commit-filter"))
ctx.cfg.commit_filter = new_filter(value, 0);
else if (!strcmp(name, "embedded"))
ctx.cfg.embedded = atoi(value);
else if (!strcmp(name, "max-message-length"))
ctx.cfg.max_msg_len = atoi(value);
else if (!strcmp(name, "max-repodesc-length"))
ctx.cfg.max_repodesc_len = atoi(value);
+ else if (!strcmp(name, "max-blob-size"))
+ ctx.cfg.max_blob_size = atoi(value);
else if (!strcmp(name, "max-repo-count"))
ctx.cfg.max_repo_count = atoi(value);
else if (!strcmp(name, "max-commit-count"))
ctx.cfg.max_commit_count = atoi(value);
else if (!strcmp(name, "scan-path"))
if (!ctx.cfg.nocache && ctx.cfg.cache_size)
process_cached_repolist(value);
else
scan_tree(value, repo_config);
else if (!strcmp(name, "source-filter"))
ctx.cfg.source_filter = new_filter(value, 1);
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);
else if (!strcmp(name, "clone-prefix"))
ctx.cfg.clone_prefix = xstrdup(value);
else if (!strcmp(name, "local-time"))
ctx.cfg.local_time = atoi(value);
else if (!prefixcmp(name, "mimetype."))
add_mimetype(name + 9, value);
else if (!strcmp(name, "include"))
parse_configfile(value, config_cb);
}
static void querystring_cb(const char *name, const char *value)
{
if (!value)
value = "";
if (!strcmp(name,"r")) {
ctx.qry.repo = xstrdup(value);
ctx.repo = cgit_get_repoinfo(value);
} else if (!strcmp(name, "p")) {
ctx.qry.page = xstrdup(value);
} else if (!strcmp(name, "url")) {
+ if (*value == '/')
+ value++;
ctx.qry.url = xstrdup(value);
cgit_parse_url(value);
} else if (!strcmp(name, "qt")) {
ctx.qry.grep = xstrdup(value);
} else if (!strcmp(name, "q")) {
ctx.qry.search = xstrdup(value);
} else if (!strcmp(name, "h")) {
ctx.qry.head = xstrdup(value);
ctx.qry.has_symref = 1;
} else if (!strcmp(name, "id")) {
ctx.qry.sha1 = xstrdup(value);
ctx.qry.has_sha1 = 1;
} else if (!strcmp(name, "id2")) {
ctx.qry.sha2 = xstrdup(value);
ctx.qry.has_sha1 = 1;
} else if (!strcmp(name, "ofs")) {
ctx.qry.ofs = atoi(value);
} else if (!strcmp(name, "path")) {
ctx.qry.path = trim_end(value, '/');
} else if (!strcmp(name, "name")) {
ctx.qry.name = xstrdup(value);
} else if (!strcmp(name, "mimetype")) {
ctx.qry.mimetype = xstrdup(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);
}
static void prepare_context(struct cgit_context *ctx)
{
memset(ctx, 0, sizeof(ctx));
ctx->cfg.agefile = "info/web/last-modified";
ctx->cfg.nocache = 0;
ctx->cfg.cache_size = 0;
ctx->cfg.cache_dynamic_ttl = 5;
ctx->cfg.cache_max_create_time = 5;
ctx->cfg.cache_repo_ttl = 5;
ctx->cfg.cache_root = CGIT_CACHE_ROOT;
ctx->cfg.cache_root_ttl = 5;
ctx->cfg.cache_scanrc_ttl = 15;
ctx->cfg.cache_static_ttl = -1;
ctx->cfg.css = "/cgit.css";
ctx->cfg.logo = "/cgit.png";
ctx->cfg.local_time = 0;
ctx->cfg.enable_tree_linenumbers = 1;
ctx->cfg.max_repo_count = 50;
ctx->cfg.max_commit_count = 50;
ctx->cfg.max_lock_attempts = 5;
ctx->cfg.max_msg_len = 80;
ctx->cfg.max_repodesc_len = 80;
+ ctx->cfg.max_blob_size = 0;
ctx->cfg.max_stats = 0;
ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
ctx->cfg.renamelimit = -1;
ctx->cfg.robots = "index, nofollow";
ctx->cfg.root_title = "Git repository browser";
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"));
ctx->env.request_method = xstrdupn(getenv("REQUEST_METHOD"));
ctx->env.script_name = xstrdupn(getenv("SCRIPT_NAME"));
ctx->env.server_name = xstrdupn(getenv("SERVER_NAME"));
ctx->env.server_port = xstrdupn(getenv("SERVER_PORT"));
ctx->page.mimetype = "text/html";
ctx->page.charset = PAGE_ENCODING;
ctx->page.filename = NULL;
ctx->page.size = 0;
ctx->page.modified = time(NULL);
ctx->page.expires = ctx->page.modified;
ctx->page.etag = NULL;
memset(&ctx->cfg.mimetypes, 0, sizeof(struct string_list));
if (ctx->env.script_name)
ctx->cfg.script_name = ctx->env.script_name;
if (ctx->env.query_string)
ctx->qry.raw = ctx->env.query_string;
if (!ctx->env.cgit_config)
ctx->env.cgit_config = CGIT_CONFIG;
}
struct refmatch {
char *req_ref;
char *first_ref;
int match;
};
int find_current_ref(const char *refname, const unsigned char *sha1,
int flags, void *cb_data)
{
struct refmatch *info;
info = (struct refmatch *)cb_data;
if (!strcmp(refname, info->req_ref))
info->match = 1;
if (!info->first_ref)
info->first_ref = xstrdup(refname);
return info->match;
}
char *find_default_branch(struct cgit_repo *repo)
{
struct refmatch info;
diff --git a/cgit.css b/cgit.css
index c47ebc9..0cb894a 100644
--- a/cgit.css
+++ b/cgit.css
@@ -117,96 +117,101 @@ table.list {
}
table.list tr {
background: white;
}
table.list tr.logheader {
background: #eee;
}
table.list tr:hover {
background: #eee;
}
table.list tr.nohover:hover {
background: white;
}
table.list th {
font-weight: bold;
/* color: #888;
border-top: dashed 1px #888;
border-bottom: dashed 1px #888;
*/
padding: 0.1em 0.5em 0.05em 0.5em;
vertical-align: baseline;
}
table.list td {
border: none;
padding: 0.1em 0.5em 0.1em 0.5em;
}
table.list td.logsubject {
font-family: monospace;
font-weight: bold;
}
table.list td.logmsg {
font-family: monospace;
white-space: pre;
padding: 1em 0.5em 2em 0.5em;
}
table.list td a {
color: black;
}
+table.list td a.ls-dir {
+ font-weight: bold;
+ color: #00f;
+}
+
table.list td a:hover {
color: #00f;
}
img {
border: none;
}
input#switch-btn {
margin: 2px 0px 0px 0px;
}
td#sidebar input.txt {
width: 100%;
margin: 2px 0px 0px 0px;
}
table#grid {
margin: 0px;
}
td#content {
vertical-align: top;
padding: 1em 2em 1em 1em;
border: none;
}
div#summary {
vertical-align: top;
margin-bottom: 1em;
}
table#downloads {
float: right;
border-collapse: collapse;
border: solid 1px #777;
margin-left: 0.5em;
margin-bottom: 0.5em;
}
table#downloads th {
background-color: #ccc;
}
div#blob {
border: solid 1px black;
}
@@ -556,48 +561,147 @@ table.stats td.sum {
table.stats td.left {
text-align: left;
}
table.vgraph {
border-collapse: separate;
border: solid 1px black;
height: 200px;
}
table.vgraph th {
background-color: #eee;
font-weight: bold;
border: solid 1px white;
padding: 1px 0.5em;
}
table.vgraph td {
vertical-align: bottom;
padding: 0px 10px;
}
table.vgraph div.bar {
background-color: #eee;
}
table.hgraph {
border: solid 1px black;
width: 800px;
}
table.hgraph th {
background-color: #eee;
font-weight: bold;
border: solid 1px black;
padding: 1px 0.5em;
}
table.hgraph td {
vertical-align: center;
padding: 2px 2px;
}
table.hgraph div.bar {
background-color: #eee;
height: 1em;
}
+
+table.ssdiff {
+ width: 100%;
+}
+
+table.ssdiff td {
+ font-size: 75%;
+ font-family: monospace;
+ white-space: pre;
+ padding: 1px 4px 1px 4px;
+ border-left: solid 1px #aaa;
+ border-right: solid 1px #aaa;
+}
+
+table.ssdiff td.add {
+ color: black;
+ background: #cfc;
+ min-width: 50%;
+}
+
+table.ssdiff td.add_dark {
+ color: black;
+ background: #aca;
+ min-width: 50%;
+}
+
+table.ssdiff span.add {
+ background: #cfc;
+ font-weight: bold;
+}
+
+table.ssdiff td.del {
+ color: black;
+ background: #fcc;
+ min-width: 50%;
+}
+
+table.ssdiff td.del_dark {
+ color: black;
+ background: #caa;
+ min-width: 50%;
+}
+
+table.ssdiff span.del {
+ background: #fcc;
+ font-weight: bold;
+}
+
+table.ssdiff td.changed {
+ color: black;
+ background: #ffc;
+ min-width: 50%;
+}
+
+table.ssdiff td.changed_dark {
+ color: black;
+ background: #cca;
+ min-width: 50%;
+}
+
+table.ssdiff td.lineno {
+ color: black;
+ background: #eee;
+ text-align: right;
+ width: 3em;
+ min-width: 3em;
+}
+
+table.ssdiff td.hunk {
+ color: #black;
+ background: #ccf;
+ border-top: solid 1px #aaa;
+ border-bottom: solid 1px #aaa;
+}
+
+table.ssdiff td.head {
+ border-top: solid 1px #aaa;
+ border-bottom: solid 1px #aaa;
+}
+
+table.ssdiff td.head div.head {
+ font-weight: bold;
+ color: black;
+}
+
+table.ssdiff td.foot {
+ border-top: solid 1px #aaa;
+ border-left: none;
+ border-right: none;
+ border-bottom: none;
+}
+
+table.ssdiff td.space {
+ border: none;
+}
+
+table.ssdiff td.space div {
+ min-height: 3em;
+} \ No newline at end of file
diff --git a/cgit.h b/cgit.h
index 6c6c460..cd4af72 100644
--- a/cgit.h
+++ b/cgit.h
@@ -27,218 +27,223 @@
#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)"
#define FMT_SHORTDATE "%Y-%m-%d"
#define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ"
/*
* Limits used for relative dates
*/
#define TM_MIN 60
#define TM_HOUR (TM_MIN * 60)
#define TM_DAY (TM_HOUR * 24)
#define TM_WEEK (TM_DAY * 7)
#define TM_YEAR (TM_DAY * 365)
#define TM_MONTH (TM_YEAR / 12.0)
/*
* Default encoding
*/
#define PAGE_ENCODING "UTF-8"
typedef void (*configfn)(const char *name, const char *value);
typedef void (*filepair_fn)(struct diff_filepair *pair);
typedef void (*linediff_fn)(char *line, int len);
struct cgit_filter {
char *cmd;
char **argv;
int old_stdout;
int pipe_fh[2];
int pid;
int exitstatus;
};
struct cgit_repo {
char *url;
char *name;
char *path;
char *desc;
char *owner;
char *defbranch;
char *module_link;
char *readme;
char *section;
char *clone_url;
int snapshots;
int enable_log_filecount;
int enable_log_linecount;
+ int enable_remote_branches;
int max_stats;
time_t mtime;
struct cgit_filter *about_filter;
struct cgit_filter *commit_filter;
struct cgit_filter *source_filter;
};
typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
const char *value);
struct cgit_repolist {
int length;
int count;
struct cgit_repo *repos;
};
struct commitinfo {
struct commit *commit;
char *author;
char *author_email;
unsigned long author_date;
char *committer;
char *committer_email;
unsigned long committer_date;
char *subject;
char *msg;
char *msg_encoding;
};
struct taginfo {
char *tagger;
char *tagger_email;
unsigned long tagger_date;
char *msg;
};
struct refinfo {
const char *refname;
struct object *object;
union {
struct taginfo *tag;
struct commitinfo *commit;
};
};
struct reflist {
struct refinfo **refs;
int alloc;
int count;
};
struct cgit_query {
int has_symref;
int has_sha1;
char *raw;
char *repo;
char *page;
char *search;
char *grep;
char *head;
char *sha1;
char *sha2;
char *path;
char *name;
char *mimetype;
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;
char *css;
char *favicon;
char *footer;
char *head_include;
char *header;
char *index_header;
char *index_info;
char *logo;
char *logo_link;
char *module_link;
char *robots;
char *root_title;
char *root_desc;
char *root_readme;
char *script_name;
char *section;
char *virtual_root;
int cache_size;
int cache_dynamic_ttl;
int cache_max_create_time;
int cache_repo_ttl;
int cache_root_ttl;
int cache_scanrc_ttl;
int cache_static_ttl;
int embedded;
int enable_filter_overrides;
int enable_index_links;
int enable_log_filecount;
int enable_log_linecount;
+ int enable_remote_branches;
int enable_tree_linenumbers;
int local_time;
int max_repo_count;
int max_commit_count;
int max_lock_attempts;
int max_msg_len;
int max_repodesc_len;
+ int max_blob_size;
int max_stats;
int nocache;
int noplainemail;
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;
};
struct cgit_page {
time_t modified;
time_t expires;
size_t size;
char *mimetype;
char *charset;
char *filename;
char *etag;
char *title;
int status;
char *statusmsg;
};
struct cgit_environment {
char *cgit_config;
char *http_host;
char *https;
char *no_http;
char *path_info;
char *query_string;
char *request_method;
char *script_name;
char *server_name;
char *server_port;
};
struct cgit_context {
struct cgit_environment env;
struct cgit_query qry;
struct cgit_config cfg;
struct cgit_repo *repo;
struct cgit_page page;
};
struct cgit_snapshot_format {
const char *suffix;
const char *mimetype;
write_archive_fn_t write_func;
int bit;
};
extern const char *cgit_version;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 0c13485..d74d9e7 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -65,290 +65,307 @@ cache-size::
The maximum number of entries in the cgit cache. Default value: "0"
(i.e. caching is disabled).
cache-static-ttl::
Number which specifies the time-to-live, in minutes, for the cached
version of repository pages accessed with a fixed SHA1. Default value:
"5".
clone-prefix::
Space-separated list of common prefixes which, when combined with a
repository url, generates valid clone urls for the repository. This
setting is only used if `repo.clone-url` is unspecified. Default value:
none.
commit-filter::
Specifies a command which will be invoked to format commit messages.
The command will get the message on its STDIN, and the STDOUT from the
command will be included verbatim as the commit message, i.e. this can
be used to implement bugtracker integration. Default value: none.
css::
Url which specifies the css document to include in all cgit pages.
Default value: "/cgit.css".
embedded::
Flag which, when set to "1", will make cgit generate a html fragment
suitable for embedding in other html pages. Default value: none. See
also: "noheader".
enable-filter-overrides::
Flag which, when set to "1", allows all filter settings to be
overridden in repository-specific cgitrc files. Default value: none.
enable-index-links::
Flag which, when set to "1", will make cgit generate extra links for
each repo in the repository index (specifically, to the "summary",
"commit" and "tree" pages). Default value: "0".
enable-log-filecount::
Flag which, when set to "1", will make cgit print the number of
modified files for each commit on the repository log page. Default
value: "0".
enable-log-linecount::
Flag which, when set to "1", will make cgit print the number of added
and removed lines for each commit on the repository log page. Default
value: "0".
+enable-remote-branches::
+ Flag which, when set to "1", will make cgit display remote branches
+ in the summary and refs views. Default value: "0". See also:
+ "repo.enable-remote-branches".
+
enable-tree-linenumbers::
Flag which, when set to "1", will make cgit generate linenumber links
for plaintext blobs printed in the tree view. Default value: "1".
favicon::
Url used as link to a shortcut icon for cgit. If specified, it is
suggested to use the value "/favicon.ico" since certain browsers will
ignore other values. Default value: none.
footer::
The content of the file specified with this option will be included
verbatim at the bottom of all pages (i.e. it replaces the standard
"generated by..." message. Default value: none.
head-include::
The content of the file specified with this option will be included
verbatim in the html HEAD section on all pages. Default value: none.
header::
The content of the file specified with this option will be included
verbatim at the top of all pages. Default value: none.
include::
Name of a configfile to include before the rest of the current config-
file is parsed. Default value: none.
index-header::
The content of the file specified with this option will be included
verbatim above the repository index. This setting is deprecated, and
will not be supported by cgit-1.0 (use root-readme instead). Default
value: none.
index-info::
The content of the file specified with this option will be included
verbatim below the heading on the repository index page. This setting
is deprecated, and will not be supported by cgit-1.0 (use root-desc
instead). Default value: none.
local-time::
Flag which, if set to "1", makes cgit print commit and tag times in the
servers timezone. Default value: "0".
logo::
Url which specifies the source of an image which will be used as a logo
on all cgit pages. Default value: "/cgit.png".
logo-link::
Url loaded when clicking on the cgit logo image. If unspecified the
calculated url of the repository index page will be used. Default
value: none.
max-commit-count::
Specifies the number of entries to list per page in "log" view. Default
value: "50".
max-message-length::
Specifies the maximum number of commit message characters to display in
"log" view. Default value: "80".
max-repo-count::
Specifies the number of entries to list per page on the repository
index page. Default value: "50".
max-repodesc-length::
Specifies the maximum number of repo description characters to display
on the repository index page. Default value: "80".
+max-blob-size::
+ Specifies the maximum size of a blob to display HTML for in KBytes.
+ Default value: "0" (limit disabled).
+
max-stats::
Set the default maximum statistics period. Valid values are "week",
"month", "quarter" and "year". If unspecified, statistics are
disabled. Default value: none. See also: "repo.max-stats".
mimetype.<ext>::
Set the mimetype for the specified filename extension. This is used
by the `plain` command when returning blob content.
module-link::
Text which will be used as the formatstring for a hyperlink when a
submodule is printed in a directory listing. The arguments for the
formatstring are the path and SHA1 of the submodule commit. Default
value: "./?repo=%s&page=commit&id=%s"
nocache::
If set to the value "1" caching will be disabled. This settings is
deprecated, and will not be honored starting with cgit-1.0. Default
value: "0".
noplainemail::
If set to "1" showing full author email adresses will be disabled.
Default value: "0".
noheader::
Flag which, when set to "1", will make cgit omit the standard header
on all pages. Default value: none. See also: "embedded".
renamelimit::
Maximum number of files to consider when detecting renames. The value
"-1" uses the compiletime value in git (for further info, look at
`man git-diff`). Default value: "-1".
repo.group::
Legacy alias for "section". This option is deprecated and will not be
supported in cgit-1.0.
robots::
Text used as content for the "robots" meta-tag. Default value:
"index, nofollow".
root-desc::
Text printed below the heading on the repository index page. Default
value: "a fast webinterface for the git dscm".
root-readme::
The content of the file specified with this option will be included
verbatim below the "about" link on the repository index page. Default
value: none.
root-title::
Text printed as heading on the repository index page. Default value:
"Git Repository Browser".
scan-path::
A path which will be scanned for repositories. If caching is enabled,
the result will be cached as a cgitrc include-file in the cache
directory. Default value: none. See also: cache-scanrc-ttl.
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::
Specifies a command which will be invoked to format plaintext blobs
in the tree view. The command will get the blob content on its STDIN
and the name of the blob as its only command line argument. The STDOUT
from the command will be included verbatim as the blob contents, i.e.
this can be used to implement e.g. syntax highlighting. Default value:
none.
summary-branches::
Specifies the number of branches to display in the repository "summary"
view. Default value: "10".
summary-log::
Specifies the number of log entries to display in the repository
"summary" view. Default value: "10".
summary-tags::
Specifies the number of tags to display in the repository "summary"
view. Default value: "10".
virtual-root::
Url which, if specified, will be used as root for all cgit links. It
will also cause cgit to generate 'virtual urls', i.e. urls like
'/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default
value: none.
NOTE: cgit has recently learned how to use PATH_INFO to achieve the
same kind of virtual urls, so this option will probably be deprecated.
REPOSITORY SETTINGS
-------------------
repo.about-filter::
Override the default about-filter. Default value: none. See also:
"enable-filter-overrides".
repo.clone-url::
A list of space-separated urls which can be used to clone this repo.
Default value: none.
repo.commit-filter::
Override the default commit-filter. Default value: none. See also:
"enable-filter-overrides".
repo.defbranch::
The name of the default branch for this repository. If no such branch
exists in the repository, the first branch name (when sorted) is used
as default instead. Default value: "master".
repo.desc::
The value to show as repository description. Default value: none.
repo.enable-log-filecount::
A flag which can be used to disable the global setting
`enable-log-filecount'. Default value: none.
repo.enable-log-linecount::
A flag which can be used to disable the global setting
`enable-log-linecount'. Default value: none.
+repo.enable-remote-branches::
+ Flag which, when set to "1", will make cgit display remote branches
+ in the summary and refs views. Default value: <enable-remote-branches>.
+
repo.max-stats::
Override the default maximum statistics period. Valid values are equal
to the values specified for the global "max-stats" setting. Default
value: none.
repo.name::
The value to show as repository name. Default value: <repo.url>.
repo.owner::
A value used to identify the owner of the repository. Default value:
none.
repo.path::
An absolute path to the repository directory. For non-bare repositories
this is the .git-directory. Default value: none.
repo.readme::
A path (relative to <repo.path>) which specifies a file to include
verbatim as the "About" page for this repo. Default value: none.
repo.snapshots::
A mask of allowed snapshot-formats for this repo, restricted by the
"snapshots" global setting. Default value: <snapshots>.
repo.section::
Override the current section name for this repository. Default value:
none.
repo.source-filter::
Override the default source-filter. Default value: none. See also:
"enable-filter-overrides".
repo.url::
The relative url used to access the repository. This must be the first
setting specified for each repo. Default value: none.
REPOSITORY-SPECIFIC CGITRC FILE
-------------------------------
When the option "scan-path" is used to auto-discover git repositories, cgit
will try to parse the file "cgitrc" within any found repository. Such a
repo-specific config file may contain any of the repo-specific options
described above, except "repo.url" and "repo.path". Additionally, the "filter"
options are only acknowledged in repo-specific config files when
"enable-filter-overrides" is set to "1".
Note: the "repo." prefix is dropped from the option names in repo-specific
config files, e.g. "repo.desc" becomes "desc".
diff --git a/filters/syntax-highlighting.sh b/filters/syntax-highlighting.sh
index 999ad0c..6b1c576 100755
--- a/filters/syntax-highlighting.sh
+++ b/filters/syntax-highlighting.sh
@@ -1,39 +1,34 @@
#!/bin/sh
# This script can be used to implement syntax highlighting in the cgit
# tree-view by refering to this file with the source-filter or repo.source-
# filter options in cgitrc.
#
+# This script requires a shell supporting the ${var##pattern} syntax.
+# It is supported by at least dash and bash, however busybox environments
+# might have to use an external call to sed instead.
+#
# Note: the highlight command (http://www.andre-simon.de/) uses css for syntax
# highlighting, so you'll probably want something like the following included
# in your css file (generated by highlight 2.4.8 and adapted for cgit):
#
# table.blob .num { color:#2928ff; }
# table.blob .esc { color:#ff00ff; }
# table.blob .str { color:#ff0000; }
# table.blob .dstr { color:#818100; }
# table.blob .slc { color:#838183; font-style:italic; }
# table.blob .com { color:#838183; font-style:italic; }
# table.blob .dir { color:#008200; }
# table.blob .sym { color:#000000; }
# table.blob .kwa { color:#000000; font-weight:bold; }
# table.blob .kwb { color:#830000; }
# table.blob .kwc { color:#000000; font-weight:bold; }
# table.blob .kwd { color:#010181; }
-case "$1" in
- *.c)
- highlight -f -I -X -S c
- ;;
- *.h)
- highlight -f -I -X -S c
- ;;
- *.sh)
- highlight -f -I -X -S sh
- ;;
- *.css)
- highlight -f -I -X -S css
- ;;
- *)
- highlight -f -I -X -S txt
- ;;
-esac
+# store filename and extension in local vars
+BASENAME="$1"
+EXTENSION="${BASENAME##*.}"
+
+# map Makefile and Makefile.* to .mk
+[ "${BASENAME%%.*}" == "Makefile" ] && EXTENSION=mk
+
+exec highlight --force -f -I -X -S $EXTENSION 2>/dev/null
diff --git a/shared.c b/shared.c
index 9362d21..5f46793 100644
--- a/shared.c
+++ b/shared.c
@@ -14,96 +14,97 @@ int cgit_cmd;
int chk_zero(int result, char *msg)
{
if (result != 0)
die("%s: %s", msg, strerror(errno));
return result;
}
int chk_positive(int result, char *msg)
{
if (result <= 0)
die("%s: %s", msg, strerror(errno));
return result;
}
int chk_non_negative(int result, char *msg)
{
if (result < 0)
die("%s: %s",msg, strerror(errno));
return result;
}
struct cgit_repo *cgit_add_repo(const char *url)
{
struct cgit_repo *ret;
if (++cgit_repolist.count > cgit_repolist.length) {
if (cgit_repolist.length == 0)
cgit_repolist.length = 8;
else
cgit_repolist.length *= 2;
cgit_repolist.repos = xrealloc(cgit_repolist.repos,
cgit_repolist.length *
sizeof(struct cgit_repo));
}
ret = &cgit_repolist.repos[cgit_repolist.count-1];
memset(ret, 0, sizeof(struct cgit_repo));
ret->url = trim_end(url, '/');
ret->name = ret->url;
ret->path = NULL;
ret->desc = "[no description]";
ret->owner = NULL;
ret->section = ctx.cfg.section;
ret->defbranch = "master";
ret->snapshots = ctx.cfg.snapshots;
ret->enable_log_filecount = ctx.cfg.enable_log_filecount;
ret->enable_log_linecount = ctx.cfg.enable_log_linecount;
+ ret->enable_remote_branches = ctx.cfg.enable_remote_branches;
ret->max_stats = ctx.cfg.max_stats;
ret->module_link = ctx.cfg.module_link;
ret->readme = NULL;
ret->mtime = -1;
ret->about_filter = ctx.cfg.about_filter;
ret->commit_filter = ctx.cfg.commit_filter;
ret->source_filter = ctx.cfg.source_filter;
return ret;
}
struct cgit_repo *cgit_get_repoinfo(const char *url)
{
int i;
struct cgit_repo *repo;
for (i=0; i<cgit_repolist.count; i++) {
repo = &cgit_repolist.repos[i];
if (!strcmp(repo->url, url))
return repo;
}
return NULL;
}
void *cgit_free_commitinfo(struct commitinfo *info)
{
free(info->author);
free(info->author_email);
free(info->committer);
free(info->committer_email);
free(info->subject);
free(info->msg);
free(info->msg_encoding);
free(info);
return NULL;
}
char *trim_end(const char *str, char c)
{
int len;
char *s, *t;
if (str == NULL)
return NULL;
t = (char *)str;
len = strlen(t);
while(len > 0 && t[len - 1] == c)
len--;
diff --git a/ui-commit.c b/ui-commit.c
index f5b0ae5..b5e3c01 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -13,106 +13,111 @@
#include "ui-log.h"
void cgit_print_commit(char *hex)
{
struct commit *commit, *parent;
struct commitinfo *info;
struct commit_list *p;
unsigned char sha1[20];
char *tmp;
int parents = 0;
if (!hex)
hex = ctx.qry.head;
if (get_sha1(hex, sha1)) {
cgit_print_error(fmt("Bad object id: %s", hex));
return;
}
commit = lookup_commit_reference(sha1);
if (!commit) {
cgit_print_error(fmt("Bad commit reference: %s", hex));
return;
}
info = cgit_parse_commit(commit);
load_ref_decorations(DECORATE_FULL_REFS);
html("<table summary='commit info' class='commit-info'>\n");
html("<tr><th>author</th><td>");
html_txt(info->author);
if (!ctx.cfg.noplainemail) {
html(" ");
html_txt(info->author_email);
}
html("</td><td class='right'>");
cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
html("</td></tr>\n");
html("<tr><th>committer</th><td>");
html_txt(info->committer);
if (!ctx.cfg.noplainemail) {
html(" ");
html_txt(info->committer_email);
}
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");
for (p = commit->parents; p ; p = p->next) {
parent = lookup_commit_reference(p->item->object.sha1);
if (!parent) {
html("<tr><td colspan='3'>");
cgit_print_error("Error reading parent commit");
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,
hex, ctx.repo->snapshots);
html("</td></tr>");
}
html("</table>\n");
html("<div class='commit-subject'>");
if (ctx.repo->commit_filter)
cgit_open_filter(ctx.repo->commit_filter);
html_txt(info->subject);
if (ctx.repo->commit_filter)
cgit_close_filter(ctx.repo->commit_filter);
show_commit_decorations(commit);
html("</div>");
html("<div class='commit-msg'>");
if (ctx.repo->commit_filter)
cgit_open_filter(ctx.repo->commit_filter);
html_txt(info->msg);
if (ctx.repo->commit_filter)
cgit_close_filter(ctx.repo->commit_filter);
html("</div>");
if (parents < 3) {
if (parents)
tmp = sha1_to_hex(commit->parents->item->object.sha1);
else
tmp = NULL;
cgit_print_diff(ctx.qry.sha1, tmp, NULL);
}
cgit_free_commitinfo(info);
}
diff --git a/ui-diff.c b/ui-diff.c
index 2196745..a92a768 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -1,313 +1,353 @@
/* ui-diff.c: show diff between two blobs
*
* Copyright (C) 2006 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
#include "html.h"
#include "ui-shared.h"
+#include "ui-ssdiff.h"
unsigned char old_rev_sha1[20];
unsigned char new_rev_sha1[20];
static int files, slots;
static int total_adds, total_rems, max_changes;
static int lines_added, lines_removed;
static struct fileinfo {
char status;
unsigned char old_sha1[20];
unsigned char new_sha1[20];
unsigned short old_mode;
unsigned short new_mode;
char *old_path;
char *new_path;
unsigned int added;
unsigned int removed;
unsigned long old_size;
unsigned long new_size;
int binary:1;
} *items;
+static int use_ssdiff = 0;
static void print_fileinfo(struct fileinfo *info)
{
char *class;
switch (info->status) {
case DIFF_STATUS_ADDED:
class = "add";
break;
case DIFF_STATUS_COPIED:
class = "cpy";
break;
case DIFF_STATUS_DELETED:
class = "del";
break;
case DIFF_STATUS_MODIFIED:
class = "upd";
break;
case DIFF_STATUS_RENAMED:
class = "mov";
break;
case DIFF_STATUS_TYPE_CHANGED:
class = "typ";
break;
case DIFF_STATUS_UNKNOWN:
class = "unk";
break;
case DIFF_STATUS_UNMERGED:
class = "stg";
break;
default:
die("bug: unhandled diff status %c", info->status);
}
html("<tr>");
htmlf("<td class='mode'>");
if (is_null_sha1(info->new_sha1)) {
cgit_print_filemode(info->old_mode);
} else {
cgit_print_filemode(info->new_mode);
}
if (info->old_mode != info->new_mode &&
!is_null_sha1(info->old_sha1) &&
!is_null_sha1(info->new_sha1)) {
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) {
htmlf("bin</td><td class='graph'>%d -> %d bytes",
info->old_size, info->new_size);
return;
}
htmlf("%d", info->added + info->removed);
html("</td><td class='graph'>");
htmlf("<table summary='file diffstat' width='%d%%'><tr>", (max_changes > 100 ? 100 : max_changes));
htmlf("<td class='add' style='width: %.1f%%;'/>",
info->added * 100.0 / max_changes);
htmlf("<td class='rem' style='width: %.1f%%;'/>",
info->removed * 100.0 / max_changes);
htmlf("<td class='none' style='width: %.1f%%;'/>",
(max_changes - info->removed - info->added) * 100.0 / max_changes);
html("</tr></table></td></tr>\n");
}
static void count_diff_lines(char *line, int len)
{
if (line && (len > 0)) {
if (line[0] == '+')
lines_added++;
else if (line[0] == '-')
lines_removed++;
}
}
static void inspect_filepair(struct diff_filepair *pair)
{
int binary = 0;
unsigned long old_size = 0;
unsigned long new_size = 0;
files++;
lines_added = 0;
lines_removed = 0;
cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, &new_size,
&binary, count_diff_lines);
if (files >= slots) {
if (slots == 0)
slots = 4;
else
slots = slots * 2;
items = xrealloc(items, slots * sizeof(struct fileinfo));
}
items[files-1].status = pair->status;
hashcpy(items[files-1].old_sha1, pair->one->sha1);
hashcpy(items[files-1].new_sha1, pair->two->sha1);
items[files-1].old_mode = pair->one->mode;
items[files-1].new_mode = pair->two->mode;
items[files-1].old_path = xstrdup(pair->one->path);
items[files-1].new_path = xstrdup(pair->two->path);
items[files-1].added = lines_added;
items[files-1].removed = lines_removed;
items[files-1].old_size = old_size;
items[files-1].new_size = new_size;
items[files-1].binary = binary;
if (lines_added + lines_removed > max_changes)
max_changes = lines_added + lines_removed;
total_adds += lines_added;
total_rems += lines_removed;
}
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]);
html("</table>");
html("<div class='diffstat-summary'>");
htmlf("%d files changed, %d insertions, %d deletions",
files, total_adds, total_rems);
html("</div>");
}
/*
* print a single line returned from xdiff
*/
static void print_line(char *line, int len)
{
char *class = "ctx";
char c = line[len-1];
if (line[0] == '+')
class = "add";
else if (line[0] == '-')
class = "del";
else if (line[0] == '@')
class = "hunk";
htmlf("<div class='%s'>", class);
line[len-1] = '\0';
html_txt(line);
html("</div>");
line[len-1] = c;
}
static void header(unsigned char *sha1, char *path1, int mode1,
unsigned char *sha2, char *path2, int mode2)
{
char *abbrev1, *abbrev2;
int subproject;
subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2));
html("<div class='head'>");
html("diff --git a/");
html_txt(path1);
html(" b/");
html_txt(path2);
if (is_null_sha1(sha1))
path1 = "dev/null";
if (is_null_sha1(sha2))
path2 = "dev/null";
if (mode1 == 0)
htmlf("<br/>new file mode %.6o", mode2);
if (mode2 == 0)
htmlf("<br/>deleted file mode %.6o", mode1);
if (!subproject) {
abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV));
htmlf("<br/>index %s..%s", abbrev1, abbrev2);
free(abbrev1);
free(abbrev2);
if (mode1 != 0 && mode2 != 0) {
htmlf(" %.6o", mode1);
if (mode2 != mode1)
htmlf("..%.6o", mode2);
}
html("<br/>--- a/");
if (mode1 != 0)
cgit_tree_link(path1, NULL, NULL, ctx.qry.head,
sha1_to_hex(old_rev_sha1), path1);
else
html_txt(path1);
html("<br/>+++ b/");
if (mode2 != 0)
cgit_tree_link(path2, NULL, NULL, ctx.qry.head,
sha1_to_hex(new_rev_sha1), path2);
else
html_txt(path2);
}
html("</div>");
}
+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, ctx.qry.path, 1);
+ else
+ cgit_diff_link("Side-by-side diff", NULL, NULL,
+ ctx.qry.head, ctx.qry.sha1,
+ ctx.qry.sha2, ctx.qry.path, 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;
+ if (use_ssdiff) {
+ cgit_ssdiff_header_begin();
+ print_line_fn = cgit_ssdiff_line_cb;
+ }
header(pair->one->sha1, pair->one->path, pair->one->mode,
pair->two->sha1, pair->two->path, pair->two->mode);
+ if (use_ssdiff)
+ cgit_ssdiff_header_end();
if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
if (S_ISGITLINK(pair->one->mode))
- print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
+ print_line_fn(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
if (S_ISGITLINK(pair->two->mode))
- print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
+ print_line_fn(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
+ if (use_ssdiff)
+ cgit_ssdiff_footer();
return;
}
- if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
- &new_size, &binary, print_line))
+ if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
+ &new_size, &binary, print_line_fn))
cgit_print_error("Error running diff");
- if (binary)
- html("Binary files differ");
+ if (binary) {
+ if (use_ssdiff)
+ html("<tr><td colspan='4'>Binary files differ</td></tr>");
+ else
+ html("Binary files differ");
+ }
+ if (use_ssdiff)
+ cgit_ssdiff_footer();
}
void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefix)
{
enum object_type type;
unsigned long size;
struct commit *commit, *commit2;
if (!new_rev)
new_rev = ctx.qry.head;
get_sha1(new_rev, new_rev_sha1);
type = sha1_object_info(new_rev_sha1, &size);
if (type == OBJ_BAD) {
cgit_print_error(fmt("Bad object name: %s", new_rev));
return;
}
commit = lookup_commit_reference(new_rev_sha1);
if (!commit || parse_commit(commit))
cgit_print_error(fmt("Bad commit: %s", sha1_to_hex(new_rev_sha1)));
if (old_rev)
get_sha1(old_rev, old_rev_sha1);
else if (commit->parents && commit->parents->item)
hashcpy(old_rev_sha1, commit->parents->item->object.sha1);
else
hashclr(old_rev_sha1);
if (!is_null_sha1(old_rev_sha1)) {
type = sha1_object_info(old_rev_sha1, &size);
if (type == OBJ_BAD) {
cgit_print_error(fmt("Bad object name: %s", sha1_to_hex(old_rev_sha1)));
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>");
+ if (use_ssdiff) {
+ html("<table summary='ssdiff' class='ssdiff'>");
+ } else {
+ html("<table summary='diff' class='diff'>");
+ html("<tr><td>");
+ }
cgit_diff_tree(old_rev_sha1, new_rev_sha1, filepair_cb, prefix);
- html("</td></tr>");
+ if (!use_ssdiff)
+ html("</td></tr>");
html("</table>");
}
diff --git a/ui-log.c b/ui-log.c
index f3132c9..0947604 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -21,120 +21,120 @@ void count_lines(char *line, int size)
add_lines++;
else if (line[0] == '-')
rem_lines++;
}
void inspect_files(struct diff_filepair *pair)
{
unsigned long old_size = 0;
unsigned long new_size = 0;
int binary = 0;
files++;
if (ctx.repo->enable_log_linecount)
cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
&new_size, &binary, count_lines);
}
void show_commit_decorations(struct commit *commit)
{
struct name_decoration *deco;
static char buf[1024];
buf[sizeof(buf) - 1] = 0;
deco = lookup_decoration(&name_decoration, &commit->object);
while (deco) {
if (!prefixcmp(deco->name, "refs/heads/")) {
strncpy(buf, deco->name + 11, sizeof(buf) - 1);
cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL,
0, NULL, NULL, ctx.qry.showmsg);
}
else if (!prefixcmp(deco->name, "tag: refs/tags/")) {
strncpy(buf, deco->name + 15, sizeof(buf) - 1);
cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
}
else if (!prefixcmp(deco->name, "refs/tags/")) {
strncpy(buf, deco->name + 10, sizeof(buf) - 1);
cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
}
else if (!prefixcmp(deco->name, "refs/remotes/")) {
strncpy(buf, deco->name + 13, sizeof(buf) - 1);
cgit_log_link(buf, NULL, "remote-deco", NULL,
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)
{
struct commitinfo *info;
char *tmp;
int cols = 2;
info = cgit_parse_commit(commit);
htmlf("<tr%s><td>",
ctx.qry.showmsg ? " class='logheader'" : "");
tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
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;
rem_lines = 0;
cgit_diff_commit(commit, inspect_files);
html("</td><td>");
htmlf("%d", files);
if (ctx.repo->enable_log_linecount) {
html("</td><td>");
htmlf("-%d/+%d", rem_lines, add_lines);
}
}
html("</td></tr>\n");
if (ctx.qry.showmsg) {
if (ctx.repo->enable_log_filecount) {
cols++;
if (ctx.repo->enable_log_linecount)
cols++;
}
htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
cols);
html_txt(info->msg);
html("</td></tr>\n");
}
cgit_free_commitinfo(info);
}
static const char *disambiguate_ref(const char *ref)
{
unsigned char sha1[20];
const char *longref;
longref = fmt("refs/heads/%s", ref);
if (get_sha1(longref, sha1) == 0)
return longref;
return ref;
}
void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
char *path, int pager)
{
struct rev_info rev;
struct commit *commit;
const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
diff --git a/ui-refs.c b/ui-refs.c
index d3b4f6e..98738db 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -29,97 +29,97 @@ static int cmp_age(int age1, int age2)
static int cmp_ref_name(const void *a, const void *b)
{
struct refinfo *r1 = *(struct refinfo **)a;
struct refinfo *r2 = *(struct refinfo **)b;
return strcmp(r1->refname, r2->refname);
}
static int cmp_branch_age(const void *a, const void *b)
{
struct refinfo *r1 = *(struct refinfo **)a;
struct refinfo *r2 = *(struct refinfo **)b;
return cmp_age(r1->commit->committer_date, r2->commit->committer_date);
}
static int cmp_tag_age(const void *a, const void *b)
{
struct refinfo *r1 = *(struct refinfo **)a;
struct refinfo *r2 = *(struct refinfo **)b;
int r1date, r2date;
if (r1->object->type != OBJ_COMMIT)
r1date = r1->tag->tagger_date;
else
r1date = r1->commit->committer_date;
if (r2->object->type != OBJ_COMMIT)
r2date = r2->tag->tagger_date;
else
r2date = r2->commit->committer_date;
return cmp_age(r1date, r2date);
}
static int print_branch(struct refinfo *ref)
{
struct commitinfo *info = ref->commit;
char *name = (char *)ref->refname;
if (!info)
return 1;
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>");
cgit_object_link(ref->object);
}
html("</td></tr>\n");
return 0;
}
static void print_tag_header()
{
html("<tr class='nohover'><th class='left'>Tag</th>"
"<th class='left'>Download</th>"
"<th class='left'>Author</th>"
"<th class='left' colspan='2'>Age</th></tr>\n");
header = 1;
}
static void print_tag_downloads(const struct cgit_repo *repo, const char *ref)
{
const struct cgit_snapshot_format* f;
char *filename;
const char *basename;
if (!ref || strlen(ref) < 2)
return;
basename = cgit_repobasename(repo->url);
if (prefixcmp(ref, basename) != 0) {
if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]))
ref++;
if (isdigit(ref[0]))
ref = xstrdup(fmt("%s-%s", basename, ref));
}
for (f = cgit_snapshot_formats; f->suffix; f++) {
if (!(repo->snapshots & f->bit))
continue;
filename = fmt("%s%s", ref, f->suffix);
cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
html("&nbsp;&nbsp;");
}
}
static int print_tag(struct refinfo *ref)
{
@@ -142,96 +142,98 @@ static int print_tag(struct refinfo *ref)
html("</td><td>");
if (info->tagger)
html(info->tagger);
html("</td><td colspan='2'>");
if (info->tagger_date > 0)
cgit_print_age(info->tagger_date, -1, NULL);
html("</td></tr>\n");
} else {
if (!header)
print_tag_header();
html("<tr><td>");
cgit_tag_link(name, NULL, NULL, ctx.qry.head, name);
html("</td><td>");
if (ctx.repo->snapshots && (ref->object->type == OBJ_COMMIT))
print_tag_downloads(ctx.repo, name);
else
cgit_object_link(ref->object);
html("</td><td>");
if (ref->object->type == OBJ_COMMIT)
html(ref->commit->author);
html("</td><td colspan='2'>");
if (ref->object->type == OBJ_COMMIT)
cgit_print_age(ref->commit->commit->date, -1, NULL);
html("</td></tr>\n");
}
return 0;
}
static void print_refs_link(char *path)
{
html("<tr class='nohover'><td colspan='4'>");
cgit_refs_link("[...]", NULL, NULL, ctx.qry.head, NULL, path);
html("</td></tr>");
}
void cgit_print_branches(int maxcount)
{
struct reflist list;
int i;
html("<tr class='nohover'><th class='left'>Branch</th>"
"<th class='left'>Commit message</th>"
"<th class='left'>Author</th>"
"<th class='left' colspan='2'>Age</th></tr>\n");
list.refs = NULL;
list.alloc = list.count = 0;
for_each_branch_ref(cgit_refs_cb, &list);
+ if (ctx.repo->enable_remote_branches)
+ for_each_remote_ref(cgit_refs_cb, &list);
if (maxcount == 0 || maxcount > list.count)
maxcount = list.count;
if (maxcount < list.count) {
qsort(list.refs, list.count, sizeof(*list.refs), cmp_branch_age);
qsort(list.refs, maxcount, sizeof(*list.refs), cmp_ref_name);
}
for(i=0; i<maxcount; i++)
print_branch(list.refs[i]);
if (maxcount < list.count)
print_refs_link("heads");
}
void cgit_print_tags(int maxcount)
{
struct reflist list;
int i;
header = 0;
list.refs = NULL;
list.alloc = list.count = 0;
for_each_tag_ref(cgit_refs_cb, &list);
if (list.count == 0)
return;
qsort(list.refs, list.count, sizeof(*list.refs), cmp_tag_age);
if (!maxcount)
maxcount = list.count;
else if (maxcount > list.count)
maxcount = list.count;
print_tag_header();
for(i=0; i<maxcount; i++)
print_tag(list.refs[i]);
if (maxcount < list.count)
print_refs_link("tags");
}
void cgit_print_refs()
{
html("<table class='list nowrap'>");
if (ctx.qry.path && !strncmp(ctx.qry.path, "heads", 5))
cgit_print_branches(0);
else if (ctx.qry.path && !strncmp(ctx.qry.path, "tags", 4))
diff --git a/ui-shared.c b/ui-shared.c
index 4049a2b..08ea003 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -272,163 +272,185 @@ void cgit_tree_link(char *name, char *title, char *class, char *head,
{
reporevlink("tree", name, title, class, head, rev, path);
}
void cgit_plain_link(char *name, char *title, char *class, char *head,
char *rev, char *path)
{
reporevlink("plain", name, title, class, head, rev, path);
}
void cgit_log_link(char *name, char *title, char *class, char *head,
char *rev, char *path, int ofs, char *grep, char *pattern,
int showmsg)
{
char *delim;
delim = repolink(title, class, "log", head, path);
if (rev && strcmp(rev, ctx.qry.head)) {
html(delim);
html("id=");
html_url_arg(rev);
delim = "&";
}
if (grep && pattern) {
html(delim);
html("qt=");
html_url_arg(grep);
delim = "&";
html(delim);
html("q=");
html_url_arg(pattern);
}
if (ofs > 0) {
html(delim);
html("ofs=");
htmlf("%d", ofs);
delim = "&";
}
if (showmsg) {
html(delim);
html("showmsg=1");
}
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);
}
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);
html("id=");
html_url_arg(new_rev);
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>");
}
void cgit_patch_link(char *name, char *title, char *class, char *head,
char *rev)
{
reporevlink("patch", name, title, class, head, rev, NULL);
}
void cgit_stats_link(char *name, char *title, char *class, char *head,
char *path)
{
reporevlink("stats", name, title, class, head, NULL, path);
}
void cgit_object_link(struct object *obj)
{
char *page, *shortrev, *fullrev, *name;
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
page = "blob";
name = fmt("%s %s...", typename(obj->type), shortrev);
reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
}
void cgit_print_date(time_t secs, char *format, int local_time)
{
char buf[64];
struct tm *time;
if (!secs)
return;
if(local_time)
time = localtime(&secs);
else
time = gmtime(&secs);
strftime(buf, sizeof(buf)-1, format, time);
html_txt(buf);
}
void cgit_print_age(time_t t, time_t max_relative, char *format)
{
time_t now, secs;
if (!t)
return;
time(&now);
secs = now - t;
if (secs > max_relative && max_relative >= 0) {
cgit_print_date(t, format, ctx.cfg.local_time);
return;
}
if (secs < TM_HOUR * 2) {
htmlf("<span class='age-mins'>%.0f min.</span>",
secs * 1.0 / TM_MIN);
return;
}
if (secs < TM_DAY * 2) {
htmlf("<span class='age-hours'>%.0f hours</span>",
secs * 1.0 / TM_HOUR);
@@ -650,124 +672,129 @@ static void print_header(struct cgit_context *ctx)
html("</td><td class='form'>");
html("<form method='get' action=''>\n");
cgit_add_hidden_formfields(0, 1, ctx->qry.page);
html("<select name='h' onchange='this.form.submit();'>\n");
for_each_branch_ref(print_branch_option, ctx->qry.head);
html("</select> ");
html("<input type='submit' name='' value='switch'/>");
html("</form>");
} else
html_txt(ctx->cfg.root_title);
html("</td></tr>\n");
html("<tr><td class='sub'>");
if (ctx->repo) {
html_txt(ctx->repo->desc);
html("</td><td class='sub right'>");
html_txt(ctx->repo->owner);
} else {
if (ctx->cfg.root_desc)
html_txt(ctx->cfg.root_desc);
else if (ctx->cfg.index_info)
html_include(ctx->cfg.index_info);
}
html("</td></tr></table>\n");
}
void cgit_print_pageheader(struct cgit_context *ctx)
{
struct cgit_cmd *cmd = cgit_get_cmd(ctx);
if (!cmd && ctx->repo)
fallback_cmd = "summary";
html("<div id='cgit'>");
if (!ctx->cfg.noheader)
print_header(ctx);
html("<table class='tabs'><tr><td>\n");
if (ctx->repo) {
cgit_summary_link("summary", NULL, hc(cmd, "summary"),
ctx->qry.head);
cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head,
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,
NULL);
html("</td><td class='form'>");
html("<form class='right' method='get' action='");
if (ctx->cfg.virtual_root)
html_url_path(cgit_fileurl(ctx->qry.repo, "log",
ctx->qry.path, NULL));
html("'>\n");
cgit_add_hidden_formfields(1, 0, "log");
html("<select name='qt'>\n");
html_option("grep", "log msg", ctx->qry.grep);
html_option("author", "author", ctx->qry.grep);
html_option("committer", "committer", ctx->qry.grep);
html("</select>\n");
html("<input class='txt' type='text' size='10' name='q' value='");
html_attr(ctx->qry.search);
html("'/>\n");
html("<input type='submit' value='search'/>\n");
html("</form>\n");
} else {
site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
if (ctx->cfg.root_readme)
site_link("about", "about", NULL, hc(cmd, "about"),
NULL, 0);
html("</td><td class='form'>");
html("<form method='get' action='");
html_attr(cgit_rooturl());
html("'>\n");
html("<input type='text' name='q' size='10' value='");
html_attr(ctx->qry.search);
html("'/>\n");
html("<input type='submit' value='search'/>\n");
html("</form>");
}
html("</td></tr></table>\n");
html("<div class='content'>");
}
void cgit_print_filemode(unsigned short mode)
{
if (S_ISDIR(mode))
html("d");
else if (S_ISLNK(mode))
html("l");
else if (S_ISGITLINK(mode))
html("m");
else
html("-");
html_fileperm(mode >> 6);
html_fileperm(mode >> 3);
html_fileperm(mode);
}
void cgit_print_snapshot_links(const char *repo, const char *head,
const char *hex, int snapshots)
{
const struct cgit_snapshot_format* f;
+ char *prefix;
char *filename;
+ unsigned char sha1[20];
+ if (get_sha1(fmt("refs/tags/%s", hex), sha1) == 0 &&
+ (hex[0] == 'v' || hex[0] == 'V') && isdigit(hex[1]))
+ hex++;
+ prefix = xstrdup(fmt("%s-%s", cgit_repobasename(repo), hex));
for (f = cgit_snapshot_formats; f->suffix; f++) {
if (!(snapshots & f->bit))
continue;
- filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
- f->suffix);
+ filename = fmt("%s%s", prefix, f->suffix);
cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
html("<br/>");
}
}
diff --git a/ui-shared.h b/ui-shared.h
index b12aa89..9ebc1f9 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -1,51 +1,52 @@
#ifndef UI_SHARED_H
#define UI_SHARED_H
extern char *cgit_httpscheme();
extern char *cgit_hosturl();
extern char *cgit_rooturl();
extern char *cgit_repourl(const char *reponame);
extern char *cgit_fileurl(const char *reponame, const char *pagename,
const char *filename, const char *query);
extern char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query);
extern void cgit_index_link(char *name, char *title, char *class,
char *pattern, int ofs);
extern void cgit_summary_link(char *name, char *title, char *class, char *head);
extern void cgit_tag_link(char *name, char *title, char *class, char *head,
char *rev);
extern void cgit_tree_link(char *name, char *title, char *class, char *head,
char *rev, char *path);
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);
extern void cgit_print_age(time_t t, time_t max_relative, char *format);
extern void cgit_print_http_headers(struct cgit_context *ctx);
extern void cgit_print_docstart(struct cgit_context *ctx);
extern void cgit_print_docend();
extern void cgit_print_pageheader(struct cgit_context *ctx);
extern void cgit_print_filemode(unsigned short mode);
extern void cgit_print_snapshot_links(const char *repo, const char *head,
const char *hex, int snapshots);
extern void cgit_add_hidden_formfields(int incl_head, int incl_search,
char *page);
#endif /* UI_SHARED_H */
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 4136b3e..1b25dca 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -1,90 +1,96 @@
/* ui-snapshot.c: generate snapshot of a commit
*
* Copyright (C) 2006 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
#include "html.h"
#include "ui-shared.h"
static int write_compressed_tar_archive(struct archiver_args *args,const char *filter)
{
int rv;
struct cgit_filter f;
f.cmd = xstrdup(filter);
f.argv = malloc(2 * sizeof(char *));
f.argv[0] = f.cmd;
f.argv[1] = NULL;
cgit_open_filter(&f);
rv = write_tar_archive(args);
cgit_close_filter(&f);
return rv;
}
static int write_tar_gzip_archive(struct archiver_args *args)
{
return write_compressed_tar_archive(args,"gzip");
}
static int write_tar_bzip2_archive(struct archiver_args *args)
{
return write_compressed_tar_archive(args,"bzip2");
}
+static int write_tar_xz_archive(struct archiver_args *args)
+{
+ return write_compressed_tar_archive(args,"xz");
+}
+
const struct cgit_snapshot_format cgit_snapshot_formats[] = {
- { ".zip", "application/x-zip", write_zip_archive, 0x1 },
- { ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x2 },
- { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x4 },
- { ".tar", "application/x-tar", write_tar_archive, 0x8 },
+ { ".zip", "application/x-zip", write_zip_archive, 0x01 },
+ { ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x02 },
+ { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x04 },
+ { ".tar", "application/x-tar", write_tar_archive, 0x08 },
+ { ".tar.xz", "application/x-xz", write_tar_xz_archive, 0x10 },
{}
};
static const struct cgit_snapshot_format *get_format(const char *filename)
{
const struct cgit_snapshot_format *fmt;
int fl, sl;
fl = strlen(filename);
for(fmt = cgit_snapshot_formats; fmt->suffix; fmt++) {
sl = strlen(fmt->suffix);
if (sl >= fl)
continue;
if (!strcmp(fmt->suffix, filename + fl - sl))
return fmt;
}
return NULL;
}
static int make_snapshot(const struct cgit_snapshot_format *format,
const char *hex, const char *prefix,
const char *filename)
{
struct archiver_args args;
struct commit *commit;
unsigned char sha1[20];
if(get_sha1(hex, sha1)) {
cgit_print_error(fmt("Bad object id: %s", hex));
return 1;
}
commit = lookup_commit_reference(sha1);
if(!commit) {
cgit_print_error(fmt("Not a commit reference: %s", hex));
return 1;
}
memset(&args, 0, sizeof(args));
if (prefix) {
args.base = fmt("%s/", prefix);
args.baselen = strlen(prefix) + 1;
} else {
args.base = "";
args.baselen = 0;
}
args.tree = commit->tree;
args.time = commit->date;
ctx.page.mimetype = xstrdup(format->mimetype);
ctx.page.filename = xstrdup(filename);
diff --git a/ui-ssdiff.c b/ui-ssdiff.c
new file mode 100644
index 0000000..408e620
--- a/dev/null
+++ b/ui-ssdiff.c
@@ -0,0 +1,369 @@
+#include "cgit.h"
+#include "html.h"
+#include "ui-shared.h"
+
+extern int use_ssdiff;
+
+static int current_old_line, current_new_line;
+
+struct deferred_lines {
+ int line_no;
+ char *line;
+ struct deferred_lines *next;
+};
+
+static struct deferred_lines *deferred_old, *deferred_old_last;
+static struct deferred_lines *deferred_new, *deferred_new_last;
+
+static char *longest_common_subsequence(char *A, char *B)
+{
+ int i, j, ri;
+ int m = strlen(A);
+ int n = strlen(B);
+ int L[m + 1][n + 1];
+ int tmp1, tmp2;
+ int lcs_length;
+ char *result;
+
+ for (i = m; i >= 0; i--) {
+ for (j = n; j >= 0; j--) {
+ if (A[i] == '\0' || B[j] == '\0') {
+ L[i][j] = 0;
+ } else if (A[i] == B[j]) {
+ L[i][j] = 1 + L[i + 1][j + 1];
+ } else {
+ tmp1 = L[i + 1][j];
+ tmp2 = L[i][j + 1];
+ L[i][j] = (tmp1 > tmp2 ? tmp1 : tmp2);
+ }
+ }
+ }
+
+ lcs_length = L[0][0];
+ result = xmalloc(lcs_length + 2);
+ memset(result, 0, sizeof(*result) * (lcs_length + 2));
+
+ ri = 0;
+ i = 0;
+ j = 0;
+ while (i < m && j < n) {
+ if (A[i] == B[j]) {
+ result[ri] = A[i];
+ ri += 1;
+ i += 1;
+ j += 1;
+ } else if (L[i + 1][j] >= L[i][j + 1]) {
+ i += 1;
+ } else {
+ j += 1;
+ }
+ }
+ return result;
+}
+
+static int line_from_hunk(char *line, char type)
+{
+ char *buf1, *buf2;
+ int len;
+
+ buf1 = strchr(line, type);
+ if (buf1 == NULL)
+ return 0;
+ buf1 += 1;
+ buf2 = strchr(buf1, ',');
+ if (buf2 == NULL)
+ return 0;
+ len = buf2 - buf1;
+ buf2 = xmalloc(len + 1);
+ strncpy(buf2, buf1, len);
+ buf2[len] = '\0';
+ int res = atoi(buf2);
+ free(buf2);
+ return res;
+}
+
+static char *replace_tabs(char *line)
+{
+ char *prev_buf = line;
+ char *cur_buf;
+ int linelen = strlen(line);
+ int n_tabs = 0;
+ int i;
+ char *result;
+ char *spaces = " ";
+
+ if (linelen == 0) {
+ result = xmalloc(1);
+ result[0] = '\0';
+ return result;
+ }
+
+ for (i = 0; i < linelen; i++)
+ if (line[i] == '\t')
+ n_tabs += 1;
+ result = xmalloc(linelen + n_tabs * 8 + 1);
+ result[0] = '\0';
+
+ while (1) {
+ cur_buf = strchr(prev_buf, '\t');
+ if (!cur_buf) {
+ strcat(result, prev_buf);
+ break;
+ } else {
+ strcat(result, " ");
+ strncat(result, spaces, 8 - (strlen(result) % 8));
+ strncat(result, prev_buf, cur_buf - prev_buf);
+ }
+ prev_buf = cur_buf + 1;
+ }
+ return result;
+}
+
+static int calc_deferred_lines(struct deferred_lines *start)
+{
+ struct deferred_lines *item = start;
+ int result = 0;
+ while (item) {
+ result += 1;
+ item = item->next;
+ }
+ return result;
+}
+
+static void deferred_old_add(char *line, int line_no)
+{
+ struct deferred_lines *item = xmalloc(sizeof(struct deferred_lines));
+ item->line = xstrdup(line);
+ item->line_no = line_no;
+ item->next = NULL;
+ if (deferred_old) {
+ deferred_old_last->next = item;
+ deferred_old_last = item;
+ } else {
+ deferred_old = deferred_old_last = item;
+ }
+}
+
+static void deferred_new_add(char *line, int line_no)
+{
+ struct deferred_lines *item = xmalloc(sizeof(struct deferred_lines));
+ item->line = xstrdup(line);
+ item->line_no = line_no;
+ item->next = NULL;
+ if (deferred_new) {
+ deferred_new_last->next = item;
+ deferred_new_last = item;
+ } else {
+ deferred_new = deferred_new_last = item;
+ }
+}
+
+static void print_part_with_lcs(char *class, char *line, char *lcs)
+{
+ int line_len = strlen(line);
+ int i, j;
+ char c[2] = " ";
+ int same = 1;
+
+ j = 0;
+ for (i = 0; i < line_len; i++) {
+ c[0] = line[i];
+ if (same) {
+ if (line[i] == lcs[j])
+ j += 1;
+ else {
+ same = 0;
+ htmlf("<span class='%s'>", class);
+ }
+ } else if (line[i] == lcs[j]) {
+ same = 1;
+ htmlf("</span>");
+ j += 1;
+ }
+ html_txt(c);
+ }
+}
+
+static void print_ssdiff_line(char *class,
+ int old_line_no,
+ char *old_line,
+ int new_line_no,
+ char *new_line, int individual_chars)
+{
+ char *lcs = NULL;
+ if (old_line)
+ old_line = replace_tabs(old_line + 1);
+ if (new_line)
+ new_line = replace_tabs(new_line + 1);
+ if (individual_chars && old_line && new_line)
+ lcs = longest_common_subsequence(old_line, new_line);
+ html("<tr>");
+ if (old_line_no > 0)
+ htmlf("<td class='lineno'>%d</td><td class='%s'>",
+ old_line_no, class);
+ else if (old_line)
+ htmlf("<td class='lineno'></td><td class='%s'>", class);
+ else
+ htmlf("<td class='lineno'></td><td class='%s_dark'>", class);
+ if (old_line) {
+ if (lcs)
+ print_part_with_lcs("del", old_line, lcs);
+ else
+ html_txt(old_line);
+ }
+
+ html("</td>");
+ if (new_line_no > 0)
+ htmlf("<td class='lineno'>%d</td><td class='%s'>",
+ new_line_no, class);
+ else if (new_line)
+ htmlf("<td class='lineno'></td><td class='%s'>", class);
+ else
+ htmlf("<td class='lineno'></td><td class='%s_dark'>", class);
+ if (new_line) {
+ if (lcs)
+ print_part_with_lcs("add", new_line, lcs);
+ else
+ html_txt(new_line);
+ }
+
+ html("</td></tr>");
+ if (lcs)
+ free(lcs);
+ if (new_line)
+ free(new_line);
+ if (old_line)
+ free(old_line);
+}
+
+static void print_deferred_old_lines()
+{
+ struct deferred_lines *iter_old, *tmp;
+ iter_old = deferred_old;
+ while (iter_old) {
+ print_ssdiff_line("del", iter_old->line_no,
+ iter_old->line, -1, NULL, 0);
+ tmp = iter_old->next;
+ free(iter_old);
+ iter_old = tmp;
+ }
+}
+
+static void print_deferred_new_lines()
+{
+ struct deferred_lines *iter_new, *tmp;
+ iter_new = deferred_new;
+ while (iter_new) {
+ print_ssdiff_line("add", -1, NULL,
+ iter_new->line_no, iter_new->line, 0);
+ tmp = iter_new->next;
+ free(iter_new);
+ iter_new = tmp;
+ }
+}
+
+static void print_deferred_changed_lines()
+{
+ struct deferred_lines *iter_old, *iter_new, *tmp;
+ int n_old_lines = calc_deferred_lines(deferred_old);
+ int n_new_lines = calc_deferred_lines(deferred_new);
+ int individual_chars = (n_old_lines == n_new_lines ? 1 : 0);
+
+ iter_old = deferred_old;
+ iter_new = deferred_new;
+ while (iter_old || iter_new) {
+ if (iter_old && iter_new)
+ print_ssdiff_line("changed", iter_old->line_no,
+ iter_old->line,
+ iter_new->line_no, iter_new->line,
+ individual_chars);
+ else if (iter_old)
+ print_ssdiff_line("changed", iter_old->line_no,
+ iter_old->line, -1, NULL, 0);
+ else if (iter_new)
+ print_ssdiff_line("changed", -1, NULL,
+ iter_new->line_no, iter_new->line, 0);
+ if (iter_old) {
+ tmp = iter_old->next;
+ free(iter_old);
+ iter_old = tmp;
+ }
+
+ if (iter_new) {
+ tmp = iter_new->next;
+ free(iter_new);
+ iter_new = tmp;
+ }
+ }
+}
+
+void cgit_ssdiff_print_deferred_lines()
+{
+ if (!deferred_old && !deferred_new)
+ return;
+ if (deferred_old && !deferred_new)
+ print_deferred_old_lines();
+ else if (!deferred_old && deferred_new)
+ print_deferred_new_lines();
+ else
+ print_deferred_changed_lines();
+ deferred_old = deferred_old_last = NULL;
+ deferred_new = deferred_new_last = NULL;
+}
+
+/*
+ * print a single line returned from xdiff
+ */
+void cgit_ssdiff_line_cb(char *line, int len)
+{
+ char c = line[len - 1];
+ line[len - 1] = '\0';
+ if (line[0] == '@') {
+ current_old_line = line_from_hunk(line, '-');
+ current_new_line = line_from_hunk(line, '+');
+ }
+
+ if (line[0] == ' ') {
+ if (deferred_old || deferred_new)
+ cgit_ssdiff_print_deferred_lines();
+ print_ssdiff_line("ctx", current_old_line, line,
+ current_new_line, line, 0);
+ current_old_line += 1;
+ current_new_line += 1;
+ } else if (line[0] == '+') {
+ deferred_new_add(line, current_new_line);
+ current_new_line += 1;
+ } else if (line[0] == '-') {
+ deferred_old_add(line, current_old_line);
+ current_old_line += 1;
+ } else if (line[0] == '@') {
+ html("<tr><td colspan='4' class='hunk'>");
+ html_txt(line);
+ html("</td></tr>");
+ } else {
+ html("<tr><td colspan='4' class='ctx'>");
+ html_txt(line);
+ html("</td></tr>");
+ }
+ line[len - 1] = c;
+}
+
+void cgit_ssdiff_header_begin()
+{
+ current_old_line = -1;
+ current_new_line = -1;
+ html("<tr><td class='space' colspan='4'><div></div></td></tr>");
+ html("<tr><td class='head' colspan='4'>");
+}
+
+void cgit_ssdiff_header_end()
+{
+ html("</td><tr>");
+}
+
+void cgit_ssdiff_footer()
+{
+ if (deferred_old || deferred_new)
+ cgit_ssdiff_print_deferred_lines();
+ html("<tr><td class='foot' colspan='4'></td></tr>");
+}
diff --git a/ui-ssdiff.h b/ui-ssdiff.h
new file mode 100644
index 0000000..64b4b12
--- a/dev/null
+++ b/ui-ssdiff.h
@@ -0,0 +1,13 @@
+#ifndef UI_SSDIFF_H
+#define UI_SSDIFF_H
+
+extern void cgit_ssdiff_print_deferred_lines();
+
+extern void cgit_ssdiff_line_cb(char *line, int len);
+
+extern void cgit_ssdiff_header_begin();
+extern void cgit_ssdiff_header_end();
+
+extern void cgit_ssdiff_footer();
+
+#endif /* UI_SSDIFF_H */
diff --git a/ui-tag.c b/ui-tag.c
index c2d72af..39e4cb8 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -1,92 +1,104 @@
/* ui-tag.c: display a tag
*
* Copyright (C) 2007 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
#include "html.h"
#include "ui-shared.h"
static void print_tag_content(char *buf)
{
char *p;
if (!buf)
return;
html("<div class='commit-subject'>");
p = strchr(buf, '\n');
if (p)
*p = '\0';
html_txt(buf);
html("</div>");
if (p) {
html("<div class='commit-msg'>");
html_txt(++p);
html("</div>");
}
}
+void print_download_links(char *revname)
+{
+ html("<tr><th>download</th><td class='sha1'>");
+ cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
+ revname, ctx.repo->snapshots);
+ html("</td></tr>");
+}
+
void cgit_print_tag(char *revname)
{
unsigned char sha1[20];
struct object *obj;
struct tag *tag;
struct taginfo *info;
if (!revname)
revname = ctx.qry.head;
if (get_sha1(fmt("refs/tags/%s", revname), sha1)) {
cgit_print_error(fmt("Bad tag reference: %s", revname));
return;
}
obj = parse_object(sha1);
if (!obj) {
cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1)));
return;
}
if (obj->type == OBJ_TAG) {
tag = lookup_tag(sha1);
if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
cgit_print_error(fmt("Bad tag object: %s", revname));
return;
}
html("<table class='commit-info'>\n");
- htmlf("<tr><td>Tag name</td><td>");
+ htmlf("<tr><td>tag name</td><td>");
html_txt(revname);
htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1));
if (info->tagger_date > 0) {
- html("<tr><td>Tag date</td><td>");
+ html("<tr><td>tag date</td><td>");
cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time);
html("</td></tr>\n");
}
if (info->tagger) {
- html("<tr><td>Tagged by</td><td>");
+ html("<tr><td>tagged by</td><td>");
html_txt(info->tagger);
if (info->tagger_email && !ctx.cfg.noplainemail) {
html(" ");
html_txt(info->tagger_email);
}
html("</td></tr>\n");
}
- html("<tr><td>Tagged object</td><td>");
+ html("<tr><td>tagged object</td><td class='sha1'>");
cgit_object_link(tag->tagged);
html("</td></tr>\n");
+ if (ctx.repo->snapshots)
+ print_download_links(revname);
html("</table>\n");
print_tag_content(info->msg);
} else {
html("<table class='commit-info'>\n");
- htmlf("<tr><td>Tag name</td><td>");
+ htmlf("<tr><td>tag name</td><td>");
html_txt(revname);
html("</td></tr>\n");
- html("<tr><td>Tagged object</td><td>");
+ html("<tr><td>Tagged object</td><td class='sha1'>");
cgit_object_link(obj);
html("</td></tr>\n");
+ if (ctx.repo->snapshots)
+ print_download_links(revname);
html("</table>\n");
}
return;
}
diff --git a/ui-tree.c b/ui-tree.c
index a164767..94aff8f 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -62,96 +62,102 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)
static void print_binary_buffer(char *buf, unsigned long size)
{
unsigned long ofs, idx;
static char ascii[ROWLEN + 1];
html("<table summary='blob content' class='bin-blob'>\n");
html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>");
for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) {
htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs);
for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
htmlf("%*s%02x",
idx == 16 ? 4 : 1, "",
buf[idx] & 0xff);
html(" </td><td class='hex'>");
for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.';
ascii[idx] = '\0';
html_txt(ascii);
html("</td></tr>\n");
}
html("</table>\n");
}
static void print_object(const unsigned char *sha1, char *path, const char *basename)
{
enum object_type type;
char *buf;
unsigned long size;
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD) {
cgit_print_error(fmt("Bad object name: %s",
sha1_to_hex(sha1)));
return;
}
buf = read_sha1_file(sha1, &type, &size);
if (!buf) {
cgit_print_error(fmt("Error reading object %s",
sha1_to_hex(sha1)));
return;
}
html(" (");
cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
curr_rev, path);
htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1));
+ if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) {
+ htmlf("<div class='error'>blob size (%dKB) exceeds display size limit (%dKB).</div>",
+ size / 1024, ctx.cfg.max_blob_size);
+ return;
+ }
+
if (buffer_is_binary(buf, size))
print_binary_buffer(buf, size);
else
print_text_buffer(basename, buf, size);
}
static int ls_item(const unsigned char *sha1, const char *base, int baselen,
const char *pathname, unsigned int mode, int stage,
void *cbdata)
{
char *name;
char *fullpath;
char *class;
enum object_type type;
unsigned long size = 0;
name = xstrdup(pathname);
fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "",
ctx.qry.path ? "/" : "", name);
if (!S_ISGITLINK(mode)) {
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD) {
htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
name,
sha1_to_hex(sha1));
return 0;
}
}
html("<tr><td class='ls-mode'>");
cgit_print_filemode(mode);
html("</td><td>");
if (S_ISGITLINK(mode)) {
htmlf("<a class='ls-mod' href='");
html_attr(fmt(ctx.repo->module_link,
name,
sha1_to_hex(sha1)));
html("'>");
html_txt(name);
html("</a>");
} else if (S_ISDIR(mode)) {
cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head,
curr_rev, fullpath);
} else {
class = strrchr(name, '.');
if (class != NULL) {