builtin_clone: use strbuf in cmd_clone()
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Miklos Vajna committed
Nov 21, 2008 at 01:45 UTC
b5ff37ac6ba4543ab3bbaf99d0641ca260567ff2
1 file changed
+25
-20
builtin-clone.c
+25
-20
@@ -358,8 +358,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
358
const char *repo_name, *repo, *work_tree, *git_dir;
359
char *path, *dir;
360
const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
361
- char branch_top[256], key[256], value[256];
362
- struct strbuf reflog_msg = STRBUF_INIT;
361
+ struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
362
+ struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
363
struct transport *transport = NULL;
364
char *src_ref_prefix = "refs/heads/";
365
@@ -463,35 +463,36 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
463
if (option_bare) {
464
if (option_mirror)
465
src_ref_prefix = "refs/";
466
- strcpy(branch_top, src_ref_prefix);
466
+ strbuf_addstr(&branch_top, src_ref_prefix);
467
468
git_config_set("core.bare", "true");
469
} else {
470
- snprintf(branch_top, sizeof(branch_top),
471
- "refs/remotes/%s/", option_origin);
470
+ strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
471
}
472
473
if (option_mirror || !option_bare) {
474
/* Configure the remote */
475
if (option_mirror) {
477
- snprintf(key, sizeof(key),
478
- "remote.%s.mirror", option_origin);
479
- git_config_set(key, "true");
476
+ strbuf_addf(&key, "remote.%s.mirror", option_origin);
477
+ git_config_set(key.buf, "true");
478
+ strbuf_reset(&key);
479
}
480
482
- snprintf(key, sizeof(key), "remote.%s.url", option_origin);
483
- git_config_set(key, repo);
481
+ strbuf_addf(&key, "remote.%s.url", option_origin);
482
+ git_config_set(key.buf, repo);
483
+ strbuf_reset(&key);
484
485
- snprintf(key, sizeof(key), "remote.%s.fetch", option_origin);
486
- snprintf(value, sizeof(value),
487
- "+%s*:%s*", src_ref_prefix, branch_top);
488
- git_config_set_multivar(key, value, "^$", 0);
485
+ strbuf_addf(&key, "remote.%s.fetch", option_origin);
486
+ strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
487
+ git_config_set_multivar(key.buf, value.buf, "^$", 0);
488
+ strbuf_reset(&key);
489
+ strbuf_reset(&value);
490
}
491
492
refspec.force = 0;
493
refspec.pattern = 1;
494
refspec.src = src_ref_prefix;
494
- refspec.dst = branch_top;
495
+ refspec.dst = branch_top.buf;
496
497
if (path && !is_bundle)
498
refs = clone_local(path, git_dir);
@@ -545,7 +546,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
546
head_points_at->old_sha1,
547
NULL, 0, DIE_ON_ERR);
548
548
- strbuf_addstr(&head_ref, branch_top);
549
+ strbuf_addstr(&head_ref, branch_top.buf);
550
strbuf_addstr(&head_ref, "HEAD");
551
552
/* Remote branch link */
@@ -553,10 +554,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
554
head_points_at->peer_ref->name,
555
reflog_msg.buf);
556
556
- snprintf(key, sizeof(key), "branch.%s.remote", head);
557
- git_config_set(key, option_origin);
558
- snprintf(key, sizeof(key), "branch.%s.merge", head);
559
- git_config_set(key, head_points_at->name);
557
+ strbuf_addf(&key, "branch.%s.remote", head);
558
+ git_config_set(key.buf, option_origin);
559
+ strbuf_reset(&key);
560
+ strbuf_addf(&key, "branch.%s.merge", head);
561
+ git_config_set(key.buf, head_points_at->name);
562
}
563
} else if (remote_head) {
564
/* Source had detached HEAD pointing somewhere. */
@@ -606,6 +608,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
608
}
609
610
strbuf_release(&reflog_msg);
611
+ strbuf_release(&branch_top);
612
+ strbuf_release(&key);
613
+ strbuf_release(&value);
614
junk_pid = 0;
615
return 0;
616
}