apply: remove `newfd` from `struct apply_state`
Similar to a previous patch, we do not need to use `newfd` to signal that we have a lockfile to clean up. We can just unconditionally call `rollback_lock_file`. If we do not hold the lock, it will be a no-op. Where we check `newfd` to decide whether we need to take the lock, we can instead use `is_lock_file_locked()`. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin Ågren committed
Oct 5, 2017 at 22:32 UTC
d13cd4c92760d8fe01fb51fbab556a4d1f3713b4
2 files changed
+7
-13
apply.c
+6
-11
@@ -79,7 +79,6 @@ int init_apply_state(struct apply_state *state,
79
{
80
memset(state, 0, sizeof(*state));
81
state->prefix = prefix;
82
- state->newfd = -1;
82
state->apply = 1;
83
state->line_termination = '\n';
84
state->p_value = 1;
@@ -4705,13 +4704,13 @@ static int apply_patch(struct apply_state *state,
4704
state->apply = 0;
4705
4706
state->update_index = state->check_index && state->apply;
4708
- if (state->update_index && state->newfd < 0) {
4707
+ if (state->update_index && !is_lock_file_locked(&state->lock_file)) {
4708
if (state->index_file)
4710
- state->newfd = hold_lock_file_for_update(&state->lock_file,
4711
- state->index_file,
4712
- LOCK_DIE_ON_ERROR);
4709
+ hold_lock_file_for_update(&state->lock_file,
4710
+ state->index_file,
4711
+ LOCK_DIE_ON_ERROR);
4712
else
4714
- state->newfd = hold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR);
4713
+ hold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR);
4714
}
4715
4716
if (state->check_index && read_apply_cache(state) < 0) {
@@ -4913,16 +4912,12 @@ int apply_all_patches(struct apply_state *state,
4912
res = -128;
4913
goto end;
4914
}
4916
- state->newfd = -1;
4915
}
4916
4917
res = !!errs;
4918
4919
end:
4922
- if (state->newfd >= 0) {
4923
- rollback_lock_file(&state->lock_file);
4924
- state->newfd = -1;
4925
- }
4920
+ rollback_lock_file(&state->lock_file);
4921
4922
if (state->apply_verbosity <= verbosity_silent) {
4923
set_error_routine(state->saved_error_routine);
apply.h
+1
-2
@@ -36,9 +36,8 @@ enum apply_verbosity {
36
struct apply_state {
37
const char *prefix;
38
39
- /* These are lock_file related */
39
+ /* Lock file */
40
struct lock_file lock_file;
41
- int newfd;
41
42
/* These control what gets looked at and modified */
43
int apply; /* this is not a dry-run */