rebase: stop reading and writing unnecessary strategy state

The state files for "--strategy" and "--strategy-option" are written and read twice, once by builtin/rebase.c and then by sequencer.c. This is an artifact of the scripted rebase and the need to support "rebase --preserve-merges". Now that "--preserve-merges" no-longer exists we only need to read and write these files in sequencer.c. This enables us to remove a call to free() in read_strategy_opts() that was added by f1f4ebf432 (sequencer.c: fix "opts->strategy" leak in read_strategy_opts(), 2022-11-08) as this commit fixes the root cause of that leak. There is further scope for removing duplication in the reading and writing of state files between builtin/rebase.c and sequencer.c but that is left for a follow up series. Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Apr 10, 2023 at 10:08 UTC 461434a013c2289fb59070e1a118d39441828847
2 files changed -25
builtin/rebase.c
-24
@@ -483,24 +483,6 @@ static int read_basic_state(struct rebase_options *opts)
483 opts->gpg_sign_opt = xstrdup(buf.buf);
484 }
485
486 - if (file_exists(state_dir_path("strategy", opts))) {
487 - strbuf_reset(&buf);
488 - if (!read_oneliner(&buf, state_dir_path("strategy", opts),
489 - READ_ONELINER_WARN_MISSING))
490 - return -1;
491 - free(opts->strategy);
492 - opts->strategy = xstrdup(buf.buf);
493 - }
494 -
495 - if (file_exists(state_dir_path("strategy_opts", opts))) {
496 - strbuf_reset(&buf);
497 - if (!read_oneliner(&buf, state_dir_path("strategy_opts", opts),
498 - READ_ONELINER_WARN_MISSING))
499 - return -1;
500 - free(opts->strategy_opts);
501 - opts->strategy_opts = xstrdup(buf.buf);
502 - }
503 -
486 strbuf_release(&buf);
487
488 return 0;
@@ -518,12 +500,6 @@ static int rebase_write_basic_state(struct rebase_options *opts)
500 write_file(state_dir_path("quiet", opts), "%s", "");
501 if (opts->flags & REBASE_VERBOSE)
502 write_file(state_dir_path("verbose", opts), "%s", "");
521 - if (opts->strategy)
522 - write_file(state_dir_path("strategy", opts), "%s",
523 - opts->strategy);
524 - if (opts->strategy_opts)
525 - write_file(state_dir_path("strategy_opts", opts), "%s",
526 - opts->strategy_opts);
503 if (opts->allow_rerere_autoupdate > 0)
504 write_file(state_dir_path("allow_rerere_autoupdate", opts),
505 "-%s-rerere-autoupdate",
sequencer.c
-1
@@ -2944,7 +2944,6 @@ static void read_strategy_opts(struct replay_opts *opts, struct strbuf *buf)
2944 strbuf_reset(buf);
2945 if (!read_oneliner(buf, rebase_path_strategy(), 0))
2946 return;
2947 - free(opts->strategy);
2947 opts->strategy = strbuf_detach(buf, NULL);
2948 if (!read_oneliner(buf, rebase_path_strategy_opts(), 0))
2949 return;