]> git.cameronkatri.com Git - cgit.git/blobdiff - ui-tree.c
Makefile: suppress pkg-config error
[cgit.git] / ui-tree.c
index aebe145cb88585ff2c05f4f3f915c47f7a914ae1..e4c3d2263cb3b85e84066ed4f0bfb6640bdcbe0a 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,6 +1,6 @@
 /* ui-tree.c: functions for tree output
  *
- * Copyright (C) 2006 Lars Hjemli
+ * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
  *
  * Licensed under GNU General Public License v2
  *   (see COPYING for full license text)
@@ -21,8 +21,7 @@ struct walk_tree_context {
 static void print_text_buffer(const char *name, char *buf, unsigned long size)
 {
        unsigned long lineno, idx;
-       const char *numberfmt =
-               "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n";
+       const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n";
 
        html("<table summary='blob content' class='blob'>\n");
 
@@ -46,13 +45,12 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size)
        }
 
        if (ctx.repo->source_filter) {
+               char *filter_arg = xstrdup(name);
                html("<td class='lines'><pre><code>");
-               ctx.repo->source_filter->argv[1] = xstrdup(name);
-               cgit_open_filter(ctx.repo->source_filter);
+               cgit_open_filter(ctx.repo->source_filter, filter_arg);
                html_raw(buf, size);
                cgit_close_filter(ctx.repo->source_filter);
-               free(ctx.repo->source_filter->argv[1]);
-               ctx.repo->source_filter->argv[1] = NULL;
+               free(filter_arg);
                html("</code></pre></td></tr></table>\n");
                return;
        }
@@ -129,14 +127,14 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
 {
        struct walk_tree_context *walk_tree_ctx = cbdata;
        char *name;
-       char *fullpath;
-       char *class;
+       struct strbuf fullpath = STRBUF_INIT;
+       struct strbuf class = STRBUF_INIT;
        enum object_type type;
        unsigned long size = 0;
 
        name = xstrdup(pathname);
-       fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "",
-                      ctx.qry.path ? "/" : "", name);
+       strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "",
+                   ctx.qry.path ? "/" : "", name);
 
        if (!S_ISGITLINK(mode)) {
                type = sha1_object_info(sha1, &size);
@@ -152,33 +150,34 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
        cgit_print_filemode(mode);
        html("</td><td>");
        if (S_ISGITLINK(mode)) {
-               cgit_submodule_link("ls-mod", fullpath, sha1_to_hex(sha1));
+               cgit_submodule_link("ls-mod", fullpath.buf, sha1_to_hex(sha1));
        } else if (S_ISDIR(mode)) {
                cgit_tree_link(name, NULL, "ls-dir", ctx.qry.head,
-                              walk_tree_ctx->curr_rev, fullpath);
+                              walk_tree_ctx->curr_rev, fullpath.buf);
        } else {
-               class = strrchr(name, '.');
-               if (class != NULL) {
-                       class = fmt("ls-blob %s", class + 1);
-               } else
-                       class = "ls-blob";
-               cgit_tree_link(name, NULL, class, ctx.qry.head,
-                              walk_tree_ctx->curr_rev, fullpath);
+               char *ext = strrchr(name, '.');
+               strbuf_addstr(&class, "ls-blob");
+               if (ext)
+                       strbuf_addf(&class, " %s", ext + 1);
+               cgit_tree_link(name, NULL, class.buf, ctx.qry.head,
+                              walk_tree_ctx->curr_rev, fullpath.buf);
        }
        htmlf("</td><td class='ls-size'>%li</td>", size);
 
        html("<td>");
        cgit_log_link("log", NULL, "button", ctx.qry.head,
-                     walk_tree_ctx->curr_rev, fullpath, 0, NULL, NULL,
+                     walk_tree_ctx->curr_rev, fullpath.buf, 0, NULL, NULL,
                      ctx.qry.showmsg);
        if (ctx.repo->max_stats)
                cgit_stats_link("stats", NULL, "button", ctx.qry.head,
-                               fullpath);
+                               fullpath.buf);
        if (!S_ISGITLINK(mode))
                cgit_plain_link("plain", NULL, "button", ctx.qry.head,
-                               walk_tree_ctx->curr_rev, fullpath);
+                               walk_tree_ctx->curr_rev, fullpath.buf);
        html("</td></tr>\n");
        free(name);
+       strbuf_release(&fullpath);
+       strbuf_release(&class);
        return 0;
 }