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>
This commit is contained in:
parent
30b5ae4d41
commit
5cae882d27
@ -32,6 +32,7 @@ struct apply_state {
|
|||||||
/* These boolean parameters control how the apply is done */
|
/* These boolean parameters control how the apply is done */
|
||||||
int apply_in_reverse;
|
int apply_in_reverse;
|
||||||
int apply_with_reject;
|
int apply_with_reject;
|
||||||
|
int apply_verbosely;
|
||||||
int unidiff_zero;
|
int unidiff_zero;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,7 +52,6 @@ static int diffstat;
|
|||||||
static int numstat;
|
static int numstat;
|
||||||
static int summary;
|
static int summary;
|
||||||
static int apply = 1;
|
static int apply = 1;
|
||||||
static int apply_verbosely;
|
|
||||||
static int allow_overlap;
|
static int allow_overlap;
|
||||||
static int no_add;
|
static int no_add;
|
||||||
static int threeway;
|
static int threeway;
|
||||||
@ -2805,7 +2805,7 @@ static int apply_one_fragment(struct apply_state *state,
|
|||||||
/* Ignore it, we already handled it */
|
/* Ignore it, we already handled it */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (apply_verbosely)
|
if (state->apply_verbosely)
|
||||||
error(_("invalid start of line: '%c'"), first);
|
error(_("invalid start of line: '%c'"), first);
|
||||||
applied_pos = -1;
|
applied_pos = -1;
|
||||||
goto out;
|
goto out;
|
||||||
@ -2920,7 +2920,7 @@ static int apply_one_fragment(struct apply_state *state,
|
|||||||
apply = 0;
|
apply = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apply_verbosely && applied_pos != pos) {
|
if (state->apply_verbosely && applied_pos != pos) {
|
||||||
int offset = applied_pos - pos;
|
int offset = applied_pos - pos;
|
||||||
if (state->apply_in_reverse)
|
if (state->apply_in_reverse)
|
||||||
offset = 0 - offset;
|
offset = 0 - offset;
|
||||||
@ -2942,7 +2942,7 @@ static int apply_one_fragment(struct apply_state *state,
|
|||||||
leading, trailing, applied_pos+1);
|
leading, trailing, applied_pos+1);
|
||||||
update_image(img, applied_pos, &preimage, &postimage);
|
update_image(img, applied_pos, &preimage, &postimage);
|
||||||
} else {
|
} else {
|
||||||
if (apply_verbosely)
|
if (state->apply_verbosely)
|
||||||
error(_("while searching for:\n%.*s"),
|
error(_("while searching for:\n%.*s"),
|
||||||
(int)(old - oldlines), oldlines);
|
(int)(old - oldlines), oldlines);
|
||||||
}
|
}
|
||||||
@ -3856,7 +3856,7 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)
|
|||||||
prepare_symlink_changes(patch);
|
prepare_symlink_changes(patch);
|
||||||
prepare_fn_table(patch);
|
prepare_fn_table(patch);
|
||||||
while (patch) {
|
while (patch) {
|
||||||
if (apply_verbosely)
|
if (state->apply_verbosely)
|
||||||
say_patch_name(stderr,
|
say_patch_name(stderr,
|
||||||
_("Checking patch %s..."), patch);
|
_("Checking patch %s..."), patch);
|
||||||
err |= check_patch(state, patch);
|
err |= check_patch(state, patch);
|
||||||
@ -4287,7 +4287,7 @@ static void write_out_one_result(struct patch *patch, int phase)
|
|||||||
create_file(patch);
|
create_file(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_out_one_reject(struct patch *patch)
|
static int write_out_one_reject(struct apply_state *state, struct patch *patch)
|
||||||
{
|
{
|
||||||
FILE *rej;
|
FILE *rej;
|
||||||
char namebuf[PATH_MAX];
|
char namebuf[PATH_MAX];
|
||||||
@ -4302,7 +4302,7 @@ static int write_out_one_reject(struct patch *patch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!cnt) {
|
if (!cnt) {
|
||||||
if (apply_verbosely)
|
if (state->apply_verbosely)
|
||||||
say_patch_name(stderr,
|
say_patch_name(stderr,
|
||||||
_("Applied patch %s cleanly."), patch);
|
_("Applied patch %s cleanly."), patch);
|
||||||
return 0;
|
return 0;
|
||||||
@ -4358,7 +4358,7 @@ static int write_out_one_reject(struct patch *patch)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_out_results(struct patch *list)
|
static int write_out_results(struct apply_state *state, struct patch *list)
|
||||||
{
|
{
|
||||||
int phase;
|
int phase;
|
||||||
int errs = 0;
|
int errs = 0;
|
||||||
@ -4373,7 +4373,7 @@ static int write_out_results(struct patch *list)
|
|||||||
else {
|
else {
|
||||||
write_out_one_result(l, phase);
|
write_out_one_result(l, phase);
|
||||||
if (phase == 1) {
|
if (phase == 1) {
|
||||||
if (write_out_one_reject(l))
|
if (write_out_one_reject(state, l))
|
||||||
errs = 1;
|
errs = 1;
|
||||||
if (l->conflicted_threeway) {
|
if (l->conflicted_threeway) {
|
||||||
string_list_append(&cpath, l->new_name);
|
string_list_append(&cpath, l->new_name);
|
||||||
@ -4437,7 +4437,7 @@ static int apply_patch(struct apply_state *state,
|
|||||||
listp = &patch->next;
|
listp = &patch->next;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (apply_verbosely)
|
if (state->apply_verbosely)
|
||||||
say_patch_name(stderr, _("Skipped patch '%s'."), patch);
|
say_patch_name(stderr, _("Skipped patch '%s'."), patch);
|
||||||
free_patch(patch);
|
free_patch(patch);
|
||||||
skipped_patch++;
|
skipped_patch++;
|
||||||
@ -4465,7 +4465,7 @@ static int apply_patch(struct apply_state *state,
|
|||||||
!state->apply_with_reject)
|
!state->apply_with_reject)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
if (apply && write_out_results(list)) {
|
if (apply && write_out_results(state, list)) {
|
||||||
if (state->apply_with_reject)
|
if (state->apply_with_reject)
|
||||||
exit(1);
|
exit(1);
|
||||||
/* with --3way, we still need to write the index out */
|
/* 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)
|
|||||||
N_("leave the rejected hunks in corresponding *.rej files")),
|
N_("leave the rejected hunks in corresponding *.rej files")),
|
||||||
OPT_BOOL(0, "allow-overlap", &allow_overlap,
|
OPT_BOOL(0, "allow-overlap", &allow_overlap,
|
||||||
N_("allow overlapping hunks")),
|
N_("allow overlapping hunks")),
|
||||||
OPT__VERBOSE(&apply_verbosely, N_("be verbose")),
|
OPT__VERBOSE(&state.apply_verbosely, N_("be verbose")),
|
||||||
OPT_BIT(0, "inaccurate-eof", &options,
|
OPT_BIT(0, "inaccurate-eof", &options,
|
||||||
N_("tolerate incorrectly detected missing new-line at the end of file"),
|
N_("tolerate incorrectly detected missing new-line at the end of file"),
|
||||||
INACCURATE_EOF),
|
INACCURATE_EOF),
|
||||||
@ -4663,7 +4663,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
|
|||||||
state.check_index = 1;
|
state.check_index = 1;
|
||||||
}
|
}
|
||||||
if (state.apply_with_reject)
|
if (state.apply_with_reject)
|
||||||
apply = apply_verbosely = 1;
|
apply = state.apply_verbosely = 1;
|
||||||
if (!force_apply && (diffstat || numstat || summary || state.check || fake_ancestor))
|
if (!force_apply && (diffstat || numstat || summary || state.check || fake_ancestor))
|
||||||
apply = 0;
|
apply = 0;
|
||||||
if (state.check_index && is_not_gitdir)
|
if (state.check_index && is_not_gitdir)
|
||||||
|
Loading…
Reference in New Issue
Block a user