diff mbox series

[v2,04/10] am: use run_command_l_opt() for show_patch()

Message ID patch-v2-04.10-5cfd6a94ce3-20221017T170316Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series run-command API: add run_command_{l,sv}_opt() | expand

Commit Message

Ævar Arnfjörð Bjarmason Oct. 17, 2022, 5:49 p.m. UTC
The "git show" invocation added in 66335298a47 (rebase: add
--show-current-patch, 2018-02-11) is one where we're not calling
oid_to_hex() twice. So we can rely on the static buffer that
oid_to_hex() points to, rather than xstrdup()-ing it. As a result we
can use the run_command_l_opt() function.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/am.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/builtin/am.c b/builtin/am.c
index 39fea248330..1d298a91306 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -2186,16 +2186,10 @@  static int show_patch(struct am_state *state, enum show_patch_type sub_mode)
 	const char *patch_path;
 	int len;
 
-	if (!is_null_oid(&state->orig_commit)) {
-		const char *av[4] = { "show", NULL, "--", NULL };
-		char *new_oid_str;
-		int ret;
-
-		av[1] = new_oid_str = xstrdup(oid_to_hex(&state->orig_commit));
-		ret = run_command_v_opt(av, RUN_GIT_CMD);
-		free(new_oid_str);
-		return ret;
-	}
+	if (!is_null_oid(&state->orig_commit))
+		return run_command_l_opt(RUN_GIT_CMD, "show",
+					 oid_to_hex(&state->orig_commit),
+					 "--", NULL);
 
 	switch (sub_mode) {
 	case SHOW_PATCH_RAW: