@@ -358,8 +358,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
358
358
const char * repo_name , * repo , * work_tree , * git_dir ;
359
359
char * path , * dir ;
360
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
363
struct transport * transport = NULL ;
364
364
char * src_ref_prefix = "refs/heads/" ;
365
365
@@ -463,35 +463,36 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
463
463
if (option_bare ) {
464
464
if (option_mirror )
465
465
src_ref_prefix = "refs/" ;
466
- strcpy ( branch_top , src_ref_prefix );
466
+ strbuf_addstr ( & branch_top , src_ref_prefix );
467
467
468
468
git_config_set ("core.bare" , "true" );
469
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 );
472
471
}
473
472
474
473
if (option_mirror || !option_bare ) {
475
474
/* Configure the remote */
476
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 );
480
479
}
481
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
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 );
489
490
}
490
491
491
492
refspec .force = 0 ;
492
493
refspec .pattern = 1 ;
493
494
refspec .src = src_ref_prefix ;
494
- refspec .dst = branch_top ;
495
+ refspec .dst = branch_top . buf ;
495
496
496
497
if (path && !is_bundle )
497
498
refs = clone_local (path , git_dir );
@@ -545,18 +546,19 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
545
546
head_points_at -> old_sha1 ,
546
547
NULL , 0 , DIE_ON_ERR );
547
548
548
- strbuf_addstr (& head_ref , branch_top );
549
+ strbuf_addstr (& head_ref , branch_top . buf );
549
550
strbuf_addstr (& head_ref , "HEAD" );
550
551
551
552
/* Remote branch link */
552
553
create_symref (head_ref .buf ,
553
554
head_points_at -> peer_ref -> name ,
554
555
reflog_msg .buf );
555
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 );
560
562
}
561
563
} else if (remote_head ) {
562
564
/* Source had detached HEAD pointing somewhere. */
@@ -606,6 +608,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
606
608
}
607
609
608
610
strbuf_release (& reflog_msg );
611
+ strbuf_release (& branch_top );
612
+ strbuf_release (& key );
613
+ strbuf_release (& value );
609
614
junk_pid = 0 ;
610
615
return 0 ;
611
616
}
0 commit comments