@@ -285,11 +285,10 @@ struct image {
285
285
struct line * line ;
286
286
};
287
287
288
- static void clear_image (struct image * image )
288
+ static void image_clear (struct image * image )
289
289
{
290
290
free (image -> buf );
291
291
free (image -> line_allocated );
292
- memset (image , 0 , sizeof (* image ));
293
292
}
294
293
295
294
static uint32_t hash_line (const char * cp , size_t len )
@@ -304,7 +303,7 @@ static uint32_t hash_line(const char *cp, size_t len)
304
303
return h ;
305
304
}
306
305
307
- static void add_line_info (struct image * img , const char * bol , size_t len , unsigned flag )
306
+ static void image_add_line (struct image * img , const char * bol , size_t len , unsigned flag )
308
307
{
309
308
ALLOC_GROW (img -> line_allocated , img -> nr + 1 , img -> alloc );
310
309
img -> line_allocated [img -> nr ].len = len ;
@@ -318,7 +317,7 @@ static void add_line_info(struct image *img, const char *bol, size_t len, unsign
318
317
* attach it to "image" and add line-based index to it.
319
318
* "image" now owns the "buf".
320
319
*/
321
- static void prepare_image (struct image * image , char * buf , size_t len ,
320
+ static void image_prepare (struct image * image , char * buf , size_t len ,
322
321
int prepare_linetable )
323
322
{
324
323
const char * cp , * ep ;
@@ -338,21 +337,21 @@ static void prepare_image(struct image *image, char *buf, size_t len,
338
337
;
339
338
if (next < ep )
340
339
next ++ ;
341
- add_line_info (image , cp , next - cp , 0 );
340
+ image_add_line (image , cp , next - cp , 0 );
342
341
cp = next ;
343
342
}
344
343
image -> line = image -> line_allocated ;
345
344
}
346
345
347
- static void remove_first_line (struct image * img )
346
+ static void image_remove_first_line (struct image * img )
348
347
{
349
348
img -> buf += img -> line [0 ].len ;
350
349
img -> len -= img -> line [0 ].len ;
351
350
img -> line ++ ;
352
351
img -> nr -- ;
353
352
}
354
353
355
- static void remove_last_line (struct image * img )
354
+ static void image_remove_last_line (struct image * img )
356
355
{
357
356
img -> len -= img -> line [-- img -> nr ].len ;
358
357
}
@@ -2322,7 +2321,7 @@ static void update_pre_post_images(struct image *preimage,
2322
2321
* are not losing preimage->buf -- apply_one_fragment() will
2323
2322
* free "oldlines".
2324
2323
*/
2325
- prepare_image (& fixed_preimage , buf , len , 1 );
2324
+ image_prepare (& fixed_preimage , buf , len , 1 );
2326
2325
assert (postlen
2327
2326
? fixed_preimage .nr == preimage -> nr
2328
2327
: fixed_preimage .nr <= preimage -> nr );
@@ -2874,7 +2873,7 @@ static void update_image(struct apply_state *state,
2874
2873
nr = img -> nr + postimage -> nr - preimage_limit ;
2875
2874
if (preimage_limit < postimage -> nr ) {
2876
2875
/*
2877
- * NOTE: this knows that we never call remove_first_line ()
2876
+ * NOTE: this knows that we never call image_remove_first_line ()
2878
2877
* on anything other than pre/post image.
2879
2878
*/
2880
2879
REALLOC_ARRAY (img -> line , nr );
@@ -2957,8 +2956,8 @@ static int apply_one_fragment(struct apply_state *state,
2957
2956
break ;
2958
2957
* old ++ = '\n' ;
2959
2958
strbuf_addch (& newlines , '\n' );
2960
- add_line_info (& preimage , "\n" , 1 , LINE_COMMON );
2961
- add_line_info (& postimage , "\n" , 1 , LINE_COMMON );
2959
+ image_add_line (& preimage , "\n" , 1 , LINE_COMMON );
2960
+ image_add_line (& postimage , "\n" , 1 , LINE_COMMON );
2962
2961
is_blank_context = 1 ;
2963
2962
break ;
2964
2963
case ' ' :
@@ -2968,7 +2967,7 @@ static int apply_one_fragment(struct apply_state *state,
2968
2967
/* fallthrough */
2969
2968
case '-' :
2970
2969
memcpy (old , patch + 1 , plen );
2971
- add_line_info (& preimage , old , plen ,
2970
+ image_add_line (& preimage , old , plen ,
2972
2971
(first == ' ' ? LINE_COMMON : 0 ));
2973
2972
old += plen ;
2974
2973
if (first == '-' )
@@ -2988,7 +2987,7 @@ static int apply_one_fragment(struct apply_state *state,
2988
2987
else {
2989
2988
ws_fix_copy (& newlines , patch + 1 , plen , ws_rule , & state -> applied_after_fixing_ws );
2990
2989
}
2991
- add_line_info (& postimage , newlines .buf + start , newlines .len - start ,
2990
+ image_add_line (& postimage , newlines .buf + start , newlines .len - start ,
2992
2991
(first == '+' ? 0 : LINE_COMMON ));
2993
2992
if (first == '+' &&
2994
2993
(ws_rule & WS_BLANK_AT_EOF ) &&
@@ -3082,14 +3081,14 @@ static int apply_one_fragment(struct apply_state *state,
3082
3081
* just reduce the larger context.
3083
3082
*/
3084
3083
if (leading >= trailing ) {
3085
- remove_first_line (& preimage );
3086
- remove_first_line (& postimage );
3084
+ image_remove_first_line (& preimage );
3085
+ image_remove_first_line (& postimage );
3087
3086
pos -- ;
3088
3087
leading -- ;
3089
3088
}
3090
3089
if (trailing > leading ) {
3091
- remove_last_line (& preimage );
3092
- remove_last_line (& postimage );
3090
+ image_remove_last_line (& preimage );
3091
+ image_remove_last_line (& postimage );
3093
3092
trailing -- ;
3094
3093
}
3095
3094
}
@@ -3103,7 +3102,7 @@ static int apply_one_fragment(struct apply_state *state,
3103
3102
found_new_blank_lines_at_end );
3104
3103
if (state -> ws_error_action == correct_ws_error ) {
3105
3104
while (new_blank_lines_at_end -- )
3106
- remove_last_line (& postimage );
3105
+ image_remove_last_line (& postimage );
3107
3106
}
3108
3107
/*
3109
3108
* We would want to prevent write_out_results()
@@ -3181,12 +3180,12 @@ static int apply_binary_fragment(struct apply_state *state,
3181
3180
fragment -> size , & len );
3182
3181
if (!dst )
3183
3182
return -1 ;
3184
- clear_image (img );
3183
+ image_clear (img );
3185
3184
img -> buf = dst ;
3186
3185
img -> len = len ;
3187
3186
return 0 ;
3188
3187
case BINARY_LITERAL_DEFLATED :
3189
- clear_image (img );
3188
+ image_clear (img );
3190
3189
img -> len = fragment -> size ;
3191
3190
img -> buf = xmemdupz (fragment -> patch , img -> len );
3192
3191
return 0 ;
@@ -3241,7 +3240,7 @@ static int apply_binary(struct apply_state *state,
3241
3240
3242
3241
get_oid_hex (patch -> new_oid_prefix , & oid );
3243
3242
if (is_null_oid (& oid )) {
3244
- clear_image (img );
3243
+ image_clear (img );
3245
3244
return 0 ; /* deletion patch */
3246
3245
}
3247
3246
@@ -3257,7 +3256,7 @@ static int apply_binary(struct apply_state *state,
3257
3256
return error (_ ("the necessary postimage %s for "
3258
3257
"'%s' cannot be read" ),
3259
3258
patch -> new_oid_prefix , name );
3260
- clear_image (img );
3259
+ image_clear (img );
3261
3260
img -> buf = result ;
3262
3261
img -> len = size ;
3263
3262
} else {
@@ -3533,7 +3532,7 @@ static int load_preimage(struct apply_state *state,
3533
3532
}
3534
3533
3535
3534
img = strbuf_detach (& buf , & len );
3536
- prepare_image (image , img , len , !patch -> is_binary );
3535
+ image_prepare (image , img , len , !patch -> is_binary );
3537
3536
return 0 ;
3538
3537
}
3539
3538
@@ -3542,7 +3541,7 @@ static int resolve_to(struct image *image, const struct object_id *result_id)
3542
3541
unsigned long size ;
3543
3542
enum object_type type ;
3544
3543
3545
- clear_image (image );
3544
+ image_clear (image );
3546
3545
3547
3546
image -> buf = repo_read_object_file (the_repository , result_id , & type ,
3548
3547
& size );
@@ -3589,7 +3588,7 @@ static int three_way_merge(struct apply_state *state,
3589
3588
free (result .ptr );
3590
3589
return -1 ;
3591
3590
}
3592
- clear_image (image );
3591
+ image_clear (image );
3593
3592
image -> buf = result .ptr ;
3594
3593
image -> len = result .size ;
3595
3594
@@ -3636,7 +3635,7 @@ static int load_current(struct apply_state *state,
3636
3635
else if (status )
3637
3636
return -1 ;
3638
3637
img = strbuf_detach (& buf , & len );
3639
- prepare_image (image , img , len , !patch -> is_binary );
3638
+ image_prepare (image , img , len , !patch -> is_binary );
3640
3639
return 0 ;
3641
3640
}
3642
3641
@@ -3671,15 +3670,15 @@ static int try_threeway(struct apply_state *state,
3671
3670
fprintf (stderr , _ ("Performing three-way merge...\n" ));
3672
3671
3673
3672
img = strbuf_detach (& buf , & len );
3674
- prepare_image (& tmp_image , img , len , 1 );
3673
+ image_prepare (& tmp_image , img , len , 1 );
3675
3674
/* Apply the patch to get the post image */
3676
3675
if (apply_fragments (state , & tmp_image , patch ) < 0 ) {
3677
- clear_image (& tmp_image );
3676
+ image_clear (& tmp_image );
3678
3677
return -1 ;
3679
3678
}
3680
3679
/* post_oid is theirs */
3681
3680
write_object_file (tmp_image .buf , tmp_image .len , OBJ_BLOB , & post_oid );
3682
- clear_image (& tmp_image );
3681
+ image_clear (& tmp_image );
3683
3682
3684
3683
/* our_oid is ours */
3685
3684
if (patch -> is_new ) {
@@ -3692,7 +3691,7 @@ static int try_threeway(struct apply_state *state,
3692
3691
patch -> old_name );
3693
3692
}
3694
3693
write_object_file (tmp_image .buf , tmp_image .len , OBJ_BLOB , & our_oid );
3695
- clear_image (& tmp_image );
3694
+ image_clear (& tmp_image );
3696
3695
3697
3696
/* in-core three-way merge between post and our using pre as base */
3698
3697
status = three_way_merge (state , image , patch -> new_name ,
@@ -3740,7 +3739,7 @@ static int apply_data(struct apply_state *state, struct patch *patch,
3740
3739
3741
3740
/* Note: with --reject, apply_fragments() returns 0 */
3742
3741
if (patch -> direct_to_threeway || apply_fragments (state , & image , patch ) < 0 ) {
3743
- clear_image (& image );
3742
+ image_clear (& image );
3744
3743
return -1 ;
3745
3744
}
3746
3745
}
0 commit comments