summaryrefslogtreecommitdiff
path: root/builtin/apply.c
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2016-06-03 18:58:52 +0200
committerJunio C Hamano <gitster@pobox.com>2016-06-03 10:31:56 -0700
commita1bc3dd46433c6e7e6f1ca5f3bd5429858a60078 (patch)
treed6651d92866a8c7c76637735b4d4d87e24ff501d /builtin/apply.c
parent8f31fac365c312aa9109a7a1fc1014e56ed473d2 (diff)
downloadgit-a1bc3dd46433c6e7e6f1ca5f3bd5429858a60078.tar.gz
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>
Diffstat (limited to 'builtin/apply.c')
-rw-r--r--builtin/apply.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/builtin/apply.c b/builtin/apply.c
index cc635ebd1a..7338ee6b68 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -57,6 +57,7 @@ struct apply_state {
* lock_file structures, it isn't safe to free(lock_file).
*/
struct lock_file *lock_file;
+ int newfd;
/* These control what gets looked at and modified */
int apply; /* this is not a dry-run */
@@ -120,8 +121,6 @@ struct apply_state {
int applied_after_fixing_ws;
};
-static int newfd = -1;
-
static const char * const apply_usage[] = {
N_("git apply [<options>] [<patch>...]"),
NULL
@@ -4552,8 +4551,8 @@ static int apply_patch(struct apply_state *state,
state->apply = 0;
state->update_index = state->check_index && state->apply;
- if (state->update_index && newfd < 0)
- newfd = hold_locked_index(state->lock_file, 1);
+ if (state->update_index && state->newfd < 0)
+ state->newfd = hold_locked_index(state->lock_file, 1);
if (state->check_index) {
if (read_cache() < 0)
@@ -4662,6 +4661,7 @@ static void init_apply_state(struct apply_state *state,
state->prefix = prefix;
state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
state->lock_file = lock_file;
+ state->newfd = -1;
state->apply = 1;
state->line_termination = '\n';
state->p_value = 1;
@@ -4782,6 +4782,7 @@ static int apply_all_patches(struct apply_state *state,
if (state->update_index) {
if (write_locked_index(&the_index, state->lock_file, COMMIT_LOCK))
die(_("Unable to write new index file"));
+ state->newfd = -1;
}
return !!errs;