Skip to content

Commit 39bc514

Browse files
committed
rebase: always use git_commit_create_with_signature
This simplifies the flow of rebase_commit__create because it doesn't have to juggle 2 different commit flows (one with signature and one without).
1 parent 7594710 commit 39bc514

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

src/rebase.c

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,8 @@ static int rebase_commit__create(
947947
git_oid tree_id, commit_id;
948948
git_buf commit_content = GIT_BUF_INIT, commit_signature = GIT_BUF_INIT,
949949
signature_field = GIT_BUF_INIT;
950-
const char *signature_field_as_string = NULL;
950+
const char *signature_field_string = NULL,
951+
*commit_signature_string = NULL;
951952
int error;
952953

953954
operation = git_array_get(rebase->operations, rebase->current);
@@ -978,42 +979,37 @@ static int rebase_commit__create(
978979
message = git_commit_message(current_commit);
979980
}
980981

981-
/* this error will be cleared by the signing process, but should be set
982-
* to signal the unsigned commit create process if we are not going to sign */
983-
error = GIT_PASSTHROUGH;
982+
if ((error = git_commit_create_buffer(&commit_content, rebase->repo, author, committer,
983+
message_encoding, message, tree, 1, (const git_commit **)&parent_commit)) < 0)
984+
goto done;
985+
984986
if (rebase->options.signing_cb) {
985-
if ((error = git_commit_create_buffer(&commit_content, rebase->repo, author, committer,
986-
message_encoding, message, tree, 1, (const git_commit **)&parent_commit)) < 0)
987+
git_error_clear();
988+
error = git_error_set_after_callback_function(rebase->options.signing_cb(
989+
&commit_signature, &signature_field, git_buf_cstr(&commit_content),
990+
rebase->options.payload), "commit signing_cb failed");
991+
if (error == GIT_PASSTHROUGH) {
992+
git_buf_dispose(&commit_signature);
993+
git_buf_dispose(&signature_field);
994+
git_error_clear();
995+
error = GIT_OK;
996+
} else if (error < 0)
987997
goto done;
998+
}
988999

989-
git_error_clear();
990-
error = git_error_set_after_callback_function(rebase->options.signing_cb(
991-
&commit_signature, &signature_field, git_buf_cstr(&commit_content),
992-
rebase->options.payload), "commit signing_cb failed");
993-
if (error == GIT_PASSTHROUGH)
994-
git_error_clear();
995-
else if (error < 0)
996-
goto done;
997-
998-
if (error != GIT_PASSTHROUGH) {
999-
if (git_buf_is_allocated(&signature_field)) {
1000-
assert(git_buf_contains_nul(&signature_field));
1001-
signature_field_as_string = git_buf_cstr(&signature_field);
1002-
}
1003-
1004-
assert(git_buf_is_allocated(&commit_signature));
1005-
assert(git_buf_contains_nul(&commit_signature));
1006-
if ((error = git_commit_create_with_signature(&commit_id, rebase->repo,
1007-
git_buf_cstr(&commit_content), git_buf_cstr(&commit_signature),
1008-
signature_field_as_string)))
1009-
goto done;
1010-
}
1000+
if (git_buf_is_allocated(&commit_signature)) {
1001+
assert(git_buf_contains_nul(&commit_signature));
1002+
commit_signature_string = git_buf_cstr(&commit_signature);
10111003
}
10121004

1013-
/* if we skipped signing, create the commit normally */
1014-
if (error == GIT_PASSTHROUGH &&
1015-
(error = git_commit_create(&commit_id, rebase->repo, NULL, author, committer,
1016-
message_encoding, message, tree, 1, (const git_commit **)&parent_commit)) < 0)
1005+
if (git_buf_is_allocated(&signature_field)) {
1006+
assert(git_buf_contains_nul(&signature_field));
1007+
signature_field_string = git_buf_cstr(&signature_field);
1008+
}
1009+
1010+
if ((error = git_commit_create_with_signature(&commit_id, rebase->repo,
1011+
git_buf_cstr(&commit_content), commit_signature_string,
1012+
signature_field_string)))
10171013
goto done;
10181014

10191015
if ((error = git_commit_lookup(&commit, rebase->repo, &commit_id)) < 0)

0 commit comments

Comments
 (0)