From: "Martin Ågren" <martin.agren@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: [PATCH v2 4/5] merge: always roll back lock in `checkout_fast_forward()`
Date: Wed, 28 Feb 2018 20:07:57 +0100 [thread overview]
Message-ID: <45540e492e4b6498254f61601779076ff6d21d1d.1519843916.git.martin.agren@gmail.com> (raw)
In-Reply-To: <cover.1519843916.git.martin.agren@gmail.com>
This function originated in builtin/merge.c. It was moved to merge.c in
commit db699a8a1f (Move try_merge_command and checkout_fast_forward to
libgit.a, 2012-10-26), but was used from sequencer.c even before that.
If a problem occurs, the function returns without rolling back the
lockfile. Teach it to do so.
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
merge.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/merge.c b/merge.c
index 195b578700..f06a4773d4 100644
--- a/merge.c
+++ b/merge.c
@@ -113,17 +113,23 @@ int checkout_fast_forward(const struct object_id *head,
setup_unpack_trees_porcelain(&opts, "merge");
trees[nr_trees] = parse_tree_indirect(head);
- if (!trees[nr_trees++])
+ if (!trees[nr_trees++]) {
+ rollback_lock_file(&lock_file);
return -1;
+ }
trees[nr_trees] = parse_tree_indirect(remote);
- if (!trees[nr_trees++])
+ if (!trees[nr_trees++]) {
+ rollback_lock_file(&lock_file);
return -1;
+ }
for (i = 0; i < nr_trees; i++) {
parse_tree(trees[i]);
init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
}
- if (unpack_trees(nr_trees, t, &opts))
+ if (unpack_trees(nr_trees, t, &opts)) {
+ rollback_lock_file(&lock_file);
return -1;
+ }
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
return error(_("unable to write new index file"));
return 0;
--
2.16.2.246.ga4ee44448f
next prev parent reply other threads:[~2018-02-28 19:08 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-27 21:30 [PATCH 0/5] roll back locks in various code paths Martin Ågren
2018-02-27 21:30 ` [PATCH 1/5] sequencer: make lockfiles non-static Martin Ågren
2018-02-27 21:30 ` [PATCH 2/5] sequencer: always roll back lock in `do_recursive_merge()` Martin Ågren
2018-02-27 21:44 ` Jeff King
2018-02-27 22:08 ` Martin Ågren
2018-02-27 22:15 ` Jeff King
2018-02-27 21:30 ` [PATCH 3/5] merge-recursive: always roll back lock in `merge_recursive_generic()` Martin Ågren
2018-02-28 11:02 ` Martin Ågren
2018-02-28 19:07 ` [PATCH v2 0/5] roll back locks in various code paths Martin Ågren
2018-02-28 19:07 ` [PATCH v2 1/5] sequencer: make lockfiles non-static Martin Ågren
2018-02-28 19:07 ` [PATCH v2 2/5] sequencer: always roll back lock in `do_recursive_merge()` Martin Ågren
2018-02-28 19:07 ` [PATCH v2 3/5] merge-recursive: always roll back lock in `merge_recursive_generic()` Martin Ågren
2018-02-28 19:07 ` Martin Ågren [this message]
2018-02-28 19:07 ` [PATCH v2 5/5] sequencer: do not roll back lockfile unnecessarily Martin Ågren
2018-02-28 19:58 ` [PATCH v2 0/5] roll back locks in various code paths Martin Ågren
2018-02-28 23:20 ` Junio C Hamano
2018-03-01 6:18 ` Martin Ågren
2018-03-01 7:41 ` Jeff King
2018-03-01 19:24 ` Junio C Hamano
2018-03-01 20:40 ` Martin Ågren
2018-03-02 10:49 ` Jeff King
2018-03-01 7:38 ` Jeff King
2018-02-27 21:30 ` [PATCH 4/5] merge: always roll back lock in `checkout_fast_forward()` Martin Ågren
2018-02-27 21:30 ` [PATCH 5/5] sequencer: do not roll back lockfile unnecessarily Martin Ågren
2018-02-27 21:47 ` [PATCH 0/5] roll back locks in various code paths Jeff King
2018-02-27 23:42 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45540e492e4b6498254f61601779076ff6d21d1d.1519843916.git.martin.agren@gmail.com \
--to=martin.agren@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).