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>
Christian Couder committed
Aug 8, 2016 at 23:03 UTC
b6446d54ec70817ddd96b5c9668dd74a996719bf
3 files changed
+33
-32
apply.c
+32
@@ -93,3 +93,35 @@ void clear_apply_state(struct apply_state *state)
93
94
/* &state->fn_table is cleared at the end of apply_patch() */
95
}
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
+1
@@ -106,5 +106,6 @@ extern int init_apply_state(struct apply_state *state,
106
const char *prefix,
107
struct lock_file *lock_file);
108
extern void clear_apply_state(struct apply_state *state);
109
+extern int check_apply_state(struct apply_state *state, int force_apply);
110
111
#endif
builtin/apply.c
-32
@@ -4551,38 +4551,6 @@ static int option_parse_directory(const struct option *opt,
4551
return 0;
4552
}
4553
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
-
4554
static int apply_all_patches(struct apply_state *state,
4555
int argc,
4556
const char **argv,