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