summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile44
-rw-r--r--cache.c4
-rw-r--r--cgit.c46
-rw-r--r--cgit.css40
-rw-r--r--cgit.h9
-rw-r--r--cgitrc.5.txt4
-rw-r--r--cmd.c3
m---------git0
-rw-r--r--parsing.c4
-rw-r--r--shared.c5
-rwxr-xr-xtests/setup.sh8
-rwxr-xr-xtests/t0010-validate-html.sh9
-rwxr-xr-xtests/t0104-tree.sh2
-rwxr-xr-xtests/t0107-snapshot.sh22
-rw-r--r--ui-log.c88
-rw-r--r--ui-patch.c4
-rw-r--r--ui-plain.c2
-rw-r--r--ui-refs.c42
-rw-r--r--ui-repolist.c144
-rw-r--r--ui-shared.c36
-rw-r--r--ui-shared.h2
-rw-r--r--ui-snapshot.c100
-rw-r--r--ui-snapshot.h3
-rw-r--r--ui-tag.c16
-rw-r--r--ui-tree.c8
25 files changed, 485 insertions, 160 deletions
diff --git a/Makefile b/Makefile
index f426f98..a52285e 100644
--- a/Makefile
+++ b/Makefile
@@ -3,2 +3,3 @@ CGIT_SCRIPT_NAME = cgit.cgi
CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
+CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
CGIT_CONFIG = /etc/cgitrc
@@ -6,4 +7,25 @@ CACHE_ROOT = /var/cache/cgit
SHA1_HEADER = <openssl/sha.h>
-GIT_VER = 1.6.0.2
+GIT_VER = 1.6.1
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 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
@@ -99,2 +121,5 @@ ifdef NO_ICONV
endif
+ifdef NO_STRCASESTR
+ CFLAGS += -DNO_STRCASESTR
+endif
@@ -108,4 +133,4 @@ cgit.o: VERSION
libgit:
- $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) libgit.a
- $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) xdiff/lib.a
+ $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 libgit.a
+ $(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) NO_CURL=1 xdiff/lib.a
@@ -115,6 +140,7 @@ test: all
install: all
- mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH)
- install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
- install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css
- install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png
+ $(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
@@ -122,4 +148,4 @@ uninstall:
rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME)
- rm -f $(CGIT_SCRIPT_PATH)/cgit.css
- rm -f $(CGIT_SCRIPT_PATH)/cgit.png
+ rm -f $(CGIT_DATA_PATH)/cgit.css
+ rm -f $(CGIT_DATA_PATH)/cgit.png
diff --git a/cache.c b/cache.c
index 57068a1..d7a8d5a 100644
--- a/cache.c
+++ b/cache.c
@@ -418,3 +418,3 @@ int cache_ls(const char *path)
}
- printf("%s %s %10zd %s\n",
+ printf("%s %s %10"PRIuMAX" %s\n",
name,
@@ -422,3 +422,3 @@ int cache_ls(const char *path)
slot.cache_st.st_mtime),
- slot.cache_st.st_size,
+ (uintmax_t)slot.cache_st.st_size,
slot.buf);
diff --git a/cgit.c b/cgit.c
index 57e11cd..608cab6 100644
--- a/cgit.c
+++ b/cgit.c
@@ -161,2 +161,6 @@ static void querystring_cb(const char *name, const char *value)
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")) {
@@ -299,3 +303,2 @@ static void process_request(void *cbdata)
ctx->page.title = "cgit error";
- ctx->repo = NULL;
cgit_print_http_headers(ctx);
@@ -445,24 +448,25 @@ int main(int argc, const char **argv)
- /* If virtual-root isn't specified in cgitrc and no url
- * parameter is specified on the querystring, lets pretend
- * that virtualroot equals SCRIPT_NAME and use PATH_INFO as
- * url. This allows cgit to work with virtual urls without
- * the need for rewriterules in the webserver (as long as
- * PATH_INFO is included in the cache lookup key).
+ /* If virtual-root isn't specified in cgitrc, lets pretend
+ * that virtual-root equals SCRIPT_NAME.
*/
- if (!ctx.cfg.virtual_root && !ctx.qry.url) {
+ if (!ctx.cfg.virtual_root)
ctx.cfg.virtual_root = ctx.cfg.script_name;
- path = getenv("PATH_INFO");
- if (path) {
- if (path[0] == '/')
- path++;
- ctx.qry.url = xstrdup(path);
- if (ctx.qry.raw) {
- qry = ctx.qry.raw;
- ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry));
- free(qry);
- } else
- ctx.qry.raw = ctx.qry.url;
- cgit_parse_url(ctx.qry.url);
- }
+
+ /* If no url parameter is specified on the querystring, lets
+ * use PATH_INFO as url. This allows cgit to work with virtual
+ * urls without the need for rewriterules in the webserver (as
+ * long as PATH_INFO is included in the cache lookup key).
+ */
+ path = getenv("PATH_INFO");
+ if (!ctx.qry.url && path) {
+ if (path[0] == '/')
+ path++;
+ ctx.qry.url = xstrdup(path);
+ if (ctx.qry.raw) {
+ qry = ctx.qry.raw;
+ ctx.qry.raw = xstrdup(fmt("%s?%s", path, qry));
+ free(qry);
+ } else
+ ctx.qry.raw = ctx.qry.url;
+ cgit_parse_url(ctx.qry.url);
}
diff --git a/cgit.css b/cgit.css
index ef30fbf..e8214de 100644
--- a/cgit.css
+++ b/cgit.css
@@ -122,2 +122,6 @@ table.list tr {
+table.list tr.logheader {
+ background: #eee;
+}
+
table.list tr:hover {
@@ -145,2 +149,13 @@ table.list td {
+table.list td.logsubject {
+ font-family: monospace;
+ font-weight: bold;
+}
+
+table.list td.logmsg {
+ font-family: monospace;
+ white-space: pre;
+ padding: 1em 0em 2em 0em;
+}
+
table.list td a {
@@ -458,2 +473,26 @@ div.footer {
}
+a.branch-deco {
+ margin: 0px 0.5em;
+ padding: 0px 0.25em;
+ background-color: #88ff88;
+ border: solid 1px #007700;
+}
+a.tag-deco {
+ margin: 0px 0.5em;
+ padding: 0px 0.25em;
+ background-color: #ffff88;
+ border: solid 1px #777700;
+}
+a.remote-deco {
+ margin: 0px 0.5em;
+ padding: 0px 0.25em;
+ background-color: #ccccff;
+ border: solid 1px #000077;
+}
+a.deco {
+ margin: 0px 0.5em;
+ padding: 0px 0.25em;
+ background-color: #ff8888;
+ border: solid 1px #770000;
+}
table.stats {
@@ -534,2 +573 @@ table.hgraph div.bar {
}
-
diff --git a/cgit.h b/cgit.h
index f2cb671..4fe94c6 100644
--- a/cgit.h
+++ b/cgit.h
@@ -64,2 +64,3 @@ struct cgit_repo {
int max_stats;
+ time_t mtime;
};
@@ -125,2 +126,4 @@ struct cgit_query {
int nohead;
+ char *sort;
+ int showmsg;
};
@@ -238,8 +241,2 @@ extern int cgit_parse_snapshots_mask(const char *str);
-/* libgit.a either links against or compiles its own implementation of
- * strcasestr(), and we'd like to reuse it. Simply re-declaring it
- * seems to do the trick.
- */
-extern char *strcasestr(const char *haystack, const char *needle);
-
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 0bbbea3..09f56a6 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -304,4 +304,4 @@ root-readme=/var/www/htdocs/about.html
-# Allow download of tar.gz, tar.bz and zip-files
-snapshots=tar.gz tar.bz zip
+# Allow download of tar.gz, tar.bz2 and zip-files
+snapshots=tar.gz tar.bz2 zip
diff --git a/cmd.c b/cmd.c
index 763a558..cf97da7 100644
--- a/cmd.c
+++ b/cmd.c
@@ -107,4 +107,3 @@ static void snapshot_fn(struct cgit_context *ctx)
{
- cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1,
- cgit_repobasename(ctx->repo->url), ctx->qry.path,
+ cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, ctx->qry.path,
ctx->repo->snapshots, ctx->qry.nohead);
diff --git a/git b/git
-Subproject 97a7a82f199f165f85fe39a3c318b18c621e633
+Subproject 8104ebfe8276657ee803cca7eb8665a78cf3ef8
diff --git a/parsing.c b/parsing.c
index c8f3048..f3f3b15 100644
--- a/parsing.c
+++ b/parsing.c
@@ -98,2 +98,5 @@ char *parse_user(char *t, char **name, char **email, unsigned long *date)
+#ifdef NO_ICONV
+#define reencode(a, b, c)
+#else
const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
@@ -112,2 +115,3 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
}
+#endif
diff --git a/shared.c b/shared.c
index 7382609..578a544 100644
--- a/shared.c
+++ b/shared.c
@@ -63,2 +63,3 @@ struct cgit_repo *cgit_add_repo(const char *url)
ret->readme = NULL;
+ ret->mtime = -1;
return ret;
@@ -269,2 +270,5 @@ int cgit_diff_files(const unsigned char *old_sha1,
+ memset(&diff_params, 0, sizeof(diff_params));
+ memset(&emit_params, 0, sizeof(emit_params));
+ memset(&emit_cb, 0, sizeof(emit_cb));
diff_params.flags = XDF_NEED_MINIMAL;
@@ -272,3 +276,2 @@ int cgit_diff_files(const unsigned char *old_sha1,
emit_params.flags = XDL_EMIT_FUNCNAMES;
- emit_params.find_func = NULL;
emit_cb.outf = filediff_cb;
diff --git a/tests/setup.sh b/tests/setup.sh
index 1457dd5..30f90d5 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -27,3 +27,4 @@ mkrepo() {
git init
- for ((n=1; n<=count; n++))
+ n=1
+ while test $n -le $count
do
@@ -32,2 +33,3 @@ mkrepo() {
git commit -m "commit $n"
+ n=$(expr $n + 1)
done
@@ -103,3 +105,3 @@ run_test()
script=$2
- ((test_count++))
+ test_count=$(expr $test_count + 1)
printf "\ntest %d: name='%s'\n" $test_count "$desc" >>test-output.log
@@ -113,3 +115,3 @@ run_test()
else
- ((test_failed++))
+ test_failed=$(expr $test_failed + 1)
printf " %2d) %-60s [failed]\n" $test_count "$desc"
diff --git a/tests/t0010-validate-html.sh b/tests/t0010-validate-html.sh
index 94aa52b..3fe4800 100755
--- a/tests/t0010-validate-html.sh
+++ b/tests/t0010-validate-html.sh
@@ -11,3 +11,3 @@ test_url()
sed -ie "1,4d" trash/tidy-$test_count || return
- tidy $tidy_opt trash/tidy-$test_count
+ "$tidy" $tidy_opt trash/tidy-$test_count
rc=$?
@@ -25,2 +25,9 @@ prepare_tests 'Validate html with tidy'
+tidy=`which tidy`
+test -n "$tidy" || {
+ echo "Skipping tests: tidy not found"
+ tests_done
+ exit
+}
+
run_test 'index page' 'test_url ""'
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh
index 0d62cc8..33f4eb0 100755
--- a/tests/t0104-tree.sh
+++ b/tests/t0104-tree.sh
@@ -17,3 +17,3 @@ run_test 'find line 1' '
run_test 'no line 2' '
- grep -e "<a id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
+ ! grep -e "<a id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
'
diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh
index d97c465..8ab4912 100755
--- a/tests/t0107-snapshot.sh
+++ b/tests/t0107-snapshot.sh
@@ -6,4 +6,4 @@ prepare_tests "Verify snapshot"
-run_test 'get foo/snapshot/test.tar.gz' '
- cgit_url "foo/snapshot/test.tar.gz" >trash/tmp
+run_test 'get foo/snapshot/master.tar.gz' '
+ cgit_url "foo/snapshot/master.tar.gz" >trash/tmp
'
@@ -12,6 +12,6 @@ run_test 'check html headers' '
head -n 1 trash/tmp |
- grep -e "Content-Type: application/x-tar" &&
+ grep -e "Content-Type: application/x-gzip" &&
head -n 2 trash/tmp |
- grep -e "Content-Disposition: inline; filename=.test.tar.gz."
+ grep -e "Content-Disposition: inline; filename=.master.tar.gz."
'
@@ -19,9 +19,9 @@ run_test 'check html headers' '
run_test 'strip off the header lines' '
- tail -n +6 trash/tmp > trash/test.tar.gz
+ tail -n +6 trash/tmp > trash/master.tar.gz
'
-run_test 'verify gzip format' 'gunzip --test trash/test.tar.gz'
+run_test 'verify gzip format' 'gunzip --test trash/master.tar.gz'
run_test 'untar' '
- rm -rf trash/foo &&
- tar -xf trash/test.tar.gz -C trash
+ rm -rf trash/master &&
+ tar -xf trash/master.tar.gz -C trash
'
@@ -29,3 +29,3 @@ run_test 'untar' '
run_test 'count files' '
- c=$(ls -1 trash/foo/ | wc -l) &&
+ c=$(ls -1 trash/master/ | wc -l) &&
test $c = 5
@@ -34,4 +34,4 @@ run_test 'count files' '
run_test 'verify untarred file-5' '
- grep -e "^5$" trash/foo/file-5 &&
- test $(cat trash/foo/file-5 | wc -l) = 1
+ grep -e "^5$" trash/master/file-5 &&
+ test $(cat trash/master/file-5 | wc -l) = 1
'
diff --git a/ui-log.c b/ui-log.c
index 8dd8b89..3202848 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -33,2 +33,34 @@ void inspect_files(struct diff_filepair *pair)
+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/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));
+ }
+ deco = deco->next;
+ }
+}
+
void print_commit(struct commit *commit)
@@ -37,5 +69,7 @@ void print_commit(struct commit *commit)
char *tmp;
+ int cols = 2;
info = cgit_parse_commit(commit);
- html("<tr><td>");
+ htmlf("<tr%s><td>",
+ ctx.qry.showmsg ? " class='logheader'" : "");
tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
@@ -45,5 +79,7 @@ void print_commit(struct commit *commit)
html_link_close();
- html("</td><td>");
+ 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));
+ show_commit_decorations(commit);
html("</td><td>");
@@ -63,2 +99,13 @@ void print_commit(struct commit *commit)
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);
@@ -66,2 +113,13 @@ void print_commit(struct commit *commit)
+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;
+}
@@ -72,3 +130,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
struct commit *commit;
- const char *argv[] = {NULL, tip, NULL, NULL, NULL};
+ const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
int argc = 2;
@@ -77,3 +135,5 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
if (!tip)
- argv[1] = ctx.qry.head;
+ tip = ctx.qry.head;
+
+ argv[1] = disambiguate_ref(tip);
@@ -94,2 +154,4 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
setup_revisions(argc, argv, &rev, NULL);
+ load_ref_decorations();
+ rev.show_decorations = 1;
rev.grep_filter.regflags |= REG_ICASE;
@@ -102,4 +164,12 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
html("<tr class='nohover'><th class='left'>Age</th>"
- "<th class='left'>Commit message</th>"
- "<th class='left'>Author</th>");
+ "<th class='left'>Commit message");
+ if (pager) {
+ html(" (");
+ cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
+ NULL, ctx.qry.head, ctx.qry.sha1,
+ ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
+ ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
+ html(")");
+ }
+ html("</th><th class='left'>Author</th>");
if (ctx.repo->enable_log_filecount) {
@@ -138,3 +208,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
ofs - cnt, ctx.qry.grep,
- ctx.qry.search);
+ ctx.qry.search, ctx.qry.showmsg);
html("&nbsp;");
@@ -145,3 +215,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
ofs + cnt, ctx.qry.grep,
- ctx.qry.search);
+ ctx.qry.search, ctx.qry.showmsg);
}
@@ -151,3 +221,3 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
- NULL, NULL);
+ NULL, NULL, ctx.qry.showmsg);
html("</td></tr>\n");
diff --git a/ui-patch.c b/ui-patch.c
index e60877d..1d77336 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -103,5 +103,5 @@ void cgit_print_patch(char *hex)
htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1));
- htmlf("From: %s%s\n", info->author, info->author_email);
+ htmlf("From: %s %s\n", info->author, info->author_email);
html("Date: ");
- cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time);
+ cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time);
htmlf("Subject: %s\n\n", info->subject);
diff --git a/ui-plain.c b/ui-plain.c
index be559e0..5addd9e 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -20,3 +20,3 @@ static void print_object(const unsigned char *sha1, const char *path)
char *buf;
- size_t size;
+ unsigned long size;
diff --git a/ui-refs.c b/ui-refs.c
index 32e0429..25da00a 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -60,3 +60,4 @@ static int print_branch(struct refinfo *ref)
html("<tr><td>");
- cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL);
+ cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL,
+ ctx.qry.showmsg);
html("</td><td>");
@@ -80,3 +81,3 @@ static void print_tag_header()
html("<tr class='nohover'><th class='left'>Tag</th>"
- "<th class='left'>Reference</th>"
+ "<th class='left'>Download</th>"
"<th class='left'>Author</th>"
@@ -86,2 +87,27 @@ static void print_tag_header()
+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)
@@ -100,3 +126,6 @@ static int print_tag(struct refinfo *ref)
html("</td><td>");
- cgit_object_link(tag->tagged);
+ if (ctx.repo->snapshots && (tag->tagged->type == OBJ_COMMIT))
+ print_tag_downloads(ctx.repo, name);
+ else
+ cgit_object_link(tag->tagged);
html("</td><td>");
@@ -112,5 +141,8 @@ static int print_tag(struct refinfo *ref)
html("<tr><td>");
- html_txt(name);
+ cgit_tag_link(name, NULL, NULL, ctx.qry.head, name);
html("</td><td>");
- cgit_object_link(ref->object);
+ if (ctx.repo->snapshots && (ref->object->type == OBJ_COMMIT))
+ print_tag_downloads(ctx.repo, name);
+ else
+ cgit_object_link(ref->object);
html("</td></tr>\n");
diff --git a/ui-repolist.c b/ui-repolist.c
index ab050c7..2c13d50 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -8,2 +8,6 @@
+/* This is needed for strcasestr to be defined by <string.h> */
+#define _GNU_SOURCE 1
+#include <string.h>
+
#include <time.h>
@@ -21,3 +25,4 @@ time_t read_agefile(char *path)
return -1;
- fgets(buf, sizeof(buf), f);
+ if (fgets(buf, sizeof(buf), f) == NULL)
+ return -1;
fclose(f);
@@ -29,3 +34,3 @@ time_t read_agefile(char *path)
-static void print_modtime(struct cgit_repo *repo)
+static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
{
@@ -33,7 +38,13 @@ static void print_modtime(struct cgit_repo *repo)
struct stat s;
+ struct cgit_repo *r = (struct cgit_repo *)repo;
+ if (repo->mtime != -1) {
+ *mtime = repo->mtime;
+ return 1;
+ }
path = fmt("%s/%s", repo->path, ctx.cfg.agefile);
if (stat(path, &s) == 0) {
- cgit_print_age(read_agefile(path), -1, NULL);
- return;
+ *mtime = read_agefile(path);
+ r->mtime = *mtime;
+ return 1;
}
@@ -41,5 +52,16 @@ static void print_modtime(struct cgit_repo *repo)
path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
- if (stat(path, &s) != 0)
- return;
- cgit_print_age(s.st_mtime, -1, NULL);
+ if (stat(path, &s) == 0)
+ *mtime = s.st_mtime;
+ else
+ *mtime = 0;
+
+ r->mtime = *mtime;
+ return (r->mtime != 0);
+}
+
+static void print_modtime(struct cgit_repo *repo)
+{
+ time_t t;
+ if (get_repo_modtime(repo, &t))
+ cgit_print_age(t, -1, NULL);
}
@@ -70,9 +92,19 @@ int is_in_url(struct cgit_repo *repo)
+void print_sort_header(const char *title, const char *sort)
+{
+ htmlf("<th class='left'><a href='./?s=%s", sort);
+ if (ctx.qry.search) {
+ html("&q=");
+ html_url_arg(ctx.qry.search);
+ }
+ htmlf("'>%s</a></th>", title);
+}
+
void print_header(int columns)
{
- html("<tr class='nohover'>"
- "<th class='left'>Name</th>"
- "<th class='left'>Description</th>"
- "<th class='left'>Owner</th>"
- "<th class='left'>Idle</th>");
+ html("<tr class='nohover'>");
+ print_sort_header("Name", "name");
+ print_sort_header("Description", "desc");
+ print_sort_header("Owner", "owner");
+ print_sort_header("Idle", "idle");
if (ctx.cfg.enable_index_links)
@@ -93,2 +125,77 @@ void print_pager(int items, int pagelen, char *search)
+static int cmp(const char *s1, const char *s2)
+{
+ if (s1 && s2)
+ return strcmp(s1, s2);
+ if (s1 && !s2)
+ return -1;
+ if (s2 && !s1)
+ return 1;
+ return 0;
+}
+
+static int sort_name(const void *a, const void *b)
+{
+ const struct cgit_repo *r1 = a;
+ const struct cgit_repo *r2 = b;
+
+ return cmp(r1->name, r2->name);
+}
+
+static int sort_desc(const void *a, const void *b)
+{
+ const struct cgit_repo *r1 = a;
+ const struct cgit_repo *r2 = b;
+
+ return cmp(r1->desc, r2->desc);
+}
+
+static int sort_owner(const void *a, const void *b)
+{
+ const struct cgit_repo *r1 = a;
+ const struct cgit_repo *r2 = b;
+
+ return cmp(r1->owner, r2->owner);
+}
+
+static int sort_idle(const void *a, const void *b)
+{
+ const struct cgit_repo *r1 = a;
+ const struct cgit_repo *r2 = b;
+ time_t t1, t2;
+
+ t1 = t2 = 0;
+ get_repo_modtime(r1, &t1);
+ get_repo_modtime(r2, &t2);
+ return t2 - t1;
+}
+
+struct sortcolumn {
+ const char *name;
+ int (*fn)(const void *a, const void *b);
+};
+
+struct sortcolumn sortcolumn[] = {
+ {"name", sort_name},
+ {"desc", sort_desc},
+ {"owner", sort_owner},
+ {"idle", sort_idle},
+ {NULL, NULL}
+};
+
+int sort_repolist(char *field)
+{
+ struct sortcolumn *column;
+
+ for (column = &sortcolumn[0]; column->name; column++) {
+ if (strcmp(field, column->name))
+ continue;
+ qsort(cgit_repolist.repos, cgit_repolist.count,
+ sizeof(struct cgit_repo), column->fn);
+ return 1;
+ }
+ return 0;
+}
+
+
void cgit_print_repolist()
@@ -97,2 +204,3 @@ void cgit_print_repolist()
char *last_group = NULL;
+ int sorted = 0;
@@ -109,2 +217,5 @@ void cgit_print_repolist()
+ if(ctx.qry.sort)
+ sorted = sort_repolist(ctx.qry.sort);
+
html("<table summary='repository list' class='list nowrap'>");
@@ -121,6 +232,7 @@ void cgit_print_repolist()
print_header(columns);
- if ((last_group == NULL && ctx.repo->group != NULL) ||
+ if (!sorted &&
+ ((last_group == NULL && ctx.repo->group != NULL) ||
(last_group != NULL && ctx.repo->group == NULL) ||
(last_group != NULL && ctx.repo->group != NULL &&
- strcmp(ctx.repo->group, last_group))) {
+ strcmp(ctx.repo->group, last_group)))) {
htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>",
@@ -132,3 +244,3 @@ void cgit_print_repolist()
htmlf("<tr><td class='%s'>",
- ctx.repo->group ? "sublevel-repo" : "toplevel-repo");
+ !sorted && ctx.repo->group ? "sublevel-repo" : "toplevel-repo");
cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
@@ -147,3 +259,3 @@ void cgit_print_repolist()
cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
- 0, NULL, NULL);
+ 0, NULL, NULL, ctx.qry.showmsg);
cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
diff --git a/ui-shared.c b/ui-shared.c
index 1bb30c2..4f28512 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -283,3 +283,4 @@ void cgit_plain_link(char *name, char *title, char *class, char *head,
void cgit_log_link(char *name, char *title, char *class, char *head,
- char *rev, char *path, int ofs, char *grep, char *pattern)
+ char *rev, char *path, int ofs, char *grep, char *pattern,
+ int showmsg)
{
@@ -307,2 +308,7 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
htmlf("%d", ofs);
+ delim = "&";
+ }
+ if (showmsg) {
+ html(delim);
+ html("showmsg=1");
}
@@ -373,7 +379,10 @@ void cgit_object_link(struct object *obj)
{
- char *page, *rev, *name;
+ 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", sha1_to_hex(obj->sha1)), NULL, NULL,
- ctx.qry.head, sha1_to_hex(obj->sha1));
+ cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
+ ctx.qry.head, fullrev);
return;
@@ -385,5 +394,4 @@ void cgit_object_link(struct object *obj)
page = "blob";
- rev = sha1_to_hex(obj->sha1);
- name = fmt("%s %s", typename(obj->type), rev);
- reporevlink(page, name, NULL, NULL, ctx.qry.head, rev, NULL);
+ name = fmt("%s %s...", typename(obj->type), shortrev);
+ reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
}
@@ -576,2 +584,4 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
html_hidden("id2", ctx.qry.sha2);
+ if (ctx.qry.showmsg)
+ html_hidden("showmsg", "1");
@@ -585,5 +595,7 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
+const char *fallback_cmd = "repolist";
+
char *hc(struct cgit_cmd *cmd, const char *page)
{
- return (strcmp(cmd->name, page) ? NULL : "active");
+ return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active");
}
@@ -594,2 +606,5 @@ void cgit_print_pageheader(struct cgit_context *ctx)
+ if (!cmd && ctx->repo)
+ fallback_cmd = "summary";
+
html("<table id='header'>\n");
@@ -642,3 +657,3 @@ void cgit_print_pageheader(struct cgit_context *ctx)
cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
- NULL, NULL, 0, NULL, NULL);
+ NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg);
cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
@@ -718,4 +733,3 @@ void cgit_print_snapshot_links(const char *repo, const char *head,
f->suffix);
- cgit_snapshot_link(filename, NULL, NULL, (char *)head,
- (char *)hex, filename);
+ cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
html("<br/>");
diff --git a/ui-shared.h b/ui-shared.h
index 1524dc3..5a3821f 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -21,3 +21,3 @@ extern void cgit_log_link(char *name, char *title, char *class, char *head,
char *rev, char *path, int ofs, char *grep,
- char *pattern);
+ char *pattern, int showmsg);
extern void cgit_commit_link(char *name, char *title, char *class, char *head,
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 9c4d086..f25613e 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -60,4 +60,4 @@ const struct cgit_snapshot_format cgit_snapshot_formats[] = {
{ ".zip", "application/x-zip", write_zip_archive, 0x1 },
- { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 },
- { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 },
+ { ".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 },
@@ -116,51 +116,45 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
-char *dwim_filename = NULL;
-const char *dwim_refname = NULL;
-
-static int ref_cb(const char *refname, const unsigned char *sha1, int flags,
- void *cb_data)
-{
- const char *r = refname;
- while (r && *r) {
- fprintf(stderr, " cmp %s with %s:", dwim_filename, r);
- if (!strcmp(dwim_filename, r)) {
- fprintf(stderr, "MATCH!\n");
- dwim_refname = refname;
- return 1;
- }
- fprintf(stderr, "no match\n");
- if (isdigit(*r))
- break;
- r++;
- }
- return 0;
-}
-
-/* Try to guess the requested revision by combining repo name and tag name
- * and comparing this to the requested snapshot name. E.g. the requested
- * snapshot is "cgit-0.7.2.tar.gz" while repo name is "cgit" and tag name
- * is "v0.7.2". First, the reponame is stripped off, leaving "-0.7.2.tar.gz".
- * Next, any '-' and '_' characters are stripped, leaving "0.7.2.tar.gz".
- * Finally, the requested format suffix is removed and we end up with "0.7.2".
- * Then we test each tag against this dwimmed filename, and for each tag
- * we even try to remove any leading characters which are non-digits. I.e.
- * we first compare with "v0.7.2", then with "0.7.2" and we've got a match.
+/* Try to guess the requested revision from the requested snapshot name.
+ * First the format extension is stripped, e.g. "cgit-0.7.2.tar.gz" become
+ * "cgit-0.7.2". If this is a valid commit object name we've got a winner.
+ * Otherwise, if the snapshot name has a prefix matching the result from
+ * repo_basename(), we strip the basename and any following '-' and '_'
+ * characters ("cgit-0.7.2" -> "0.7.2") and check the resulting name once
+ * more. If this still isn't a valid commit object name, we check if pre-
+ * pending a 'v' to the remaining snapshot name ("0.7.2" -> "v0.7.2") gives
+ * us something valid.
*/
static const char *get_ref_from_filename(const char *url, const char *filename,
- const struct cgit_snapshot_format *fmt)
+ const struct cgit_snapshot_format *format)
{
- const char *reponame = cgit_repobasename(url);
- fprintf(stderr, "reponame=%s, filename=%s\n", reponame, filename);
- if (prefixcmp(filename, reponame))
- return NULL;
- filename += strlen(reponame);
- while (filename && (*filename == '-' || *filename == '_'))
- filename++;
- dwim_filename = xstrdup(filename);
- dwim_filename[strlen(filename) - strlen(fmt->suffix)] = '\0';
- for_each_tag_ref(ref_cb, NULL);
- return dwim_refname;
+ const char *reponame;
+ unsigned char sha1[20];
+ char *snapshot;
+
+ snapshot = xstrdup(filename);
+ snapshot[strlen(snapshot) - strlen(format->suffix)] = '\0';
+ fprintf(stderr, "snapshot=%s\n", snapshot);
+
+ if (get_sha1(snapshot, sha1) == 0)
+ return snapshot;
+
+ reponame = cgit_repobasename(url);
+ fprintf(stderr, "reponame=%s\n", reponame);
+ if (prefixcmp(snapshot, reponame) == 0) {
+ snapshot += strlen(reponame);
+ while (snapshot && (*snapshot == '-' || *snapshot == '_'))
+ snapshot++;
+ }
+
+ if (get_sha1(snapshot, sha1) == 0)
+ return snapshot;
+
+ snapshot = fmt("v%s", snapshot);
+ if (get_sha1(snapshot, sha1) == 0)
+ return snapshot;
+
+ return NULL;
}
-void cgit_print_snapshot(const char *head, const char *hex, const char *prefix,
+void cgit_print_snapshot(const char *head, const char *hex,
const char *filename, int snapshots, int dwim)
@@ -168,2 +162,3 @@ void cgit_print_snapshot(const char *head, const char *hex, const char *prefix,
const struct cgit_snapshot_format* f;
+ char *prefix = NULL;
@@ -180,4 +175,11 @@ void cgit_print_snapshot(const char *head, const char *hex, const char *prefix,
- if (!hex && dwim)
+ if (!hex && dwim) {
hex = get_ref_from_filename(ctx.repo->url, filename, f);
+ if (hex == NULL) {
+ html_status(404, "Not found", 0);
+ return;
+ }
+ prefix = xstrdup(filename);
+ prefix[strlen(filename) - strlen(f->suffix)] = '\0';
+ }
@@ -186,3 +188,7 @@ void cgit_print_snapshot(const char *head, const char *hex, const char *prefix,
+ if (!prefix)
+ prefix = xstrdup(cgit_repobasename(ctx.repo->url));
+
make_snapshot(f, hex, prefix, filename);
+ free(prefix);
}
diff --git a/ui-snapshot.h b/ui-snapshot.h
index 3540303..b6ede52 100644
--- a/ui-snapshot.h
+++ b/ui-snapshot.h
@@ -4,4 +4,3 @@
extern void cgit_print_snapshot(const char *head, const char *hex,
- const char *prefix, const char *filename,
- int snapshot, int dwim);
+ const char *filename, int snapshot, int dwim);
diff --git a/ui-tag.c b/ui-tag.c
index 3aea87d..0e056e0 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -55,4 +55,5 @@ void cgit_print_tag(char *revname)
html("<table class='commit-info'>\n");
- htmlf("<tr><td>Tag name</td><td>%s (%s)</td></tr>\n",
- revname, sha1_to_hex(sha1));
+ htmlf("<tr><td>Tag name</td><td>");
+ html_txt(revname);
+ htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1));
if (info->tagger_date > 0) {
@@ -76,3 +77,12 @@ void cgit_print_tag(char *revname)
print_tag_content(info->msg);
- }
+ } else {
+ html("<table class='commit-info'>\n");
+ htmlf("<tr><td>Tag name</td><td>");
+ html_txt(revname);
+ html("</td></tr>\n");
+ html("<tr><td>Tagged object</td><td>");
+ cgit_object_link(obj);
+ html("</td></tr>\n");
+ html("</table>\n");
+ }
return;
diff --git a/ui-tree.c b/ui-tree.c
index e27e796..4b8e7a0 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -56,4 +56,6 @@ static void print_object(const unsigned char *sha1, char *path)
}
- htmlf(linefmt, ++lineno);
- html_txt(buf + start);
+ if (start < idx) {
+ htmlf(linefmt, ++lineno);
+ html_txt(buf + start);
+ }
html("</td></tr>\n");
@@ -108,3 +110,3 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev,
- fullpath, 0, NULL, NULL);
+ fullpath, 0, NULL, NULL, ctx.qry.showmsg);
if (ctx.repo->max_stats)