@@ -424,42 +424,45 @@ static void print_ref_list(int kinds, int detached, int verbose, int abbrev, str
424
424
425
425
static void rename_branch (const char * oldname , const char * newname , int force )
426
426
{
427
- char oldref [ PATH_MAX ] , newref [ PATH_MAX ] , logmsg [ PATH_MAX * 2 + 100 ] ;
427
+ struct strbuf oldref = STRBUF_INIT , newref = STRBUF_INIT , logmsg = STRBUF_INIT ;
428
428
unsigned char sha1 [20 ];
429
- char oldsection [ PATH_MAX ] , newsection [ PATH_MAX ] ;
429
+ struct strbuf oldsection = STRBUF_INIT , newsection = STRBUF_INIT ;
430
430
431
431
if (!oldname )
432
432
die ("cannot rename the current branch while not on any." );
433
433
434
- if (snprintf (oldref , sizeof (oldref ), "refs/heads/%s" , oldname ) > sizeof (oldref ))
435
- die ("Old branchname too long" );
434
+ strbuf_addf (& oldref , "refs/heads/%s" , oldname );
436
435
437
- if (check_ref_format (oldref ))
438
- die ("Invalid branch name: %s" , oldref );
436
+ if (check_ref_format (oldref . buf ))
437
+ die ("Invalid branch name: %s" , oldref . buf );
439
438
440
- if (snprintf (newref , sizeof (newref ), "refs/heads/%s" , newname ) > sizeof (newref ))
441
- die ("New branchname too long" );
439
+ strbuf_addf (& newref , "refs/heads/%s" , newname );
442
440
443
- if (check_ref_format (newref ))
444
- die ("Invalid branch name: %s" , newref );
441
+ if (check_ref_format (newref . buf ))
442
+ die ("Invalid branch name: %s" , newref . buf );
445
443
446
- if (resolve_ref (newref , sha1 , 1 , NULL ) && !force )
444
+ if (resolve_ref (newref . buf , sha1 , 1 , NULL ) && !force )
447
445
die ("A branch named '%s' already exists." , newname );
448
446
449
- snprintf ( logmsg , sizeof ( logmsg ) , "Branch: renamed %s to %s" ,
450
- oldref , newref );
447
+ strbuf_addf ( & logmsg , "Branch: renamed %s to %s" ,
448
+ oldref . buf , newref . buf );
451
449
452
- if (rename_ref (oldref , newref , logmsg ))
450
+ if (rename_ref (oldref . buf , newref . buf , logmsg . buf ))
453
451
die ("Branch rename failed" );
452
+ strbuf_release (& logmsg );
454
453
455
454
/* no need to pass logmsg here as HEAD didn't really move */
456
- if (!strcmp (oldname , head ) && create_symref ("HEAD" , newref , NULL ))
455
+ if (!strcmp (oldname , head ) && create_symref ("HEAD" , newref . buf , NULL ))
457
456
die ("Branch renamed to %s, but HEAD is not updated!" , newname );
458
457
459
- snprintf (oldsection , sizeof (oldsection ), "branch.%s" , oldref + 11 );
460
- snprintf (newsection , sizeof (newsection ), "branch.%s" , newref + 11 );
461
- if (git_config_rename_section (oldsection , newsection ) < 0 )
458
+ strbuf_addf (& oldsection , "branch.%s" , oldref .buf + 11 );
459
+ strbuf_release (& oldref );
460
+ strbuf_addf (& newsection , "branch.%s" , newref .buf + 11 );
461
+ strbuf_release (& newref );
462
+ if (git_config_rename_section (oldsection .buf , newsection .buf ) < 0 )
462
463
die ("Branch is renamed, but update of config-file failed" );
464
+ strbuf_release (& oldsection );
465
+ strbuf_release (& newsection );
463
466
}
464
467
465
468
static int opt_parse_with_commit (const struct option * opt , const char * arg , int unset )
0 commit comments