@@ -541,13 +541,15 @@ static int reset_head(struct object_id *oid, const char *action,
541
541
if (switch_to_branch && !starts_with (switch_to_branch , "refs/" ))
542
542
BUG ("Not a fully qualified branch: '%s'" , switch_to_branch );
543
543
544
- if (hold_locked_index (& lock , LOCK_REPORT_ON_ERROR ) < 0 )
545
- return -1 ;
544
+ if (hold_locked_index (& lock , LOCK_REPORT_ON_ERROR ) < 0 ) {
545
+ ret = -1 ;
546
+ goto leave_reset_head ;
547
+ }
546
548
547
549
if (!oid ) {
548
550
if (get_oid ("HEAD" , & head_oid )) {
549
- rollback_lock_file ( & lock );
550
- return error ( _ ( "could not determine HEAD revision" )) ;
551
+ ret = error ( _ ( "could not determine HEAD revision" ) );
552
+ goto leave_reset_head ;
551
553
}
552
554
oid = & head_oid ;
553
555
}
@@ -564,32 +566,27 @@ static int reset_head(struct object_id *oid, const char *action,
564
566
unpack_tree_opts .reset = 1 ;
565
567
566
568
if (read_index_unmerged (the_repository -> index ) < 0 ) {
567
- rollback_lock_file ( & lock );
568
- return error ( _ ( "could not read index" )) ;
569
+ ret = error ( _ ( "could not read index" ) );
570
+ goto leave_reset_head ;
569
571
}
570
572
571
573
if (!fill_tree_descriptor (& desc , oid )) {
572
- error (_ ("failed to find tree of %s" ), oid_to_hex (oid ));
573
- rollback_lock_file (& lock );
574
- free ((void * )desc .buffer );
575
- return -1 ;
574
+ ret = error (_ ("failed to find tree of %s" ), oid_to_hex (oid ));
575
+ goto leave_reset_head ;
576
576
}
577
577
578
578
if (unpack_trees (1 , & desc , & unpack_tree_opts )) {
579
- rollback_lock_file (& lock );
580
- free ((void * )desc .buffer );
581
- return -1 ;
579
+ ret = -1 ;
580
+ goto leave_reset_head ;
582
581
}
583
582
584
583
tree = parse_tree_indirect (oid );
585
584
prime_cache_tree (the_repository -> index , tree );
586
585
587
- if (write_locked_index (the_repository -> index , & lock , COMMIT_LOCK ) < 0 )
586
+ if (write_locked_index (the_repository -> index , & lock , COMMIT_LOCK ) < 0 ) {
588
587
ret = error (_ ("could not write index" ));
589
- free ((void * )desc .buffer );
590
-
591
- if (ret )
592
- return ret ;
588
+ goto leave_reset_head ;
589
+ }
593
590
594
591
reflog_action = getenv (GIT_REFLOG_ACTION_ENVIRONMENT );
595
592
strbuf_addf (& msg , "%s: " , reflog_action ? reflog_action : "rebase" );
@@ -622,7 +619,10 @@ static int reset_head(struct object_id *oid, const char *action,
622
619
UPDATE_REFS_MSG_ON_ERR );
623
620
}
624
621
622
+ leave_reset_head :
625
623
strbuf_release (& msg );
624
+ rollback_lock_file (& lock );
625
+ free ((void * )desc .buffer );
626
626
return ret ;
627
627
}
628
628
0 commit comments