terminate diffbuf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 56e1996..668a3df 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -639,7 +639,6 @@ gw_summary(struct trans *gw_trans)
free(heads_html);
free(heads);
}
-
return error;
}
@@ -1032,7 +1031,7 @@ gw_get_time_str(time_t committer_time, int ref_tm)
char *minutes = "minutes ago", *seconds = "seconds ago";
char *now = "right now";
char *repo_age, *s;
- char datebuf[BUFFER_SIZE];
+ char datebuf[29];
switch (ref_tm) {
case TM_DIFF:
@@ -1186,10 +1185,10 @@ gw_get_repo_owner(struct trans *gw_trans, char *dir)
if ((f = fopen(d_file, "r")) == NULL)
goto err;
- if ((buf = calloc(BUFFER_SIZE, sizeof(char *))) == NULL)
+ if ((buf = calloc(128, sizeof(char *))) == NULL)
goto err;
- while ((fgets(buf, BUFFER_SIZE, f)) != NULL) {
+ while ((fgets(buf, 128, f)) != NULL) {
if ((pos = strstr(buf, gotweb)) != NULL)
break;
@@ -1201,7 +1200,7 @@ gw_get_repo_owner(struct trans *gw_trans, char *dir)
goto err;
do {
- fgets(buf, BUFFER_SIZE, f);
+ fgets(buf, 128, f);
} while ((comp = strcasestr(buf, gw_owner)) == NULL);
if (comp == NULL)
@@ -1285,30 +1284,32 @@ gw_get_repo_log(struct trans *gw_trans, const char *search_pattern,
struct buf *diffbuf = NULL;
time_t committer_time;
+ error = buf_alloc(&diffbuf, 0);
+ if (error != NULL)
+ return NULL;
+
if (search_pattern &&
regcomp(®ex, search_pattern, REG_EXTENDED | REG_NOSUB |
REG_NEWLINE))
return NULL;
- SIMPLEQ_INIT(&refs);
-
error = got_repo_open(&repo, gw_trans->repo_path, NULL);
if (error != NULL)
- goto done;
+ return NULL;
- error = buf_alloc(&diffbuf, BUFFER_SIZE);
- if (error != NULL)
- goto done;
+ SIMPLEQ_INIT(&refs);
if (start_commit == NULL) {
struct got_reference *head_ref;
error = got_ref_open(&head_ref, repo, gw_trans->headref, 0);
if (error != NULL)
goto done;
+
error = got_ref_resolve(&id1, repo, head_ref);
got_ref_close(head_ref);
if (error != NULL)
goto done;
+
error = got_object_open_as_commit(&commit, repo, id1);
} else {
struct got_reference *ref;
@@ -1364,6 +1365,7 @@ gw_get_repo_log(struct trans *gw_trans, const char *search_pattern,
if (error != NULL)
goto done;
+
error = got_repo_map_path(&in_repo_path, repo, gw_trans->repo_path, 1);
if (error != NULL)
goto done;
@@ -1702,8 +1704,7 @@ gw_get_repo_log(struct trans *gw_trans, const char *search_pattern,
return NULL;
}
- error = buf_append(&newsize, diffbuf, commit_row,
- strlen(commit_row));
+ error = buf_puts(&newsize, diffbuf, commit_row);
free(commit_parent);
free(commit_diff_disp);
@@ -1733,7 +1734,10 @@ gw_get_repo_log(struct trans *gw_trans, const char *search_pattern,
if (error)
goto done;
- logs = strdup(diffbuf->cb_buf);
+ if (buf_len(diffbuf) > 0) {
+ error = buf_putc(diffbuf, '\0');
+ logs = strdup(buf_get(diffbuf));
+ }
done:
buf_free(diffbuf);
if (commit != NULL)
@@ -1768,16 +1772,15 @@ gw_get_repo_tags(struct trans *gw_trans, int limit, int tag_type)
struct buf *diffbuf = NULL;
size_t newsize;
- error = buf_alloc(&diffbuf, BUFFER_SIZE);
+ error = buf_alloc(&diffbuf, 0);
if (error != NULL)
- goto done;
+ return NULL;
+ SIMPLEQ_INIT(&refs);
error = got_repo_open(&repo, gw_trans->repo_path, NULL);
if (error != NULL)
goto done;
- SIMPLEQ_INIT(&refs);
-
error = got_ref_list(&refs, repo, "refs/tags", cmp_tags, repo);
if (error)
goto done;
@@ -1816,7 +1819,6 @@ gw_get_repo_tags(struct trans *gw_trans, int limit, int tag_type)
tag_log0 = strdup(got_object_tag_get_message(tag));
- got_object_tag_close(tag);
if (tag_log0 == NULL) {
error = got_error_from_errno("strdup");
goto done;
@@ -1859,70 +1861,25 @@ gw_get_repo_tags(struct trans *gw_trans, int limit, int tag_type)
default:
break;
}
- /* /1* printf("%stag %s %s\n", GOT_COMMIT_SEP_STR, refname, refstr); *1/ */
- /* free(refstr); */
-
- /* error = got_ref_resolve(&id, repo, re->ref); */
- /* if (error) */
- /* break; */
- /* error = got_object_open_as_tag(&tag, repo, id); */
- /* free(id); */
- /* if (error) */
- /* break; */
- /* /1* printf("from: %s\n", got_object_tag_get_tagger(tag)); *1/ */
- /* tagger_time = got_object_tag_get_tagger_time(tag); */
- /* /1* datestr = get_datestr(&tagger_time, datebuf); *1/ */
- /* /1* if (datestr) *1/ */
- /* /1* printf("date: %s UTC\n", datestr); *1/ */
- /* error = got_object_id_str(&id_str, */
- /* got_object_tag_get_object_id(tag)); */
- /* if (error) */
- /* break; */
- /* switch (got_object_tag_get_object_type(tag)) { */
- /* case GOT_OBJ_TYPE_BLOB: */
- /* /1* printf("object: %s %s\n", GOT_OBJ_LABEL_BLOB, id_str); *1/ */
- /* break; */
- /* case GOT_OBJ_TYPE_TREE: */
- /* /1* printf("object: %s %s\n", GOT_OBJ_LABEL_TREE, id_str); *1/ */
- /* break; */
- /* case GOT_OBJ_TYPE_COMMIT: */
- /* /1* printf("object: %s %s\n", GOT_OBJ_LABEL_COMMIT, id_str); *1/ */
- /* break; */
- /* case GOT_OBJ_TYPE_TAG: */
- /* /1* printf("object: %s %s\n", GOT_OBJ_LABEL_TAG, id_str); *1/ */
- /* break; */
- /* default: */
- /* break; */
- /* } */
- /* free(id_str); */
- /* tagmsg0 = strdup(got_object_tag_get_message(tag)); */
- /* got_object_tag_close(tag); */
- /* if (tagmsg0 == NULL) { */
- /* error = got_error_from_errno("strdup"); */
- /* break; */
- /* } */
-
- /* tagmsg = tagmsg0; */
- /* do { */
- /* line = strsep(&tagmsg, "\n"); */
- /* if (line) */
- /* printf(" %s\n", line); */
- /* } while (line); */
- /* free(tagmsg0); */
- /* error = buf_append(&newsize, diffbuf, tags_row, */
- /* strlen(tags_row)); */
- error = buf_append(&newsize, diffbuf, tag_row, strlen(tag_row));
+ got_object_tag_close(tag);
+
+ error = buf_puts(&newsize, diffbuf, tag_row);
+
+ free(id_str);
+ free(refstr);
+ free(age);
free(tag_log0);
free(tag_row);
- free(age);
- free(id_str);
- id_str = NULL;
if (error || (limit && --limit == 0))
break;
}
- tags = strdup(diffbuf->cb_buf);
+
+ if (buf_len(diffbuf) > 0) {
+ error = buf_putc(diffbuf, '\0');
+ tags = strdup(buf_get(diffbuf));
+ }
done:
buf_free(diffbuf);
got_ref_list_free(&refs);
@@ -1945,9 +1902,9 @@ gw_get_repo_heads(struct trans *gw_trans)
struct buf *diffbuf = NULL;
size_t newsize;
- error = buf_alloc(&diffbuf, BUFFER_SIZE);
+ error = buf_alloc(&diffbuf, 0);
if (error != NULL)
- goto done;
+ return NULL;
error = got_repo_open(&repo, gw_trans->repo_path, NULL);
if (error != NULL)
@@ -1993,14 +1950,16 @@ gw_get_repo_heads(struct trans *gw_trans)
goto done;
}
- error = buf_append(&newsize, diffbuf, head_row,
- strlen(head_row));
+ error = buf_puts(&newsize, diffbuf, head_row);
free(head_navs_disp);
free(head_row);
}
- heads = strdup(diffbuf->cb_buf);
+ if (buf_len(diffbuf) > 0) {
+ error = buf_putc(diffbuf, '\0');
+ heads = strdup(buf_get(diffbuf));
+ }
done:
buf_free(diffbuf);
got_ref_list_free(&refs);
@@ -2050,9 +2009,9 @@ gw_html_escape(const char *html)
{
char *escaped_str = NULL, *buf;
char c[1];
- size_t sz, i;
+ size_t sz, i, buff_sz = 2048;
- if ((buf = calloc(BUFFER_SIZE, sizeof(char *))) == NULL)
+ if ((buf = calloc(buff_sz, sizeof(char *))) == NULL)
return NULL;
if (html == NULL)
@@ -2061,9 +2020,9 @@ gw_html_escape(const char *html)
if ((sz = strlen(html)) == 0)
return NULL;
- /* only work with BUFFER_SIZE */
- if (BUFFER_SIZE < sz)
- sz = BUFFER_SIZE;
+ /* only work with buff_sz */
+ if (buff_sz < sz)
+ sz = buff_sz;
for (i = 0; i < sz; i++) {
c[0] = html[i];