rebase: use strvec_pushf() for format-patch revisions

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 and plugging a small leak on the error code path. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Dec 19, 2023 at 08:42 UTC 45184afb4d4a76a01483e086d9f0cf0af10a7286
1 file changed +6 -11
builtin/rebase.c
+6 -11
@@ -606,7 +606,6 @@ static int run_am(struct rebase_options *opts)
606 {
607 struct child_process am = CHILD_PROCESS_INIT;
608 struct child_process format_patch = CHILD_PROCESS_INIT;
609 - struct strbuf revisions = STRBUF_INIT;
609 int status;
610 char *rebased_patches;
611
@@ -639,13 +638,6 @@ static int run_am(struct rebase_options *opts)
638 return run_command(&am);
639 }
640
642 - strbuf_addf(&revisions, "%s...%s",
643 - oid_to_hex(opts->root ?
644 - /* this is now equivalent to !opts->upstream */
645 - &opts->onto->object.oid :
646 - &opts->upstream->object.oid),
647 - oid_to_hex(&opts->orig_head->object.oid));
648 -
641 rebased_patches = xstrdup(git_path("rebased-patches"));
642 format_patch.out = open(rebased_patches,
643 O_WRONLY | O_CREAT | O_TRUNC, 0666);
@@ -666,7 +658,12 @@ static int run_am(struct rebase_options *opts)
658 if (opts->git_format_patch_opt.len)
659 strvec_split(&format_patch.args,
660 opts->git_format_patch_opt.buf);
669 - strvec_push(&format_patch.args, revisions.buf);
661 + strvec_pushf(&format_patch.args, "%s...%s",
662 + oid_to_hex(opts->root ?
663 + /* this is now equivalent to !opts->upstream */
664 + &opts->onto->object.oid :
665 + &opts->upstream->object.oid),
666 + oid_to_hex(&opts->orig_head->object.oid));
667 if (opts->restrict_revision)
668 strvec_pushf(&format_patch.args, "^%s",
669 oid_to_hex(&opts->restrict_revision->object.oid));
@@ -689,10 +686,8 @@ static int run_am(struct rebase_options *opts)
686 "As a result, git cannot rebase them."),
687 opts->revisions);
688
692 - strbuf_release(&revisions);
689 return status;
690 }
695 - strbuf_release(&revisions);
691
692 am.in = open(rebased_patches, O_RDONLY);
693 if (am.in < 0) {