Git fork

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>

authored by

Brandon Casey and committed by
Shawn O. Pearce
f285a2d7 7e7abea9

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