Skip to content

Commit a3152ed

Browse files
phillipwoodgitster
authored andcommitted
sequencer: start removing private fields from public API
"struct replay_opts" has a number of fields that are for internal use. While they are marked as private having them in a public struct is a distraction for callers and means that every time the internal details are changed we have to recompile all the files that include sequencer.h even though the public API is unchanged. This commit starts the process of removing the private fields by adding an opaque pointer to a "struct replay_ctx" to "struct replay_opts" and moving the "reflog_message" member to the new private struct. The sequencer currently updates the state files on disc each time it processes a command in the todo list. This is an artifact of the scripted implementation and makes the code hard to reason about as it is not possible to get a complete view of the state in memory. In the future we will add new members to "struct replay_ctx" to remedy this and avoid writing state to disc unless the sequencer stops for user interaction. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 42aae6a commit a3152ed

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

sequencer.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,24 @@ static GIT_PATH_FUNC(rebase_path_no_reschedule_failed_exec, "rebase-merge/no-res
207207
static GIT_PATH_FUNC(rebase_path_drop_redundant_commits, "rebase-merge/drop_redundant_commits")
208208
static GIT_PATH_FUNC(rebase_path_keep_redundant_commits, "rebase-merge/keep_redundant_commits")
209209

210+
/*
211+
* A 'struct replay_ctx' represents the private state of the sequencer.
212+
*/
213+
struct replay_ctx {
214+
/*
215+
* Stores the reflog message that will be used when creating a
216+
* commit. Points to a static buffer and should not be free()'d.
217+
*/
218+
const char *reflog_message;
219+
};
220+
221+
struct replay_ctx* replay_ctx_new(void)
222+
{
223+
struct replay_ctx *ctx = xcalloc(1, sizeof(*ctx));
224+
225+
return ctx;
226+
}
227+
210228
/**
211229
* A 'struct update_refs_record' represents a value in the update-refs
212230
* list. We use a string_list to map refs to these (before, after) pairs.
@@ -377,6 +395,7 @@ void replay_opts_release(struct replay_opts *opts)
377395
if (opts->revs)
378396
release_revisions(opts->revs);
379397
free(opts->revs);
398+
free(opts->ctx);
380399
}
381400

382401
int sequencer_remove_state(struct replay_opts *opts)
@@ -1054,6 +1073,7 @@ static int run_git_commit(const char *defmsg,
10541073
struct replay_opts *opts,
10551074
unsigned int flags)
10561075
{
1076+
struct replay_ctx *ctx = opts->ctx;
10571077
struct child_process cmd = CHILD_PROCESS_INIT;
10581078

10591079
if ((flags & CLEANUP_MSG) && (flags & VERBATIM_MSG))
@@ -1071,7 +1091,7 @@ static int run_git_commit(const char *defmsg,
10711091
gpg_opt, gpg_opt);
10721092
}
10731093

1074-
strvec_pushf(&cmd.env, GIT_REFLOG_ACTION "=%s", opts->reflog_message);
1094+
strvec_pushf(&cmd.env, GIT_REFLOG_ACTION "=%s", ctx->reflog_message);
10751095

10761096
if (opts->committer_date_is_author_date)
10771097
strvec_pushf(&cmd.env, "GIT_COMMITTER_DATE=%s",
@@ -1457,6 +1477,7 @@ static int try_to_commit(struct repository *r,
14571477
struct replay_opts *opts, unsigned int flags,
14581478
struct object_id *oid)
14591479
{
1480+
struct replay_ctx *ctx = opts->ctx;
14601481
struct object_id tree;
14611482
struct commit *current_head = NULL;
14621483
struct commit_list *parents = NULL;
@@ -1618,7 +1639,7 @@ static int try_to_commit(struct repository *r,
16181639
goto out;
16191640
}
16201641

1621-
if (update_head_with_reflog(current_head, oid, opts->reflog_message,
1642+
if (update_head_with_reflog(current_head, oid, ctx->reflog_message,
16221643
msg, &err)) {
16231644
res = error("%s", err.buf);
16241645
goto out;
@@ -4725,11 +4746,12 @@ static int pick_one_commit(struct repository *r,
47254746
struct replay_opts *opts,
47264747
int *check_todo, int* reschedule)
47274748
{
4749+
struct replay_ctx *ctx = opts->ctx;
47284750
int res;
47294751
struct todo_item *item = todo_list->items + todo_list->current;
47304752
const char *arg = todo_item_get_arg(todo_list, item);
47314753
if (is_rebase_i(opts))
4732-
opts->reflog_message = reflog_message(
4754+
ctx->reflog_message = reflog_message(
47334755
opts, command_to_string(item->command), NULL);
47344756

47354757
res = do_pick_commit(r, item, opts, is_final_fixup(todo_list),
@@ -4786,9 +4808,10 @@ static int pick_commits(struct repository *r,
47864808
struct todo_list *todo_list,
47874809
struct replay_opts *opts)
47884810
{
4811+
struct replay_ctx *ctx = opts->ctx;
47894812
int res = 0, reschedule = 0;
47904813

4791-
opts->reflog_message = sequencer_reflog_action(opts);
4814+
ctx->reflog_message = sequencer_reflog_action(opts);
47924815
if (opts->allow_ff)
47934816
assert(!(opts->signoff || opts->no_commit ||
47944817
opts->record_origin || should_edit(opts) ||
@@ -5205,6 +5228,7 @@ static int commit_staged_changes(struct repository *r,
52055228

52065229
int sequencer_continue(struct repository *r, struct replay_opts *opts)
52075230
{
5231+
struct replay_ctx *ctx = opts->ctx;
52085232
struct todo_list todo_list = TODO_LIST_INIT;
52095233
int res;
52105234

@@ -5224,7 +5248,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
52245248
unlink(rebase_path_dropped());
52255249
}
52265250

5227-
opts->reflog_message = reflog_message(opts, "continue", NULL);
5251+
ctx->reflog_message = reflog_message(opts, "continue", NULL);
52285252
if (commit_staged_changes(r, opts, &todo_list)) {
52295253
res = -1;
52305254
goto release_todo_list;
@@ -5276,7 +5300,7 @@ static int single_pick(struct repository *r,
52765300
TODO_PICK : TODO_REVERT;
52775301
item.commit = cmit;
52785302

5279-
opts->reflog_message = sequencer_reflog_action(opts);
5303+
opts->ctx->reflog_message = sequencer_reflog_action(opts);
52805304
return do_pick_commit(r, &item, opts, 0, &check_todo);
52815305
}
52825306

sequencer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ enum commit_msg_cleanup_mode {
2929
COMMIT_MSG_CLEANUP_ALL
3030
};
3131

32+
struct replay_ctx;
33+
struct replay_ctx* replay_ctx_new(void);
34+
3235
struct replay_opts {
3336
enum replay_action action;
3437

@@ -78,13 +81,14 @@ struct replay_opts {
7881
struct rev_info *revs;
7982

8083
/* Private use */
81-
const char *reflog_message;
84+
struct replay_ctx *ctx;
8285
};
8386
#define REPLAY_OPTS_INIT { \
8487
.edit = -1, \
8588
.action = -1, \
8689
.current_fixups = STRBUF_INIT, \
8790
.xopts = STRVEC_INIT, \
91+
.ctx = replay_ctx_new(), \
8892
}
8993

9094
/*

0 commit comments

Comments
 (0)