Commit f285a2d7 authored by Brandon Casey's avatar Brandon Casey Committed by Shawn O. Pearce

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: default avatarBrandon Casey <[email protected]>
Signed-off-by: default avatarShawn O. Pearce <[email protected]>
parent 7e7abea9
......@@ -124,11 +124,10 @@ static int write_tar_entry(struct archiver_args *args,
unsigned int mode, void *buffer, unsigned long size)
{
struct ustar_header header;
struct strbuf ext_header;
struct strbuf ext_header = STRBUF_INIT;
int err = 0;
memset(&header, 0, sizeof(header));
strbuf_init(&ext_header, 0);
if (!sha1) {
*header.typeflag = TYPEFLAG_GLOBAL_HEADER;
......@@ -211,10 +210,9 @@ static int write_tar_entry(struct archiver_args *args,
static int write_global_extended_header(struct archiver_args *args)
{
const unsigned char *sha1 = args->commit_sha1;
struct strbuf ext_header;
struct strbuf ext_header = STRBUF_INIT;
int err;
strbuf_init(&ext_header, 0);
strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40);
err = write_tar_entry(args, NULL, NULL, 0, 0, ext_header.buf,
ext_header.len);
......
......@@ -29,11 +29,10 @@ static void format_subst(const struct commit *commit,
struct strbuf *buf)
{
char *to_free = NULL;
struct strbuf fmt;
struct strbuf fmt = STRBUF_INIT;
if (src == buf->buf)
to_free = strbuf_detach(buf, NULL);
strbuf_init(&fmt, 0);
for (;;) {
const char *b, *c;
......@@ -65,10 +64,9 @@ static void *sha1_file_to_archive(const char *path, const unsigned char *sha1,
buffer = read_sha1_file(sha1, type, sizep);
if (buffer && S_ISREG(mode)) {
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
size_t size = 0;
strbuf_init(&buf, 0);
strbuf_attach(&buf, buffer, *sizep, *sizep + 1);
convert_to_working_tree(path, buf.buf, buf.len, &buf);
if (commit)
......
......@@ -321,13 +321,12 @@ static char *find_name(const char *line, char *def, int p_value, int terminate)
const char *start = line;
if (*line == '"') {
struct strbuf name;
struct strbuf name = STRBUF_INIT;
/*
* Proposed "new-style" GNU patch/diff format; see
* http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
*/
strbuf_init(&name, 0);
if (!unquote_c_style(&name, line, NULL)) {
char *cp;
......@@ -675,11 +674,8 @@ static char *git_header_name(char *line, int llen)
if (*line == '"') {
const char *cp;
struct strbuf first;
struct strbuf sp;
strbuf_init(&first, 0);
strbuf_init(&sp, 0);
struct strbuf first = STRBUF_INIT;
struct strbuf sp = STRBUF_INIT;
if (unquote_c_style(&first, line, &second))
goto free_and_fail1;
......@@ -741,10 +737,9 @@ static char *git_header_name(char *line, int llen)
*/
for (second = name; second < line + llen; second++) {
if (*second == '"') {
struct strbuf sp;
struct strbuf sp = STRBUF_INIT;
const char *np;
strbuf_init(&sp, 0);
if (unquote_c_style(&sp, second, NULL))
goto free_and_fail2;
......@@ -1508,11 +1503,10 @@ static const char minuses[]=
static void show_stats(struct patch *patch)
{
struct strbuf qname;
struct strbuf qname = STRBUF_INIT;
char *cp = patch->new_name ? patch->new_name : patch->old_name;
int max, add, del;
strbuf_init(&qname, 0);
quote_c_style(cp, &qname, NULL, 0);
/*
......@@ -2292,14 +2286,12 @@ static void add_to_fn_table(struct patch *patch)
static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *ce)
{
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
struct image image;
size_t len;
char *img;
struct patch *tpatch;
strbuf_init(&buf, 0);
if (!(patch->is_copy || patch->is_rename) &&
((tpatch = in_fn_table(patch->old_name)) != NULL)) {
if (tpatch == (struct patch *) -1) {
......@@ -2779,7 +2771,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
{
int fd;
struct strbuf nbuf;
struct strbuf nbuf = STRBUF_INIT;
if (S_ISGITLINK(mode)) {
struct stat st;
......@@ -2798,7 +2790,6 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
if (fd < 0)
return -1;
strbuf_init(&nbuf, 0);
if (convert_to_working_tree(path, buf, size, &nbuf)) {
size = nbuf.len;
buf = nbuf.buf;
......@@ -3060,13 +3051,12 @@ static void prefix_patches(struct patch *p)
static int apply_patch(int fd, const char *filename, int options)
{
size_t offset;
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
struct patch *list = NULL, **listp = &list;
int skipped_patch = 0;
/* FIXME - memory leak when using multiple patch files as inputs */
memset(&fn_table, 0, sizeof(struct string_list));
strbuf_init(&buf, 0);
patch_input_file = filename;
read_patch_file(&buf, fd);
offset = 0;
......
......@@ -2062,7 +2062,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
struct commit *commit;
struct origin *origin;
unsigned char head_sha1[20];
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
const char *ident;
time_t now;
int size, len;
......@@ -2082,7 +2082,6 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
origin = make_origin(commit, path);
strbuf_init(&buf, 0);
if (!contents_from || strcmp("-", contents_from)) {
struct stat st;
const char *read_from;
......
......@@ -334,11 +334,10 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
}
if (verbose) {
struct strbuf subject;
struct strbuf subject = STRBUF_INIT;
const char *sub = " **** invalid ref ****";
char stat[128];
strbuf_init(&subject, 0);
stat[0] = '\0';
commit = item->commit;
......
......@@ -189,9 +189,8 @@ static int batch_one_object(const char *obj_name, int print_contents)
static int batch_objects(int print_contents)
{
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
strbuf_init(&buf, 0);
while (strbuf_getline(&buf, stdin, '\n') != EOF) {
int error = batch_one_object(buf.buf, print_contents);
if (error)
......
......@@ -268,13 +268,11 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
}
if (read_from_stdin) {
struct strbuf buf, nbuf;
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
if (all)
die("git checkout-index: don't mix '--all' and '--stdin'");
strbuf_init(&buf, 0);
strbuf_init(&nbuf, 0);
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
const char *p;
if (line_termination && buf.buf[0] == '"') {
......
......@@ -310,8 +310,7 @@ static void show_local_changes(struct object *head)
static void describe_detached_head(char *msg, struct commit *commit)
{
struct strbuf sb;
strbuf_init(&sb, 0);
struct strbuf sb = STRBUF_INIT;
parse_commit(commit);
pretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, 0, NULL, NULL, 0, 0);
fprintf(stderr, "%s %s... %s\n", msg,
......@@ -360,8 +359,7 @@ struct branch_info {
static void setup_branch_path(struct branch_info *branch)
{
struct strbuf buf;
strbuf_init(&buf, 0);
struct strbuf buf = STRBUF_INIT;
strbuf_addstr(&buf, "refs/heads/");
strbuf_addstr(&buf, branch->name);
branch->path = strbuf_detach(&buf, NULL);
......@@ -484,7 +482,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
struct branch_info *old,
struct branch_info *new)
{
struct strbuf msg;
struct strbuf msg = STRBUF_INIT;
const char *old_desc;
if (opts->new_branch) {
create_branch(old->name, opts->new_branch, new->name, 0,
......@@ -493,7 +491,6 @@ static void update_refs_for_switch(struct checkout_opts *opts,
setup_branch_path(new);
}
strbuf_init(&msg, 0);
old_desc = old->name;
if (!old_desc)
old_desc = sha1_to_hex(old->commit->object.sha1);
......@@ -738,8 +735,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
}
if (opts.new_branch) {
struct strbuf buf;
strbuf_init(&buf, 0);
struct strbuf buf = STRBUF_INIT;
strbuf_addstr(&buf, "refs/heads/");
strbuf_addstr(&buf, opts.new_branch);
if (!get_sha1(buf.buf, rev))
......
......@@ -31,11 +31,11 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
int i;
int show_only = 0, remove_directories = 0, quiet = 0, ignored = 0;
int ignored_only = 0, baselen = 0, config_set = 0, errors = 0;
struct strbuf directory;
struct strbuf directory = STRBUF_INIT;
struct dir_struct dir;
const char *path, *base;
static const char **pathspec;
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
const char *qname;
char *seen = NULL;
struct option options[] = {
......@@ -58,7 +58,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, options, builtin_clean_usage, 0);
strbuf_init(&buf, 0);
memset(&dir, 0, sizeof(dir));
if (ignored_only)
dir.show_ignored = 1;
......@@ -88,7 +87,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
if (baselen)
path = base = xmemdupz(*pathspec, baselen);
read_directory(&dir, path, base, baselen, pathspec);
strbuf_init(&directory, 0);
if (pathspec)
seen = xmalloc(argc > 0 ? argc : 1);
......
......@@ -264,10 +264,9 @@ pid_t junk_pid;
static void remove_junk(void)
{
struct strbuf sb;
struct strbuf sb = STRBUF_INIT;
if (getpid() != junk_pid)
return;
strbuf_init(&sb, 0);
if (junk_git_dir) {
strbuf_addstr(&sb, junk_git_dir);
remove_dir_recursively(&sb, 0);
......@@ -354,7 +353,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
char *path, *dir;
const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
char branch_top[256], key[256], value[256];
struct strbuf reflog_msg;
struct strbuf reflog_msg = STRBUF_INIT;
struct transport *transport = NULL;
char *src_ref_prefix = "refs/heads/";
......@@ -404,7 +403,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (!stat(dir, &buf))
die("destination directory '%s' already exists.", dir);
strbuf_init(&reflog_msg, 0);
strbuf_addf(&reflog_msg, "clone: from %s", repo);
if (option_bare)
......@@ -526,7 +524,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
create_symref("HEAD", head_points_at->name, NULL);
if (!option_bare) {
struct strbuf head_ref;
struct strbuf head_ref = STRBUF_INIT;
const char *head = head_points_at->name;
if (!prefixcmp(head, "refs/heads/"))
......@@ -539,7 +537,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
head_points_at->old_sha1,
NULL, 0, DIE_ON_ERR);
strbuf_init(&head_ref, 0);
strbuf_addstr(&head_ref, branch_top);
strbuf_addstr(&head_ref, "HEAD");
......
......@@ -448,7 +448,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
{
struct stat statbuf;
int commitable, saved_color_setting;
struct strbuf sb;
struct strbuf sb = STRBUF_INIT;
char *buffer;
FILE *fp;
const char *hook_arg1 = NULL;
......@@ -458,7 +458,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
if (!no_verify && run_hook(index_file, "pre-commit", NULL))
return 0;
strbuf_init(&sb, 0);
if (message.len) {
strbuf_addbuf(&sb, &message);
hook_arg1 = "message";
......@@ -511,10 +510,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
stripspace(&sb, 0);
if (signoff) {
struct strbuf sob;
struct strbuf sob = STRBUF_INIT;
int i;
strbuf_init(&sob, 0);
strbuf_addstr(&sob, sign_off_header);
strbuf_addstr(&sob, fmt_name(getenv("GIT_COMMITTER_NAME"),
getenv("GIT_COMMITTER_EMAIL")));
......@@ -672,7 +670,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
*/
static int message_is_empty(struct strbuf *sb)
{
struct strbuf tmpl;
struct strbuf tmpl = STRBUF_INIT;
const char *nl;
int eol, i, start = 0;
......@@ -680,7 +678,6 @@ static int message_is_empty(struct strbuf *sb)
return 0;
/* See if the template is just a prefix of the message. */
strbuf_init(&tmpl, 0);
if (template_file && strbuf_read_file(&tmpl, template_file, 0) > 0) {
stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
if (start + tmpl.len <= sb->len &&
......@@ -931,7 +928,7 @@ static const char commit_utf8_warn[] =
int cmd_commit(int argc, const char **argv, const char *prefix)
{
struct strbuf sb;
struct strbuf sb = STRBUF_INIT;
const char *index_file, *reflog_msg;
char *nl, *p;
unsigned char commit_sha1[20];
......@@ -966,12 +963,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
for (c = commit->parents; c; c = c->next)
pptr = &commit_list_insert(c->item, pptr)->next;
} else if (in_merge) {
struct strbuf m;
struct strbuf m = STRBUF_INIT;
FILE *fp;
reflog_msg = "commit (merge)";
pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next;
strbuf_init(&m, 0);
fp = fopen(git_path("MERGE_HEAD"), "r");
if (fp == NULL)
die("could not open %s for reading: %s",
......@@ -991,7 +987,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
parents = reduce_heads(parents);
/* Finally, get the commit message */
strbuf_init(&sb, 0);
if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
rollback_index_files();
die("could not read commit message");
......
......@@ -5,8 +5,7 @@
static char *get_stdin(void)
{
struct strbuf buf;
strbuf_init(&buf, 0);
struct strbuf buf = STRBUF_INIT;
if (strbuf_read(&buf, 0, 1024) < 0) {
die("error reading standard input: %s", strerror(errno));
}
......
......@@ -358,7 +358,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
};
FILE *in = stdin;
struct strbuf input, output;
struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
int ret;
git_config(fmt_merge_msg_config, NULL);
......@@ -372,10 +372,8 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
die("cannot open %s", inpath);
}
strbuf_init(&input, 0);
if (strbuf_read(&input, fileno(in), 0) < 0)
die("could not read input file %s", strerror(errno));
strbuf_init(&output, 0);
ret = fmt_merge_msg(merge_summary, &input, &output);
if (ret)
......
......@@ -322,11 +322,9 @@ static const char *cmd_to_page(const char *git_cmd)
static void setup_man_path(void)
{
struct strbuf new_path;
struct strbuf new_path = STRBUF_INIT;
const char *old_path = getenv("MANPATH");
strbuf_init(&new_path, 0);
/* We should always put ':' after our path. If there is no
* old_path, the ':' at the end will let 'man' to try
* system-wide paths after ours to find the manual page. If
......
......@@ -628,10 +628,9 @@ static void gen_message_id(struct rev_info *info, char *base)
const char *committer = git_committer_info(IDENT_WARN_ON_NO_NAME);
const char *email_start = strrchr(committer, '<');
const char *email_end = strrchr(committer, '>');
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
if (!email_start || !email_end || email_start > email_end - 1)
die("Could not extract email from committer identity.");
strbuf_init(&buf, 0);
strbuf_addf(&buf, "%s.%lu.git.%.*s", base,
(unsigned long) time(NULL),
(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,
const char *msg;
const char *extra_headers = rev->extra_headers;
struct shortlog log;
struct strbuf sb;
struct strbuf sb = STRBUF_INIT;
int i;
const char *encoding = "utf-8";
struct diff_options opts;
......@@ -671,7 +670,6 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
committer = git_committer_info(0);
msg = body;
strbuf_init(&sb, 0);
pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822,
encoding);
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)
const char *in_reply_to = NULL;
struct patch_ids ids;
char *add_signoff = NULL;
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
git_config(git_format_config, NULL);
init_revisions(&rev, prefix);
......@@ -861,8 +859,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
}
argc = j;
strbuf_init(&buf, 0);
for (i = 0; i < extra_hdr_nr; i++) {
strbuf_addstr(&buf, extra_hdr[i]);
strbuf_addch(&buf, '\n');
......@@ -1139,8 +1135,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
sign = '-';
if (verbose) {
struct strbuf buf;
strbuf_init(&buf, 0);
struct strbuf buf = STRBUF_INIT;
pretty_print_commit(CMIT_FMT_ONELINE, commit,
&buf, 0, NULL, NULL, 0, 0);
printf("%c %s %s\n", sign,
......
......@@ -226,7 +226,7 @@ static void reset_hard(unsigned const char *sha1, int verbose)
static void restore_state(void)
{
struct strbuf sb;
struct strbuf sb = STRBUF_INIT;
const char *args[] = { "stash", "apply", NULL, NULL };
if (is_null_sha1(stash))
......@@ -234,7 +234,6 @@ static void restore_state(void)
reset_hard(head, 1);
strbuf_init(&sb, 0);
args[2] = sha1_to_hex(stash);
/*
......@@ -258,7 +257,7 @@ static void squash_message(void)
{
struct rev_info rev;
struct commit *commit;
struct strbuf out;
struct strbuf out = STRBUF_INIT;
struct commit_list *j;
int fd;
......@@ -282,7 +281,6 @@ static void squash_message(void)
if (prepare_revision_walk(&rev))
die("revision walk setup failed");
strbuf_init(&out, 0);
strbuf_addstr(&out, "Squashed commit of the following:\n");
while ((commit = get_revision(&rev)) != NULL) {
strbuf_addch(&out, '\n');
......@@ -327,9 +325,8 @@ static int run_hook(const char *name)
static void finish(const unsigned char *new_head, const char *msg)
{
struct strbuf reflog_message;
struct strbuf reflog_message = STRBUF_INIT;
strbuf_init(&reflog_message, 0);
if (!msg)
strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION"));
else {
......@@ -380,7 +377,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
{
struct object *remote_head;
unsigned char branch_head[20], buf_sha[20];
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
const char *ptr;
int len, early;
......@@ -389,7 +386,6 @@ static void merge_name(const char *remote, struct strbuf *msg)
if (!remote_head)
die("'%s' does not point to a commit", remote);
strbuf_init(&buf, 0);
strbuf_addstr(&buf, "refs/heads/");
strbuf_addstr(&buf, remote);
resolve_ref(buf.buf, branch_head, 0, 0);
......@@ -444,10 +440,9 @@ static void merge_name(const char *remote, struct strbuf *msg)
if (!strcmp(remote, "FETCH_HEAD") &&
!access(git_path("FETCH_HEAD"), R_OK)) {
FILE *fp;
struct strbuf line;
struct strbuf line = STRBUF_INIT;
char *ptr;
strbuf_init(&line, 0);
fp = fopen(git_path("FETCH_HEAD"), "r");
if (!fp)
die("could not open %s for reading: %s",
......@@ -545,7 +540,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
const char **args;
int i = 0, ret;
struct commit_list *j;
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
int index_fd;
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
......@@ -592,7 +587,6 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
} else {
args = xmalloc((4 + commit_list_count(common) +
commit_list_count(remoteheads)) * sizeof(char *));
strbuf_init(&buf, 0);
strbuf_addf(&buf, "merge-%s", strategy);
args[i++] = buf.buf;
for (j = common; j; j = j->next)
......@@ -847,7 +841,7 @@ static int evaluate_result(void)
int cmd_merge(int argc, const char **argv, const char *prefix)
{
unsigned char result_tree[20];
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
const char *head_arg;
int flag, head_invalid = 0, i;
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)
* Traditional format never would have "-m" so it is an
* additional safety measure to check for it.
*/
strbuf_init(&buf, 0);
if (!have_message && is_old_style_invocation(argc, argv)) {
strbuf_addstr(&merge_msg, argv[0]);
......@@ -926,7 +919,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
reset_hard(remote_head->sha1, 0);
return 0;
} else {
struct strbuf msg;
struct strbuf msg = STRBUF_INIT;
/* We are invoked directly as the first-class UI. */
head_arg = "HEAD";
......@@ -939,7 +932,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
* codepath so we discard the error in this
* loop.
*/
strbuf_init(&msg, 0);
for (i = 0; i < argc; i++)
merge_name(argv[i], &msg);
fmt_merge_msg(option_log, &msg, &merge_msg);
......@@ -1014,7 +1006,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
!common->next &&
!hashcmp(common->item->object.sha1, head)) {
/* Again the most common case of merging one remote. */
struct strbuf msg;
struct strbuf msg = STRBUF_INIT;
struct object *o;
char hex[41];
......@@ -1024,7 +1016,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
hex,
find_unique_abbrev(remoteheads->item->object.sha1,
DEFAULT_ABBREV));
strbuf_init(&msg, 0);
strbuf_addstr(&msg, "Fast forward");
if (have_message)
strbuf_addstr(&msg,
......
......@@ -54,7 +54,7 @@ static int add(int argc, const char **argv)
struct string_list track = { NULL, 0, 0 };
const char *master = NULL;
struct remote *remote;
struct strbuf buf, buf2;
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
const char *name, *url;
int i;
......@@ -81,9 +81,6 @@ static int add(int argc, const char **argv)
remote->fetch_refspec_nr))
die("remote %s already exists.", name);
strbuf_init(&buf, 0);
strbuf_init(&buf2, 0);
strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
if (!valid_fetch_refspec(buf2.buf))
die("'%s' is not a valid remote name", name);
......@@ -352,7 +349,7 @@ static int rm(int argc, const char **argv)
OPT_END()
};
struct remote *remote;
struct strbuf buf;
struct strbuf buf = STRBUF_INIT;
struct known_remotes known_remotes = { NULL, NULL };
struct string_list branches = { NULL, 0, 0, 1 };
struct branches_for_remote cb_data = { NULL, &branches, &known_remotes };
......@@ -368,7 +365,6 @@ static int rm(int argc, const char **argv)
known_remotes.to_delete = remote;
for_each_remote(add_known_remote, &known_remotes);
strbuf_init(&buf, 0);
strbuf_addf(&buf, "remote.%s", remote->name);
if (git_config_rename_section(buf.buf, NULL) < 1)
return error("Could not remove config section '%s'", buf.buf);
......
......@@ -107,8 +107,7 @@ static void show_commit(struct commit *commit)
putchar('\n');
if (revs.verbose_header && commit->buffer) {
struct strbuf buf;
strbuf_init(&buf, 0);
struct strbuf buf = STRBUF_INIT;
pretty_print_commit(revs.commit_format, commit,
&buf, revs.abbrev, NULL, NULL,
revs.date_mode, 0);
......
......@@ -307,19 +307,17 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
OPT_END(),
};
struct strbuf sb, parsed;
struct strbuf sb = STRBUF_INIT, parsed = STRBUF_INIT;
const char **usage = NULL;
struct option *opts = NULL;
int onb = 0, osz = 0, unb = 0, usz = 0;
strbuf_init(&parsed, 0);
strbuf_addstr(&parsed, "set --");
argc = parse_options(argc, argv, parseopt_opts, parseopt_usage,
PARSE_OPT_KEEP_DASHDASH);
if (argc < 1 || strcmp(argv[0], "--"))
usage_with_options(parseopt_usage, parseopt_opts);
strbuf_init(&sb, 0);
/* get the usage up to the first line with a -- on it */
for (;;) {
if (strbuf_getline(&sb, stdin, '\n') == EOF)
......
......@@ -259,11 +259,10 @@ static void join_revs(struct commit_list **list_p,
static void show_one_commit(struct commit *commit, int no_name)
{
struct strbuf pretty;
struct strbuf pretty = STRBUF_INIT;
const char *pretty_str = "(unavailable)";
struct commit_name *name = commit->util;
strbuf_init(&pretty, 0);
if (commit->object.parsed) {
pretty_print_commit(CMIT_FMT_ONELINE, commit,
&pretty, 0, NULL, NULL, 0, 0);
......
......@@ -70,14 +70,13 @@ void stripspace(struct strbuf *sb, int skip_comments)