summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--Makefile2
-rw-r--r--cgit.c23
-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.c38
-rw-r--r--ui-repolist.c137
-rw-r--r--ui-shared.c29
-rw-r--r--ui-shared.h2
-rw-r--r--ui-snapshot.c98
-rw-r--r--ui-snapshot.h3
-rw-r--r--ui-tag.c9
-rw-r--r--ui-tree.c2
17 files changed, 377 insertions, 109 deletions
diff --git a/Makefile b/Makefile
index 21d6cc8..7793c0b 100644
--- a/Makefile
+++ b/Makefile
@@ -6,5 +6,5 @@ CGIT_CONFIG = /etc/cgitrc
6CACHE_ROOT = /var/cache/cgit 6CACHE_ROOT = /var/cache/cgit
7SHA1_HEADER = <openssl/sha.h> 7SHA1_HEADER = <openssl/sha.h>
8GIT_VER = 1.6.0.3 8GIT_VER = 1.6.1
9GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 9GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
10INSTALL = install 10INSTALL = install
diff --git a/cgit.c b/cgit.c
index 6e5215e..f35f605 100644
--- a/cgit.c
+++ b/cgit.c
@@ -155,4 +155,8 @@ static void querystring_cb(const char *name, const char *value)
155 } else if (!strcmp(name, "mimetype")) { 155 } else if (!strcmp(name, "mimetype")) {
156 ctx.qry.mimetype = xstrdup(value); 156 ctx.qry.mimetype = xstrdup(value);
157 } else if (!strcmp(name, "s")){
158 ctx.qry.sort = xstrdup(value);
159 } else if (!strcmp(name, "showmsg")) {
160 ctx.qry.showmsg = atoi(value);
157 } 161 }
158} 162}
@@ -435,15 +439,17 @@ int main(int argc, const char **argv)
435 http_parse_querystring(ctx.qry.raw, querystring_cb); 439 http_parse_querystring(ctx.qry.raw, querystring_cb);
436 440
437 /* If virtual-root isn't specified in cgitrc and no url 441 /* If virtual-root isn't specified in cgitrc, lets pretend
438 * parameter is specified on the querystring, lets pretend 442 * that virtual-root equals SCRIPT_NAME.
439 * that virtualroot equals SCRIPT_NAME and use PATH_INFO as
440 * url. This allows cgit to work with virtual urls without
441 * the need for rewriterules in the webserver (as long as
442 * PATH_INFO is included in the cache lookup key).
443 */ 443 */
444 if (!ctx.cfg.virtual_root && !ctx.qry.url) { 444 if (!ctx.cfg.virtual_root)
445 ctx.cfg.virtual_root = ctx.cfg.script_name; 445 ctx.cfg.virtual_root = ctx.cfg.script_name;
446
447 /* If no url parameter is specified on the querystring, lets
448 * use PATH_INFO as url. This allows cgit to work with virtual
449 * urls without the need for rewriterules in the webserver (as
450 * long as PATH_INFO is included in the cache lookup key).
451 */
446 path = getenv("PATH_INFO"); 452 path = getenv("PATH_INFO");
447 if (path) { 453 if (!ctx.qry.url && path) {
448 if (path[0] == '/') 454 if (path[0] == '/')
449 path++; 455 path++;
@@ -457,5 +463,4 @@ int main(int argc, const char **argv)
457 cgit_parse_url(ctx.qry.url); 463 cgit_parse_url(ctx.qry.url);
458 } 464 }
459 }
460 465
461 ttl = calc_ttl(); 466 ttl = calc_ttl();
diff --git a/cgit.css b/cgit.css
index a37d218..f19446d 100644
--- a/cgit.css
+++ b/cgit.css
@@ -121,4 +121,8 @@ table.list tr {
121} 121}
122 122
123table.list tr.logheader {
124 background: #eee;
125}
126
123table.list tr:hover { 127table.list tr:hover {
124 background: #eee; 128 background: #eee;
@@ -144,4 +148,15 @@ table.list td {
144} 148}
145 149
150table.list td.logsubject {
151 font-family: monospace;
152 font-weight: bold;
153}
154
155table.list td.logmsg {
156 font-family: monospace;
157 white-space: pre;
158 padding: 1em 0em 2em 0em;
159}
160
146table.list td a { 161table.list td a {
147 color: black; 162 color: black;
@@ -457,2 +472,26 @@ div.footer {
457 color: #ccc; 472 color: #ccc;
458} 473}
474a.branch-deco {
475 margin: 0px 0.5em;
476 padding: 0px 0.25em;
477 background-color: #88ff88;
478 border: solid 1px #007700;
479}
480a.tag-deco {
481 margin: 0px 0.5em;
482 padding: 0px 0.25em;
483 background-color: #ffff88;
484 border: solid 1px #777700;
485}
486a.remote-deco {
487 margin: 0px 0.5em;
488 padding: 0px 0.25em;
489 background-color: #ccccff;
490 border: solid 1px #000077;
491}
492a.deco {
493 margin: 0px 0.5em;
494 padding: 0px 0.25em;
495 background-color: #ff8888;
496 border: solid 1px #770000;
497}
diff --git a/cgit.h b/cgit.h
index 92f0c5a..cb2f176 100644
--- a/cgit.h
+++ b/cgit.h
@@ -62,4 +62,5 @@ struct cgit_repo {
62 int enable_log_filecount; 62 int enable_log_filecount;
63 int enable_log_linecount; 63 int enable_log_linecount;
64 time_t mtime;
64}; 65};
65 66
@@ -122,4 +123,6 @@ struct cgit_query {
122 int ofs; 123 int ofs;
123 int nohead; 124 int nohead;
125 char *sort;
126 int showmsg;
124}; 127};
125 128
diff --git a/cmd.c b/cmd.c
index 5b3c14c..8914fa5 100644
--- a/cmd.c
+++ b/cmd.c
@@ -105,6 +105,5 @@ static void refs_fn(struct cgit_context *ctx)
105static void snapshot_fn(struct cgit_context *ctx) 105static void snapshot_fn(struct cgit_context *ctx)
106{ 106{
107 cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, 107 cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, ctx->qry.path,
108 cgit_repobasename(ctx->repo->url), ctx->qry.path,
109 ctx->repo->snapshots, ctx->qry.nohead); 108 ctx->repo->snapshots, ctx->qry.nohead);
110} 109}
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
@@ -61,4 +61,5 @@ struct cgit_repo *cgit_add_repo(const char *url)
61 ret->module_link = ctx.cfg.module_link; 61 ret->module_link = ctx.cfg.module_link;
62 ret->readme = NULL; 62 ret->readme = NULL;
63 ret->mtime = -1;
63 return ret; 64 return ret;
64} 65}
@@ -267,8 +268,10 @@ int cgit_diff_files(const unsigned char *old_sha1,
267 return 1; 268 return 1;
268 269
270 memset(&diff_params, 0, sizeof(diff_params));
271 memset(&emit_params, 0, sizeof(emit_params));
272 memset(&emit_cb, 0, sizeof(emit_cb));
269 diff_params.flags = XDF_NEED_MINIMAL; 273 diff_params.flags = XDF_NEED_MINIMAL;
270 emit_params.ctxlen = 3; 274 emit_params.ctxlen = 3;
271 emit_params.flags = XDL_EMIT_FUNCNAMES; 275 emit_params.flags = XDL_EMIT_FUNCNAMES;
272 emit_params.find_func = NULL;
273 emit_cb.outf = filediff_cb; 276 emit_cb.outf = filediff_cb;
274 emit_cb.priv = fn; 277 emit_cb.priv = fn;
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
@@ -5,34 +5,34 @@
5prepare_tests "Verify snapshot" 5prepare_tests "Verify snapshot"
6 6
7run_test 'get foo/snapshot/test.tar.gz' ' 7run_test 'get foo/snapshot/master.tar.gz' '
8 cgit_url "foo/snapshot/test.tar.gz" >trash/tmp 8 cgit_url "foo/snapshot/master.tar.gz" >trash/tmp
9' 9'
10 10
11run_test 'check html headers' ' 11run_test 'check html headers' '
12 head -n 1 trash/tmp | 12 head -n 1 trash/tmp |
13 grep -e "Content-Type: application/x-tar" && 13 grep -e "Content-Type: application/x-gzip" &&
14 14
15 head -n 2 trash/tmp | 15 head -n 2 trash/tmp |
16 grep -e "Content-Disposition: inline; filename=.test.tar.gz." 16 grep -e "Content-Disposition: inline; filename=.master.tar.gz."
17' 17'
18 18
19run_test 'strip off the header lines' ' 19run_test 'strip off the header lines' '
20 tail -n +6 trash/tmp > trash/test.tar.gz 20 tail -n +6 trash/tmp > trash/master.tar.gz
21' 21'
22 22
23run_test 'verify gzip format' 'gunzip --test trash/test.tar.gz' 23run_test 'verify gzip format' 'gunzip --test trash/master.tar.gz'
24run_test 'untar' ' 24run_test 'untar' '
25 rm -rf trash/foo && 25 rm -rf trash/master &&
26 tar -xf trash/test.tar.gz -C trash 26 tar -xf trash/master.tar.gz -C trash
27' 27'
28 28
29run_test 'count files' ' 29run_test 'count files' '
30 c=$(ls -1 trash/foo/ | wc -l) && 30 c=$(ls -1 trash/master/ | wc -l) &&
31 test $c = 5 31 test $c = 5
32' 32'
33 33
34run_test 'verify untarred file-5' ' 34run_test 'verify untarred file-5' '
35 grep -e "^5$" trash/foo/file-5 && 35 grep -e "^5$" trash/master/file-5 &&
36 test $(cat trash/foo/file-5 | wc -l) = 1 36 test $(cat trash/master/file-5 | wc -l) = 1
37' 37'
38 38
diff --git a/ui-log.c b/ui-log.c
index d212984..3202848 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -32,11 +32,45 @@ void inspect_files(struct diff_filepair *pair)
32} 32}
33 33
34void show_commit_decorations(struct commit *commit)
35{
36 struct name_decoration *deco;
37 static char buf[1024];
38
39 buf[sizeof(buf) - 1] = 0;
40 deco = lookup_decoration(&name_decoration, &commit->object);
41 while (deco) {
42 if (!prefixcmp(deco->name, "refs/heads/")) {
43 strncpy(buf, deco->name + 11, sizeof(buf) - 1);
44 cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL,
45 0, NULL, NULL, ctx.qry.showmsg);
46 }
47 else if (!prefixcmp(deco->name, "tag: refs/tags/")) {
48 strncpy(buf, deco->name + 15, sizeof(buf) - 1);
49 cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
50 }
51 else if (!prefixcmp(deco->name, "refs/remotes/")) {
52 strncpy(buf, deco->name + 13, sizeof(buf) - 1);
53 cgit_log_link(buf, NULL, "remote-deco", NULL,
54 sha1_to_hex(commit->object.sha1), NULL,
55 0, NULL, NULL, ctx.qry.showmsg);
56 }
57 else {
58 strncpy(buf, deco->name, sizeof(buf) - 1);
59 cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
60 sha1_to_hex(commit->object.sha1));
61 }
62 deco = deco->next;
63 }
64}
65
34void print_commit(struct commit *commit) 66void print_commit(struct commit *commit)
35{ 67{
36 struct commitinfo *info; 68 struct commitinfo *info;
37 char *tmp; 69 char *tmp;
70 int cols = 2;
38 71
39 info = cgit_parse_commit(commit); 72 info = cgit_parse_commit(commit);
40 html("<tr><td>"); 73 htmlf("<tr%s><td>",
74 ctx.qry.showmsg ? " class='logheader'" : "");
41 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1)); 75 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
42 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp); 76 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
@@ -44,7 +78,9 @@ void print_commit(struct commit *commit)
44 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); 78 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
45 html_link_close(); 79 html_link_close();
46 html("</td><td>"); 80 htmlf("</td><td%s>",
81 ctx.qry.showmsg ? " class='logsubject'" : "");
47 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, 82 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
48 sha1_to_hex(commit->object.sha1)); 83 sha1_to_hex(commit->object.sha1));
84 show_commit_decorations(commit);
49 html("</td><td>"); 85 html("</td><td>");
50 html_txt(info->author); 86 html_txt(info->author);
@@ -62,4 +98,15 @@ void print_commit(struct commit *commit)
62 } 98 }
63 html("</td></tr>\n"); 99 html("</td></tr>\n");
100 if (ctx.qry.showmsg) {
101 if (ctx.repo->enable_log_filecount) {
102 cols++;
103 if (ctx.repo->enable_log_linecount)
104 cols++;
105 }
106 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
107 cols);
108 html_txt(info->msg);
109 html("</td></tr>\n");
110 }
64 cgit_free_commitinfo(info); 111 cgit_free_commitinfo(info);
65} 112}
@@ -106,4 +153,6 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
106 rev.show_root_diff = 0; 153 rev.show_root_diff = 0;
107 setup_revisions(argc, argv, &rev, NULL); 154 setup_revisions(argc, argv, &rev, NULL);
155 load_ref_decorations();
156 rev.show_decorations = 1;
108 rev.grep_filter.regflags |= REG_ICASE; 157 rev.grep_filter.regflags |= REG_ICASE;
109 compile_grep_patterns(&rev.grep_filter); 158 compile_grep_patterns(&rev.grep_filter);
@@ -114,6 +163,14 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
114 163
115 html("<tr class='nohover'><th class='left'>Age</th>" 164 html("<tr class='nohover'><th class='left'>Age</th>"
116 "<th class='left'>Commit message</th>" 165 "<th class='left'>Commit message");
117 "<th class='left'>Author</th>"); 166 if (pager) {
167 html(" (");
168 cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
169 NULL, ctx.qry.head, ctx.qry.sha1,
170 ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
171 ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
172 html(")");
173 }
174 html("</th><th class='left'>Author</th>");
118 if (ctx.repo->enable_log_filecount) { 175 if (ctx.repo->enable_log_filecount) {
119 html("<th class='left'>Files</th>"); 176 html("<th class='left'>Files</th>");
@@ -150,5 +207,5 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
150 ctx.qry.sha1, ctx.qry.path, 207 ctx.qry.sha1, ctx.qry.path,
151 ofs - cnt, ctx.qry.grep, 208 ofs - cnt, ctx.qry.grep,
152 ctx.qry.search); 209 ctx.qry.search, ctx.qry.showmsg);
153 html("&nbsp;"); 210 html("&nbsp;");
154 } 211 }
@@ -157,5 +214,5 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
157 ctx.qry.sha1, ctx.qry.path, 214 ctx.qry.sha1, ctx.qry.path,
158 ofs + cnt, ctx.qry.grep, 215 ofs + cnt, ctx.qry.grep,
159 ctx.qry.search); 216 ctx.qry.search, ctx.qry.showmsg);
160 } 217 }
161 html("</div>"); 218 html("</div>");
@@ -163,5 +220,5 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
163 html("<tr class='nohover'><td colspan='3'>"); 220 html("<tr class='nohover'><td colspan='3'>");
164 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0, 221 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
165 NULL, NULL); 222 NULL, NULL, ctx.qry.showmsg);
166 html("</td></tr>\n"); 223 html("</td></tr>\n");
167 } 224 }
diff --git a/ui-refs.c b/ui-refs.c
index 32e0429..25da00a 100644
--- a/ui-refs.c
+++ b/ui-refs.c
@@ -59,5 +59,6 @@ static int print_branch(struct refinfo *ref)
59 return 1; 59 return 1;
60 html("<tr><td>"); 60 html("<tr><td>");
61 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL); 61 cgit_log_link(name, NULL, NULL, name, NULL, NULL, 0, NULL, NULL,
62 ctx.qry.showmsg);
62 html("</td><td>"); 63 html("</td><td>");
63 64
@@ -79,5 +80,5 @@ static void print_tag_header()
79{ 80{
80 html("<tr class='nohover'><th class='left'>Tag</th>" 81 html("<tr class='nohover'><th class='left'>Tag</th>"
81 "<th class='left'>Reference</th>" 82 "<th class='left'>Download</th>"
82 "<th class='left'>Author</th>" 83 "<th class='left'>Author</th>"
83 "<th class='left' colspan='2'>Age</th></tr>\n"); 84 "<th class='left' colspan='2'>Age</th></tr>\n");
@@ -85,4 +86,29 @@ static void print_tag_header()
85} 86}
86 87
88static void print_tag_downloads(const struct cgit_repo *repo, const char *ref)
89{
90 const struct cgit_snapshot_format* f;
91 char *filename;
92 const char *basename;
93
94 if (!ref || strlen(ref) < 2)
95 return;
96
97 basename = cgit_repobasename(repo->url);
98 if (prefixcmp(ref, basename) != 0) {
99 if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1]))
100 ref++;
101 if (isdigit(ref[0]))
102 ref = xstrdup(fmt("%s-%s", basename, ref));
103 }
104
105 for (f = cgit_snapshot_formats; f->suffix; f++) {
106 if (!(repo->snapshots & f->bit))
107 continue;
108 filename = fmt("%s%s", ref, f->suffix);
109 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
110 html("&nbsp;&nbsp;");
111 }
112}
87static int print_tag(struct refinfo *ref) 113static int print_tag(struct refinfo *ref)
88{ 114{
@@ -99,4 +125,7 @@ static int print_tag(struct refinfo *ref)
99 cgit_tag_link(name, NULL, NULL, ctx.qry.head, name); 125 cgit_tag_link(name, NULL, NULL, ctx.qry.head, name);
100 html("</td><td>"); 126 html("</td><td>");
127 if (ctx.repo->snapshots && (tag->tagged->type == OBJ_COMMIT))
128 print_tag_downloads(ctx.repo, name);
129 else
101 cgit_object_link(tag->tagged); 130 cgit_object_link(tag->tagged);
102 html("</td><td>"); 131 html("</td><td>");
@@ -111,6 +140,9 @@ static int print_tag(struct refinfo *ref)
111 print_tag_header(); 140 print_tag_header();
112 html("<tr><td>"); 141 html("<tr><td>");
113 html_txt(name); 142 cgit_tag_link(name, NULL, NULL, ctx.qry.head, name);
114 html("</td><td>"); 143 html("</td><td>");
144 if (ctx.repo->snapshots && (ref->object->type == OBJ_COMMIT))
145 print_tag_downloads(ctx.repo, name);
146 else
115 cgit_object_link(ref->object); 147 cgit_object_link(ref->object);
116 html("</td></tr>\n"); 148 html("</td></tr>\n");
diff --git a/ui-repolist.c b/ui-repolist.c
index 2324273..2c13d50 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -33,19 +33,36 @@ time_t read_agefile(char *path)
33} 33}
34 34
35static void print_modtime(struct cgit_repo *repo) 35static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime)
36{ 36{
37 char *path; 37 char *path;
38 struct stat s; 38 struct stat s;
39 struct cgit_repo *r = (struct cgit_repo *)repo;
39 40
41 if (repo->mtime != -1) {
42 *mtime = repo->mtime;
43 return 1;
44 }
40 path = fmt("%s/%s", repo->path, ctx.cfg.agefile); 45 path = fmt("%s/%s", repo->path, ctx.cfg.agefile);
41 if (stat(path, &s) == 0) { 46 if (stat(path, &s) == 0) {
42 cgit_print_age(read_agefile(path), -1, NULL); 47 *mtime = read_agefile(path);
43 return; 48 r->mtime = *mtime;
49 return 1;
44 } 50 }
45 51
46 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); 52 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
47 if (stat(path, &s) != 0) 53 if (stat(path, &s) == 0)
48 return; 54 *mtime = s.st_mtime;
49 cgit_print_age(s.st_mtime, -1, NULL); 55 else
56 *mtime = 0;
57
58 r->mtime = *mtime;
59 return (r->mtime != 0);
60}
61
62static void print_modtime(struct cgit_repo *repo)
63{
64 time_t t;
65 if (get_repo_modtime(repo, &t))
66 cgit_print_age(t, -1, NULL);
50} 67}
51 68
@@ -74,11 +91,21 @@ int is_in_url(struct cgit_repo *repo)
74} 91}
75 92
93void print_sort_header(const char *title, const char *sort)
94{
95 htmlf("<th class='left'><a href='./?s=%s", sort);
96 if (ctx.qry.search) {
97 html("&q=");
98 html_url_arg(ctx.qry.search);
99 }
100 htmlf("'>%s</a></th>", title);
101}
102
76void print_header(int columns) 103void print_header(int columns)
77{ 104{
78 html("<tr class='nohover'>" 105 html("<tr class='nohover'>");
79 "<th class='left'>Name</th>" 106 print_sort_header("Name", "name");
80 "<th class='left'>Description</th>" 107 print_sort_header("Description", "desc");
81 "<th class='left'>Owner</th>" 108 print_sort_header("Owner", "owner");
82 "<th class='left'>Idle</th>"); 109 print_sort_header("Idle", "idle");
83 if (ctx.cfg.enable_index_links) 110 if (ctx.cfg.enable_index_links)
84 html("<th class='left'>Links</th>"); 111 html("<th class='left'>Links</th>");
@@ -97,8 +124,84 @@ void print_pager(int items, int pagelen, char *search)
97} 124}
98 125
126static int cmp(const char *s1, const char *s2)
127{
128 if (s1 && s2)
129 return strcmp(s1, s2);
130 if (s1 && !s2)
131 return -1;
132 if (s2 && !s1)
133 return 1;
134 return 0;
135}
136
137static int sort_name(const void *a, const void *b)
138{
139 const struct cgit_repo *r1 = a;
140 const struct cgit_repo *r2 = b;
141
142 return cmp(r1->name, r2->name);
143}
144
145static int sort_desc(const void *a, const void *b)
146{
147 const struct cgit_repo *r1 = a;
148 const struct cgit_repo *r2 = b;
149
150 return cmp(r1->desc, r2->desc);
151}
152
153static int sort_owner(const void *a, const void *b)
154{
155 const struct cgit_repo *r1 = a;
156 const struct cgit_repo *r2 = b;
157
158 return cmp(r1->owner, r2->owner);
159}
160
161static int sort_idle(const void *a, const void *b)
162{
163 const struct cgit_repo *r1 = a;
164 const struct cgit_repo *r2 = b;
165 time_t t1, t2;
166
167 t1 = t2 = 0;
168 get_repo_modtime(r1, &t1);
169 get_repo_modtime(r2, &t2);
170 return t2 - t1;
171}
172
173struct sortcolumn {
174 const char *name;
175 int (*fn)(const void *a, const void *b);
176};
177
178struct sortcolumn sortcolumn[] = {
179 {"name", sort_name},
180 {"desc", sort_desc},
181 {"owner", sort_owner},
182 {"idle", sort_idle},
183 {NULL, NULL}
184};
185
186int sort_repolist(char *field)
187{
188 struct sortcolumn *column;
189
190 for (column = &sortcolumn[0]; column->name; column++) {
191 if (strcmp(field, column->name))
192 continue;
193 qsort(cgit_repolist.repos, cgit_repolist.count,
194 sizeof(struct cgit_repo), column->fn);
195 return 1;
196 }
197 return 0;
198}
199
200
99void cgit_print_repolist() 201void cgit_print_repolist()
100{ 202{
101 int i, columns = 4, hits = 0, header = 0; 203 int i, columns = 4, hits = 0, header = 0;
102 char *last_group = NULL; 204 char *last_group = NULL;
205 int sorted = 0;
103 206
104 if (ctx.cfg.enable_index_links) 207 if (ctx.cfg.enable_index_links)
@@ -113,4 +216,7 @@ void cgit_print_repolist()
113 html_include(ctx.cfg.index_header); 216 html_include(ctx.cfg.index_header);
114 217
218 if(ctx.qry.sort)
219 sorted = sort_repolist(ctx.qry.sort);
220
115 html("<table summary='repository list' class='list nowrap'>"); 221 html("<table summary='repository list' class='list nowrap'>");
116 for (i=0; i<cgit_repolist.count; i++) { 222 for (i=0; i<cgit_repolist.count; i++) {
@@ -125,8 +231,9 @@ void cgit_print_repolist()
125 if (!header++) 231 if (!header++)
126 print_header(columns); 232 print_header(columns);
127 if ((last_group == NULL && ctx.repo->group != NULL) || 233 if (!sorted &&
234 ((last_group == NULL && ctx.repo->group != NULL) ||
128 (last_group != NULL && ctx.repo->group == NULL) || 235 (last_group != NULL && ctx.repo->group == NULL) ||
129 (last_group != NULL && ctx.repo->group != NULL && 236 (last_group != NULL && ctx.repo->group != NULL &&
130 strcmp(ctx.repo->group, last_group))) { 237 strcmp(ctx.repo->group, last_group)))) {
131 htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>", 238 htmlf("<tr class='nohover'><td colspan='%d' class='repogroup'>",
132 columns); 239 columns);
@@ -136,5 +243,5 @@ void cgit_print_repolist()
136 } 243 }
137 htmlf("<tr><td class='%s'>", 244 htmlf("<tr><td class='%s'>",
138 ctx.repo->group ? "sublevel-repo" : "toplevel-repo"); 245 !sorted && ctx.repo->group ? "sublevel-repo" : "toplevel-repo");
139 cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); 246 cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
140 html("</td><td>"); 247 html("</td><td>");
@@ -151,5 +258,5 @@ void cgit_print_repolist()
151 cgit_summary_link("summary", NULL, "button", NULL); 258 cgit_summary_link("summary", NULL, "button", NULL);
152 cgit_log_link("log", NULL, "button", NULL, NULL, NULL, 259 cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
153 0, NULL, NULL); 260 0, NULL, NULL, ctx.qry.showmsg);
154 cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL); 261 cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
155 html("</td>"); 262 html("</td>");
diff --git a/ui-shared.c b/ui-shared.c
index 76cd00d..fba1ba6 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -282,5 +282,6 @@ void cgit_plain_link(char *name, char *title, char *class, char *head,
282 282
283void cgit_log_link(char *name, char *title, char *class, char *head, 283void cgit_log_link(char *name, char *title, char *class, char *head,
284 char *rev, char *path, int ofs, char *grep, char *pattern) 284 char *rev, char *path, int ofs, char *grep, char *pattern,
285 int showmsg)
285{ 286{
286 char *delim; 287 char *delim;
@@ -306,4 +307,9 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
306 html("ofs="); 307 html("ofs=");
307 htmlf("%d", ofs); 308 htmlf("%d", ofs);
309 delim = "&";
310 }
311 if (showmsg) {
312 html(delim);
313 html("showmsg=1");
308 } 314 }
309 html("'>"); 315 html("'>");
@@ -366,9 +372,12 @@ void cgit_patch_link(char *name, char *title, char *class, char *head,
366void cgit_object_link(struct object *obj) 372void cgit_object_link(struct object *obj)
367{ 373{
368 char *page, *rev, *name; 374 char *page, *shortrev, *fullrev, *name;
369 375
376 fullrev = sha1_to_hex(obj->sha1);
377 shortrev = xstrdup(fullrev);
378 shortrev[10] = '\0';
370 if (obj->type == OBJ_COMMIT) { 379 if (obj->type == OBJ_COMMIT) {
371 cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, 380 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
372 ctx.qry.head, sha1_to_hex(obj->sha1)); 381 ctx.qry.head, fullrev);
373 return; 382 return;
374 } else if (obj->type == OBJ_TREE) 383 } else if (obj->type == OBJ_TREE)
@@ -378,7 +387,6 @@ void cgit_object_link(struct object *obj)
378 else 387 else
379 page = "blob"; 388 page = "blob";
380 rev = sha1_to_hex(obj->sha1); 389 name = fmt("%s %s...", typename(obj->type), shortrev);
381 name = fmt("%s %s", typename(obj->type), rev); 390 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
382 reporevlink(page, name, NULL, NULL, ctx.qry.head, rev, NULL);
383} 391}
384 392
@@ -569,4 +577,6 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page)
569 if (ctx.qry.sha2) 577 if (ctx.qry.sha2)
570 html_hidden("id2", ctx.qry.sha2); 578 html_hidden("id2", ctx.qry.sha2);
579 if (ctx.qry.showmsg)
580 html_hidden("showmsg", "1");
571 581
572 if (incl_search) { 582 if (incl_search) {
@@ -640,5 +650,5 @@ void cgit_print_pageheader(struct cgit_context *ctx)
640 ctx->qry.sha1, NULL); 650 ctx->qry.sha1, NULL);
641 cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, 651 cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
642 NULL, NULL, 0, NULL, NULL); 652 NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg);
643 cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, 653 cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
644 ctx->qry.sha1, NULL); 654 ctx->qry.sha1, NULL);
@@ -713,6 +723,5 @@ void cgit_print_snapshot_links(const char *repo, const char *head,
713 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, 723 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
714 f->suffix); 724 f->suffix);
715 cgit_snapshot_link(filename, NULL, NULL, (char *)head, 725 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
716 (char *)hex, filename);
717 html("<br/>"); 726 html("<br/>");
718 } 727 }
diff --git a/ui-shared.h b/ui-shared.h
index 3c8a6d0..2ab53ae 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -20,5 +20,5 @@ extern void cgit_plain_link(char *name, char *title, char *class, char *head,
20extern void cgit_log_link(char *name, char *title, char *class, char *head, 20extern void cgit_log_link(char *name, char *title, char *class, char *head,
21 char *rev, char *path, int ofs, char *grep, 21 char *rev, char *path, int ofs, char *grep,
22 char *pattern); 22 char *pattern, int showmsg);
23extern void cgit_commit_link(char *name, char *title, char *class, char *head, 23extern void cgit_commit_link(char *name, char *title, char *class, char *head,
24 char *rev); 24 char *rev);
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 9c4d086..f25613e 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -59,6 +59,6 @@ static int write_tar_bzip2_archive(struct archiver_args *args)
59const struct cgit_snapshot_format cgit_snapshot_formats[] = { 59const struct cgit_snapshot_format cgit_snapshot_formats[] = {
60 { ".zip", "application/x-zip", write_zip_archive, 0x1 }, 60 { ".zip", "application/x-zip", write_zip_archive, 0x1 },
61 { ".tar.gz", "application/x-tar", write_tar_gzip_archive, 0x2 }, 61 { ".tar.gz", "application/x-gzip", write_tar_gzip_archive, 0x2 },
62 { ".tar.bz2", "application/x-tar", write_tar_bzip2_archive, 0x4 }, 62 { ".tar.bz2", "application/x-bzip2", write_tar_bzip2_archive, 0x4 },
63 { ".tar", "application/x-tar", write_tar_archive, 0x8 }, 63 { ".tar", "application/x-tar", write_tar_archive, 0x8 },
64 {} 64 {}
@@ -115,56 +115,51 @@ static int make_snapshot(const struct cgit_snapshot_format *format,
115} 115}
116 116
117char *dwim_filename = NULL; 117/* Try to guess the requested revision from the requested snapshot name.
118const char *dwim_refname = NULL; 118 * First the format extension is stripped, e.g. "cgit-0.7.2.tar.gz" become
119 119 * "cgit-0.7.2". If this is a valid commit object name we've got a winner.
120static int ref_cb(const char *refname, const unsigned char *sha1, int flags, 120 * Otherwise, if the snapshot name has a prefix matching the result from
121 void *cb_data) 121 * repo_basename(), we strip the basename and any following '-' and '_'
122{ 122 * characters ("cgit-0.7.2" -> "0.7.2") and check the resulting name once
123 const char *r = refname; 123 * more. If this still isn't a valid commit object name, we check if pre-
124 while (r && *r) { 124 * pending a 'v' to the remaining snapshot name ("0.7.2" -> "v0.7.2") gives
125 fprintf(stderr, " cmp %s with %s:", dwim_filename, r); 125 * us something valid.
126 if (!strcmp(dwim_filename, r)) {
127 fprintf(stderr, "MATCH!\n");
128 dwim_refname = refname;
129 return 1;
130 }
131 fprintf(stderr, "no match\n");
132 if (isdigit(*r))
133 break;
134 r++;
135 }
136 return 0;
137}
138
139/* Try to guess the requested revision by combining repo name and tag name
140 * and comparing this to the requested snapshot name. E.g. the requested
141 * snapshot is "cgit-0.7.2.tar.gz" while repo name is "cgit" and tag name
142 * is "v0.7.2". First, the reponame is stripped off, leaving "-0.7.2.tar.gz".
143 * Next, any '-' and '_' characters are stripped, leaving "0.7.2.tar.gz".
144 * Finally, the requested format suffix is removed and we end up with "0.7.2".
145 * Then we test each tag against this dwimmed filename, and for each tag
146 * we even try to remove any leading characters which are non-digits. I.e.
147 * we first compare with "v0.7.2", then with "0.7.2" and we've got a match.
148 */ 126 */
149static const char *get_ref_from_filename(const char *url, const char *filename, 127static const char *get_ref_from_filename(const char *url, const char *filename,
150 const struct cgit_snapshot_format *fmt) 128 const struct cgit_snapshot_format *format)
151{ 129{
152 const char *reponame = cgit_repobasename(url); 130 const char *reponame;
153 fprintf(stderr, "reponame=%s, filename=%s\n", reponame, filename); 131 unsigned char sha1[20];
154 if (prefixcmp(filename, reponame)) 132 char *snapshot;
133
134 snapshot = xstrdup(filename);
135 snapshot[strlen(snapshot) - strlen(format->suffix)] = '\0';
136 fprintf(stderr, "snapshot=%s\n", snapshot);
137
138 if (get_sha1(snapshot, sha1) == 0)
139 return snapshot;
140
141 reponame = cgit_repobasename(url);
142 fprintf(stderr, "reponame=%s\n", reponame);
143 if (prefixcmp(snapshot, reponame) == 0) {
144 snapshot += strlen(reponame);
145 while (snapshot && (*snapshot == '-' || *snapshot == '_'))
146 snapshot++;
147 }
148
149 if (get_sha1(snapshot, sha1) == 0)
150 return snapshot;
151
152 snapshot = fmt("v%s", snapshot);
153 if (get_sha1(snapshot, sha1) == 0)
154 return snapshot;
155
155 return NULL; 156 return NULL;
156 filename += strlen(reponame);
157 while (filename && (*filename == '-' || *filename == '_'))
158 filename++;
159 dwim_filename = xstrdup(filename);
160 dwim_filename[strlen(filename) - strlen(fmt->suffix)] = '\0';
161 for_each_tag_ref(ref_cb, NULL);
162 return dwim_refname;
163} 157}
164 158
165void cgit_print_snapshot(const char *head, const char *hex, const char *prefix, 159void cgit_print_snapshot(const char *head, const char *hex,
166 const char *filename, int snapshots, int dwim) 160 const char *filename, int snapshots, int dwim)
167{ 161{
168 const struct cgit_snapshot_format* f; 162 const struct cgit_snapshot_format* f;
163 char *prefix = NULL;
169 164
170 f = get_format(filename); 165 f = get_format(filename);
@@ -179,10 +174,21 @@ void cgit_print_snapshot(const char *head, const char *hex, const char *prefix,
179 } 174 }
180 175
181 if (!hex && dwim) 176 if (!hex && dwim) {
182 hex = get_ref_from_filename(ctx.repo->url, filename, f); 177 hex = get_ref_from_filename(ctx.repo->url, filename, f);
178 if (hex == NULL) {
179 html_status(404, "Not found", 0);
180 return;
181 }
182 prefix = xstrdup(filename);
183 prefix[strlen(filename) - strlen(f->suffix)] = '\0';
184 }
183 185
184 if (!hex) 186 if (!hex)
185 hex = head; 187 hex = head;
186 188
189 if (!prefix)
190 prefix = xstrdup(cgit_repobasename(ctx.repo->url));
191
187 make_snapshot(f, hex, prefix, filename); 192 make_snapshot(f, hex, prefix, filename);
193 free(prefix);
188} 194}
diff --git a/ui-snapshot.h b/ui-snapshot.h
index 3540303..b6ede52 100644
--- a/ui-snapshot.h
+++ b/ui-snapshot.h
@@ -3,6 +3,5 @@
3 3
4extern void cgit_print_snapshot(const char *head, const char *hex, 4extern void cgit_print_snapshot(const char *head, const char *hex,
5 const char *prefix, const char *filename, 5 const char *filename, int snapshot, int dwim);
6 int snapshot, int dwim);
7 6
8#endif /* UI_SNAPSHOT_H */ 7#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
@@ -76,4 +76,13 @@ void cgit_print_tag(char *revname)
76 html("</table>\n"); 76 html("</table>\n");
77 print_tag_content(info->msg); 77 print_tag_content(info->msg);
78 } else {
79 html("<table class='commit-info'>\n");
80 htmlf("<tr><td>Tag name</td><td>");
81 html_txt(revname);
82 html("</td></tr>\n");
83 html("<tr><td>Tagged object</td><td>");
84 cgit_object_link(obj);
85 html("</td></tr>\n");
86 html("</table>\n");
78 } 87 }
79 return; 88 return;
diff --git a/ui-tree.c b/ui-tree.c
index 4bf372a..9876c99 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -109,5 +109,5 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
109 html("<td>"); 109 html("<td>");
110 cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, 110 cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev,
111 fullpath, 0, NULL, NULL); 111 fullpath, 0, NULL, NULL, ctx.qry.showmsg);
112 html("</td></tr>\n"); 112 html("</td></tr>\n");
113 free(name); 113 free(name);