summaryrefslogtreecommitdiff
path: root/apply.c
diff options
context:
space:
mode:
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/apply.c b/apply.c
index 71cbbd1..d676deb 100644
--- a/apply.c
+++ b/apply.c
@@ -75,13 +75,10 @@ static int parse_ignorewhitespace_option(struct apply_state *state,
}
int init_apply_state(struct apply_state *state,
- const char *prefix,
- struct lock_file *lock_file)
+ const char *prefix)
{
memset(state, 0, sizeof(*state));
state->prefix = prefix;
- state->lock_file = lock_file;
- state->newfd = -1;
state->apply = 1;
state->line_termination = '\n';
state->p_value = 1;
@@ -146,8 +143,6 @@ int check_apply_state(struct apply_state *state, int force_apply)
}
if (state->check_index)
state->unsafe_paths = 0;
- if (!state->lock_file)
- return error("BUG: state->lock_file should not be NULL");
if (state->apply_verbosity <= verbosity_silent) {
state->saved_error_routine = get_error_routine();
@@ -2920,6 +2915,7 @@ static int apply_one_fragment(struct apply_state *state,
if (plen && (ws_rule & WS_BLANK_AT_EOF) &&
ws_blank_line(patch + 1, plen, ws_rule))
is_blank_context = 1;
+ /* fallthrough */
case '-':
memcpy(old, patch + 1, plen);
add_line_info(&preimage, old, plen,
@@ -2927,7 +2923,7 @@ static int apply_one_fragment(struct apply_state *state,
old += plen;
if (first == '-')
break;
- /* Fall-through for ' ' */
+ /* fallthrough */
case '+':
/* --no-add does not add new lines */
if (first == '+' && state->no_add)
@@ -4708,13 +4704,13 @@ static int apply_patch(struct apply_state *state,
state->apply = 0;
state->update_index = state->check_index && state->apply;
- if (state->update_index && state->newfd < 0) {
+ if (state->update_index && !is_lock_file_locked(&state->lock_file)) {
if (state->index_file)
- state->newfd = hold_lock_file_for_update(state->lock_file,
- state->index_file,
- LOCK_DIE_ON_ERROR);
+ hold_lock_file_for_update(&state->lock_file,
+ state->index_file,
+ LOCK_DIE_ON_ERROR);
else
- state->newfd = hold_locked_index(state->lock_file, LOCK_DIE_ON_ERROR);
+ hold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR);
}
if (state->check_index && read_apply_cache(state) < 0) {
@@ -4910,22 +4906,18 @@ int apply_all_patches(struct apply_state *state,
}
if (state->update_index) {
- res = write_locked_index(&the_index, state->lock_file, COMMIT_LOCK);
+ res = write_locked_index(&the_index, &state->lock_file, COMMIT_LOCK);
if (res) {
error(_("Unable to write new index file"));
res = -128;
goto end;
}
- state->newfd = -1;
}
res = !!errs;
end:
- if (state->newfd >= 0) {
- rollback_lock_file(state->lock_file);
- state->newfd = -1;
- }
+ rollback_lock_file(&state->lock_file);
if (state->apply_verbosity <= verbosity_silent) {
set_error_routine(state->saved_error_routine);