aboutsummaryrefslogtreecommitdiffstats
path: root/ui-tree.c
diff options
context:
space:
mode:
authorJohn Keeping <john@keeping.me.uk>2013-04-06 10:28:57 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2013-04-08 16:12:52 +0200
commitfb3655df3bf85bd405c5921bbd4b3a54c705c839 (patch)
tree419a962a0b82f5ba3023791549044ff462229250 /ui-tree.c
parent42d5476f258e7909682f1b611da00d64507d45c6 (diff)
use struct strbuf instead of static buffers
Use "struct strbuf" from Git to remove the limit on file path length. Notes on scan-tree: This is slightly involved since I decided to pass the strbuf into add_repo() and modify if whenever a new file name is required, which should avoid any extra allocations within that function. The pattern there is to append the filename, use it and then reset the buffer to its original length (retaining a trailing '/'). Notes on ui-snapshot: Since write_archive modifies the argv array passed to it we copy the argv_array values into a new array of char* and then free the original argv_array structure and the new array without worrying about what the values now look like. Signed-off-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'ui-tree.c')
-rw-r--r--ui-tree.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/ui-tree.c b/ui-tree.c
index aebe145..aa5dee9 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -129,14 +129,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 +152,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;
}