builtin/apply: move 'newfd' global into 'struct apply_state'

To libify the apply functionality the 'newfd' variable should not be static and global to the file. Let's move it into 'struct apply_state'. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Jun 3, 2016 at 18:58 UTC a1bc3dd46433c6e7e6f1ca5f3bd5429858a60078
1 file changed +5 -4
builtin/apply.c
+5 -4
@@ -57,6 +57,7 @@ struct apply_state {
57 * lock_file structures, it isn't safe to free(lock_file).
58 */
59 struct lock_file *lock_file;
60 + int newfd;
61
62 /* These control what gets looked at and modified */
63 int apply; /* this is not a dry-run */
@@ -120,8 +121,6 @@ struct apply_state {
121 int applied_after_fixing_ws;
122 };
123
123 -static int newfd = -1;
124 -
124 static const char * const apply_usage[] = {
125 N_("git apply [<options>] [<patch>...]"),
126 NULL
@@ -4552,8 +4551,8 @@ static int apply_patch(struct apply_state *state,
4551 state->apply = 0;
4552
4553 state->update_index = state->check_index && state->apply;
4555 - if (state->update_index && newfd < 0)
4556 - newfd = hold_locked_index(state->lock_file, 1);
4554 + if (state->update_index && state->newfd < 0)
4555 + state->newfd = hold_locked_index(state->lock_file, 1);
4556
4557 if (state->check_index) {
4558 if (read_cache() < 0)
@@ -4662,6 +4661,7 @@ static void init_apply_state(struct apply_state *state,
4661 state->prefix = prefix;
4662 state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
4663 state->lock_file = lock_file;
4664 + state->newfd = -1;
4665 state->apply = 1;
4666 state->line_termination = '\n';
4667 state->p_value = 1;
@@ -4782,6 +4782,7 @@ static int apply_all_patches(struct apply_state *state,
4782 if (state->update_index) {
4783 if (write_locked_index(&the_index, state->lock_file, COMMIT_LOCK))
4784 die(_("Unable to write new index file"));
4785 + state->newfd = -1;
4786 }
4787
4788 return !!errs;