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