Skip to content

Commit a1bc3dd

Browse files
chriscoolgitster
authored andcommitted
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>
1 parent 8f31fac commit a1bc3dd

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

builtin/apply.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct apply_state {
5757
* lock_file structures, it isn't safe to free(lock_file).
5858
*/
5959
struct lock_file *lock_file;
60+
int newfd;
6061

6162
/* These control what gets looked at and modified */
6263
int apply; /* this is not a dry-run */
@@ -120,8 +121,6 @@ struct apply_state {
120121
int applied_after_fixing_ws;
121122
};
122123

123-
static int newfd = -1;
124-
125124
static const char * const apply_usage[] = {
126125
N_("git apply [<options>] [<patch>...]"),
127126
NULL
@@ -4552,8 +4551,8 @@ static int apply_patch(struct apply_state *state,
45524551
state->apply = 0;
45534552

45544553
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);
45574556

45584557
if (state->check_index) {
45594558
if (read_cache() < 0)
@@ -4662,6 +4661,7 @@ static void init_apply_state(struct apply_state *state,
46624661
state->prefix = prefix;
46634662
state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
46644663
state->lock_file = lock_file;
4664+
state->newfd = -1;
46654665
state->apply = 1;
46664666
state->line_termination = '\n';
46674667
state->p_value = 1;
@@ -4782,6 +4782,7 @@ static int apply_all_patches(struct apply_state *state,
47824782
if (state->update_index) {
47834783
if (write_locked_index(&the_index, state->lock_file, COMMIT_LOCK))
47844784
die(_("Unable to write new index file"));
4785+
state->newfd = -1;
47854786
}
47864787

47874788
return !!errs;

0 commit comments

Comments
 (0)