@@ -3900,11 +3900,12 @@ static int preimage_sha1_in_gitlink_patch(struct patch *p, unsigned char sha1[20
3900
3900
}
3901
3901
3902
3902
/* Build an index that contains the just the files needed for a 3way merge */
3903
- static void build_fake_ancestor (struct patch * list , const char * filename )
3903
+ static int build_fake_ancestor (struct patch * list , const char * filename )
3904
3904
{
3905
3905
struct patch * patch ;
3906
3906
struct index_state result = { NULL };
3907
3907
static struct lock_file lock ;
3908
+ int res ;
3908
3909
3909
3910
/* Once we start supporting the reverse patch, it may be
3910
3911
* worth showing the new sha1 prefix, but until then...
@@ -3922,31 +3923,38 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
3922
3923
if (!preimage_sha1_in_gitlink_patch (patch , sha1 ))
3923
3924
; /* ok, the textual part looks sane */
3924
3925
else
3925
- die ("sha1 information is lacking or useless for submodule %s" ,
3926
- name );
3926
+ return error ("sha1 information is lacking or "
3927
+ "useless for submodule %s" , name );
3927
3928
} else if (!get_sha1_blob (patch -> old_sha1_prefix , sha1 )) {
3928
3929
; /* ok */
3929
3930
} else if (!patch -> lines_added && !patch -> lines_deleted ) {
3930
3931
/* mode-only change: update the current */
3931
3932
if (get_current_sha1 (patch -> old_name , sha1 ))
3932
- die ("mode change for %s, which is not "
3933
- "in current HEAD" , name );
3933
+ return error ("mode change for %s, which is not "
3934
+ "in current HEAD" , name );
3934
3935
} else
3935
- die ("sha1 information is lacking or useless "
3936
- "(%s)." , name );
3936
+ return error ("sha1 information is lacking or useless "
3937
+ "(%s)." , name );
3937
3938
3938
3939
ce = make_cache_entry (patch -> old_mode , sha1 , name , 0 , 0 );
3939
3940
if (!ce )
3940
- die (_ ("make_cache_entry failed for path '%s'" ), name );
3941
- if (add_index_entry (& result , ce , ADD_CACHE_OK_TO_ADD ))
3942
- die ("Could not add %s to temporary index" , name );
3941
+ return error (_ ("make_cache_entry failed for path '%s'" ),
3942
+ name );
3943
+ if (add_index_entry (& result , ce , ADD_CACHE_OK_TO_ADD )) {
3944
+ free (ce );
3945
+ return error ("Could not add %s to temporary index" ,
3946
+ name );
3947
+ }
3943
3948
}
3944
3949
3945
3950
hold_lock_file_for_update (& lock , filename , LOCK_DIE_ON_ERROR );
3946
- if (write_locked_index (& result , & lock , COMMIT_LOCK ))
3947
- die ("Could not write temporary index to %s" , filename );
3948
-
3951
+ res = write_locked_index (& result , & lock , COMMIT_LOCK );
3949
3952
discard_index (& result );
3953
+
3954
+ if (res )
3955
+ return error ("Could not write temporary index to %s" , filename );
3956
+
3957
+ return 0 ;
3950
3958
}
3951
3959
3952
3960
static void stat_patch_list (struct apply_state * state , struct patch * patch )
@@ -4495,8 +4503,11 @@ static int apply_patch(struct apply_state *state,
4495
4503
goto end ;
4496
4504
}
4497
4505
4498
- if (state -> fake_ancestor )
4499
- build_fake_ancestor (list , state -> fake_ancestor );
4506
+ if (state -> fake_ancestor &&
4507
+ build_fake_ancestor (list , state -> fake_ancestor )) {
4508
+ res = -128 ;
4509
+ goto end ;
4510
+ }
4500
4511
4501
4512
if (state -> diffstat )
4502
4513
stat_patch_list (state , list );
0 commit comments