diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2015-02-03 21:51:48 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-02-14 09:25:35 -0500 |
| commit | be8404a7680fa1951e20abdaea704156b3345876 (patch) | |
| tree | 2f8dd9b78755df86378a8f5c2e99ff9a287b4992 /src/rebase.c | |
| parent | 8b0ddd5dd90e1d62f32faf14d5cb4bf88f04a095 (diff) | |
| download | libgit2-be8404a7680fa1951e20abdaea704156b3345876.tar.gz | |
merge-like operations: lock index while working
Diffstat (limited to 'src/rebase.c')
| -rw-r--r-- | src/rebase.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/rebase.c b/src/rebase.c index 2e805929e..9e6c4c1d7 100644 --- a/src/rebase.c +++ b/src/rebase.c @@ -14,6 +14,7 @@ #include "array.h" #include "config.h" #include "annotated_commit.h" +#include "index.h" #include <git2/types.h> #include <git2/annotated_commit.h> @@ -725,7 +726,9 @@ static int rebase_next_merge( git_checkout_options checkout_opts = {0}; git_commit *current_commit = NULL, *parent_commit = NULL; git_tree *current_tree = NULL, *head_tree = NULL, *parent_tree = NULL; - git_index *index = NULL; + git_index *index = NULL, *index_new = NULL; + git_indexwriter indexwriter = GIT_INDEXWRITER_INIT; + bool write_index = false; git_rebase_operation *operation; char current_idstr[GIT_OID_HEXSZ]; unsigned int parent_count; @@ -755,6 +758,17 @@ static int rebase_next_merge( git_oid_fmt(current_idstr, &operation->id); + write_index = (checkout_opts.checkout_strategy & GIT_CHECKOUT_DONT_WRITE_INDEX) == 0; + + if (write_index) { + /* Never let checkout update the index, we'll update it ourselves. */ + checkout_opts.checkout_strategy |= GIT_CHECKOUT_DONT_WRITE_INDEX; + + if ((error = git_repository_index(&index, rebase->repo)) < 0 || + (error = git_indexwriter_init(&indexwriter, index)) < 0) + goto done; + } + if ((error = rebase_setupfile(rebase, MSGNUM_FILE, -1, "%d\n", rebase->current+1)) < 0 || (error = rebase_setupfile(rebase, CURRENT_FILE, -1, "%.*s\n", GIT_OID_HEXSZ, current_idstr)) < 0) goto done; @@ -762,14 +776,17 @@ static int rebase_next_merge( normalize_checkout_opts(rebase, current_commit, &checkout_opts, given_checkout_opts); if ((error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, NULL)) < 0 || - (error = git_merge__check_result(rebase->repo, index)) < 0 || - (error = git_checkout_index(rebase->repo, index, &checkout_opts)) < 0) + (error = git_merge__check_result(rebase->repo, index_new)) < 0 || + (error = git_checkout_index(rebase->repo, index_new, &checkout_opts)) < 0 || + (write_index && (error = git_indexwriter_commit(&indexwriter)) < 0)) goto done; *out = operation; done: + git_indexwriter_cleanup(&indexwriter); git_index_free(index); + git_index_free(index_new); git_tree_free(current_tree); git_tree_free(head_tree); git_tree_free(parent_tree); |
