From: Junio C Hamano <gitster@pobox.com>
To: "Øystein Walle" <oystwa@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] rebase: write script before initializing state
Date: Mon, 09 Jun 2025 16:03:13 -0700 [thread overview]
Message-ID: <xmqqa56gplfy.fsf@gitster.g> (raw)
In-Reply-To: <20250609221055.136074-1-oystwa@gmail.com> ("Øystein Walle"'s message of "Tue, 10 Jun 2025 00:10:55 +0200")
Øystein Walle <oystwa@gmail.com> writes:
> ...
> By attempting to write the rebase script before initializing the state
> this potential scenario is avoided.
> ---
Missing sign-off.
> The diff looks perhaps more messy than required. The only required
> change is the filling in of make_script_args and the call to
> sequencer_make_script() above the call to init_basic_state(). But then
> the `if (ret)` looks out of place, and moving that up means adding `goto
> cleanup` which means the code that was previously the else case can be
> dedented.
"git show --histogram" may do a lot better job than the default
algorithm used by "git show" for this patch.
diff --git a/builtin/rebase.c b/builtin/rebase.c
index d4715ed35d..06da8e4f36 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -283,53 +283,53 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
{
int ret = -1;
char *revisions = NULL, *shortrevisions = NULL;
struct strvec make_script_args = STRVEC_INIT;
struct todo_list todo_list = TODO_LIST_INIT;
struct replay_opts replay = get_replay_opts(opts);
if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head->object.oid,
&revisions, &shortrevisions))
goto cleanup;
+ strvec_pushl(&make_script_args, "", revisions, NULL);
+ if (opts->restrict_revision)
+ strvec_pushf(&make_script_args, "^%s",
+ oid_to_hex(&opts->restrict_revision->object.oid));
+
+ ret = sequencer_make_script(the_repository, &todo_list.buf,
+ make_script_args.nr, make_script_args.v,
+ flags);
+ if (ret) {
+ error(_("could not generate todo list"));
+ goto cleanup;
+ }
+
if (init_basic_state(&replay,
opts->head_name ? opts->head_name : "detached HEAD",
opts->onto, &opts->orig_head->object.oid))
goto cleanup;
if (!opts->upstream && opts->squash_onto)
write_file(path_squash_onto(), "%s\n",
oid_to_hex(opts->squash_onto));
- strvec_pushl(&make_script_args, "", revisions, NULL);
- if (opts->restrict_revision)
- strvec_pushf(&make_script_args, "^%s",
- oid_to_hex(&opts->restrict_revision->object.oid));
+ discard_index(the_repository->index);
+ if (todo_list_parse_insn_buffer(the_repository, &replay,
+ todo_list.buf.buf, &todo_list))
+ BUG("unusable todo list");
- ret = sequencer_make_script(the_repository, &todo_list.buf,
- make_script_args.nr, make_script_args.v,
- flags);
-
- if (ret)
- error(_("could not generate todo list"));
- else {
- discard_index(the_repository->index);
- if (todo_list_parse_insn_buffer(the_repository, &replay,
- todo_list.buf.buf, &todo_list))
- BUG("unusable todo list");
-
- ret = complete_action(the_repository, &replay, flags,
- shortrevisions, opts->onto_name, opts->onto,
- &opts->orig_head->object.oid, &opts->exec,
- opts->autosquash, opts->update_refs, &todo_list);
- }
+ ret = complete_action(the_repository, &replay, flags,
+ shortrevisions, opts->onto_name, opts->onto,
+ &opts->orig_head->object.oid, &opts->exec,
+ opts->autosquash, opts->update_refs, &todo_list);
cleanup:
replay_opts_release(&replay);
free(revisions);
free(shortrevisions);
todo_list_release(&todo_list);
strvec_clear(&make_script_args);
return ret;
}
diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh
index fcc40d6fe1..d4c624b841 100755
--- a/t/t3415-rebase-autosquash.sh
+++ b/t/t3415-rebase-autosquash.sh
@@ -394,6 +394,16 @@ test_expect_success 'autosquash with empty custom instructionFormat' '
)
'
+test_expect_success 'autosquash with invalid custom instructionFormat' '
+ git reset --hard base &&
+ test_commit invalid-instructionFormat-test &&
+ (
+ test_must_fail git -c rebase.instructionFormat=blah \
+ rebase --autosquash --force-rebase -i HEAD^ &&
+ test_path_is_missing .git/rebase-merge
+ )
+'
+
set_backup_editor () {
write_script backup-editor.sh <<-\EOF
cp "$1" .git/backup-"$(basename "$1")"
next prev parent reply other threads:[~2025-06-09 23:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 22:10 [PATCH] rebase: write script before initializing state Øystein Walle
2025-06-09 23:03 ` Junio C Hamano [this message]
2025-06-10 10:13 ` Phillip Wood
2025-07-09 0:14 ` Junio C Hamano
2025-07-11 20:36 ` [PATCH v2] " Øystein Walle
2025-07-11 21:25 ` Junio C Hamano
2025-07-24 14:22 ` Phillip Wood
2025-07-23 21:34 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqa56gplfy.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=oystwa@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.