@@ -279,9 +279,8 @@ struct line {
279
279
struct image {
280
280
char * buf ;
281
281
size_t len ;
282
- size_t nr ;
283
- size_t alloc ;
284
282
struct line * line ;
283
+ size_t line_nr , line_alloc ;
285
284
};
286
285
#define IMAGE_INIT { 0 }
287
286
@@ -312,11 +311,11 @@ static uint32_t hash_line(const char *cp, size_t len)
312
311
313
312
static void image_add_line (struct image * img , const char * bol , size_t len , unsigned flag )
314
313
{
315
- ALLOC_GROW (img -> line , img -> nr + 1 , img -> alloc );
316
- img -> line [img -> nr ].len = len ;
317
- img -> line [img -> nr ].hash = hash_line (bol , len );
318
- img -> line [img -> nr ].flag = flag ;
319
- img -> nr ++ ;
314
+ ALLOC_GROW (img -> line , img -> line_nr + 1 , img -> line_alloc );
315
+ img -> line [img -> line_nr ].len = len ;
316
+ img -> line [img -> line_nr ].hash = hash_line (bol , len );
317
+ img -> line [img -> line_nr ].flag = flag ;
318
+ img -> line_nr ++ ;
320
319
}
321
320
322
321
/*
@@ -353,14 +352,14 @@ static void image_remove_first_line(struct image *img)
353
352
{
354
353
img -> buf += img -> line [0 ].len ;
355
354
img -> len -= img -> line [0 ].len ;
356
- img -> nr -- ;
357
- if (img -> nr )
358
- MOVE_ARRAY (img -> line , img -> line + 1 , img -> nr );
355
+ img -> line_nr -- ;
356
+ if (img -> line_nr )
357
+ MOVE_ARRAY (img -> line , img -> line + 1 , img -> line_nr );
359
358
}
360
359
361
360
static void image_remove_last_line (struct image * img )
362
361
{
363
- img -> len -= img -> line [-- img -> nr ].len ;
362
+ img -> len -= img -> line [-- img -> line_nr ].len ;
364
363
}
365
364
366
365
/* fmt must contain _one_ %s and no other substitution */
@@ -2330,9 +2329,9 @@ static void update_pre_post_images(struct image *preimage,
2330
2329
*/
2331
2330
image_prepare (& fixed_preimage , buf , len , 1 );
2332
2331
assert (postlen
2333
- ? fixed_preimage .nr == preimage -> nr
2334
- : fixed_preimage .nr <= preimage -> nr );
2335
- for (i = 0 ; i < fixed_preimage .nr ; i ++ )
2332
+ ? fixed_preimage .line_nr == preimage -> line_nr
2333
+ : fixed_preimage .line_nr <= preimage -> line_nr );
2334
+ for (i = 0 ; i < fixed_preimage .line_nr ; i ++ )
2336
2335
fixed_preimage .line [i ].flag = preimage -> line [i ].flag ;
2337
2336
free (preimage -> line );
2338
2337
* preimage = fixed_preimage ;
@@ -2353,7 +2352,7 @@ static void update_pre_post_images(struct image *preimage,
2353
2352
new_buf = old_buf ;
2354
2353
fixed = preimage -> buf ;
2355
2354
2356
- for (i = reduced = ctx = 0 ; i < postimage -> nr ; i ++ ) {
2355
+ for (i = reduced = ctx = 0 ; i < postimage -> line_nr ; i ++ ) {
2357
2356
size_t l_len = postimage -> line [i ].len ;
2358
2357
if (!(postimage -> line [i ].flag & LINE_COMMON )) {
2359
2358
/* an added line -- no counterparts in preimage */
@@ -2367,7 +2366,7 @@ static void update_pre_post_images(struct image *preimage,
2367
2366
old_buf += l_len ;
2368
2367
2369
2368
/* and find the corresponding one in the fixed preimage */
2370
- while (ctx < preimage -> nr &&
2369
+ while (ctx < preimage -> line_nr &&
2371
2370
!(preimage -> line [ctx ].flag & LINE_COMMON )) {
2372
2371
fixed += preimage -> line [ctx ].len ;
2373
2372
ctx ++ ;
@@ -2377,7 +2376,7 @@ static void update_pre_post_images(struct image *preimage,
2377
2376
* preimage is expected to run out, if the caller
2378
2377
* fixed addition of trailing blank lines.
2379
2378
*/
2380
- if (preimage -> nr <= ctx ) {
2379
+ if (preimage -> line_nr <= ctx ) {
2381
2380
reduced ++ ;
2382
2381
continue ;
2383
2382
}
@@ -2399,7 +2398,7 @@ static void update_pre_post_images(struct image *preimage,
2399
2398
2400
2399
/* Fix the length of the whole thing */
2401
2400
postimage -> len = new_buf - postimage -> buf ;
2402
- postimage -> nr -= reduced ;
2401
+ postimage -> line_nr -= reduced ;
2403
2402
}
2404
2403
2405
2404
/*
@@ -2482,7 +2481,7 @@ static int line_by_line_fuzzy_match(struct image *img,
2482
2481
* we are removing blank lines at the end of the file.)
2483
2482
*/
2484
2483
buf = preimage_eof = preimage -> buf + preoff ;
2485
- for ( ; i < preimage -> nr ; i ++ )
2484
+ for ( ; i < preimage -> line_nr ; i ++ )
2486
2485
preoff += preimage -> line [i ].len ;
2487
2486
preimage_end = preimage -> buf + preoff ;
2488
2487
for ( ; buf < preimage_end ; buf ++ )
@@ -2522,12 +2521,12 @@ static int match_fragment(struct apply_state *state,
2522
2521
int preimage_limit ;
2523
2522
int ret ;
2524
2523
2525
- if (preimage -> nr + current_lno <= img -> nr ) {
2524
+ if (preimage -> line_nr + current_lno <= img -> line_nr ) {
2526
2525
/*
2527
2526
* The hunk falls within the boundaries of img.
2528
2527
*/
2529
- preimage_limit = preimage -> nr ;
2530
- if (match_end && (preimage -> nr + current_lno != img -> nr )) {
2528
+ preimage_limit = preimage -> line_nr ;
2529
+ if (match_end && (preimage -> line_nr + current_lno != img -> line_nr )) {
2531
2530
ret = 0 ;
2532
2531
goto out ;
2533
2532
}
@@ -2540,7 +2539,7 @@ static int match_fragment(struct apply_state *state,
2540
2539
* match with img, and the remainder of the preimage
2541
2540
* must be blank.
2542
2541
*/
2543
- preimage_limit = img -> nr - current_lno ;
2542
+ preimage_limit = img -> line_nr - current_lno ;
2544
2543
} else {
2545
2544
/*
2546
2545
* The hunk extends beyond the end of the img and
@@ -2565,7 +2564,7 @@ static int match_fragment(struct apply_state *state,
2565
2564
}
2566
2565
}
2567
2566
2568
- if (preimage_limit == preimage -> nr ) {
2567
+ if (preimage_limit == preimage -> line_nr ) {
2569
2568
/*
2570
2569
* Do we have an exact match? If we were told to match
2571
2570
* at the end, size must be exactly at current+fragsize,
@@ -2637,7 +2636,7 @@ static int match_fragment(struct apply_state *state,
2637
2636
2638
2637
/* First count added lines in postimage */
2639
2638
postlen = 0 ;
2640
- for (i = 0 ; i < postimage -> nr ; i ++ ) {
2639
+ for (i = 0 ; i < postimage -> line_nr ; i ++ ) {
2641
2640
if (!(postimage -> line [i ].flag & LINE_COMMON ))
2642
2641
postlen += postimage -> line [i ].len ;
2643
2642
}
@@ -2699,7 +2698,7 @@ static int match_fragment(struct apply_state *state,
2699
2698
* empty or only contain whitespace (if WS_BLANK_AT_EOL is
2700
2699
* false).
2701
2700
*/
2702
- for ( ; i < preimage -> nr ; i ++ ) {
2701
+ for ( ; i < preimage -> line_nr ; i ++ ) {
2703
2702
size_t fixstart = fixed .len ; /* start of the fixed preimage */
2704
2703
size_t oldlen = preimage -> line [i ].len ;
2705
2704
int j ;
@@ -2754,7 +2753,7 @@ static int find_pos(struct apply_state *state,
2754
2753
* than `match_beginning`.
2755
2754
*/
2756
2755
if (state -> allow_overlap && match_beginning && match_end &&
2757
- img -> nr - preimage -> nr != 0 )
2756
+ img -> line_nr - preimage -> line_nr != 0 )
2758
2757
match_beginning = 0 ;
2759
2758
2760
2759
/*
@@ -2765,15 +2764,15 @@ static int find_pos(struct apply_state *state,
2765
2764
if (match_beginning )
2766
2765
line = 0 ;
2767
2766
else if (match_end )
2768
- line = img -> nr - preimage -> nr ;
2767
+ line = img -> line_nr - preimage -> line_nr ;
2769
2768
2770
2769
/*
2771
2770
* Because the comparison is unsigned, the following test
2772
2771
* will also take care of a negative line number that can
2773
2772
* result when match_end and preimage is larger than the target.
2774
2773
*/
2775
- if ((size_t ) line > img -> nr )
2776
- line = img -> nr ;
2774
+ if ((size_t ) line > img -> line_nr )
2775
+ line = img -> line_nr ;
2777
2776
2778
2777
current = 0 ;
2779
2778
for (i = 0 ; i < line ; i ++ )
@@ -2796,7 +2795,7 @@ static int find_pos(struct apply_state *state,
2796
2795
return current_lno ;
2797
2796
2798
2797
again :
2799
- if (backwards_lno == 0 && forwards_lno == img -> nr )
2798
+ if (backwards_lno == 0 && forwards_lno == img -> line_nr )
2800
2799
break ;
2801
2800
2802
2801
if (i & 1 ) {
@@ -2809,7 +2808,7 @@ static int find_pos(struct apply_state *state,
2809
2808
current = backwards ;
2810
2809
current_lno = backwards_lno ;
2811
2810
} else {
2812
- if (forwards_lno == img -> nr ) {
2811
+ if (forwards_lno == img -> line_nr ) {
2813
2812
i ++ ;
2814
2813
goto again ;
2815
2814
}
@@ -2852,9 +2851,9 @@ static void update_image(struct apply_state *state,
2852
2851
* to the number of lines in the preimage that falls
2853
2852
* within the boundaries.
2854
2853
*/
2855
- preimage_limit = preimage -> nr ;
2856
- if (preimage_limit > img -> nr - applied_pos )
2857
- preimage_limit = img -> nr - applied_pos ;
2854
+ preimage_limit = preimage -> line_nr ;
2855
+ if (preimage_limit > img -> line_nr - applied_pos )
2856
+ preimage_limit = img -> line_nr - applied_pos ;
2858
2857
2859
2858
for (i = 0 ; i < applied_pos ; i ++ )
2860
2859
applied_at += img -> line [i ].len ;
@@ -2877,22 +2876,22 @@ static void update_image(struct apply_state *state,
2877
2876
result [img -> len ] = '\0' ;
2878
2877
2879
2878
/* Adjust the line table */
2880
- nr = img -> nr + postimage -> nr - preimage_limit ;
2881
- if (preimage_limit < postimage -> nr )
2879
+ nr = img -> line_nr + postimage -> line_nr - preimage_limit ;
2880
+ if (preimage_limit < postimage -> line_nr )
2882
2881
/*
2883
2882
* NOTE: this knows that we never call image_remove_first_line()
2884
2883
* on anything other than pre/post image.
2885
2884
*/
2886
2885
REALLOC_ARRAY (img -> line , nr );
2887
- if (preimage_limit != postimage -> nr )
2888
- MOVE_ARRAY (img -> line + applied_pos + postimage -> nr ,
2886
+ if (preimage_limit != postimage -> line_nr )
2887
+ MOVE_ARRAY (img -> line + applied_pos + postimage -> line_nr ,
2889
2888
img -> line + applied_pos + preimage_limit ,
2890
- img -> nr - (applied_pos + preimage_limit ));
2891
- COPY_ARRAY (img -> line + applied_pos , postimage -> line , postimage -> nr );
2889
+ img -> line_nr - (applied_pos + preimage_limit ));
2890
+ COPY_ARRAY (img -> line + applied_pos , postimage -> line , postimage -> line_nr );
2892
2891
if (!state -> allow_overlap )
2893
- for (i = 0 ; i < postimage -> nr ; i ++ )
2892
+ for (i = 0 ; i < postimage -> line_nr ; i ++ )
2894
2893
img -> line [applied_pos + i ].flag |= LINE_PATCHED ;
2895
- img -> nr = nr ;
2894
+ img -> line_nr = nr ;
2896
2895
}
2897
2896
2898
2897
/*
@@ -3024,8 +3023,8 @@ static int apply_one_fragment(struct apply_state *state,
3024
3023
newlines .len > 0 && newlines .buf [newlines .len - 1 ] == '\n' ) {
3025
3024
old -- ;
3026
3025
strbuf_setlen (& newlines , newlines .len - 1 );
3027
- preimage .line [preimage .nr - 1 ].len -- ;
3028
- postimage .line [postimage .nr - 1 ].len -- ;
3026
+ preimage .line [preimage .line_nr - 1 ].len -- ;
3027
+ postimage .line [postimage .line_nr - 1 ].len -- ;
3029
3028
}
3030
3029
3031
3030
leading = frag -> leading ;
@@ -3096,7 +3095,7 @@ static int apply_one_fragment(struct apply_state *state,
3096
3095
3097
3096
if (applied_pos >= 0 ) {
3098
3097
if (new_blank_lines_at_end &&
3099
- preimage .nr + applied_pos >= img -> nr &&
3098
+ preimage .line_nr + applied_pos >= img -> line_nr &&
3100
3099
(ws_rule & WS_BLANK_AT_EOF ) &&
3101
3100
state -> ws_error_action != nowarn_ws_error ) {
3102
3101
record_ws_error (state , WS_BLANK_AT_EOF , "+" , 1 ,
0 commit comments