replay: allow callers to sign commits

Add a signing-key option to replay_revisions_options and pass it to
commit_tree_extended() when creating replayed commits.

This provides the replay infrastructure for history commands to sign
replayed descendants.

Signed-off-by: Souma <git@5ouma.me>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
seen
Souma 2026-10-03 22:40:57 +09:00 committed by Junio C Hamano
parent c46c1e3772
commit 60a86bfc98
2 changed files with 14 additions and 5 deletions

View File

@ -85,13 +85,13 @@ static struct commit *create_commit(struct repository *repo,
struct tree *tree,
struct commit *based_on,
struct commit *parent,
enum replay_mode mode)
enum replay_mode mode,
const char *sign_commit)
{
struct object_id ret;
struct object *obj = NULL;
struct commit_list *parents = NULL;
char *author = NULL;
char *sign_commit = NULL; /* FIXME: cli users might want to sign again */
struct commit_extra_header *extra = NULL;
struct strbuf msg = STRBUF_INIT;
const char *out_enc = get_commit_output_encoding();
@ -288,7 +288,8 @@ static struct commit *pick_regular_commit(struct repository *repo,
struct merge_options *merge_opt,
struct merge_result *result,
enum replay_mode mode,
enum replay_empty_commit_action empty)
enum replay_empty_commit_action empty,
const char *sign_commit)
{
struct tree *pickme_tree, *base_tree, *replayed_base_tree;

@ -361,7 +362,8 @@ static struct commit *pick_regular_commit(struct repository *repo,
}
}

return create_commit(repo, result->tree, pickme, replayed_base, mode);
return create_commit(repo, result->tree, pickme, replayed_base, mode,
sign_commit);
}

void replay_result_release(struct replay_result *result)
@ -481,7 +483,8 @@ int replay_revisions(struct rev_info *revs,

last_commit = pick_regular_commit(revs->repo, commit, base,
&merge_opt, &result,
mode, opts->empty);
mode, opts->empty,
opts->sign_commit);
}

if (!last_commit)

View File

@ -57,6 +57,12 @@ struct replay_revisions_options {
*/
int contained;

/*
* Key used to sign newly-created commits. An empty string requests the
* default configured signing key, and NULL disables signing.
*/
const char *sign_commit;

/*
* Controls what to do when a replayed commit becomes empty.
* Defaults to REPLAY_EMPTY_COMMIT_DROP.