const char *prefix;
int prefix_length;
+ /*
+ * Since lockfile.c keeps a linked list of all created
+ * lock_file structures, it isn't safe to free(lock_file).
+ */
+ struct lock_file *lock_file;
+
/* These control what gets looked at and modified */
int apply; /* this is not a dry-run */
int cached; /* apply to the index only */
state->update_index = state->check_index && state->apply;
if (state->update_index && newfd < 0)
- newfd = hold_locked_index(&lock_file, 1);
+ newfd = hold_locked_index(state->lock_file, 1);
if (state->check_index) {
if (read_cache() < 0)
return 0;
}
-static void init_apply_state(struct apply_state *state, const char *prefix)
+static void init_apply_state(struct apply_state *state,
+ const char *prefix,
+ struct lock_file *lock_file)
{
memset(state, 0, sizeof(*state));
state->prefix = prefix;
state->prefix_length = state->prefix ? strlen(state->prefix) : 0;
+ state->lock_file = lock_file;
state->apply = 1;
state->line_termination = '\n';
state->p_value = 1;
}
if (state->check_index)
state->unsafe_paths = 0;
+ if (!state->lock_file)
+ die("BUG: state->lock_file should not be NULL");
}
static int apply_all_patches(struct apply_state *state,
}
if (state->update_index) {
- if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
+ if (write_locked_index(&the_index, state->lock_file, COMMIT_LOCK))
die(_("Unable to write new index file"));
}
OPT_END()
};
- init_apply_state(&state, prefix);
+ init_apply_state(&state, prefix, &lock_file);
argc = parse_options(argc, argv, state.prefix, builtin_apply_options,
apply_usage, 0);