@@ -68,7 +68,7 @@ struct rebase_options {
68
68
const char * upstream_name ;
69
69
const char * upstream_arg ;
70
70
char * head_name ;
71
- struct object_id orig_head ;
71
+ struct commit * orig_head ;
72
72
struct commit * onto ;
73
73
const char * onto_name ;
74
74
const char * revisions ;
@@ -260,13 +260,13 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
260
260
struct replay_opts replay = get_replay_opts (opts );
261
261
struct string_list commands = STRING_LIST_INIT_DUP ;
262
262
263
- if (get_revision_ranges (opts -> upstream , opts -> onto , & opts -> orig_head ,
263
+ if (get_revision_ranges (opts -> upstream , opts -> onto , & opts -> orig_head -> object . oid ,
264
264
& revisions , & shortrevisions ))
265
265
return -1 ;
266
266
267
267
if (init_basic_state (& replay ,
268
268
opts -> head_name ? opts -> head_name : "detached HEAD" ,
269
- opts -> onto , & opts -> orig_head )) {
269
+ opts -> onto , & opts -> orig_head -> object . oid )) {
270
270
free (revisions );
271
271
free (shortrevisions );
272
272
@@ -297,8 +297,8 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
297
297
split_exec_commands (opts -> cmd , & commands );
298
298
ret = complete_action (the_repository , & replay , flags ,
299
299
shortrevisions , opts -> onto_name , opts -> onto ,
300
- & opts -> orig_head , & commands , opts -> autosquash ,
301
- & todo_list );
300
+ & opts -> orig_head -> object . oid , & commands ,
301
+ opts -> autosquash , & todo_list );
302
302
}
303
303
304
304
string_list_clear (& commands , 0 );
@@ -446,7 +446,8 @@ static int read_basic_state(struct rebase_options *opts)
446
446
} else if (!read_oneliner (& buf , state_dir_path ("head" , opts ),
447
447
READ_ONELINER_WARN_MISSING ))
448
448
return -1 ;
449
- if (get_oid_hex (buf .buf , & opts -> orig_head ))
449
+ if (get_oid_hex (buf .buf , & oid ) ||
450
+ !(opts -> orig_head = lookup_commit_object (the_repository , & oid )))
450
451
return error (_ ("invalid orig-head: '%s'" ), buf .buf );
451
452
452
453
if (file_exists (state_dir_path ("quiet" , opts )))
@@ -515,7 +516,7 @@ static int rebase_write_basic_state(struct rebase_options *opts)
515
516
write_file (state_dir_path ("onto" , opts ), "%s" ,
516
517
opts -> onto ? oid_to_hex (& opts -> onto -> object .oid ) : "" );
517
518
write_file (state_dir_path ("orig-head" , opts ), "%s" ,
518
- oid_to_hex (& opts -> orig_head ));
519
+ oid_to_hex (& opts -> orig_head -> object . oid ));
519
520
if (!(opts -> flags & REBASE_NO_QUIET ))
520
521
write_file (state_dir_path ("quiet" , opts ), "%s" , "" );
521
522
if (opts -> flags & REBASE_VERBOSE )
@@ -644,7 +645,7 @@ static int run_am(struct rebase_options *opts)
644
645
/* this is now equivalent to !opts->upstream */
645
646
& opts -> onto -> object .oid :
646
647
& opts -> upstream -> object .oid ),
647
- oid_to_hex (& opts -> orig_head ));
648
+ oid_to_hex (& opts -> orig_head -> object . oid ));
648
649
649
650
rebased_patches = xstrdup (git_path ("rebased-patches" ));
650
651
format_patch .out = open (rebased_patches ,
@@ -678,7 +679,7 @@ static int run_am(struct rebase_options *opts)
678
679
free (rebased_patches );
679
680
strvec_clear (& am .args );
680
681
681
- ropts .oid = & opts -> orig_head ;
682
+ ropts .oid = & opts -> orig_head -> object . oid ;
682
683
ropts .branch = opts -> head_name ;
683
684
ropts .default_reflog_action = DEFAULT_REFLOG_ACTION ;
684
685
reset_head (the_repository , & ropts );
@@ -826,7 +827,7 @@ static int checkout_up_to_date(struct rebase_options *options)
826
827
strbuf_addf (& buf , "%s: checkout %s" ,
827
828
getenv (GIT_REFLOG_ACTION_ENVIRONMENT ),
828
829
options -> switch_to );
829
- ropts .oid = & options -> orig_head ;
830
+ ropts .oid = & options -> orig_head -> object . oid ;
830
831
ropts .branch = options -> head_name ;
831
832
ropts .flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK ;
832
833
if (!ropts .branch )
@@ -859,15 +860,11 @@ static int is_linear_history(struct commit *from, struct commit *to)
859
860
860
861
static int can_fast_forward (struct commit * onto , struct commit * upstream ,
861
862
struct commit * restrict_revision ,
862
- struct object_id * head_oid , struct object_id * merge_base )
863
+ struct commit * head , struct object_id * merge_base )
863
864
{
864
- struct commit * head = lookup_commit (the_repository , head_oid );
865
865
struct commit_list * merge_bases = NULL ;
866
866
int res = 0 ;
867
867
868
- if (!head )
869
- goto done ;
870
-
871
868
merge_bases = get_merge_bases (onto , head );
872
869
if (!merge_bases || merge_bases -> next ) {
873
870
oidcpy (merge_base , null_oid ());
@@ -1302,13 +1299,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1302
1299
1303
1300
if (read_basic_state (& options ))
1304
1301
exit (1 );
1305
- ropts .oid = & options .orig_head ;
1302
+ ropts .oid = & options .orig_head -> object . oid ;
1306
1303
ropts .branch = options .head_name ;
1307
1304
ropts .flags = RESET_HEAD_HARD ;
1308
1305
ropts .default_reflog_action = DEFAULT_REFLOG_ACTION ;
1309
1306
if (reset_head (the_repository , & ropts ) < 0 )
1310
1307
die (_ ("could not move back to %s" ),
1311
- oid_to_hex (& options .orig_head ));
1308
+ oid_to_hex (& options .orig_head -> object . oid ));
1312
1309
remove_branch_state (the_repository , 0 );
1313
1310
ret = finish_rebase (& options );
1314
1311
goto cleanup ;
@@ -1594,25 +1591,27 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1594
1591
*/
1595
1592
if (argc == 1 ) {
1596
1593
/* Is it "rebase other branchname" or "rebase other commit"? */
1594
+ struct object_id branch_oid ;
1597
1595
branch_name = argv [0 ];
1598
1596
options .switch_to = argv [0 ];
1599
1597
1600
1598
/* Is it a local branch? */
1601
1599
strbuf_reset (& buf );
1602
1600
strbuf_addf (& buf , "refs/heads/%s" , branch_name );
1603
- if (!read_ref (buf .buf , & options . orig_head )) {
1601
+ if (!read_ref (buf .buf , & branch_oid )) {
1604
1602
die_if_checked_out (buf .buf , 1 );
1605
1603
options .head_name = xstrdup (buf .buf );
1604
+ options .orig_head =
1605
+ lookup_commit_object (the_repository ,
1606
+ & branch_oid );
1606
1607
/* If not is it a valid ref (branch or commit)? */
1607
1608
} else {
1608
- struct commit * commit =
1609
+ options . orig_head =
1609
1610
lookup_commit_reference_by_name (branch_name );
1610
- if (!commit )
1611
- die (_ ("no such branch/commit '%s'" ),
1612
- branch_name );
1613
- oidcpy (& options .orig_head , & commit -> object .oid );
1614
1611
options .head_name = NULL ;
1615
1612
}
1613
+ if (!options .orig_head )
1614
+ die (_ ("no such branch/commit '%s'" ), branch_name );
1616
1615
} else if (argc == 0 ) {
1617
1616
/* Do not need to switch branches, we are already on it. */
1618
1617
options .head_name =
@@ -1629,8 +1628,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1629
1628
FREE_AND_NULL (options .head_name );
1630
1629
branch_name = "HEAD" ;
1631
1630
}
1632
- if (get_oid ("HEAD" , & options .orig_head ))
1633
- die (_ ("Could not resolve HEAD to a revision" ));
1631
+ options .orig_head = lookup_commit_reference_by_name ("HEAD" );
1632
+ if (!options .orig_head )
1633
+ die (_ ("Could not resolve HEAD to a commit" ));
1634
1634
} else
1635
1635
BUG ("unexpected number of arguments left to parse" );
1636
1636
@@ -1662,13 +1662,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1662
1662
options .onto_name );
1663
1663
}
1664
1664
1665
- if (options .fork_point > 0 ) {
1666
- struct commit * head =
1667
- lookup_commit_reference (the_repository ,
1668
- & options .orig_head );
1665
+ if (options .fork_point > 0 )
1669
1666
options .restrict_revision =
1670
- get_fork_point (options .upstream_name , head );
1671
- }
1667
+ get_fork_point (options .upstream_name , options .orig_head );
1672
1668
1673
1669
if (repo_read_index (the_repository ) < 0 )
1674
1670
die (_ ("could not read index" ));
@@ -1698,7 +1694,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1698
1694
* call it before checking allow_preemptive_ff.
1699
1695
*/
1700
1696
if (can_fast_forward (options .onto , options .upstream , options .restrict_revision ,
1701
- & options .orig_head , & merge_base ) &&
1697
+ options .orig_head , & merge_base ) &&
1702
1698
allow_preemptive_ff ) {
1703
1699
int flag ;
1704
1700
@@ -1775,7 +1771,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1775
1771
strbuf_addf (& msg , "%s: checkout %s" ,
1776
1772
getenv (GIT_REFLOG_ACTION_ENVIRONMENT ), options .onto_name );
1777
1773
ropts .oid = & options .onto -> object .oid ;
1778
- ropts .orig_head = & options .orig_head ,
1774
+ ropts .orig_head = & options .orig_head -> object . oid ,
1779
1775
ropts .flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD |
1780
1776
RESET_HEAD_RUN_POST_CHECKOUT_HOOK ;
1781
1777
ropts .head_msg = msg .buf ;
@@ -1789,7 +1785,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1789
1785
* we just fast-forwarded.
1790
1786
*/
1791
1787
strbuf_reset (& msg );
1792
- if (oideq (& merge_base , & options .orig_head )) {
1788
+ if (oideq (& merge_base , & options .orig_head -> object . oid )) {
1793
1789
printf (_ ("Fast-forwarded %s to %s.\n" ),
1794
1790
branch_name , options .onto_name );
1795
1791
strbuf_addf (& msg , "rebase finished: %s onto %s" ,
@@ -1810,7 +1806,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1810
1806
(options .restrict_revision ?
1811
1807
oid_to_hex (& options .restrict_revision -> object .oid ) :
1812
1808
oid_to_hex (& options .upstream -> object .oid )),
1813
- oid_to_hex (& options .orig_head ));
1809
+ oid_to_hex (& options .orig_head -> object . oid ));
1814
1810
1815
1811
options .revisions = revisions .buf ;
1816
1812
0 commit comments