aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--cgit.c45
-rw-r--r--cgit.css39
-rw-r--r--cgit.h3
-rw-r--r--cmd.c3
m---------git0
-rw-r--r--shared.c5
-rwxr-xr-xtests/t0107-snapshot.sh22
-rw-r--r--ui-log.c71
-rw-r--r--ui-refs.c42
-rw-r--r--ui-repolist.c137
-rw-r--r--ui-shared.c29
-rw-r--r--ui-shared.h2
-rw-r--r--ui-snapshot.c100
-rw-r--r--ui-snapshot.h3
-rw-r--r--ui-tag.c11
-rw-r--r--ui-tree.c2
17 files changed, 392 insertions, 124 deletions
diff --git a/Makefile b/Makefile
index 21d6cc8..7793c0b 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ 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.3
+GIT_VER = 1.6.1
GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
INSTALL = install
diff --git a/cgit.c b/cgit.c
index 6e5215e..f35f605 100644
--- a/cgit.c
+++ b/cgit.c
@@ -154,6 +154,10 @@ static void querystring_cb(const char *name, const char *value)
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);
}
}
@@ -434,28 +438,29 @@ int main(int argc, const char **argv)
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();
diff --git a/cgit.css b/cgit.css
index a37d218..f19446d 100644
--- a/cgit.css
+++ b/cgit.css
@@ -120,6 +120,10 @@ table.list tr {
background: white;
}
+table.list tr.logheader {
+ background: #eee;
+}
+
table.list tr:hover {
background: #eee;
}
@@ -143,6 +147,17 @@ table.list td {
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;
}
@@ -456,3 +471,27 @@ div.footer {
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;
+}
diff --git a/cgit.h b/cgit.h
index 92f0c5a..cb2f176 100644
--- a/cgit.h
+++ b/cgit.h
@@ -61,6 +61,7 @@ struct cgit_repo {
int snapshots;
int enable_log_filecount;
int enable_log_linecount;
+ time_t mtime;
};
struct cgit_repolist {
@@ -121,6 +122,8 @@ struct cgit_query {
char *url;
int ofs;
int nohead;
+ char *sort;
+ int showmsg;
};
struct cgit_config {
diff --git a/cmd.c b/cmd.c
index 5b3c14c..8914fa5 100644
--- a/cmd.c
+++ b/cmd.c
@@ -104,8 +104,7 @@ static void refs_fn(struct cgit_context *ctx)
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 031e6c898f61db1ae0c0be641eac6532c1000d5
+Subproject 8104ebfe8276657ee803cca7eb8665a78cf3ef8
diff --git a/shared.c b/shared.c
index f5875e4..a764c4d 100644
--- a/shared.c
+++ b/shared.c
@@ -60,6 +60,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
ret->enable_log_linecount = ctx.cfg.enable_log_linecount;
ret->module_link = ctx.cfg.module_link;
ret->readme = NULL;
+ ret->mtime = -1;
return ret;
}
@@ -266,10 +267,12 @@ int cgit_diff_files(const unsigned char *old_sha1,
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);
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
@@ -4,36 +4,36 @@
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 d212984..3202848 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -31,21 +31,57 @@ void inspect_files(struct diff_filepair *pair)
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) {
@@ -61,6 +97,17 @@ 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);
}
@@ -105,6 +152,8 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
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);
@@ -113,8 +162,16 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
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++;
@@ -149,20 +206,20 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
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-refs.c b/ui-refs.c
index 32e0429..25da00a 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -58,7 +58,8 @@ static int print_branch(struct refinfo *ref)
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) {
@@ -78,12 +79,37 @@ static int print_branch(struct refinfo *ref)
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;
@@ -98,7 +124,10 @@ static int print_tag(struct refinfo *ref)
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);
@@ -110,9 +139,12 @@ static int print_tag(struct refinfo *ref)
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;
diff --git a/ui-repolist.c b/ui-repolist.c
index 2324273..2c13d50 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -32,21 +32,38 @@ time_t read_agefile(char *path)
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)
@@ -73,13 +90,23 @@ int is_in_url(struct cgit_repo *repo)
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");
@@ -96,10 +123,86 @@ void print_pager(int items, int pagelen, char *search)
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++;
@@ -112,6 +215,9 @@ void cgit_print_repolist()
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];
@@ -124,10 +230,11 @@ void cgit_print_repolist()
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);
@@ -135,7 +242,7 @@ void cgit_print_repolist()
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);
@@ -150,7 +257,7 @@ void cgit_print_repolist()
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>");
}
diff --git a/ui-shared.c b/ui-shared.c
index 76cd00d..fba1ba6 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -281,7 +281,8 @@ 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)
{
char *delim;
@@ -305,6 +306,11 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
html(delim);
html("ofs=");
htmlf("%d", ofs);
+ delim = "&";
+ }
+ if (showmsg) {
+ html(delim);
+ html("showmsg=1");
}
html("'>");
html_txt(name);
@@ -365,11 +371,14 @@ void cgit_patch_link(char *name, char *title, char *class, char *head,
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";
@@ -377,9 +386,8 @@ void cgit_object_link(struct object *obj)
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)
@@ -568,6 +576,8 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page)
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)
@@ -639,7 +649,7 @@ void cgit_print_pageheader(struct cgit_context *ctx)
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"),
@@ -712,8 +722,7 @@ void cgit_print_snapshot_links(const char *repo, const char *head,
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 3c8a6d0..2ab53ae 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -19,7 +19,7 @@ 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,
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 9c4d086..f25613e 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -58,8 +58,8 @@ static int write_tar_bzip2_archive(struct archiver_args *args)
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 },
{}
};
@@ -114,58 +114,53 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
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) {
@@ -178,11 +173,22 @@ void cgit_print_snapshot(const char *head, const char *hex, const char *prefix,
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
@@ -2,7 +2,6 @@
#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 54b9f4c..0e056e0 100644
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -75,6 +75,15 @@ void cgit_print_tag(char *revname)
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 4bf372a..9876c99 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -108,7 +108,7 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
html("<td>");
cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev,
- fullpath, 0, NULL, NULL);
+ fullpath, 0, NULL, NULL, ctx.qry.showmsg);
html("</td></tr>\n");
free(name);
return 0;