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
@@ -1,14 +1,36 @@
CGIT_VERSION = v0.8.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.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
#
# Let the user override the above settings.
#
-include cgit.conf
@@ -94,37 +116,41 @@ 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
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) 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
test: all
$(QUIET_SUBDIR0)tests $(QUIET_SUBDIR1) 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
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
clean:
rm -f cgit VERSION *.o *.d
get-git:
curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git
diff --git a/cache.c b/cache.c
index 57068a1..d7a8d5a 100644
--- a/cache.c
+++ b/cache.c
@@ -413,17 +413,17 @@ int cache_ls(const char *path)
strcpy(name, ent->d_name);
if ((err = open_slot(&slot)) != 0) {
cache_log("[cgit] unable to open path %s: %s (%d)\n",
fullname, strerror(err), err);
continue;
}
- printf("%s %s %10zd %s\n",
+ printf("%s %s %10"PRIuMAX" %s\n",
name,
sprintftime("%Y-%m-%d %H:%M:%S",
slot.cache_st.st_mtime),
- slot.cache_st.st_size,
+ (uintmax_t)slot.cache_st.st_size,
slot.buf);
close_slot(&slot);
}
closedir(dir);
return 0;
}
diff --git a/cgit.c b/cgit.c
index 57e11cd..608cab6 100644
--- a/cgit.c
+++ b/cgit.c
@@ -156,12 +156,16 @@ static void querystring_cb(const char *name, const char *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);
}
}
static void prepare_context(struct cgit_context *ctx)
@@ -294,13 +298,12 @@ static void process_request(void *cbdata)
struct cgit_context *ctx = cbdata;
struct cgit_cmd *cmd;
cmd = cgit_get_cmd(ctx);
if (!cmd) {
ctx->page.title = "cgit error";
- ctx->repo = NULL;
cgit_print_http_headers(ctx);
cgit_print_docstart(ctx);
cgit_print_pageheader(ctx);
cgit_print_error("Invalid request");
cgit_print_docend();
return;
@@ -440,34 +443,35 @@ int main(int argc, const char **argv)
cgit_parse_args(argc, argv);
parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
config_cb);
ctx.repo = NULL;
http_parse_querystring(ctx.qry.raw, querystring_cb);
- /* 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);
}
ttl = calc_ttl();
ctx.page.expires += ttl*60;
if (ctx.cfg.nocache)
ctx.cfg.cache_size = 0;
diff --git a/cgit.css b/cgit.css
index ef30fbf..e8214de 100644
--- a/cgit.css
+++ b/cgit.css
@@ -117,12 +117,16 @@ 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;
@@ -140,12 +144,23 @@ table.list th {
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 0em 2em 0em;
+}
+
table.list td a {
color: black;
}
table.list td a:hover {
color: #00f;
@@ -453,12 +468,36 @@ span.age-years {
div.footer {
margin-top: 0.5em;
text-align: center;
font-size: 80%;
color: #ccc;
}
+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 {
border: solid 1px black;
border-collapse: collapse;
}
table.stats th {
@@ -529,7 +568,6 @@ table.hgraph td {
}
table.hgraph div.bar {
background-color: #eee;
height: 1em;
}
-
diff --git a/cgit.h b/cgit.h
index f2cb671..4fe94c6 100644
--- a/cgit.h
+++ b/cgit.h
@@ -59,12 +59,13 @@ struct cgit_repo {
char *readme;
char *clone_url;
int snapshots;
int enable_log_filecount;
int enable_log_linecount;
int max_stats;
+ time_t mtime;
};
struct cgit_repolist {
int length;
int count;
struct cgit_repo *repos;
@@ -120,12 +121,14 @@ struct cgit_query {
char *name;
char *mimetype;
char *url;
char *period;
int ofs;
int nohead;
+ char *sort;
+ int showmsg;
};
struct cgit_config {
char *agefile;
char *cache_root;
char *clone_prefix;
@@ -233,14 +236,8 @@ extern struct taginfo *cgit_parse_tag(struct tag *tag);
extern void cgit_parse_url(const char *url);
extern const char *cgit_repobasename(const char *reponame);
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);
-
#endif /* CGIT_H */
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 0bbbea3..09f56a6 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -299,14 +299,14 @@ root-desc=tracking the foobar development
# Include some more info about foobar.com on the index page
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
##
## List of repositories.
## PS: Any repositories listed when repo.group is unset will not be
## displayed under a group heading
diff --git a/cmd.c b/cmd.c
index 763a558..cf97da7 100644
--- a/cmd.c
+++ b/cmd.c
@@ -102,14 +102,13 @@ static void refs_fn(struct cgit_context *ctx)
{
cgit_print_refs();
}
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);
}
static void stats_fn(struct cgit_context *ctx)
{
cgit_show_stats(ctx);
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
@@ -93,12 +93,15 @@ char *parse_user(char *t, char **name, char **email, unsigned long *date)
}
p++;
}
return p;
}
+#ifdef NO_ICONV
+#define reencode(a, b, c)
+#else
const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
{
char *tmp;
if (!txt || !*txt || !src_enc || !dst_enc)
return *txt;
@@ -107,12 +110,13 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
if (tmp) {
free(*txt);
*txt = tmp;
}
return *txt;
}
+#endif
struct commitinfo *cgit_parse_commit(struct commit *commit)
{
struct commitinfo *ret;
char *p = commit->buffer, *t = commit->buffer;
diff --git a/shared.c b/shared.c
index 7382609..578a544 100644
--- a/shared.c
+++ b/shared.c
@@ -58,12 +58,13 @@ struct cgit_repo *cgit_add_repo(const char *url)
ret->snapshots = ctx.cfg.snapshots;
ret->enable_log_filecount = ctx.cfg.enable_log_filecount;
ret->enable_log_linecount = ctx.cfg.enable_log_linecount;
ret->max_stats = ctx.cfg.max_stats;
ret->module_link = ctx.cfg.module_link;
ret->readme = NULL;
+ ret->mtime = -1;
return ret;
}
struct cgit_repo *cgit_get_repoinfo(const char *url)
{
int i;
@@ -264,16 +265,18 @@ int cgit_diff_files(const unsigned char *old_sha1,
xdemitconf_t emit_params;
xdemitcb_t emit_cb;
if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1))
return 1;
+ 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;
emit_params.ctxlen = 3;
emit_params.flags = XDL_EMIT_FUNCNAMES;
- emit_params.find_func = NULL;
emit_cb.outf = filediff_cb;
emit_cb.priv = fn;
xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb);
return 0;
}
diff --git a/tests/setup.sh b/tests/setup.sh
index 1457dd5..30f90d5 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -22,17 +22,19 @@ mkrepo() {
dir=$PWD
test -d $name && return
printf "Creating testrepo %s\n" $name
mkdir -p $name
cd $name
git init
- for ((n=1; n<=count; n++))
+ n=1
+ while test $n -le $count
do
echo $n >file-$n
git add file-$n
git commit -m "commit $n"
+ n=$(expr $n + 1)
done
if test "$3" = "testplus"
then
echo "hello" >a+b
git add a+b
git commit -m "add a+b"
@@ -98,23 +100,23 @@ tests_done()
}
run_test()
{
desc=$1
script=$2
- ((test_count++))
+ test_count=$(expr $test_count + 1)
printf "\ntest %d: name='%s'\n" $test_count "$desc" >>test-output.log
printf "test %d: eval='%s'\n" $test_count "$2" >>test-output.log
eval "$2" >>test-output.log 2>>test-output.log
res=$?
printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log
if test $res = 0
then
printf " %2d) %-60s [ok]\n" $test_count "$desc"
else
- ((test_failed++))
+ test_failed=$(expr $test_failed + 1)
printf " %2d) %-60s [failed]\n" $test_count "$desc"
fi
}
cgit_query()
{
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
@@ -6,13 +6,13 @@
test_url()
{
tidy_opt="-eq"
test -z "$NO_TIDY_WARNINGS" || tidy_opt+=" --show-warnings no"
cgit_url "$1" >trash/tidy-$test_count || return
sed -ie "1,4d" trash/tidy-$test_count || return
- tidy $tidy_opt trash/tidy-$test_count
+ "$tidy" $tidy_opt trash/tidy-$test_count
rc=$?
# tidy returns with exitcode 1 on warnings, 2 on error
if test $rc = 2
then
false
@@ -20,12 +20,19 @@ test_url()
:
fi
}
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 ""'
run_test 'foo' 'test_url "foo"'
run_test 'foo/log' 'test_url "foo/log"'
run_test 'foo/tree' 'test_url "foo/tree"'
run_test 'foo/tree/file-1' 'test_url "foo/tree/file-1"'
run_test 'foo/commit' 'test_url "foo/commit"'
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
@@ -12,13 +12,13 @@ run_test 'generate bar/tree/file-50' 'cgit_url "bar/tree/file-50" >trash/tmp'
run_test 'find line 1' '
grep -e "<a id=.n1. name=.n1. href=.#n1.>1</a>" trash/tmp
'
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
'
run_test 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >trash/tmp'
run_test 'verify a+b link' '
grep -e "/foo+bar/tree/a+b" 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
@@ -1,39 +1,39 @@
#!/bin/sh
. ./setup.sh
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
'
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."
'
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
'
run_test 'count files' '
- c=$(ls -1 trash/foo/ | wc -l) &&
+ c=$(ls -1 trash/master/ | wc -l) &&
test $c = 5
'
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
'
tests_done
diff --git a/ui-log.c b/ui-log.c
index 8dd8b89..3202848 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -28,27 +28,63 @@ void inspect_files(struct diff_filepair *pair)
{
files++;
if (ctx.repo->enable_log_linecount)
cgit_diff_files(pair->one->sha1, pair->two->sha1, 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/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)
{
struct commitinfo *info;
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));
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();
- 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>");
html_txt(info->author);
if (ctx.repo->enable_log_filecount) {
files = 0;
add_lines = 0;
rem_lines = 0;
@@ -58,27 +94,51 @@ void print_commit(struct commit *commit)
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, tip, NULL, NULL, NULL};
+ const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
int argc = 2;
int i, columns = 3;
if (!tip)
- argv[1] = ctx.qry.head;
+ tip = ctx.qry.head;
+
+ argv[1] = disambiguate_ref(tip);
if (grep && pattern && (!strcmp(grep, "grep") ||
!strcmp(grep, "author") ||
!strcmp(grep, "committer")))
argv[argc++] = fmt("--%s=%s", grep, pattern);
@@ -89,22 +149,32 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
init_revisions(&rev, NULL);
rev.abbrev = DEFAULT_ABBREV;
rev.commit_format = CMIT_FMT_DEFAULT;
rev.verbose_header = 1;
rev.show_root_diff = 0;
setup_revisions(argc, argv, &rev, NULL);
+ load_ref_decorations();
+ rev.show_decorations = 1;
rev.grep_filter.regflags |= REG_ICASE;
compile_grep_patterns(&rev.grep_filter);
prepare_revision_walk(&rev);
if (pager)
html("<table class='list nowrap'>");
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) {
html("<th class='left'>Files</th>");
columns++;
if (ctx.repo->enable_log_linecount) {
html("<th class='left'>Lines</th>");
columns++;
@@ -133,23 +203,23 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
htmlf("</table><div class='pager'>",
columns);
if (ofs > 0) {
cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
ctx.qry.sha1, ctx.qry.path,
ofs - cnt, ctx.qry.grep,
- ctx.qry.search);
+ ctx.qry.search, ctx.qry.showmsg);
html("&nbsp;");
}
if ((commit = get_revision(&rev)) != NULL) {
cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
ctx.qry.sha1, ctx.qry.path,
ofs + cnt, ctx.qry.grep,
- ctx.qry.search);
+ ctx.qry.search, ctx.qry.showmsg);
}
html("</div>");
} else if ((commit = get_revision(&rev)) != NULL) {
html("<tr class='nohover'><td colspan='3'>");
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
@@ -98,15 +98,15 @@ void cgit_print_patch(char *hex)
patchname = fmt("%s.patch", sha1_to_hex(sha1));
ctx.page.mimetype = "text/plain";
ctx.page.filename = patchname;
cgit_print_http_headers(&ctx);
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);
if (info->msg && *info->msg) {
htmlf("%s", info->msg);
if (info->msg[strlen(info->msg) - 1] != '\n')
html("\n");
}
diff --git a/ui-plain.c b/ui-plain.c
index be559e0..5addd9e 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -15,13 +15,13 @@ char *match_path;
int match;
static void print_object(const unsigned char *sha1, const char *path)
{
enum object_type type;
char *buf;
- size_t size;
+ unsigned long size;
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD) {
html_status(404, "Not found", 0);
return;
}
diff --git a/ui-refs.c b/ui-refs.c
index 32e0429..25da00a 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -55,13 +55,14 @@ 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);
+ 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);
html("</td><td>");
html_txt(info->author);
@@ -75,18 +76,43 @@ static int print_branch(struct refinfo *ref)
return 0;
}
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>"
"<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)
{
struct tag *tag;
struct taginfo *info;
char *name = (char *)ref->refname;
@@ -95,27 +121,33 @@ static int print_tag(struct refinfo *ref)
info = ref->tag;
if (!tag || !info)
return 1;
html("<tr><td>");
cgit_tag_link(name, NULL, NULL, ctx.qry.head, name);
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>");
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>");
- 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");
}
return 0;
}
static void print_refs_link(char *path)
diff --git a/ui-repolist.c b/ui-repolist.c
index ab050c7..2c13d50 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -3,12 +3,16 @@
* Copyright (C) 2006 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
+/* This is needed for strcasestr to be defined by <string.h> */
+#define _GNU_SOURCE 1
+#include <string.h>
+
#include <time.h>
#include "cgit.h"
#include "html.h"
#include "ui-shared.h"
@@ -16,35 +20,53 @@ time_t read_agefile(char *path)
{
FILE *f;
static char buf[64], buf2[64];
if (!(f = fopen(path, "r")))
return -1;
- fgets(buf, sizeof(buf), f);
+ if (fgets(buf, sizeof(buf), f) == NULL)
+ return -1;
fclose(f);
if (parse_date(buf, buf2, sizeof(buf2)))
return strtoul(buf2, NULL, 10);
else
return 0;
}
-static void print_modtime(struct cgit_repo *repo)
+static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
{
char *path;
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;
}
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);
}
int is_match(struct cgit_repo *repo)
{
if (!ctx.qry.search)
return 1;
@@ -65,19 +87,29 @@ int is_in_url(struct cgit_repo *repo)
return 1;
if (repo->url && !prefixcmp(repo->url, ctx.qry.url))
return 1;
return 0;
}
+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)
html("<th class='left'>Links</th>");
html("</tr>\n");
}
@@ -88,52 +120,132 @@ void print_pager(int items, int pagelen, char *search)
for(i = 0; i * pagelen < items; i++)
cgit_index_link(fmt("[%d]", i+1), fmt("Page %d", i+1), NULL,
search, i * pagelen);
html("</div>");
}
+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()
{
int i, columns = 4, hits = 0, header = 0;
char *last_group = NULL;
+ int sorted = 0;
if (ctx.cfg.enable_index_links)
columns++;
ctx.page.title = ctx.cfg.root_title;
cgit_print_http_headers(&ctx);
cgit_print_docstart(&ctx);
cgit_print_pageheader(&ctx);
if (ctx.cfg.index_header)
html_include(ctx.cfg.index_header);
+ if(ctx.qry.sort)
+ sorted = sort_repolist(ctx.qry.sort);
+
html("<table summary='repository list' class='list nowrap'>");
for (i=0; i<cgit_repolist.count; i++) {
ctx.repo = &cgit_repolist.repos[i];
if (!(is_match(ctx.repo) && is_in_url(ctx.repo)))
continue;
hits++;
if (hits <= ctx.qry.ofs)
continue;
if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
continue;
if (!header++)
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'>",
columns);
html_txt(ctx.repo->group);
html("</td></tr>");
last_group = ctx.repo->group;
}
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);
html("</td><td>");
html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
html_link_close();
html("</td><td>");
@@ -142,13 +254,13 @@ void cgit_print_repolist()
print_modtime(ctx.repo);
html("</td>");
if (ctx.cfg.enable_index_links) {
html("<td>");
cgit_summary_link("summary", NULL, "button", NULL);
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);
html("</td>");
}
html("</tr>\n");
}
html("</table>");
diff --git a/ui-shared.c b/ui-shared.c
index 1bb30c2..4f28512 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -278,13 +278,14 @@ 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)
+ 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);
@@ -302,12 +303,17 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
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>");
}
@@ -368,27 +374,29 @@ void cgit_stats_link(char *name, char *title, char *class, char *head,
{
reporevlink("stats", name, title, class, head, NULL, path);
}
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;
} else if (obj->type == OBJ_TREE)
page = "tree";
else if (obj->type == OBJ_TAG)
page = "tag";
else
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);
}
void cgit_print_date(time_t secs, char *format, int local_time)
{
char buf[64];
struct tm *time;
@@ -571,30 +579,37 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
html_hidden("h", ctx.qry.head);
if (ctx.qry.sha1)
html_hidden("id", ctx.qry.sha1);
if (ctx.qry.sha2)
html_hidden("id2", ctx.qry.sha2);
+ if (ctx.qry.showmsg)
+ html_hidden("showmsg", "1");
if (incl_search) {
if (ctx.qry.grep)
html_hidden("qt", ctx.qry.grep);
if (ctx.qry.search)
html_hidden("q", ctx.qry.search);
}
}
+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");
}
void cgit_print_pageheader(struct cgit_context *ctx)
{
struct cgit_cmd *cmd = cgit_get_cmd(ctx);
+ if (!cmd && ctx->repo)
+ fallback_cmd = "summary";
+
html("<table id='header'>\n");
html("<tr>\n");
html("<td class='logo' rowspan='2'><a href='");
if (ctx->cfg.logo_link)
html_attr(ctx->cfg.logo_link);
else
@@ -637,13 +652,13 @@ void cgit_print_pageheader(struct cgit_context *ctx)
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);
+ 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);
cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
ctx->qry.sha1, ctx->qry.sha2, NULL);
@@ -713,11 +728,10 @@ void cgit_print_snapshot_links(const char *repo, const char *head,
for (f = cgit_snapshot_formats; f->suffix; f++) {
if (!(snapshots & f->bit))
continue;
filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
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
@@ -16,13 +16,13 @@ extern void cgit_tag_link(char *name, char *title, char *class, char *head,
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);
+ char *pattern, int showmsg);
extern void cgit_commit_link(char *name, char *title, char *class, char *head,
char *rev);
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);
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 9c4d086..f25613e 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -55,14 +55,14 @@ static int write_tar_bzip2_archive(struct archiver_args *args)
{
return write_compressed_tar_archive(args,"bzip2");
}
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 },
{}
};
static const struct cgit_snapshot_format *get_format(const char *filename)
{
@@ -111,78 +111,84 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
ctx.page.filename = xstrdup(filename);
cgit_print_http_headers(&ctx);
format->write_func(&args);
return 0;
}
-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)
{
const struct cgit_snapshot_format* f;
+ char *prefix = NULL;
f = get_format(filename);
if (!f) {
ctx.page.mimetype = "text/html";
cgit_print_http_headers(&ctx);
cgit_print_docstart(&ctx);
cgit_print_pageheader(&ctx);
cgit_print_error(fmt("Unsupported snapshot format: %s", filename));
cgit_print_docend();
return;
}
- 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';
+ }
if (!hex)
hex = head;
+ 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
@@ -1,8 +1,7 @@
#ifndef UI_SNAPSHOT_H
#define UI_SNAPSHOT_H
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);
#endif /* UI_SNAPSHOT_H */
diff --git a/ui-tag.c b/ui-tag.c
index 3aea87d..0e056e0 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -50,14 +50,15 @@ void cgit_print_tag(char *revname)
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>%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) {
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) {
@@ -71,9 +72,18 @@ void cgit_print_tag(char *revname)
}
html("<tr><td>Tagged object</td><td>");
cgit_object_link(tag->tagged);
html("</td></tr>\n");
html("</table>\n");
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
@@ -51,14 +51,16 @@ static void print_object(const unsigned char *sha1, char *path)
html_txt(buf + start);
html("</td></tr>\n");
start = idx + 1;
}
idx++;
}
- htmlf(linefmt, ++lineno);
- html_txt(buf + start);
+ if (start < idx) {
+ htmlf(linefmt, ++lineno);
+ html_txt(buf + start);
+ }
html("</td></tr>\n");
html("</table>\n");
}
static int ls_item(const unsigned char *sha1, const char *base, int baselen,
@@ -103,13 +105,13 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
curr_rev, fullpath);
}
htmlf("</td><td class='ls-size'>%li</td>", size);
html("<td>");
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)
cgit_stats_link("stats", NULL, "button", ctx.qry.head,
fullpath);
html("</td></tr>\n");
free(name);
return 0;