From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] rebase: use strvec_pushf() for format-patch revisions
Date: Tue, 19 Dec 2023 09:12:33 -0800 [thread overview]
Message-ID: <xmqqmsu6ce0u.fsf@gitster.g> (raw)
In-Reply-To: <4ab7431c-6c1b-448c-b4d2-e8b9be0e4eef@web.de> ("René Scharfe"'s message of "Tue, 19 Dec 2023 08:42:18 +0100")
René Scharfe <l.s.r@web.de> writes:
> In run_am(), a strbuf is used to create a revision argument that is then
> added to the argument list for git format-patch using strvec_push().
> Use strvec_pushf() to add it directly instead, simplifying the code.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
Makes sense. Between the location of the original strbuf_addf()
call and the new strvec_pushf() call, nobody mucks with *opts so
this change won't affect the correctness. We no longer use the
extra strbuf, and upon failing to open the rebased-patches file,
we no longer leak the contents of it. Good.
> @@ -615,34 +614,32 @@ static int run_am(struct rebase_options *opts)
> return run_command(&am);
> }
>
> - strbuf_addf(&revisions, "%s...%s",
> - oid_to_hex(opts->root ?
> - /* this is now equivalent to !opts->upstream */
> - &opts->onto->object.oid :
> - &opts->upstream->object.oid),
> - oid_to_hex(&opts->orig_head->object.oid));
> -
> rebased_patches = xstrdup(git_path("rebased-patches"));
> format_patch.out = open(rebased_patches,
> O_WRONLY | O_CREAT | O_TRUNC, 0666);
> if (format_patch.out < 0) {
> status = error_errno(_("could not open '%s' for writing"),
> rebased_patches);
> free(rebased_patches);
> strvec_clear(&am.args);
> return status;
> }
>
> format_patch.git_cmd = 1;
> strvec_pushl(&format_patch.args, "format-patch", "-k", "--stdout",
> "--full-index", "--cherry-pick", "--right-only",
> "--default-prefix", "--no-renames",
> "--no-cover-letter", "--pretty=mboxrd", "--topo-order",
> "--no-base", NULL);
> if (opts->git_format_patch_opt.len)
> strvec_split(&format_patch.args,
> opts->git_format_patch_opt.buf);
> - strvec_push(&format_patch.args, revisions.buf);
> + strvec_pushf(&format_patch.args, "%s...%s",
> + oid_to_hex(opts->root ?
> + /* this is now equivalent to !opts->upstream */
> + &opts->onto->object.oid :
> + &opts->upstream->object.oid),
> + oid_to_hex(&opts->orig_head->object.oid));
> if (opts->restrict_revision)
> strvec_pushf(&format_patch.args, "^%s",
> oid_to_hex(&opts->restrict_revision->object.oid));
> @@ -665,10 +662,8 @@ static int run_am(struct rebase_options *opts)
> "As a result, git cannot rebase them."),
> opts->revisions);
>
> - strbuf_release(&revisions);
> return status;
> }
> - strbuf_release(&revisions);
>
> am.in = open(rebased_patches, O_RDONLY);
> if (am.in < 0) {
> --
> 2.43.0
next prev parent reply other threads:[~2023-12-19 17:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-19 7:42 [PATCH] rebase: use strvec_pushf() for format-patch revisions René Scharfe
2023-12-19 11:07 ` Phillip Wood
2023-12-19 12:25 ` Patrick Steinhardt
2023-12-19 17:12 ` Junio C Hamano [this message]
2023-12-20 8:04 ` René Scharfe
2023-12-20 15:57 ` 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=xmqqmsu6ce0u.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
/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.