]> git.ipfire.org Git - thirdparty/git.git/commitdiff
apply: remove `newfd` from `struct apply_state`
authorMartin Ågren <martin.agren@gmail.com>
Thu, 5 Oct 2017 20:32:10 +0000 (22:32 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Oct 2017 01:07:18 +0000 (10:07 +0900)
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>
apply.c
apply.h

diff --git a/apply.c b/apply.c
index 5a6ca10a7a946a7eaf913a113b3ad14cc4044ada..d676debd5964b90b2d0ca56bc81e58d8cf6f5b6a 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -79,7 +79,6 @@ int init_apply_state(struct apply_state *state,
 {
        memset(state, 0, sizeof(*state));
        state->prefix = prefix;
-       state->newfd = -1;
        state->apply = 1;
        state->line_termination = '\n';
        state->p_value = 1;
@@ -4705,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) {
@@ -4913,16 +4912,12 @@ int apply_all_patches(struct apply_state *state,
                        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);
diff --git a/apply.h b/apply.h
index cf00cda171cf42cef1164916c973e2e339f41b54..dc4a0190570d060d23e8464f465232eddcf76deb 100644 (file)
--- a/apply.h
+++ b/apply.h
@@ -36,9 +36,8 @@ enum apply_verbosity {
 struct apply_state {
        const char *prefix;
 
-       /* These are lock_file related */
+       /* 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 */