summaryrefslogtreecommitdiff
path: root/src/cherrypick.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-02-03 21:51:48 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2015-02-14 09:25:35 -0500
commitbe8404a7680fa1951e20abdaea704156b3345876 (patch)
tree2f8dd9b78755df86378a8f5c2e99ff9a287b4992 /src/cherrypick.c
parent8b0ddd5dd90e1d62f32faf14d5cb4bf88f04a095 (diff)
downloadlibgit2-be8404a7680fa1951e20abdaea704156b3345876.tar.gz
merge-like operations: lock index while working
Diffstat (limited to 'src/cherrypick.c')
-rw-r--r--src/cherrypick.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/cherrypick.c b/src/cherrypick.c
index e58d0ab4c..3754b1f77 100644
--- a/src/cherrypick.c
+++ b/src/cherrypick.c
@@ -10,6 +10,7 @@
#include "filebuf.h"
#include "merge.h"
#include "vector.h"
+#include "index.h"
#include "git2/types.h"
#include "git2/merge.h"
@@ -171,7 +172,9 @@ int git_cherrypick(
char commit_oidstr[GIT_OID_HEXSZ + 1];
const char *commit_msg, *commit_summary;
git_buf their_label = GIT_BUF_INIT;
- git_index *index_new = NULL;
+ git_index *index = NULL, *index_new = NULL;
+ git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
+ bool write_index = false;
int error = 0;
assert(repo && commit);
@@ -191,21 +194,38 @@ int git_cherrypick(
if ((error = write_merge_msg(repo, commit_msg)) < 0 ||
(error = git_buf_printf(&their_label, "%.7s... %s", commit_oidstr, commit_summary)) < 0 ||
- (error = cherrypick_normalize_opts(repo, &opts, given_opts, git_buf_cstr(&their_label))) < 0 ||
- (error = write_cherrypick_head(repo, commit_oidstr)) < 0 ||
+ (error = cherrypick_normalize_opts(repo, &opts, given_opts, git_buf_cstr(&their_label))) < 0)
+ goto on_error;
+
+ write_index = (opts.checkout_opts.checkout_strategy & GIT_CHECKOUT_DONT_WRITE_INDEX) == 0;
+
+ if (write_index) {
+ /* Never let checkout update the index, we'll update it ourselves. */
+ opts.checkout_opts.checkout_strategy |= GIT_CHECKOUT_DONT_WRITE_INDEX;
+
+ if ((error = git_repository_index(&index, repo)) < 0 ||
+ (error = git_indexwriter_init(&indexwriter, index)) < 0)
+ goto on_error;
+ }
+
+ if ((error = write_cherrypick_head(repo, commit_oidstr)) < 0 ||
(error = git_repository_head(&our_ref, repo)) < 0 ||
(error = git_reference_peel((git_object **)&our_commit, our_ref, GIT_OBJ_COMMIT)) < 0 ||
(error = git_cherrypick_commit(&index_new, repo, commit, our_commit, opts.mainline, &opts.merge_opts)) < 0 ||
(error = git_merge__check_result(repo, index_new)) < 0 ||
(error = git_merge__append_conflicts_to_merge_msg(repo, index_new)) < 0 ||
- (error = git_checkout_index(repo, index_new, &opts.checkout_opts)) < 0)
+ (error = git_checkout_index(repo, index_new, &opts.checkout_opts)) < 0 ||
+ (write_index && (error = git_indexwriter_commit(&indexwriter)) < 0))
goto on_error;
+
goto done;
on_error:
cherrypick_state_cleanup(repo);
done:
+ git_indexwriter_cleanup(&indexwriter);
+ git_index_free(index);
git_index_free(index_new);
git_commit_free(our_commit);
git_reference_free(our_ref);