@matheusbsbs / matheus-bagliano / commits / f285a2d7ed
Fork 0

Replace calls to strbuf_init(&foo, 0) with STRBUF_INIT initializer

Many call sites use strbuf_init(&foo, 0) to initialize local strbuf variable "foo" which has not been accessed since its declaration. These can be replaced with a static initialization using the STRBUF_INIT macro which is just as readable, saves a function call, and takes up fewer lines. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Brandon Casey committed Oct 9, 2008 at 14:12 UTC f285a2d7ed6548666989406de8f0e7233eb84368
46 files changed +91 -197
archive-tar.c
+2 -4
@@ -124,11 +124,10 @@ static int write_tar_entry(struct archiver_args *args,
124 unsigned int mode, void *buffer, unsigned long size)
125 {
126 struct ustar_header header;
127 - struct strbuf ext_header;
127 + struct strbuf ext_header = STRBUF_INIT;
128 int err = 0;
129
130 memset(&header, 0, sizeof(header));
131 - strbuf_init(&ext_header, 0);
131
132 if (!sha1) {
133 *header.typeflag = TYPEFLAG_GLOBAL_HEADER;
@@ -211,10 +210,9 @@ static int write_tar_entry(struct archiver_args *args,
210 static int write_global_extended_header(struct archiver_args *args)
211 {
212 const unsigned char *sha1 = args->commit_sha1;
214 - struct strbuf ext_header;
213 + struct strbuf ext_header = STRBUF_INIT;
214 int err;
215
217 - strbuf_init(&ext_header, 0);
216 strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40);
217 err = write_tar_entry(args, NULL, NULL, 0, 0, ext_header.buf,
218 ext_header.len);
archive.c
+2 -4
@@ -29,11 +29,10 @@ static void format_subst(const struct commit *commit,
29 struct strbuf *buf)
30 {
31 char *to_free = NULL;
32 - struct strbuf fmt;
32 + struct strbuf fmt = STRBUF_INIT;
33
34 if (src == buf->buf)
35 to_free = strbuf_detach(buf, NULL);
36 - strbuf_init(&fmt, 0);
36 for (;;) {
37 const char *b, *c;
38
@@ -65,10 +64,9 @@ static void *sha1_file_to_archive(const char *path, const unsigned char *sha1,
64
65 buffer = read_sha1_file(sha1, type, sizep);
66 if (buffer && S_ISREG(mode)) {
68 - struct strbuf buf;
67 + struct strbuf buf = STRBUF_INIT;
68 size_t size = 0;
69
71 - strbuf_init(&buf, 0);
70 strbuf_attach(&buf, buffer, *sizep, *sizep + 1);
71 convert_to_working_tree(path, buf.buf, buf.len, &buf);
72 if (commit)
builtin-apply.c
+8 -18
@@ -321,13 +321,12 @@ static char *find_name(const char *line, char *def, int p_value, int terminate)
321 const char *start = line;
322
323 if (*line == '"') {
324 - struct strbuf name;
324 + struct strbuf name = STRBUF_INIT;
325
326 /*
327 * Proposed "new-style" GNU patch/diff format; see
328 * http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
329 */
330 - strbuf_init(&name, 0);
330 if (!unquote_c_style(&name, line, NULL)) {
331 char *cp;
332
@@ -675,11 +674,8 @@ static char *git_header_name(char *line, int llen)
674
675 if (*line == '"') {
676 const char *cp;
678 - struct strbuf first;
679 - struct strbuf sp;
680 -
681 - strbuf_init(&first, 0);
682 - strbuf_init(&sp, 0);
677 + struct strbuf first = STRBUF_INIT;
678 + struct strbuf sp = STRBUF_INIT;
679
680 if (unquote_c_style(&first, line, &second))
681 goto free_and_fail1;
@@ -741,10 +737,9 @@ static char *git_header_name(char *line, int llen)
737 */
738 for (second = name; second < line + llen; second++) {
739 if (*second == '"') {
744 - struct strbuf sp;
740 + struct strbuf sp = STRBUF_INIT;
741 const char *np;
742
747 - strbuf_init(&sp, 0);
743 if (unquote_c_style(&sp, second, NULL))
744 goto free_and_fail2;
745
@@ -1508,11 +1503,10 @@ static const char minuses[]=
1503
1504 static void show_stats(struct patch *patch)
1505 {
1511 - struct strbuf qname;
1506 + struct strbuf qname = STRBUF_INIT;
1507 char *cp = patch->new_name ? patch->new_name : patch->old_name;
1508 int max, add, del;
1509
1515 - strbuf_init(&qname, 0);
1510 quote_c_style(cp, &qname, NULL, 0);
1511
1512 /*
@@ -2292,14 +2286,12 @@ static void add_to_fn_table(struct patch *patch)
2286
2287 static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *ce)
2288 {
2295 - struct strbuf buf;
2289 + struct strbuf buf = STRBUF_INIT;
2290 struct image image;
2291 size_t len;
2292 char *img;
2293 struct patch *tpatch;
2294
2301 - strbuf_init(&buf, 0);
2302 -
2295 if (!(patch->is_copy || patch->is_rename) &&
2296 ((tpatch = in_fn_table(patch->old_name)) != NULL)) {
2297 if (tpatch == (struct patch *) -1) {
@@ -2779,7 +2771,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
2771 static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
2772 {
2773 int fd;
2782 - struct strbuf nbuf;
2774 + struct strbuf nbuf = STRBUF_INIT;
2775
2776 if (S_ISGITLINK(mode)) {
2777 struct stat st;
@@ -2798,7 +2790,6 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
2790 if (fd < 0)
2791 return -1;
2792
2801 - strbuf_init(&nbuf, 0);
2793 if (convert_to_working_tree(path, buf, size, &nbuf)) {
2794 size = nbuf.len;
2795 buf = nbuf.buf;
@@ -3060,13 +3051,12 @@ static void prefix_patches(struct patch *p)
3051 static int apply_patch(int fd, const char *filename, int options)
3052 {
3053 size_t offset;
3063 - struct strbuf buf;
3054 + struct strbuf buf = STRBUF_INIT;
3055 struct patch *list = NULL, **listp = &list;
3056 int skipped_patch = 0;
3057
3058 /* FIXME - memory leak when using multiple patch files as inputs */
3059 memset(&fn_table, 0, sizeof(struct string_list));
3069 - strbuf_init(&buf, 0);
3060 patch_input_file = filename;
3061 read_patch_file(&buf, fd);
3062 offset = 0;
builtin-blame.c
+1 -2
@@ -2062,7 +2062,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
2062 struct commit *commit;
2063 struct origin *origin;
2064 unsigned char head_sha1[20];
2065 - struct strbuf buf;
2065 + struct strbuf buf = STRBUF_INIT;
2066 const char *ident;
2067 time_t now;
2068 int size, len;
@@ -2082,7 +2082,6 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
2082
2083 origin = make_origin(commit, path);
2084
2085 - strbuf_init(&buf, 0);
2085 if (!contents_from || strcmp("-", contents_from)) {
2086 struct stat st;
2087 const char *read_from;
builtin-branch.c
+1 -2
@@ -334,11 +334,10 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
334 }
335
336 if (verbose) {
337 - struct strbuf subject;
337 + struct strbuf subject = STRBUF_INIT;
338 const char *sub = " **** invalid ref ****";
339 char stat[128];
340
341 - strbuf_init(&subject, 0);
341 stat[0] = '\0';
342
343 commit = item->commit;
builtin-cat-file.c
+1 -2
@@ -189,9 +189,8 @@ static int batch_one_object(const char *obj_name, int print_contents)
189
190 static int batch_objects(int print_contents)
191 {
192 - struct strbuf buf;
192 + struct strbuf buf = STRBUF_INIT;
193
194 - strbuf_init(&buf, 0);
194 while (strbuf_getline(&buf, stdin, '\n') != EOF) {
195 int error = batch_one_object(buf.buf, print_contents);
196 if (error)
builtin-checkout-index.c
+1 -3
@@ -268,13 +268,11 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
268 }
269
270 if (read_from_stdin) {
271 - struct strbuf buf, nbuf;
271 + struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
272
273 if (all)
274 die("git checkout-index: don't mix '--all' and '--stdin'");
275
276 - strbuf_init(&buf, 0);
277 - strbuf_init(&nbuf, 0);
276 while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
277 const char *p;
278 if (line_termination && buf.buf[0] == '"') {
builtin-checkout.c
+4 -8
@@ -310,8 +310,7 @@ static void show_local_changes(struct object *head)
310
311 static void describe_detached_head(char *msg, struct commit *commit)
312 {
313 - struct strbuf sb;
314 - strbuf_init(&sb, 0);
313 + struct strbuf sb = STRBUF_INIT;
314 parse_commit(commit);
315 pretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, 0, NULL, NULL, 0, 0);
316 fprintf(stderr, "%s %s... %s\n", msg,
@@ -360,8 +359,7 @@ struct branch_info {
359
360 static void setup_branch_path(struct branch_info *branch)
361 {
363 - struct strbuf buf;
364 - strbuf_init(&buf, 0);
362 + struct strbuf buf = STRBUF_INIT;
363 strbuf_addstr(&buf, "refs/heads/");
364 strbuf_addstr(&buf, branch->name);
365 branch->path = strbuf_detach(&buf, NULL);
@@ -484,7 +482,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
482 struct branch_info *old,
483 struct branch_info *new)
484 {
487 - struct strbuf msg;
485 + struct strbuf msg = STRBUF_INIT;
486 const char *old_desc;
487 if (opts->new_branch) {
488 create_branch(old->name, opts->new_branch, new->name, 0,
@@ -493,7 +491,6 @@ static void update_refs_for_switch(struct checkout_opts *opts,
491 setup_branch_path(new);
492 }
493
496 - strbuf_init(&msg, 0);
494 old_desc = old->name;
495 if (!old_desc)
496 old_desc = sha1_to_hex(old->commit->object.sha1);
@@ -738,8 +735,7 @@ no_reference:
735 }
736
737 if (opts.new_branch) {
741 - struct strbuf buf;
742 - strbuf_init(&buf, 0);
738 + struct strbuf buf = STRBUF_INIT;
739 strbuf_addstr(&buf, "refs/heads/");
740 strbuf_addstr(&buf, opts.new_branch);
741 if (!get_sha1(buf.buf, rev))
builtin-clean.c
+2 -4
@@ -31,11 +31,11 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
31 int i;
32 int show_only = 0, remove_directories = 0, quiet = 0, ignored = 0;
33 int ignored_only = 0, baselen = 0, config_set = 0, errors = 0;
34 - struct strbuf directory;
34 + struct strbuf directory = STRBUF_INIT;
35 struct dir_struct dir;
36 const char *path, *base;
37 static const char **pathspec;
38 - struct strbuf buf;
38 + struct strbuf buf = STRBUF_INIT;
39 const char *qname;
40 char *seen = NULL;
41 struct option options[] = {
@@ -58,7 +58,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
58
59 argc = parse_options(argc, argv, options, builtin_clean_usage, 0);
60
61 - strbuf_init(&buf, 0);
61 memset(&dir, 0, sizeof(dir));
62 if (ignored_only)
63 dir.show_ignored = 1;
@@ -88,7 +87,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
87 if (baselen)
88 path = base = xmemdupz(*pathspec, baselen);
89 read_directory(&dir, path, base, baselen, pathspec);
91 - strbuf_init(&directory, 0);
90
91 if (pathspec)
92 seen = xmalloc(argc > 0 ? argc : 1);
builtin-clone.c
+3 -6
@@ -264,10 +264,9 @@ pid_t junk_pid;
264
265 static void remove_junk(void)
266 {
267 - struct strbuf sb;
267 + struct strbuf sb = STRBUF_INIT;
268 if (getpid() != junk_pid)
269 return;
270 - strbuf_init(&sb, 0);
270 if (junk_git_dir) {
271 strbuf_addstr(&sb, junk_git_dir);
272 remove_dir_recursively(&sb, 0);
@@ -354,7 +353,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
353 char *path, *dir;
354 const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
355 char branch_top[256], key[256], value[256];
357 - struct strbuf reflog_msg;
356 + struct strbuf reflog_msg = STRBUF_INIT;
357 struct transport *transport = NULL;
358 char *src_ref_prefix = "refs/heads/";
359
@@ -404,7 +403,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
403 if (!stat(dir, &buf))
404 die("destination directory '%s' already exists.", dir);
405
407 - strbuf_init(&reflog_msg, 0);
406 strbuf_addf(&reflog_msg, "clone: from %s", repo);
407
408 if (option_bare)
@@ -526,7 +524,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
524 create_symref("HEAD", head_points_at->name, NULL);
525
526 if (!option_bare) {
529 - struct strbuf head_ref;
527 + struct strbuf head_ref = STRBUF_INIT;
528 const char *head = head_points_at->name;
529
530 if (!prefixcmp(head, "refs/heads/"))
@@ -539,7 +537,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
537 head_points_at->old_sha1,
538 NULL, 0, DIE_ON_ERR);
539
542 - strbuf_init(&head_ref, 0);
540 strbuf_addstr(&head_ref, branch_top);
541 strbuf_addstr(&head_ref, "HEAD");
542
builtin-commit.c
+5 -10
@@ -448,7 +448,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
448 {
449 struct stat statbuf;
450 int commitable, saved_color_setting;
451 - struct strbuf sb;
451 + struct strbuf sb = STRBUF_INIT;
452 char *buffer;
453 FILE *fp;
454 const char *hook_arg1 = NULL;
@@ -458,7 +458,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
458 if (!no_verify && run_hook(index_file, "pre-commit", NULL))
459 return 0;
460
461 - strbuf_init(&sb, 0);
461 if (message.len) {
462 strbuf_addbuf(&sb, &message);
463 hook_arg1 = "message";
@@ -511,10 +510,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
510 stripspace(&sb, 0);
511
512 if (signoff) {
514 - struct strbuf sob;
513 + struct strbuf sob = STRBUF_INIT;
514 int i;
515
517 - strbuf_init(&sob, 0);
516 strbuf_addstr(&sob, sign_off_header);
517 strbuf_addstr(&sob, fmt_name(getenv("GIT_COMMITTER_NAME"),
518 getenv("GIT_COMMITTER_EMAIL")));
@@ -672,7 +670,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
670 */
671 static int message_is_empty(struct strbuf *sb)
672 {
675 - struct strbuf tmpl;
673 + struct strbuf tmpl = STRBUF_INIT;
674 const char *nl;
675 int eol, i, start = 0;
676
@@ -680,7 +678,6 @@ static int message_is_empty(struct strbuf *sb)
678 return 0;
679
680 /* See if the template is just a prefix of the message. */
683 - strbuf_init(&tmpl, 0);
681 if (template_file && strbuf_read_file(&tmpl, template_file, 0) > 0) {
682 stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
683 if (start + tmpl.len <= sb->len &&
@@ -931,7 +928,7 @@ static const char commit_utf8_warn[] =
928
929 int cmd_commit(int argc, const char **argv, const char *prefix)
930 {
934 - struct strbuf sb;
931 + struct strbuf sb = STRBUF_INIT;
932 const char *index_file, *reflog_msg;
933 char *nl, *p;
934 unsigned char commit_sha1[20];
@@ -966,12 +963,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
963 for (c = commit->parents; c; c = c->next)
964 pptr = &commit_list_insert(c->item, pptr)->next;
965 } else if (in_merge) {
969 - struct strbuf m;
966 + struct strbuf m = STRBUF_INIT;
967 FILE *fp;
968
969 reflog_msg = "commit (merge)";
970 pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
974 - strbuf_init(&m, 0);
971 fp = fopen(git_path("MERGE_HEAD"), "r");
972 if (fp == NULL)
973 die("could not open %s for reading: %s",
@@ -991,7 +987,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
987 parents = reduce_heads(parents);
988
989 /* Finally, get the commit message */
994 - strbuf_init(&sb, 0);
990 if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
991 rollback_index_files();
992 die("could not read commit message");
builtin-fetch--tool.c
+1 -2
@@ -5,8 +5,7 @@
5
6 static char *get_stdin(void)
7 {
8 - struct strbuf buf;
9 - strbuf_init(&buf, 0);
8 + struct strbuf buf = STRBUF_INIT;
9 if (strbuf_read(&buf, 0, 1024) < 0) {
10 die("error reading standard input: %s", strerror(errno));
11 }
builtin-fmt-merge-msg.c
+1 -3
@@ -358,7 +358,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
358 };
359
360 FILE *in = stdin;
361 - struct strbuf input, output;
361 + struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
362 int ret;
363
364 git_config(fmt_merge_msg_config, NULL);
@@ -372,10 +372,8 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
372 die("cannot open %s", inpath);
373 }
374
375 - strbuf_init(&input, 0);
375 if (strbuf_read(&input, fileno(in), 0) < 0)
376 die("could not read input file %s", strerror(errno));
378 - strbuf_init(&output, 0);
377
378 ret = fmt_merge_msg(merge_summary, &input, &output);
379 if (ret)
builtin-help.c
+1 -3
@@ -322,11 +322,9 @@ static const char *cmd_to_page(const char *git_cmd)
322
323 static void setup_man_path(void)
324 {
325 - struct strbuf new_path;
325 + struct strbuf new_path = STRBUF_INIT;
326 const char *old_path = getenv("MANPATH");
327
328 - strbuf_init(&new_path, 0);
329 -
328 /* We should always put ':' after our path. If there is no
329 * old_path, the ':' at the end will let 'man' to try
330 * system-wide paths after ours to find the manual page. If
builtin-log.c
+4 -9
@@ -628,10 +628,9 @@ static void gen_message_id(struct rev_info *info, char *base)
628 const char *committer = git_committer_info(IDENT_WARN_ON_NO_NAME);
629 const char *email_start = strrchr(committer, '<');
630 const char *email_end = strrchr(committer, '>');
631 - struct strbuf buf;
631 + struct strbuf buf = STRBUF_INIT;
632 if (!email_start || !email_end || email_start > email_end - 1)
633 die("Could not extract email from committer identity.");
634 - strbuf_init(&buf, 0);
634 strbuf_addf(&buf, "%s.%lu.git.%.*s", base,
635 (unsigned long) time(NULL),
636 (int)(email_end - email_start - 1), email_start + 1);
@@ -650,7 +649,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
649 const char *msg;
650 const char *extra_headers = rev->extra_headers;
651 struct shortlog log;
653 - struct strbuf sb;
652 + struct strbuf sb = STRBUF_INIT;
653 int i;
654 const char *encoding = "utf-8";
655 struct diff_options opts;
@@ -671,7 +670,6 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
670 committer = git_committer_info(0);
671
672 msg = body;
674 - strbuf_init(&sb, 0);
673 pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822,
674 encoding);
675 pp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers,
@@ -753,7 +751,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
751 const char *in_reply_to = NULL;
752 struct patch_ids ids;
753 char *add_signoff = NULL;
756 - struct strbuf buf;
754 + struct strbuf buf = STRBUF_INIT;
755
756 git_config(git_format_config, NULL);
757 init_revisions(&rev, prefix);
@@ -861,8 +859,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
859 }
860 argc = j;
861
864 - strbuf_init(&buf, 0);
865 -
862 for (i = 0; i < extra_hdr_nr; i++) {
863 strbuf_addstr(&buf, extra_hdr[i]);
864 strbuf_addch(&buf, '\n');
@@ -1139,8 +1135,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
1135 sign = '-';
1136
1137 if (verbose) {
1142 - struct strbuf buf;
1143 - strbuf_init(&buf, 0);
1138 + struct strbuf buf = STRBUF_INIT;
1139 pretty_print_commit(CMIT_FMT_ONELINE, commit,
1140 &buf, 0, NULL, NULL, 0, 0);
1141 printf("%c %s %s\n", sign,
builtin-merge.c
+9 -18
@@ -226,7 +226,7 @@ static void reset_hard(unsigned const char *sha1, int verbose)
226
227 static void restore_state(void)
228 {
229 - struct strbuf sb;
229 + struct strbuf sb = STRBUF_INIT;
230 const char *args[] = { "stash", "apply", NULL, NULL };
231
232 if (is_null_sha1(stash))
@@ -234,7 +234,6 @@ static void restore_state(void)
234
235 reset_hard(head, 1);
236
237 - strbuf_init(&sb, 0);
237 args[2] = sha1_to_hex(stash);
238
239 /*
@@ -258,7 +257,7 @@ static void squash_message(void)
257 {
258 struct rev_info rev;
259 struct commit *commit;
261 - struct strbuf out;
260 + struct strbuf out = STRBUF_INIT;
261 struct commit_list *j;
262 int fd;
263
@@ -282,7 +281,6 @@ static void squash_message(void)
281 if (prepare_revision_walk(&rev))
282 die("revision walk setup failed");
283
285 - strbuf_init(&out, 0);
284 strbuf_addstr(&out, "Squashed commit of the following:\n");
285 while ((commit = get_revision(&rev)) != NULL) {
286 strbuf_addch(&out, '\n');
@@ -327,9 +325,8 @@ static int run_hook(const char *name)
325
326 static void finish(const unsigned char *new_head, const char *msg)
327 {
330 - struct strbuf reflog_message;
328 + struct strbuf reflog_message = STRBUF_INIT;
329
332 - strbuf_init(&reflog_message, 0);
330 if (!msg)
331 strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION"));
332 else {
@@ -380,7 +377,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
377 {
378 struct object *remote_head;
379 unsigned char branch_head[20], buf_sha[20];
383 - struct strbuf buf;
380 + struct strbuf buf = STRBUF_INIT;
381 const char *ptr;
382 int len, early;
383
@@ -389,7 +386,6 @@ static void merge_name(const char *remote, struct strbuf *msg)
386 if (!remote_head)
387 die("'%s' does not point to a commit", remote);
388
392 - strbuf_init(&buf, 0);
389 strbuf_addstr(&buf, "refs/heads/");
390 strbuf_addstr(&buf, remote);
391 resolve_ref(buf.buf, branch_head, 0, 0);
@@ -444,10 +440,9 @@ static void merge_name(const char *remote, struct strbuf *msg)
440 if (!strcmp(remote, "FETCH_HEAD") &&
441 !access(git_path("FETCH_HEAD"), R_OK)) {
442 FILE *fp;
447 - struct strbuf line;
443 + struct strbuf line = STRBUF_INIT;
444 char *ptr;
445
450 - strbuf_init(&line, 0);
446 fp = fopen(git_path("FETCH_HEAD"), "r");
447 if (!fp)
448 die("could not open %s for reading: %s",
@@ -545,7 +540,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
540 const char **args;
541 int i = 0, ret;
542 struct commit_list *j;
548 - struct strbuf buf;
543 + struct strbuf buf = STRBUF_INIT;
544 int index_fd;
545 struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
546
@@ -592,7 +587,6 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
587 } else {
588 args = xmalloc((4 + commit_list_count(common) +
589 commit_list_count(remoteheads)) * sizeof(char *));
595 - strbuf_init(&buf, 0);
590 strbuf_addf(&buf, "merge-%s", strategy);
591 args[i++] = buf.buf;
592 for (j = common; j; j = j->next)
@@ -847,7 +841,7 @@ static int evaluate_result(void)
841 int cmd_merge(int argc, const char **argv, const char *prefix)
842 {
843 unsigned char result_tree[20];
850 - struct strbuf buf;
844 + struct strbuf buf = STRBUF_INIT;
845 const char *head_arg;
846 int flag, head_invalid = 0, i;
847 int best_cnt = -1, merge_was_ok = 0, automerge_was_ok = 0;
@@ -896,7 +890,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
890 * Traditional format never would have "-m" so it is an
891 * additional safety measure to check for it.
892 */
899 - strbuf_init(&buf, 0);
893
894 if (!have_message && is_old_style_invocation(argc, argv)) {
895 strbuf_addstr(&merge_msg, argv[0]);
@@ -926,7 +919,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
919 reset_hard(remote_head->sha1, 0);
920 return 0;
921 } else {
929 - struct strbuf msg;
922 + struct strbuf msg = STRBUF_INIT;
923
924 /* We are invoked directly as the first-class UI. */
925 head_arg = "HEAD";
@@ -939,7 +932,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
932 * codepath so we discard the error in this
933 * loop.
934 */
942 - strbuf_init(&msg, 0);
935 for (i = 0; i < argc; i++)
936 merge_name(argv[i], &msg);
937 fmt_merge_msg(option_log, &msg, &merge_msg);
@@ -1014,7 +1006,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1006 !common->next &&
1007 !hashcmp(common->item->object.sha1, head)) {
1008 /* Again the most common case of merging one remote. */
1017 - struct strbuf msg;
1009 + struct strbuf msg = STRBUF_INIT;
1010 struct object *o;
1011 char hex[41];
1012
@@ -1024,7 +1016,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1016 hex,
1017 find_unique_abbrev(remoteheads->item->object.sha1,
1018 DEFAULT_ABBREV));
1027 - strbuf_init(&msg, 0);
1019 strbuf_addstr(&msg, "Fast forward");
1020 if (have_message)
1021 strbuf_addstr(&msg,
builtin-remote.c
+2 -6
@@ -54,7 +54,7 @@ static int add(int argc, const char **argv)
54 struct string_list track = { NULL, 0, 0 };
55 const char *master = NULL;
56 struct remote *remote;
57 - struct strbuf buf, buf2;
57 + struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
58 const char *name, *url;
59 int i;
60
@@ -81,9 +81,6 @@ static int add(int argc, const char **argv)
81 remote->fetch_refspec_nr))
82 die("remote %s already exists.", name);
83
84 - strbuf_init(&buf, 0);
85 - strbuf_init(&buf2, 0);
86 -
84 strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
85 if (!valid_fetch_refspec(buf2.buf))
86 die("'%s' is not a valid remote name", name);
@@ -352,7 +349,7 @@ static int rm(int argc, const char **argv)
349 OPT_END()
350 };
351 struct remote *remote;
355 - struct strbuf buf;
352 + struct strbuf buf = STRBUF_INIT;
353 struct known_remotes known_remotes = { NULL, NULL };
354 struct string_list branches = { NULL, 0, 0, 1 };
355 struct branches_for_remote cb_data = { NULL, &branches, &known_remotes };
@@ -368,7 +365,6 @@ static int rm(int argc, const char **argv)
365 known_remotes.to_delete = remote;
366 for_each_remote(add_known_remote, &known_remotes);
367
371 - strbuf_init(&buf, 0);
368 strbuf_addf(&buf, "remote.%s", remote->name);
369 if (git_config_rename_section(buf.buf, NULL) < 1)
370 return error("Could not remove config section '%s'", buf.buf);
builtin-rev-list.c
+1 -2
@@ -107,8 +107,7 @@ static void show_commit(struct commit *commit)
107 putchar('\n');
108
109 if (revs.verbose_header && commit->buffer) {
110 - struct strbuf buf;
111 - strbuf_init(&buf, 0);
110 + struct strbuf buf = STRBUF_INIT;
111 pretty_print_commit(revs.commit_format, commit,
112 &buf, revs.abbrev, NULL, NULL,
113 revs.date_mode, 0);
builtin-rev-parse.c
+1 -3
@@ -307,19 +307,17 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
307 OPT_END(),
308 };
309
310 - struct strbuf sb, parsed;
310 + struct strbuf sb = STRBUF_INIT, parsed = STRBUF_INIT;
311 const char **usage = NULL;
312 struct option *opts = NULL;
313 int onb = 0, osz = 0, unb = 0, usz = 0;
314
315 - strbuf_init(&parsed, 0);
315 strbuf_addstr(&parsed, "set --");
316 argc = parse_options(argc, argv, parseopt_opts, parseopt_usage,
317 PARSE_OPT_KEEP_DASHDASH);
318 if (argc < 1 || strcmp(argv[0], "--"))
319 usage_with_options(parseopt_usage, parseopt_opts);
320
322 - strbuf_init(&sb, 0);
321 /* get the usage up to the first line with a -- on it */
322 for (;;) {
323 if (strbuf_getline(&sb, stdin, '\n') == EOF)
builtin-show-branch.c
+1 -2
@@ -259,11 +259,10 @@ static void join_revs(struct commit_list **list_p,
259
260 static void show_one_commit(struct commit *commit, int no_name)
261 {
262 - struct strbuf pretty;
262 + struct strbuf pretty = STRBUF_INIT;
263 const char *pretty_str = "(unavailable)";
264 struct commit_name *name = commit->util;
265
266 - strbuf_init(&pretty, 0);
266 if (commit->object.parsed) {
267 pretty_print_commit(CMIT_FMT_ONELINE, commit,
268 &pretty, 0, NULL, NULL, 0, 0);
builtin-stripspace.c
+1 -2
@@ -70,14 +70,13 @@ void stripspace(struct strbuf *sb, int skip_comments)
70
71 int cmd_stripspace(int argc, const char **argv, const char *prefix)
72 {
73 - struct strbuf buf;
73 + struct strbuf buf = STRBUF_INIT;
74 int strip_comments = 0;
75
76 if (argc > 1 && (!strcmp(argv[1], "-s") ||
77 !strcmp(argv[1], "--strip-comments")))
78 strip_comments = 1;
79
80 - strbuf_init(&buf, 0);
80 if (strbuf_read(&buf, 0, 1024) < 0)
81 die("could not read the input");
82
builtin-tag.c
+1 -2
@@ -338,7 +338,7 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
338
339 int cmd_tag(int argc, const char **argv, const char *prefix)
340 {
341 - struct strbuf buf;
341 + struct strbuf buf = STRBUF_INIT;
342 unsigned char object[20], prev[20];
343 char ref[PATH_MAX];
344 const char *object_ref, *tag;
@@ -388,7 +388,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
388 if (verify)
389 return for_each_tag_name(argv, verify_tag);
390
391 - strbuf_init(&buf, 0);
391 if (msg.given || msgfile) {
392 if (msg.given && msgfile)
393 die("only one -F or -m option is allowed.");
builtin-update-index.c
+3 -7
@@ -297,11 +297,9 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
297
298 static void read_index_info(int line_termination)
299 {
300 - struct strbuf buf;
301 - struct strbuf uq;
300 + struct strbuf buf = STRBUF_INIT;
301 + struct strbuf uq = STRBUF_INIT;
302
303 - strbuf_init(&buf, 0);
304 - strbuf_init(&uq, 0);
303 while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
304 char *ptr, *tab;
305 char *path_name;
@@ -717,10 +715,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
715 free((char*)p);
716 }
717 if (read_from_stdin) {
720 - struct strbuf buf, nbuf;
718 + struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
719
722 - strbuf_init(&buf, 0);
723 - strbuf_init(&nbuf, 0);
720 setup_work_tree();
721 while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
722 const char *p;
combine-diff.c
+1 -2
@@ -742,9 +742,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
742
743 /* If not a fake symlink, apply filters, e.g. autocrlf */
744 if (is_file) {
745 - struct strbuf buf;
745 + struct strbuf buf = STRBUF_INIT;
746
747 - strbuf_init(&buf, 0);
747 if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) {
748 free(result);
749 result = strbuf_detach(&buf, &len);
config.c
+2 -4
@@ -753,9 +753,8 @@ static int store_write_section(int fd, const char* key)
753 {
754 const char *dot;
755 int i, success;
756 - struct strbuf sb;
756 + struct strbuf sb = STRBUF_INIT;
757
758 - strbuf_init(&sb, 0);
758 dot = memchr(key, '.', store.baselen);
759 if (dot) {
760 strbuf_addf(&sb, "[%.*s \"", (int)(dot - key), key);
@@ -780,7 +779,7 @@ static int store_write_pair(int fd, const char* key, const char* value)
779 int i, success;
780 int length = strlen(key + store.baselen + 1);
781 const char *quote = "";
783 - struct strbuf sb;
782 + struct strbuf sb = STRBUF_INIT;
783
784 /*
785 * Check to see if the value needs to be surrounded with a dq pair.
@@ -797,7 +796,6 @@ static int store_write_pair(int fd, const char* key, const char* value)
796 if (i && value[i - 1] == ' ')
797 quote = "\"";
798
800 - strbuf_init(&sb, 0);
799 strbuf_addf(&sb, "\t%.*s = %s",
800 length, key + store.baselen + 1, quote);
801
convert.c
+1 -2
@@ -281,7 +281,7 @@ static int apply_filter(const char *path, const char *src, size_t len,
281 * (child --> cmd) --> us
282 */
283 int ret = 1;
284 - struct strbuf nbuf;
284 + struct strbuf nbuf = STRBUF_INIT;
285 struct async async;
286 struct filter_params params;
287
@@ -299,7 +299,6 @@ static int apply_filter(const char *path, const char *src, size_t len,
299 if (start_async(&async))
300 return 0; /* error was already reported */
301
302 - strbuf_init(&nbuf, 0);
302 if (strbuf_read(&nbuf, async.out, len) < 0) {
303 error("read from external filter %s failed", cmd);
304 ret = 0;
diff.c
+5 -10
@@ -217,9 +217,8 @@ static char *quote_two(const char *one, const char *two)
217 {
218 int need_one = quote_c_style(one, NULL, NULL, 1);
219 int need_two = quote_c_style(two, NULL, NULL, 1);
220 - struct strbuf res;
220 + struct strbuf res = STRBUF_INIT;
221
222 - strbuf_init(&res, 0);
222 if (need_one + need_two) {
223 strbuf_addch(&res, '"');
224 quote_c_style(one, &res, NULL, 1);
@@ -683,7 +682,7 @@ static char *pprint_rename(const char *a, const char *b)
682 {
683 const char *old = a;
684 const char *new = b;
686 - struct strbuf name;
685 + struct strbuf name = STRBUF_INIT;
686 int pfx_length, sfx_length;
687 int len_a = strlen(a);
688 int len_b = strlen(b);
@@ -691,7 +690,6 @@ static char *pprint_rename(const char *a, const char *b)
690 int qlen_a = quote_c_style(a, NULL, NULL, 0);
691 int qlen_b = quote_c_style(b, NULL, NULL, 0);
692
694 - strbuf_init(&name, 0);
693 if (qlen_a || qlen_b) {
694 quote_c_style(a, &name, NULL, 0);
695 strbuf_addstr(&name, " => ");
@@ -834,8 +832,7 @@ static void fill_print_name(struct diffstat_file *file)
832 return;
833
834 if (!file->is_renamed) {
837 - struct strbuf buf;
838 - strbuf_init(&buf, 0);
835 + struct strbuf buf = STRBUF_INIT;
836 if (quote_c_style(file->name, &buf, NULL, 0)) {
837 pname = strbuf_detach(&buf, NULL);
838 } else {
@@ -1820,10 +1817,9 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
1817
1818 static int populate_from_stdin(struct diff_filespec *s)
1819 {
1823 - struct strbuf buf;
1820 + struct strbuf buf = STRBUF_INIT;
1821 size_t size = 0;
1822
1826 - strbuf_init(&buf, 0);
1823 if (strbuf_read(&buf, 0, 0) < 0)
1824 return error("error while reading from stdin %s",
1825 strerror(errno));
@@ -1875,7 +1871,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
1871
1872 if (!s->sha1_valid ||
1873 reuse_worktree_file(s->path, s->sha1, 0)) {
1878 - struct strbuf buf;
1874 + struct strbuf buf = STRBUF_INIT;
1875 struct stat st;
1876 int fd;
1877
@@ -1918,7 +1914,6 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
1914 /*
1915 * Convert from working tree format to canonical git format
1916 */
1921 - strbuf_init(&buf, 0);
1917 if (convert_to_git(s->path, s->data, s->size, &buf, safe_crlf)) {
1918 size_t size = 0;
1919 munmap(s->data, s->size);
editor.c
+1 -2
@@ -26,9 +26,8 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
26 int i = 0;
27 int failed;
28 const char *args[6];
29 - struct strbuf arg0;
29 + struct strbuf arg0 = STRBUF_INIT;
30
31 - strbuf_init(&arg0, 0);
31 if (strcspn(editor, "$ \t'") != len) {
32 /* there are specials */
33 strbuf_addf(&arg0, "%s \"$@\"", editor);
exec_cmd.c
+1 -3
@@ -59,9 +59,7 @@ static void add_path(struct strbuf *out, const char *path)
59 void setup_path(void)
60 {
61 const char *old_path = getenv("PATH");
62 - struct strbuf new_path;
63 -
64 - strbuf_init(&new_path, 0);
62 + struct strbuf new_path = STRBUF_INIT;
63
64 add_path(&new_path, argv_exec_path);
65 add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
fsck.c
+1 -2
@@ -307,9 +307,8 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...)
307 {
308 va_list ap;
309 int len;
310 - struct strbuf sb;
310 + struct strbuf sb = STRBUF_INIT;
311
312 - strbuf_init(&sb, 0);
312 strbuf_addf(&sb, "object %s:", obj->sha1?sha1_to_hex(obj->sha1):"(null)");
313
314 va_start(ap, fmt);
git.c
+1 -2
@@ -389,10 +389,9 @@ static void handle_internal_command(int argc, const char **argv)
389
390 static void execv_dashed_external(const char **argv)
391 {
392 - struct strbuf cmd;
392 + struct strbuf cmd = STRBUF_INIT;
393 const char *tmp;
394
395 - strbuf_init(&cmd, 0);
395 strbuf_addf(&cmd, "git-%s", argv[0]);
396
397 /*
graph.c
+4 -9
@@ -1010,14 +1010,12 @@ int graph_is_commit_finished(struct git_graph const *graph)
1010
1011 void graph_show_commit(struct git_graph *graph)
1012 {
1013 - struct strbuf msgbuf;
1013 + struct strbuf msgbuf = STRBUF_INIT;
1014 int shown_commit_line = 0;
1015
1016 if (!graph)
1017 return;
1018
1019 - strbuf_init(&msgbuf, 0);
1020 -
1019 while (!shown_commit_line) {
1020 shown_commit_line = graph_next_line(graph, &msgbuf);
1021 fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
@@ -1031,12 +1029,11 @@ void graph_show_commit(struct git_graph *graph)
1029
1030 void graph_show_oneline(struct git_graph *graph)
1031 {
1034 - struct strbuf msgbuf;
1032 + struct strbuf msgbuf = STRBUF_INIT;
1033
1034 if (!graph)
1035 return;
1036
1039 - strbuf_init(&msgbuf, 0);
1037 graph_next_line(graph, &msgbuf);
1038 fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
1039 strbuf_release(&msgbuf);
@@ -1044,12 +1041,11 @@ void graph_show_oneline(struct git_graph *graph)
1041
1042 void graph_show_padding(struct git_graph *graph)
1043 {
1047 - struct strbuf msgbuf;
1044 + struct strbuf msgbuf = STRBUF_INIT;
1045
1046 if (!graph)
1047 return;
1048
1052 - strbuf_init(&msgbuf, 0);
1049 graph_padding_line(graph, &msgbuf);
1050 fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
1051 strbuf_release(&msgbuf);
@@ -1057,7 +1053,7 @@ void graph_show_padding(struct git_graph *graph)
1053
1054 int graph_show_remainder(struct git_graph *graph)
1055 {
1060 - struct strbuf msgbuf;
1056 + struct strbuf msgbuf = STRBUF_INIT;
1057 int shown = 0;
1058
1059 if (!graph)
@@ -1066,7 +1062,6 @@ int graph_show_remainder(struct git_graph *graph)
1062 if (graph_is_commit_finished(graph))
1063 return 0;
1064
1069 - strbuf_init(&msgbuf, 0);
1065 for (;;) {
1066 graph_next_line(graph, &msgbuf);
1067 fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
hash-object.c
+1 -3
@@ -34,10 +34,8 @@ static void hash_object(const char *path, const char *type, int write_object,
34
35 static void hash_stdin_paths(const char *type, int write_objects)
36 {
37 - struct strbuf buf, nbuf;
37 + struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
38
39 - strbuf_init(&buf, 0);
40 - strbuf_init(&nbuf, 0);
39 while (strbuf_getline(&buf, stdin, '\n') != EOF) {
40 if (buf.buf[0] == '"') {
41 strbuf_reset(&nbuf);
imap-send.c
+1 -2
@@ -1266,10 +1266,9 @@ static int imap_store_msg(struct store *gctx, struct msg_data *data, int *uid)
1266
1267 static int read_message(FILE *f, struct msg_data *msg)
1268 {
1269 - struct strbuf buf;
1269 + struct strbuf buf = STRBUF_INIT;
1270
1271 memset(msg, 0, sizeof(*msg));
1272 - strbuf_init(&buf, 0);
1272
1273 do {
1274 if (strbuf_fread(&buf, CHUNKSIZE, f) <= 0)
log-tree.c
+1 -2
@@ -252,7 +252,7 @@ void log_write_email_headers(struct rev_info *opt, const char *name,
252
253 void show_log(struct rev_info *opt)
254 {
255 - struct strbuf msgbuf;
255 + struct strbuf msgbuf = STRBUF_INIT;
256 struct log_info *log = opt->loginfo;
257 struct commit *commit = log->commit, *parent = log->parent;
258 int abbrev = opt->diffopt.abbrev;
@@ -381,7 +381,6 @@ void show_log(struct rev_info *opt)
381 /*
382 * And then the pretty-printed message itself
383 */
384 - strbuf_init(&msgbuf, 0);
384 if (need_8bit_cte >= 0)
385 need_8bit_cte = has_non_ascii(opt->add_signoff);
386 pretty_print_commit(opt->commit_format, commit, &msgbuf,
merge-recursive.c
+1 -2
@@ -498,8 +498,7 @@ static void update_file_flags(struct merge_options *o,
498 if (type != OBJ_BLOB)
499 die("blob expected for %s '%s'", sha1_to_hex(sha), path);
500 if (S_ISREG(mode)) {
501 - struct strbuf strbuf;
502 - strbuf_init(&strbuf, 0);
501 + struct strbuf strbuf = STRBUF_INIT;
502 if (convert_to_working_tree(path, buf, size, &strbuf)) {
503 free(buf);
504 size = strbuf.len;
mktag.c
+1 -2
@@ -153,7 +153,7 @@ static int verify_tag(char *buffer, unsigned long size)
153
154 int main(int argc, char **argv)
155 {
156 - struct strbuf buf;
156 + struct strbuf buf = STRBUF_INIT;
157 unsigned char result_sha1[20];
158
159 if (argc != 1)
@@ -161,7 +161,6 @@ int main(int argc, char **argv)
161
162 setup_git_directory();
163
164 - strbuf_init(&buf, 0);
164 if (strbuf_read(&buf, 0, 4096) < 0) {
165 die("could not read from stdin");
166 }
mktree.c
+2 -4
@@ -65,8 +65,8 @@ static const char mktree_usage[] = "git-mktree [-z]";
65
66 int main(int ac, char **av)
67 {
68 - struct strbuf sb;
69 - struct strbuf p_uq;
68 + struct strbuf sb = STRBUF_INIT;
69 + struct strbuf p_uq = STRBUF_INIT;
70 unsigned char sha1[20];
71 int line_termination = '\n';
72
@@ -82,8 +82,6 @@ int main(int ac, char **av)
82 av++;
83 }
84
85 - strbuf_init(&sb, 0);
86 - strbuf_init(&p_uq, 0);
85 while (strbuf_getline(&sb, stdin, line_termination) != EOF) {
86 char *ptr, *ntr;
87 unsigned mode;
pretty.c
+1 -2
@@ -234,7 +234,7 @@ static char *get_header(const struct commit *commit, const char *key)
234
235 static char *replace_encoding_header(char *buf, const char *encoding)
236 {
237 - struct strbuf tmp;
237 + struct strbuf tmp = STRBUF_INIT;
238 size_t start, len;
239 char *cp = buf;
240
@@ -250,7 +250,6 @@ static char *replace_encoding_header(char *buf, const char *encoding)
250 return buf; /* should not happen but be defensive */
251 len = cp + 1 - (buf + start);
252
253 - strbuf_init(&tmp, 0);
253 strbuf_attach(&tmp, buf, strlen(buf), strlen(buf) + 1);
254 if (is_encoding_utf8(encoding)) {
255 /* we have re-coded to UTF-8; drop the header */
read-cache.c
+1 -2
@@ -1467,9 +1467,8 @@ int write_index(const struct index_state *istate, int newfd)
1467
1468 /* Write extension data here */
1469 if (istate->cache_tree) {
1470 - struct strbuf sb;
1470 + struct strbuf sb = STRBUF_INIT;
1471
1472 - strbuf_init(&sb, 0);
1472 cache_tree_write(&sb, istate->cache_tree);
1473 err = write_index_ext_header(&c, newfd, CACHE_EXT_TREE, sb.len) < 0
1474 || ce_write(&c, newfd, sb.buf, sb.len) < 0;
remote.c
+1 -2
@@ -245,7 +245,7 @@ static void read_branches_file(struct remote *remote)
245 {
246 const char *slash = strchr(remote->name, '/');
247 char *frag;
248 - struct strbuf branch;
248 + struct strbuf branch = STRBUF_INIT;
249 int n = slash ? slash - remote->name : 1000;
250 FILE *f = fopen(git_path("branches/%.*s", n, remote->name), "r");
251 char *s, *p;
@@ -283,7 +283,6 @@ static void read_branches_file(struct remote *remote)
283 * #branch specified. The "master" (or specified) branch is
284 * fetched and stored in the local branch of the same name.
285 */
286 - strbuf_init(&branch, 0);
286 frag = strchr(p, '#');
287 if (frag) {
288 *(frag++) = '\0';
rerere.c
+1 -3
@@ -79,7 +79,7 @@ static int handle_file(const char *path,
79 enum {
80 RR_CONTEXT = 0, RR_SIDE_1, RR_SIDE_2, RR_ORIGINAL,
81 } hunk = RR_CONTEXT;
82 - struct strbuf one, two;
82 + struct strbuf one = STRBUF_INIT, two = STRBUF_INIT;
83 FILE *f = fopen(path, "r");
84 FILE *out = NULL;
85
@@ -97,8 +97,6 @@ static int handle_file(const char *path,
97 if (sha1)
98 git_SHA1_Init(&ctx);
99
100 - strbuf_init(&one, 0);
101 - strbuf_init(&two, 0);
100 while (fgets(buf, sizeof(buf), f)) {
101 if (!prefixcmp(buf, "<<<<<<< ")) {
102 if (hunk != RR_CONTEXT)
sha1_file.c
+2 -4
@@ -2386,8 +2386,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
2386 * Convert blobs to git internal format
2387 */
2388 if ((type == OBJ_BLOB) && path) {
2389 - struct strbuf nbuf;
2390 - strbuf_init(&nbuf, 0);
2389 + struct strbuf nbuf = STRBUF_INIT;
2390 if (convert_to_git(path, buf, size, &nbuf,
2391 write_object ? safe_crlf : 0)) {
2392 buf = strbuf_detach(&nbuf, &size);
@@ -2411,8 +2410,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
2410 size_t size = xsize_t(st->st_size);
2411
2412 if (!S_ISREG(st->st_mode)) {
2414 - struct strbuf sbuf;
2415 - strbuf_init(&sbuf, 0);
2413 + struct strbuf sbuf = STRBUF_INIT;
2414 if (strbuf_read(&sbuf, fd, 4096) >= 0)
2415 ret = index_mem(sha1, sbuf.buf, sbuf.len, write_object,
2416 type, path);
walker.c
+1 -2
@@ -215,9 +215,8 @@ static int mark_complete(const char *path, const unsigned char *sha1, int flag,
215 int walker_targets_stdin(char ***target, const char ***write_ref)
216 {
217 int targets = 0, targets_alloc = 0;
218 - struct strbuf buf;
218 + struct strbuf buf = STRBUF_INIT;
219 *target = NULL; *write_ref = NULL;
220 - strbuf_init(&buf, 0);
220 while (1) {
221 char *rf_one = NULL;
222 char *tg_one;
ws.c
+1 -2
@@ -99,8 +99,7 @@ unsigned whitespace_rule(const char *pathname)
99 /* The returned string should be freed by the caller. */
100 char *whitespace_error_string(unsigned ws)
101 {
102 - struct strbuf err;
103 - strbuf_init(&err, 0);
102 + struct strbuf err = STRBUF_INIT;
103 if (ws & WS_TRAILING_SPACE)
104 strbuf_addstr(&err, "trailing whitespace");
105 if (ws & WS_SPACE_BEFORE_TAB) {
wt-status.c
+3 -7
@@ -103,10 +103,8 @@ static void wt_status_print_filepair(struct wt_status *s,
103 {
104 const char *c = color(t);
105 const char *one, *two;
106 - struct strbuf onebuf, twobuf;
106 + struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
107
108 - strbuf_init(&onebuf, 0);
109 - strbuf_init(&twobuf, 0);
108 one = quote_path(p->one->path, -1, &onebuf, s->prefix);
109 two = quote_path(p->two->path, -1, &twobuf, s->prefix);
110
@@ -190,9 +188,8 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
188 static void wt_status_print_initial(struct wt_status *s)
189 {
190 int i;
193 - struct strbuf buf;
191 + struct strbuf buf = STRBUF_INIT;
192
195 - strbuf_init(&buf, 0);
193 if (active_nr) {
194 s->commitable = 1;
195 wt_status_print_cached_header(s);
@@ -268,9 +265,8 @@ static void wt_status_print_untracked(struct wt_status *s)
265 struct dir_struct dir;
266 int i;
267 int shown_header = 0;
271 - struct strbuf buf;
268 + struct strbuf buf = STRBUF_INIT;
269
273 - strbuf_init(&buf, 0);
270 memset(&dir, 0, sizeof(dir));
271
272 if (!s->untracked) {