@@ -358,8 +358,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
358358 const char * repo_name , * repo , * work_tree , * git_dir ;
359359 char * path , * dir ;
360360 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 ;
363363 struct transport * transport = NULL ;
364364 char * src_ref_prefix = "refs/heads/" ;
365365
@@ -463,35 +463,36 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
463463 if (option_bare ) {
464464 if (option_mirror )
465465 src_ref_prefix = "refs/" ;
466- strcpy ( branch_top , src_ref_prefix );
466+ strbuf_addstr ( & branch_top , src_ref_prefix );
467467
468468 git_config_set ("core.bare" , "true" );
469469 } else {
470- snprintf (branch_top , sizeof (branch_top ),
471- "refs/remotes/%s/" , option_origin );
470+ strbuf_addf (& branch_top , "refs/remotes/%s/" , option_origin );
472471 }
473472
474473 if (option_mirror || !option_bare ) {
475474 /* Configure the remote */
476475 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 );
480479 }
481480
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 );
484484
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 );
489490 }
490491
491492 refspec .force = 0 ;
492493 refspec .pattern = 1 ;
493494 refspec .src = src_ref_prefix ;
494- refspec .dst = branch_top ;
495+ refspec .dst = branch_top . buf ;
495496
496497 if (path && !is_bundle )
497498 refs = clone_local (path , git_dir );
@@ -545,18 +546,19 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
545546 head_points_at -> old_sha1 ,
546547 NULL , 0 , DIE_ON_ERR );
547548
548- strbuf_addstr (& head_ref , branch_top );
549+ strbuf_addstr (& head_ref , branch_top . buf );
549550 strbuf_addstr (& head_ref , "HEAD" );
550551
551552 /* Remote branch link */
552553 create_symref (head_ref .buf ,
553554 head_points_at -> peer_ref -> name ,
554555 reflog_msg .buf );
555556
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 );
560562 }
561563 } else if (remote_head ) {
562564 /* Source had detached HEAD pointing somewhere. */
@@ -606,6 +608,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
606608 }
607609
608610 strbuf_release (& reflog_msg );
611+ strbuf_release (& branch_top );
612+ strbuf_release (& key );
613+ strbuf_release (& value );
609614 junk_pid = 0 ;
610615 return 0 ;
611616}
0 commit comments