Skip to content

Commit b6446d5

Browse files
chriscoolgitster
authored andcommitted
builtin/apply: move check_apply_state() to apply.c
To libify `git apply` functionality we must make check_apply_state() usable outside "builtin/apply.c". Let's do that by moving it into "apply.c". Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f36538d commit b6446d5

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

apply.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,35 @@ void clear_apply_state(struct apply_state *state)
9393

9494
/* &state->fn_table is cleared at the end of apply_patch() */
9595
}
96+
97+
int check_apply_state(struct apply_state *state, int force_apply)
98+
{
99+
int is_not_gitdir = !startup_info->have_repository;
100+
101+
if (state->apply_with_reject && state->threeway)
102+
return error("--reject and --3way cannot be used together.");
103+
if (state->cached && state->threeway)
104+
return error("--cached and --3way cannot be used together.");
105+
if (state->threeway) {
106+
if (is_not_gitdir)
107+
return error(_("--3way outside a repository"));
108+
state->check_index = 1;
109+
}
110+
if (state->apply_with_reject)
111+
state->apply = state->apply_verbosely = 1;
112+
if (!force_apply && (state->diffstat || state->numstat || state->summary || state->check || state->fake_ancestor))
113+
state->apply = 0;
114+
if (state->check_index && is_not_gitdir)
115+
return error(_("--index outside a repository"));
116+
if (state->cached) {
117+
if (is_not_gitdir)
118+
return error(_("--cached outside a repository"));
119+
state->check_index = 1;
120+
}
121+
if (state->check_index)
122+
state->unsafe_paths = 0;
123+
if (!state->lock_file)
124+
return error("BUG: state->lock_file should not be NULL");
125+
126+
return 0;
127+
}

apply.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@ extern int init_apply_state(struct apply_state *state,
106106
const char *prefix,
107107
struct lock_file *lock_file);
108108
extern void clear_apply_state(struct apply_state *state);
109+
extern int check_apply_state(struct apply_state *state, int force_apply);
109110

110111
#endif

builtin/apply.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4551,38 +4551,6 @@ static int option_parse_directory(const struct option *opt,
45514551
return 0;
45524552
}
45534553

4554-
static int check_apply_state(struct apply_state *state, int force_apply)
4555-
{
4556-
int is_not_gitdir = !startup_info->have_repository;
4557-
4558-
if (state->apply_with_reject && state->threeway)
4559-
return error("--reject and --3way cannot be used together.");
4560-
if (state->cached && state->threeway)
4561-
return error("--cached and --3way cannot be used together.");
4562-
if (state->threeway) {
4563-
if (is_not_gitdir)
4564-
return error(_("--3way outside a repository"));
4565-
state->check_index = 1;
4566-
}
4567-
if (state->apply_with_reject)
4568-
state->apply = state->apply_verbosely = 1;
4569-
if (!force_apply && (state->diffstat || state->numstat || state->summary || state->check || state->fake_ancestor))
4570-
state->apply = 0;
4571-
if (state->check_index && is_not_gitdir)
4572-
return error(_("--index outside a repository"));
4573-
if (state->cached) {
4574-
if (is_not_gitdir)
4575-
return error(_("--cached outside a repository"));
4576-
state->check_index = 1;
4577-
}
4578-
if (state->check_index)
4579-
state->unsafe_paths = 0;
4580-
if (!state->lock_file)
4581-
return error("BUG: state->lock_file should not be NULL");
4582-
4583-
return 0;
4584-
}
4585-
45864554
static int apply_all_patches(struct apply_state *state,
45874555
int argc,
45884556
const char **argv,

0 commit comments

Comments
 (0)