diff options
author | John Keeping <john@keeping.me.uk> | 2013-04-06 18:28:57 (JST) |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2013-04-08 23:12:52 (JST) |
commit | fb3655df3bf85bd405c5921bbd4b3a54c705c839 (patch) | |
tree | 419a962a0b82f5ba3023791549044ff462229250 /ui-tag.c | |
parent | 42d5476f258e7909682f1b611da00d64507d45c6 (diff) | |
download | cgit-fb3655df3bf85bd405c5921bbd4b3a54c705c839.zip cgit-fb3655df3bf85bd405c5921bbd4b3a54c705c839.tar.gz |
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-tag.c')
-rw-r--r-- | ui-tag.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -41,6 +41,7 @@ static void print_download_links(char *revname) | |||
41 | 41 | ||
42 | void cgit_print_tag(char *revname) | 42 | void cgit_print_tag(char *revname) |
43 | { | 43 | { |
44 | struct strbuf fullref = STRBUF_INIT; | ||
44 | unsigned char sha1[20]; | 45 | unsigned char sha1[20]; |
45 | struct object *obj; | 46 | struct object *obj; |
46 | struct tag *tag; | 47 | struct tag *tag; |
@@ -49,20 +50,21 @@ void cgit_print_tag(char *revname) | |||
49 | if (!revname) | 50 | if (!revname) |
50 | revname = ctx.qry.head; | 51 | revname = ctx.qry.head; |
51 | 52 | ||
52 | if (get_sha1(fmt("refs/tags/%s", revname), sha1)) { | 53 | strbuf_addf(&fullref, "refs/tags/%s", revname); |
54 | if (get_sha1(fullref.buf, sha1)) { | ||
53 | cgit_print_error("Bad tag reference: %s", revname); | 55 | cgit_print_error("Bad tag reference: %s", revname); |
54 | return; | 56 | goto cleanup; |
55 | } | 57 | } |
56 | obj = parse_object(sha1); | 58 | obj = parse_object(sha1); |
57 | if (!obj) { | 59 | if (!obj) { |
58 | cgit_print_error("Bad object id: %s", sha1_to_hex(sha1)); | 60 | cgit_print_error("Bad object id: %s", sha1_to_hex(sha1)); |
59 | return; | 61 | goto cleanup; |
60 | } | 62 | } |
61 | if (obj->type == OBJ_TAG) { | 63 | if (obj->type == OBJ_TAG) { |
62 | tag = lookup_tag(sha1); | 64 | tag = lookup_tag(sha1); |
63 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { | 65 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { |
64 | cgit_print_error("Bad tag object: %s", revname); | 66 | cgit_print_error("Bad tag object: %s", revname); |
65 | return; | 67 | goto cleanup; |
66 | } | 68 | } |
67 | html("<table class='commit-info'>\n"); | 69 | html("<table class='commit-info'>\n"); |
68 | htmlf("<tr><td>tag name</td><td>"); | 70 | htmlf("<tr><td>tag name</td><td>"); |
@@ -101,5 +103,7 @@ void cgit_print_tag(char *revname) | |||
101 | print_download_links(revname); | 103 | print_download_links(revname); |
102 | html("</table>\n"); | 104 | html("</table>\n"); |
103 | } | 105 | } |
104 | return; | 106 | |
107 | cleanup: | ||
108 | strbuf_release(&fullref); | ||
105 | } | 109 | } |