]> gitweb.ps.run Git - ps-cgit/commitdiff
Merge branch 'lh/stats'
authorLars Hjemli <hjemli@gmail.com>
Tue, 27 Jan 2009 19:16:37 +0000 (20:16 +0100)
committerLars Hjemli <hjemli@gmail.com>
Tue, 27 Jan 2009 19:16:37 +0000 (20:16 +0100)
Conflicts:
cgit.c
cgit.css
cgit.h
ui-tree.c

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
25 files changed:
Makefile
cache.c
cgit.c
cgit.css
cgit.h
cgitrc.5.txt
cmd.c
git
parsing.c
shared.c
tests/setup.sh
tests/t0010-validate-html.sh
tests/t0104-tree.sh
tests/t0107-snapshot.sh
ui-log.c
ui-patch.c
ui-plain.c
ui-refs.c
ui-repolist.c
ui-shared.c
ui-shared.h
ui-snapshot.c
ui-snapshot.h
ui-tag.c
ui-tree.c

index f426f985982f20dff008c4254e23ebf0afc17a98..a52285e0ef5809284b724afbe2051e368328ecf6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,33 @@
 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.
@@ -97,6 +119,9 @@ 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)
@@ -106,22 +131,23 @@ 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
diff --git a/cache.c b/cache.c
index 57068a11faa727f339777ec0ed0bc0e4d3b7a684..d7a8d5a913c72930a6c208246f7a8fea3300fe02 100644 (file)
--- a/cache.c
+++ b/cache.c
@@ -416,11 +416,11 @@ int cache_ls(const char *path)
                                  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);
        }
diff --git a/cgit.c b/cgit.c
index 57e11cdfb0b1095c2bd9b742a12f79793e4841a0..608cab658425e5c11270ac3d1690a842eec71891 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -159,6 +159,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);
        } else if (!strcmp(name, "period")) {
                ctx.qry.period = xstrdup(value);
        }
@@ -297,7 +301,6 @@ static void process_request(void *cbdata)
        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);
@@ -443,28 +446,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();
index ef30fbf899803c2a102875c1dfb3d25dd4f55760..e8214de13550e0e18bd2ef1b41f9d375bddb416c 100644 (file)
--- 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,6 +471,30 @@ 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;
+}
 table.stats {
        border: solid 1px black;
        border-collapse: collapse;
@@ -532,4 +571,3 @@ table.hgraph div.bar {
        background-color: #eee;
        height: 1em;
 }
-
diff --git a/cgit.h b/cgit.h
index f2cb671b12962d9b13ced83aa2685b4bc343796a..4fe94c69e6939d969572a6c1b4601d5267f390c2 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -62,6 +62,7 @@ struct cgit_repo {
        int enable_log_filecount;
        int enable_log_linecount;
        int max_stats;
+       time_t mtime;
 };
 
 struct cgit_repolist {
@@ -123,6 +124,8 @@ struct cgit_query {
        char *period;
        int   ofs;
        int nohead;
+       char *sort;
+       int showmsg;
 };
 
 struct cgit_config {
@@ -236,11 +239,5 @@ 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 */
index 0bbbea3b69c891068bda9e29666877ae2008a119..09f56a68366f015818a18d0f1ec92202d509582a 100644 (file)
@@ -302,8 +302,8 @@ root-desc=tracking the foobar development
 root-readme=/var/www/htdocs/about.html
 
 
-# Allow download of tar.gz, tar.bz and zip-files
-snapshots=tar.gz tar.bz zip
+# Allow download of tar.gz, tar.bz2 and zip-files
+snapshots=tar.gz tar.bz2 zip
 
 
 ##
diff --git a/cmd.c b/cmd.c
index 763a558710a6a4f76590dabcf3a800b3c79aa356..cf97da75a17f733b0627066921dbabf424165a6c 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -105,8 +105,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
index 97a7a82f199f165f85fe39a3c318b18c621e6335..8104ebfe8276657ee803cca7eb8665a78cf3ef83 160000 (submodule)
--- a/git
+++ b/git
@@ -1 +1 @@
-Subproject commit 97a7a82f199f165f85fe39a3c318b18c621e6335
+Subproject commit 8104ebfe8276657ee803cca7eb8665a78cf3ef83
index c8f30482eb301ba430ec97fc42c86feb47629c53..f3f3b15f736521f267e87dd474fee0af5c961250 100644 (file)
--- a/parsing.c
+++ b/parsing.c
@@ -96,6 +96,9 @@ char *parse_user(char *t, char **name, char **email, unsigned long *date)
        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;
@@ -110,6 +113,7 @@ const char *reencode(char **txt, const char *src_enc, const char *dst_enc)
        }
        return *txt;
 }
+#endif
 
 struct commitinfo *cgit_parse_commit(struct commit *commit)
 {
index 73826090669d2bfc8e6d59842e5212c7040230c4..578a54430a38d89036c2ae747e41a48d0f9666f1 100644 (file)
--- a/shared.c
+++ b/shared.c
@@ -61,6 +61,7 @@ struct cgit_repo *cgit_add_repo(const char *url)
        ret->max_stats = ctx.cfg.max_stats;
        ret->module_link = ctx.cfg.module_link;
        ret->readme = NULL;
+       ret->mtime = -1;
        return ret;
 }
 
@@ -267,10 +268,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);
index 1457dd51ec948595ff9f73a758c01f04501347b4..30f90d5c39663166ad51e3c41995e255041420ee 100755 (executable)
@@ -25,11 +25,13 @@ mkrepo() {
        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
@@ -101,7 +103,7 @@ 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
@@ -111,7 +113,7 @@ run_test()
        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
 }
index 94aa52b5c7cd894712b146ee77dd82dc5b45bef8..3fe4800ecf7b6fceb3d84b5102bc25152e786ce1 100755 (executable)
@@ -9,7 +9,7 @@ test_url()
        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
@@ -23,6 +23,13 @@ test_url()
 
 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"'
index 0d62cc82c5d5dbbc90e351a73e3c748e427ba7c0..33f4eb00ff2808e9f4335b397e809d695b464301 100755 (executable)
@@ -15,7 +15,7 @@ run_test 'find line 1' '
 '
 
 run_test 'no line 2' '
-       grep -e "<a id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
+       grep -e "<a id=.n2. name=.n2. href=.#n2.>2</a>" trash/tmp
 '
 
 run_test 'generate foo+bar/tree' 'cgit_url "foo%2bbar/tree" >trash/tmp'
index d97c4655b166e167dfc3e8e652708337a83d8f13..8ab4912a282b667fb19779138c7fe739acdfc321 100755 (executable)
@@ -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
index 8dd8b898c4deadb9c89dc53f070c2f22e0f56eb0..32028484b7a531898aa4c3a00e51ebad4ec53da6 100644 (file)
--- 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,21 +97,45 @@ 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);
 }
 
+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") ||
@@ -92,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);
@@ -100,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++;
@@ -136,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");
        }
 }
index e60877d8ed2fcf2a6a76dab90d08b5eadcc9ea6f..1d7733645d68efb41e682fa8e24c80dc9f8958df 100644 (file)
@@ -101,9 +101,9 @@ void cgit_print_patch(char *hex)
        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);
index be559e02e5192606e6ceccda40c2b05afaf70862..5addd9e686539ca41f264394ecf6836aa739af4e 100644 (file)
@@ -18,7 +18,7 @@ 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) {
index 32e0429242776e7d48e7666a1d585a2dca58685a..25da00a0f25ada4218e9e518f022dc32838a5769 100644 (file)
--- 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;
index ab050c788af1ca58564f9dd70c7ebc984feadabb..2c13d5041b2a4931358b241b6316db3d96a9a6b5 100644 (file)
@@ -6,6 +6,10 @@
  *   (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"
@@ -19,7 +23,8 @@ time_t read_agefile(char *path)
 
        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);
@@ -27,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)
@@ -68,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");
@@ -91,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++;
@@ -107,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];
@@ -119,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);
@@ -130,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);
@@ -145,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>");
                }
index 1bb30c291646c3e0d07fc5ca736024c1de6dd39d..4f2851273418dc9a81c4af942660e4923a149f5e 100644 (file)
@@ -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);
@@ -371,11 +377,14 @@ void cgit_stats_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";
@@ -383,9 +392,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)
@@ -574,6 +582,8 @@ void cgit_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)
@@ -583,15 +593,20 @@ void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
        }
 }
 
+const char *fallback_cmd = "repolist";
+
 char *hc(struct cgit_cmd *cmd, const char *page)
 {
-       return (strcmp(cmd->name, page) ? NULL : "active");
+       return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active");
 }
 
 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='");
@@ -640,7 +655,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"),
@@ -716,8 +731,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/>");
        }
 }
index 1524dc35a3b1e28a2be61d5de38021517c83f4d0..5a3821f20e1e973f1446845d2641f5e5bc13f5a1 100644 (file)
@@ -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,
index 9c4d086eeba591d1069a28e20401b2f2b4631f02..f25613e9d6c98530e48c1814305000d22ebbb44f 100644 (file)
@@ -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);
 }
index 35403033394035374ddda0f2844f341c9400a298..b6ede5225a847c57ae734f1d59f875994a94c571 100644 (file)
@@ -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 */
index 3aea87d8032869c4adcc6b4041f16729b5db1a00..0e056e016092f53c508d86cdefd3e76f0fcb7d36 100644 (file)
--- a/ui-tag.c
+++ b/ui-tag.c
@@ -53,8 +53,9 @@ void cgit_print_tag(char *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);
@@ -74,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;
 }
index e27e79680a58d8625308657de7a5e66280aaf4df..4b8e7a034cd7482075a9015c13584bd077d200f1 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -54,8 +54,10 @@ static void print_object(const unsigned char *sha1, char *path)
                }
                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");
 }
@@ -106,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);
        if (ctx.repo->max_stats)
                cgit_stats_link("stats", NULL, "button", ctx.qry.head,
                                fullpath);