diff options
author | René Scharfe <l.s.r@web.de> | 2023-12-19 08:42:18 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-12-20 18:26:58 +0100 |
commit | 45184afb4d4a76a01483e086d9f0cf0af10a7286 (patch) | |
tree | 2612b3b1d5e5994f40188886f6bb48502cc3841d /builtin/rebase.c | |
parent | Git 2.40.1 (diff) | |
download | git-45184afb4d4a76a01483e086d9f0cf0af10a7286.tar.xz git-45184afb4d4a76a01483e086d9f0cf0af10a7286.zip |
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>
Diffstat (limited to '')
-rw-r--r-- | builtin/rebase.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c index 6635f10d52..9110b102df 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -606,7 +606,6 @@ static int run_am(struct rebase_options *opts) { struct child_process am = CHILD_PROCESS_INIT; struct child_process format_patch = CHILD_PROCESS_INIT; - struct strbuf revisions = STRBUF_INIT; int status; char *rebased_patches; @@ -639,13 +638,6 @@ 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); @@ -666,7 +658,12 @@ static int run_am(struct rebase_options *opts) 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)); @@ -689,10 +686,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) { |