builtin/apply: move 'allow_overlap' global into 'struct apply_state'
To libify the apply functionality the 'allow_overlap' variable should not be static and global to the file. Let's move it into 'struct apply_state'. Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
May 24, 2016 at 10:10 UTC
6ca4c390933597f20db006445e844797ca7cd2c9
1 file changed
+6
-5
builtin/apply.c
+6
-5
@@ -31,6 +31,7 @@ struct apply_state {
31
int update_index; /* check_index && apply */
32
33
/* These boolean parameters control how the apply is done */
34
+ int allow_overlap;
35
int apply_in_reverse;
36
int apply_with_reject;
37
int apply_verbosely;
@@ -52,7 +53,6 @@ static int diffstat;
53
static int numstat;
54
static int summary;
55
static int apply = 1;
55
-static int allow_overlap;
56
static int no_add;
57
static int threeway;
58
static int unsafe_paths;
@@ -2627,7 +2627,8 @@ static void remove_last_line(struct image *img)
2627
* apply at applied_pos (counts in line numbers) in "img".
2628
* Update "img" to remove "preimage" and replace it with "postimage".
2629
*/
2630
-static void update_image(struct image *img,
2630
+static void update_image(struct apply_state *state,
2631
+ struct image *img,
2632
int applied_pos,
2633
struct image *preimage,
2634
struct image *postimage)
@@ -2692,7 +2693,7 @@ static void update_image(struct image *img,
2693
memcpy(img->line + applied_pos,
2694
postimage->line,
2695
postimage->nr * sizeof(*img->line));
2695
- if (!allow_overlap)
2696
+ if (!state->allow_overlap)
2697
for (i = 0; i < postimage->nr; i++)
2698
img->line[applied_pos + i].flag |= LINE_PATCHED;
2699
img->nr = nr;
@@ -2940,7 +2941,7 @@ static int apply_one_fragment(struct apply_state *state,
2941
fprintf_ln(stderr, _("Context reduced to (%ld/%ld)"
2942
" to apply fragment at %d"),
2943
leading, trailing, applied_pos+1);
2943
- update_image(img, applied_pos, &preimage, &postimage);
2944
+ update_image(state, img, applied_pos, &preimage, &postimage);
2945
} else {
2946
if (state->apply_verbosely)
2947
error(_("while searching for:\n%.*s"),
@@ -4640,7 +4641,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4641
N_("don't expect at least one line of context")),
4642
OPT_BOOL(0, "reject", &state.apply_with_reject,
4643
N_("leave the rejected hunks in corresponding *.rej files")),
4643
- OPT_BOOL(0, "allow-overlap", &allow_overlap,
4644
+ OPT_BOOL(0, "allow-overlap", &state.allow_overlap,
4645
N_("allow overlapping hunks")),
4646
OPT__VERBOSE(&state.apply_verbosely, N_("be verbose")),
4647
OPT_BIT(0, "inaccurate-eof", &options,