@@ -3694,6 +3694,28 @@ static const char *reflog_message(struct replay_opts *opts,
3694
3694
return buf .buf ;
3695
3695
}
3696
3696
3697
+ static struct commit * lookup_label (struct repository * r , const char * label ,
3698
+ int len , struct strbuf * buf )
3699
+ {
3700
+ struct commit * commit ;
3701
+ struct object_id oid ;
3702
+
3703
+ strbuf_reset (buf );
3704
+ strbuf_addf (buf , "refs/rewritten/%.*s" , len , label );
3705
+ if (!read_ref (buf -> buf , & oid )) {
3706
+ commit = lookup_commit_object (r , & oid );
3707
+ } else {
3708
+ /* fall back to non-rewritten ref or commit */
3709
+ strbuf_splice (buf , 0 , strlen ("refs/rewritten/" ), "" , 0 );
3710
+ commit = lookup_commit_reference_by_name (buf -> buf );
3711
+ }
3712
+
3713
+ if (!commit )
3714
+ error (_ ("could not resolve '%s'" ), buf -> buf );
3715
+
3716
+ return commit ;
3717
+ }
3718
+
3697
3719
static int do_reset (struct repository * r ,
3698
3720
const char * name , int len ,
3699
3721
struct replay_opts * opts )
@@ -3725,19 +3747,20 @@ static int do_reset(struct repository *r,
3725
3747
oidcpy (& oid , & opts -> squash_onto );
3726
3748
} else {
3727
3749
int i ;
3750
+ struct commit * commit ;
3728
3751
3729
3752
/* Determine the length of the label */
3730
3753
for (i = 0 ; i < len ; i ++ )
3731
3754
if (isspace (name [i ]))
3732
3755
break ;
3733
3756
len = i ;
3734
3757
3735
- strbuf_addf (& ref_name , "refs/rewritten/%.*s" , len , name );
3736
- if (get_oid (ref_name .buf , & oid ) &&
3737
- get_oid (ref_name .buf + strlen ("refs/rewritten/" ), & oid )) {
3738
- ret = error (_ ("could not read '%s'" ), ref_name .buf );
3758
+ commit = lookup_label (r , name , len , & ref_name );
3759
+ if (!commit ) {
3760
+ ret = -1 ;
3739
3761
goto cleanup ;
3740
3762
}
3763
+ oid = commit -> object .oid ;
3741
3764
}
3742
3765
3743
3766
setup_unpack_trees_porcelain (& unpack_tree_opts , "reset" );
@@ -3785,26 +3808,6 @@ static int do_reset(struct repository *r,
3785
3808
return ret ;
3786
3809
}
3787
3810
3788
- static struct commit * lookup_label (const char * label , int len ,
3789
- struct strbuf * buf )
3790
- {
3791
- struct commit * commit ;
3792
-
3793
- strbuf_reset (buf );
3794
- strbuf_addf (buf , "refs/rewritten/%.*s" , len , label );
3795
- commit = lookup_commit_reference_by_name (buf -> buf );
3796
- if (!commit ) {
3797
- /* fall back to non-rewritten ref or commit */
3798
- strbuf_splice (buf , 0 , strlen ("refs/rewritten/" ), "" , 0 );
3799
- commit = lookup_commit_reference_by_name (buf -> buf );
3800
- }
3801
-
3802
- if (!commit )
3803
- error (_ ("could not resolve '%s'" ), buf -> buf );
3804
-
3805
- return commit ;
3806
- }
3807
-
3808
3811
static int do_merge (struct repository * r ,
3809
3812
struct commit * commit ,
3810
3813
const char * arg , int arg_len ,
@@ -3852,7 +3855,7 @@ static int do_merge(struct repository *r,
3852
3855
k = strcspn (p , " \t\n" );
3853
3856
if (!k )
3854
3857
continue ;
3855
- merge_commit = lookup_label (p , k , & ref_name );
3858
+ merge_commit = lookup_label (r , p , k , & ref_name );
3856
3859
if (!merge_commit ) {
3857
3860
ret = error (_ ("unable to parse '%.*s'" ), k , p );
3858
3861
goto leave_merge ;
0 commit comments