diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2015-02-03 22:31:10 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-02-14 09:25:36 -0500 |
| commit | 41fae48df21c7d1140da539cb61fa3fd0598a3e7 (patch) | |
| tree | 0a022196f9c01f9036f24a4b6abb2f2dfb299828 /src/rebase.c | |
| parent | be8404a7680fa1951e20abdaea704156b3345876 (diff) | |
| download | libgit2-41fae48df21c7d1140da539cb61fa3fd0598a3e7.tar.gz | |
indexwriter: an indexwriter for repo operations
Provide git_indexwriter_init_for_operation for the common locking
pattern in merge, rebase, revert and cherry-pick.
Diffstat (limited to 'src/rebase.c')
| -rw-r--r-- | src/rebase.c | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/src/rebase.c b/src/rebase.c index 9e6c4c1d7..b24830bd9 100644 --- a/src/rebase.c +++ b/src/rebase.c @@ -726,9 +726,8 @@ 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, *index_new = NULL; + git_index *index = 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; @@ -758,27 +757,15 @@ 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; - 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_new)) < 0 || - (error = git_checkout_index(rebase->repo, index_new, &checkout_opts)) < 0 || - (write_index && (error = git_indexwriter_commit(&indexwriter)) < 0)) + if ((error = git_indexwriter_init_for_operation(&indexwriter, rebase->repo, &checkout_opts.checkout_strategy)) < 0 || + (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 || + (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_indexwriter_commit(&indexwriter)) < 0) goto done; *out = operation; @@ -786,7 +773,6 @@ static int rebase_next_merge( 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); |
