builtin/apply: move 'apply_verbosely' global into 'struct apply_state'
To libify the apply functionality the 'apply_verbosely' 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
5cae882d27c99604bc654ea35102d17b178affdd
1 file changed
+13
-13
builtin/apply.c
+13
-13
@@ -32,6 +32,7 @@ struct apply_state {
32
/* These boolean parameters control how the apply is done */
33
int apply_in_reverse;
34
int apply_with_reject;
35
+ int apply_verbosely;
36
int unidiff_zero;
37
};
38
@@ -51,7 +52,6 @@ static int diffstat;
52
static int numstat;
53
static int summary;
54
static int apply = 1;
54
-static int apply_verbosely;
55
static int allow_overlap;
56
static int no_add;
57
static int threeway;
@@ -2805,7 +2805,7 @@ static int apply_one_fragment(struct apply_state *state,
2805
/* Ignore it, we already handled it */
2806
break;
2807
default:
2808
- if (apply_verbosely)
2808
+ if (state->apply_verbosely)
2809
error(_("invalid start of line: '%c'"), first);
2810
applied_pos = -1;
2811
goto out;
@@ -2920,7 +2920,7 @@ static int apply_one_fragment(struct apply_state *state,
2920
apply = 0;
2921
}
2922
2923
- if (apply_verbosely && applied_pos != pos) {
2923
+ if (state->apply_verbosely && applied_pos != pos) {
2924
int offset = applied_pos - pos;
2925
if (state->apply_in_reverse)
2926
offset = 0 - offset;
@@ -2942,7 +2942,7 @@ static int apply_one_fragment(struct apply_state *state,
2942
leading, trailing, applied_pos+1);
2943
update_image(img, applied_pos, &preimage, &postimage);
2944
} else {
2945
- if (apply_verbosely)
2945
+ if (state->apply_verbosely)
2946
error(_("while searching for:\n%.*s"),
2947
(int)(old - oldlines), oldlines);
2948
}
@@ -3856,7 +3856,7 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)
3856
prepare_symlink_changes(patch);
3857
prepare_fn_table(patch);
3858
while (patch) {
3859
- if (apply_verbosely)
3859
+ if (state->apply_verbosely)
3860
say_patch_name(stderr,
3861
_("Checking patch %s..."), patch);
3862
err |= check_patch(state, patch);
@@ -4287,7 +4287,7 @@ static void write_out_one_result(struct patch *patch, int phase)
4287
create_file(patch);
4288
}
4289
4290
-static int write_out_one_reject(struct patch *patch)
4290
+static int write_out_one_reject(struct apply_state *state, struct patch *patch)
4291
{
4292
FILE *rej;
4293
char namebuf[PATH_MAX];
@@ -4302,7 +4302,7 @@ static int write_out_one_reject(struct patch *patch)
4302
}
4303
4304
if (!cnt) {
4305
- if (apply_verbosely)
4305
+ if (state->apply_verbosely)
4306
say_patch_name(stderr,
4307
_("Applied patch %s cleanly."), patch);
4308
return 0;
@@ -4358,7 +4358,7 @@ static int write_out_one_reject(struct patch *patch)
4358
return -1;
4359
}
4360
4361
-static int write_out_results(struct patch *list)
4361
+static int write_out_results(struct apply_state *state, struct patch *list)
4362
{
4363
int phase;
4364
int errs = 0;
@@ -4373,7 +4373,7 @@ static int write_out_results(struct patch *list)
4373
else {
4374
write_out_one_result(l, phase);
4375
if (phase == 1) {
4376
- if (write_out_one_reject(l))
4376
+ if (write_out_one_reject(state, l))
4377
errs = 1;
4378
if (l->conflicted_threeway) {
4379
string_list_append(&cpath, l->new_name);
@@ -4437,7 +4437,7 @@ static int apply_patch(struct apply_state *state,
4437
listp = &patch->next;
4438
}
4439
else {
4440
- if (apply_verbosely)
4440
+ if (state->apply_verbosely)
4441
say_patch_name(stderr, _("Skipped patch '%s'."), patch);
4442
free_patch(patch);
4443
skipped_patch++;
@@ -4465,7 +4465,7 @@ static int apply_patch(struct apply_state *state,
4465
!state->apply_with_reject)
4466
exit(1);
4467
4468
- if (apply && write_out_results(list)) {
4468
+ if (apply && write_out_results(state, list)) {
4469
if (state->apply_with_reject)
4470
exit(1);
4471
/* with --3way, we still need to write the index out */
@@ -4635,7 +4635,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4635
N_("leave the rejected hunks in corresponding *.rej files")),
4636
OPT_BOOL(0, "allow-overlap", &allow_overlap,
4637
N_("allow overlapping hunks")),
4638
- OPT__VERBOSE(&apply_verbosely, N_("be verbose")),
4638
+ OPT__VERBOSE(&state.apply_verbosely, N_("be verbose")),
4639
OPT_BIT(0, "inaccurate-eof", &options,
4640
N_("tolerate incorrectly detected missing new-line at the end of file"),
4641
INACCURATE_EOF),
@@ -4663,7 +4663,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4663
state.check_index = 1;
4664
}
4665
if (state.apply_with_reject)
4666
- apply = apply_verbosely = 1;
4666
+ apply = state.apply_verbosely = 1;
4667
if (!force_apply && (diffstat || numstat || summary || state.check || fake_ancestor))
4668
apply = 0;
4669
if (state.check_index && is_not_gitdir)