@@ -285,11 +285,10 @@ struct image {
285285 struct line * line ;
286286};
287287
288- static void clear_image (struct image * image )
288+ static void image_clear (struct image * image )
289289{
290290 free (image -> buf );
291291 free (image -> line_allocated );
292- memset (image , 0 , sizeof (* image ));
293292}
294293
295294static 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)
304303 return h ;
305304}
306305
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 )
308307{
309308 ALLOC_GROW (img -> line_allocated , img -> nr + 1 , img -> alloc );
310309 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
318317 * attach it to "image" and add line-based index to it.
319318 * "image" now owns the "buf".
320319 */
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 ,
322321 int prepare_linetable )
323322{
324323 const char * cp , * ep ;
@@ -338,21 +337,21 @@ static void prepare_image(struct image *image, char *buf, size_t len,
338337 ;
339338 if (next < ep )
340339 next ++ ;
341- add_line_info (image , cp , next - cp , 0 );
340+ image_add_line (image , cp , next - cp , 0 );
342341 cp = next ;
343342 }
344343 image -> line = image -> line_allocated ;
345344}
346345
347- static void remove_first_line (struct image * img )
346+ static void image_remove_first_line (struct image * img )
348347{
349348 img -> buf += img -> line [0 ].len ;
350349 img -> len -= img -> line [0 ].len ;
351350 img -> line ++ ;
352351 img -> nr -- ;
353352}
354353
355- static void remove_last_line (struct image * img )
354+ static void image_remove_last_line (struct image * img )
356355{
357356 img -> len -= img -> line [-- img -> nr ].len ;
358357}
@@ -2322,7 +2321,7 @@ static void update_pre_post_images(struct image *preimage,
23222321 * are not losing preimage->buf -- apply_one_fragment() will
23232322 * free "oldlines".
23242323 */
2325- prepare_image (& fixed_preimage , buf , len , 1 );
2324+ image_prepare (& fixed_preimage , buf , len , 1 );
23262325 assert (postlen
23272326 ? fixed_preimage .nr == preimage -> nr
23282327 : fixed_preimage .nr <= preimage -> nr );
@@ -2874,7 +2873,7 @@ static void update_image(struct apply_state *state,
28742873 nr = img -> nr + postimage -> nr - preimage_limit ;
28752874 if (preimage_limit < postimage -> nr ) {
28762875 /*
2877- * NOTE: this knows that we never call remove_first_line ()
2876+ * NOTE: this knows that we never call image_remove_first_line ()
28782877 * on anything other than pre/post image.
28792878 */
28802879 REALLOC_ARRAY (img -> line , nr );
@@ -2957,8 +2956,8 @@ static int apply_one_fragment(struct apply_state *state,
29572956 break ;
29582957 * old ++ = '\n' ;
29592958 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 );
29622961 is_blank_context = 1 ;
29632962 break ;
29642963 case ' ' :
@@ -2968,7 +2967,7 @@ static int apply_one_fragment(struct apply_state *state,
29682967 /* fallthrough */
29692968 case '-' :
29702969 memcpy (old , patch + 1 , plen );
2971- add_line_info (& preimage , old , plen ,
2970+ image_add_line (& preimage , old , plen ,
29722971 (first == ' ' ? LINE_COMMON : 0 ));
29732972 old += plen ;
29742973 if (first == '-' )
@@ -2988,7 +2987,7 @@ static int apply_one_fragment(struct apply_state *state,
29882987 else {
29892988 ws_fix_copy (& newlines , patch + 1 , plen , ws_rule , & state -> applied_after_fixing_ws );
29902989 }
2991- add_line_info (& postimage , newlines .buf + start , newlines .len - start ,
2990+ image_add_line (& postimage , newlines .buf + start , newlines .len - start ,
29922991 (first == '+' ? 0 : LINE_COMMON ));
29932992 if (first == '+' &&
29942993 (ws_rule & WS_BLANK_AT_EOF ) &&
@@ -3082,14 +3081,14 @@ static int apply_one_fragment(struct apply_state *state,
30823081 * just reduce the larger context.
30833082 */
30843083 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 );
30873086 pos -- ;
30883087 leading -- ;
30893088 }
30903089 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 );
30933092 trailing -- ;
30943093 }
30953094 }
@@ -3103,7 +3102,7 @@ static int apply_one_fragment(struct apply_state *state,
31033102 found_new_blank_lines_at_end );
31043103 if (state -> ws_error_action == correct_ws_error ) {
31053104 while (new_blank_lines_at_end -- )
3106- remove_last_line (& postimage );
3105+ image_remove_last_line (& postimage );
31073106 }
31083107 /*
31093108 * We would want to prevent write_out_results()
@@ -3181,12 +3180,12 @@ static int apply_binary_fragment(struct apply_state *state,
31813180 fragment -> size , & len );
31823181 if (!dst )
31833182 return -1 ;
3184- clear_image (img );
3183+ image_clear (img );
31853184 img -> buf = dst ;
31863185 img -> len = len ;
31873186 return 0 ;
31883187 case BINARY_LITERAL_DEFLATED :
3189- clear_image (img );
3188+ image_clear (img );
31903189 img -> len = fragment -> size ;
31913190 img -> buf = xmemdupz (fragment -> patch , img -> len );
31923191 return 0 ;
@@ -3241,7 +3240,7 @@ static int apply_binary(struct apply_state *state,
32413240
32423241 get_oid_hex (patch -> new_oid_prefix , & oid );
32433242 if (is_null_oid (& oid )) {
3244- clear_image (img );
3243+ image_clear (img );
32453244 return 0 ; /* deletion patch */
32463245 }
32473246
@@ -3257,7 +3256,7 @@ static int apply_binary(struct apply_state *state,
32573256 return error (_ ("the necessary postimage %s for "
32583257 "'%s' cannot be read" ),
32593258 patch -> new_oid_prefix , name );
3260- clear_image (img );
3259+ image_clear (img );
32613260 img -> buf = result ;
32623261 img -> len = size ;
32633262 } else {
@@ -3533,7 +3532,7 @@ static int load_preimage(struct apply_state *state,
35333532 }
35343533
35353534 img = strbuf_detach (& buf , & len );
3536- prepare_image (image , img , len , !patch -> is_binary );
3535+ image_prepare (image , img , len , !patch -> is_binary );
35373536 return 0 ;
35383537}
35393538
@@ -3542,7 +3541,7 @@ static int resolve_to(struct image *image, const struct object_id *result_id)
35423541 unsigned long size ;
35433542 enum object_type type ;
35443543
3545- clear_image (image );
3544+ image_clear (image );
35463545
35473546 image -> buf = repo_read_object_file (the_repository , result_id , & type ,
35483547 & size );
@@ -3589,7 +3588,7 @@ static int three_way_merge(struct apply_state *state,
35893588 free (result .ptr );
35903589 return -1 ;
35913590 }
3592- clear_image (image );
3591+ image_clear (image );
35933592 image -> buf = result .ptr ;
35943593 image -> len = result .size ;
35953594
@@ -3636,7 +3635,7 @@ static int load_current(struct apply_state *state,
36363635 else if (status )
36373636 return -1 ;
36383637 img = strbuf_detach (& buf , & len );
3639- prepare_image (image , img , len , !patch -> is_binary );
3638+ image_prepare (image , img , len , !patch -> is_binary );
36403639 return 0 ;
36413640}
36423641
@@ -3671,15 +3670,15 @@ static int try_threeway(struct apply_state *state,
36713670 fprintf (stderr , _ ("Performing three-way merge...\n" ));
36723671
36733672 img = strbuf_detach (& buf , & len );
3674- prepare_image (& tmp_image , img , len , 1 );
3673+ image_prepare (& tmp_image , img , len , 1 );
36753674 /* Apply the patch to get the post image */
36763675 if (apply_fragments (state , & tmp_image , patch ) < 0 ) {
3677- clear_image (& tmp_image );
3676+ image_clear (& tmp_image );
36783677 return -1 ;
36793678 }
36803679 /* post_oid is theirs */
36813680 write_object_file (tmp_image .buf , tmp_image .len , OBJ_BLOB , & post_oid );
3682- clear_image (& tmp_image );
3681+ image_clear (& tmp_image );
36833682
36843683 /* our_oid is ours */
36853684 if (patch -> is_new ) {
@@ -3692,7 +3691,7 @@ static int try_threeway(struct apply_state *state,
36923691 patch -> old_name );
36933692 }
36943693 write_object_file (tmp_image .buf , tmp_image .len , OBJ_BLOB , & our_oid );
3695- clear_image (& tmp_image );
3694+ image_clear (& tmp_image );
36963695
36973696 /* in-core three-way merge between post and our using pre as base */
36983697 status = three_way_merge (state , image , patch -> new_name ,
@@ -3740,7 +3739,7 @@ static int apply_data(struct apply_state *state, struct patch *patch,
37403739
37413740 /* Note: with --reject, apply_fragments() returns 0 */
37423741 if (patch -> direct_to_threeway || apply_fragments (state , & image , patch ) < 0 ) {
3743- clear_image (& image );
3742+ image_clear (& image );
37443743 return -1 ;
37453744 }
37463745 }
0 commit comments