@@ -279,9 +279,8 @@ struct line {
279279struct image {
280280 char * buf ;
281281 size_t len ;
282- size_t nr ;
283- size_t alloc ;
284282 struct line * line ;
283+ size_t line_nr , line_alloc ;
285284};
286285#define IMAGE_INIT { 0 }
287286
@@ -312,11 +311,11 @@ static uint32_t hash_line(const char *cp, size_t len)
312311
313312static void image_add_line (struct image * img , const char * bol , size_t len , unsigned flag )
314313{
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 ++ ;
320319}
321320
322321/*
@@ -353,14 +352,14 @@ static void image_remove_first_line(struct image *img)
353352{
354353 img -> buf += img -> line [0 ].len ;
355354 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 );
359358}
360359
361360static void image_remove_last_line (struct image * img )
362361{
363- img -> len -= img -> line [-- img -> nr ].len ;
362+ img -> len -= img -> line [-- img -> line_nr ].len ;
364363}
365364
366365/* fmt must contain _one_ %s and no other substitution */
@@ -2330,9 +2329,9 @@ static void update_pre_post_images(struct image *preimage,
23302329 */
23312330 image_prepare (& fixed_preimage , buf , len , 1 );
23322331 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 ++ )
23362335 fixed_preimage .line [i ].flag = preimage -> line [i ].flag ;
23372336 free (preimage -> line );
23382337 * preimage = fixed_preimage ;
@@ -2353,7 +2352,7 @@ static void update_pre_post_images(struct image *preimage,
23532352 new_buf = old_buf ;
23542353 fixed = preimage -> buf ;
23552354
2356- for (i = reduced = ctx = 0 ; i < postimage -> nr ; i ++ ) {
2355+ for (i = reduced = ctx = 0 ; i < postimage -> line_nr ; i ++ ) {
23572356 size_t l_len = postimage -> line [i ].len ;
23582357 if (!(postimage -> line [i ].flag & LINE_COMMON )) {
23592358 /* an added line -- no counterparts in preimage */
@@ -2367,7 +2366,7 @@ static void update_pre_post_images(struct image *preimage,
23672366 old_buf += l_len ;
23682367
23692368 /* and find the corresponding one in the fixed preimage */
2370- while (ctx < preimage -> nr &&
2369+ while (ctx < preimage -> line_nr &&
23712370 !(preimage -> line [ctx ].flag & LINE_COMMON )) {
23722371 fixed += preimage -> line [ctx ].len ;
23732372 ctx ++ ;
@@ -2377,7 +2376,7 @@ static void update_pre_post_images(struct image *preimage,
23772376 * preimage is expected to run out, if the caller
23782377 * fixed addition of trailing blank lines.
23792378 */
2380- if (preimage -> nr <= ctx ) {
2379+ if (preimage -> line_nr <= ctx ) {
23812380 reduced ++ ;
23822381 continue ;
23832382 }
@@ -2399,7 +2398,7 @@ static void update_pre_post_images(struct image *preimage,
23992398
24002399 /* Fix the length of the whole thing */
24012400 postimage -> len = new_buf - postimage -> buf ;
2402- postimage -> nr -= reduced ;
2401+ postimage -> line_nr -= reduced ;
24032402}
24042403
24052404/*
@@ -2482,7 +2481,7 @@ static int line_by_line_fuzzy_match(struct image *img,
24822481 * we are removing blank lines at the end of the file.)
24832482 */
24842483 buf = preimage_eof = preimage -> buf + preoff ;
2485- for ( ; i < preimage -> nr ; i ++ )
2484+ for ( ; i < preimage -> line_nr ; i ++ )
24862485 preoff += preimage -> line [i ].len ;
24872486 preimage_end = preimage -> buf + preoff ;
24882487 for ( ; buf < preimage_end ; buf ++ )
@@ -2522,12 +2521,12 @@ static int match_fragment(struct apply_state *state,
25222521 int preimage_limit ;
25232522 int ret ;
25242523
2525- if (preimage -> nr + current_lno <= img -> nr ) {
2524+ if (preimage -> line_nr + current_lno <= img -> line_nr ) {
25262525 /*
25272526 * The hunk falls within the boundaries of img.
25282527 */
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 )) {
25312530 ret = 0 ;
25322531 goto out ;
25332532 }
@@ -2540,7 +2539,7 @@ static int match_fragment(struct apply_state *state,
25402539 * match with img, and the remainder of the preimage
25412540 * must be blank.
25422541 */
2543- preimage_limit = img -> nr - current_lno ;
2542+ preimage_limit = img -> line_nr - current_lno ;
25442543 } else {
25452544 /*
25462545 * The hunk extends beyond the end of the img and
@@ -2565,7 +2564,7 @@ static int match_fragment(struct apply_state *state,
25652564 }
25662565 }
25672566
2568- if (preimage_limit == preimage -> nr ) {
2567+ if (preimage_limit == preimage -> line_nr ) {
25692568 /*
25702569 * Do we have an exact match? If we were told to match
25712570 * at the end, size must be exactly at current+fragsize,
@@ -2637,7 +2636,7 @@ static int match_fragment(struct apply_state *state,
26372636
26382637 /* First count added lines in postimage */
26392638 postlen = 0 ;
2640- for (i = 0 ; i < postimage -> nr ; i ++ ) {
2639+ for (i = 0 ; i < postimage -> line_nr ; i ++ ) {
26412640 if (!(postimage -> line [i ].flag & LINE_COMMON ))
26422641 postlen += postimage -> line [i ].len ;
26432642 }
@@ -2699,7 +2698,7 @@ static int match_fragment(struct apply_state *state,
26992698 * empty or only contain whitespace (if WS_BLANK_AT_EOL is
27002699 * false).
27012700 */
2702- for ( ; i < preimage -> nr ; i ++ ) {
2701+ for ( ; i < preimage -> line_nr ; i ++ ) {
27032702 size_t fixstart = fixed .len ; /* start of the fixed preimage */
27042703 size_t oldlen = preimage -> line [i ].len ;
27052704 int j ;
@@ -2754,7 +2753,7 @@ static int find_pos(struct apply_state *state,
27542753 * than `match_beginning`.
27552754 */
27562755 if (state -> allow_overlap && match_beginning && match_end &&
2757- img -> nr - preimage -> nr != 0 )
2756+ img -> line_nr - preimage -> line_nr != 0 )
27582757 match_beginning = 0 ;
27592758
27602759 /*
@@ -2765,15 +2764,15 @@ static int find_pos(struct apply_state *state,
27652764 if (match_beginning )
27662765 line = 0 ;
27672766 else if (match_end )
2768- line = img -> nr - preimage -> nr ;
2767+ line = img -> line_nr - preimage -> line_nr ;
27692768
27702769 /*
27712770 * Because the comparison is unsigned, the following test
27722771 * will also take care of a negative line number that can
27732772 * result when match_end and preimage is larger than the target.
27742773 */
2775- if ((size_t ) line > img -> nr )
2776- line = img -> nr ;
2774+ if ((size_t ) line > img -> line_nr )
2775+ line = img -> line_nr ;
27772776
27782777 current = 0 ;
27792778 for (i = 0 ; i < line ; i ++ )
@@ -2796,7 +2795,7 @@ static int find_pos(struct apply_state *state,
27962795 return current_lno ;
27972796
27982797 again :
2799- if (backwards_lno == 0 && forwards_lno == img -> nr )
2798+ if (backwards_lno == 0 && forwards_lno == img -> line_nr )
28002799 break ;
28012800
28022801 if (i & 1 ) {
@@ -2809,7 +2808,7 @@ static int find_pos(struct apply_state *state,
28092808 current = backwards ;
28102809 current_lno = backwards_lno ;
28112810 } else {
2812- if (forwards_lno == img -> nr ) {
2811+ if (forwards_lno == img -> line_nr ) {
28132812 i ++ ;
28142813 goto again ;
28152814 }
@@ -2852,9 +2851,9 @@ static void update_image(struct apply_state *state,
28522851 * to the number of lines in the preimage that falls
28532852 * within the boundaries.
28542853 */
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 ;
28582857
28592858 for (i = 0 ; i < applied_pos ; i ++ )
28602859 applied_at += img -> line [i ].len ;
@@ -2877,22 +2876,22 @@ static void update_image(struct apply_state *state,
28772876 result [img -> len ] = '\0' ;
28782877
28792878 /* 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 )
28822881 /*
28832882 * NOTE: this knows that we never call image_remove_first_line()
28842883 * on anything other than pre/post image.
28852884 */
28862885 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 ,
28892888 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 );
28922891 if (!state -> allow_overlap )
2893- for (i = 0 ; i < postimage -> nr ; i ++ )
2892+ for (i = 0 ; i < postimage -> line_nr ; i ++ )
28942893 img -> line [applied_pos + i ].flag |= LINE_PATCHED ;
2895- img -> nr = nr ;
2894+ img -> line_nr = nr ;
28962895}
28972896
28982897/*
@@ -3024,8 +3023,8 @@ static int apply_one_fragment(struct apply_state *state,
30243023 newlines .len > 0 && newlines .buf [newlines .len - 1 ] == '\n' ) {
30253024 old -- ;
30263025 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 -- ;
30293028 }
30303029
30313030 leading = frag -> leading ;
@@ -3096,7 +3095,7 @@ static int apply_one_fragment(struct apply_state *state,
30963095
30973096 if (applied_pos >= 0 ) {
30983097 if (new_blank_lines_at_end &&
3099- preimage .nr + applied_pos >= img -> nr &&
3098+ preimage .line_nr + applied_pos >= img -> line_nr &&
31003099 (ws_rule & WS_BLANK_AT_EOF ) &&
31013100 state -> ws_error_action != nowarn_ws_error ) {
31023101 record_ws_error (state , WS_BLANK_AT_EOF , "+" , 1 ,
0 commit comments