Skip to content

Commit 45184af

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d1bd1d commit 45184af

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

builtin/rebase.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,6 @@ static int run_am(struct rebase_options *opts)
606606
{
607607
struct child_process am = CHILD_PROCESS_INIT;
608608
struct child_process format_patch = CHILD_PROCESS_INIT;
609-
struct strbuf revisions = STRBUF_INIT;
610609
int status;
611610
char *rebased_patches;
612611

@@ -639,13 +638,6 @@ static int run_am(struct rebase_options *opts)
639638
return run_command(&am);
640639
}
641640

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-
649641
rebased_patches = xstrdup(git_path("rebased-patches"));
650642
format_patch.out = open(rebased_patches,
651643
O_WRONLY | O_CREAT | O_TRUNC, 0666);
@@ -666,7 +658,12 @@ static int run_am(struct rebase_options *opts)
666658
if (opts->git_format_patch_opt.len)
667659
strvec_split(&format_patch.args,
668660
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));
670667
if (opts->restrict_revision)
671668
strvec_pushf(&format_patch.args, "^%s",
672669
oid_to_hex(&opts->restrict_revision->object.oid));
@@ -689,10 +686,8 @@ static int run_am(struct rebase_options *opts)
689686
"As a result, git cannot rebase them."),
690687
opts->revisions);
691688

692-
strbuf_release(&revisions);
693689
return status;
694690
}
695-
strbuf_release(&revisions);
696691

697692
am.in = open(rebased_patches, O_RDONLY);
698693
if (am.in < 0) {

0 commit comments

Comments
 (0)