git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/6] editor: use run_command's shell feature

From
Jeff King <peff@peff.net>
Date
Dec 30, 2009, 10:56 UTC
Message-ID
<20091230105616.GD22959@coredump.intra.peff.net>
In-Reply-To
<20091230095634.GA16349@coredump.intra.peff.net>

Now that run_command implements the same code in a more general form, we can make use of it.

Signed-off-by: Jeff King <peff@peff.net>
---
Should also be non-controversial, and the diffstat shows that this is
the payoff for all of the added code earlier in the series. :)
 editor.c |   21 ++-------------------
 1 files changed, 2 insertions(+), 19 deletions(-)
diff --git a/editor.c b/editor.c
index 615f575..d834003 100644
--- a/editor.c
+++ b/editor.c
@@ -36,26 +36,9 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
 		return error("Terminal is dumb, but EDITOR unset");
 
 	if (strcmp(editor, ":")) {
-		size_t len = strlen(editor);
-		int i = 0;
-		int failed;
-		const char *args[6];
-		struct strbuf arg0 = STRBUF_INIT;
+		const char *args[] = { editor, path, NULL };
 
-		if (strcspn(editor, "|&;<>()$`\\\"' \t\n*?[#~=%") != len) {
-			/* there are specials */
-			strbuf_addf(&arg0, "%s \"$@\"", editor);
-			args[i++] = "sh";
-			args[i++] = "-c";
-			args[i++] = arg0.buf;
-		}
-		args[i++] = editor;
-		args[i++] = path;
-		args[i] = NULL;
-
-		failed = run_command_v_opt_cd_env(args, 0, NULL, env);
-		strbuf_release(&arg0);
-		if (failed)
+		if (run_command_v_opt_cd_env(args, RUN_USING_SHELL, NULL, env))
 			return error("There was a problem with the editor '%s'.",
 					editor);
 	}
-- 
1.6.6.65.g050d2.dirty
Previous: Johannes SixtNext: Jeff King
Message 25 of 33 in “Giving command line parameter to textconv command?”
  1. Nanako ShiraishiDec 14, 2009
  2. Junio C HamanoDec 14, 2009
  3. Nanako ShiraishiDec 15, 2009
  4. Junio C HamanoDec 15, 2009
  5. Jeff KingDec 15, 2009
  6. Junio C HamanoDec 16, 2009
  7. Jeff KingDec 16, 2009
  8. Jeff KingDec 15, 2009
  9. Junio C HamanoDec 15, 2009
  10. Nanako ShiraishiDec 30, 2009
  11. Junio C HamanoDec 30, 2009
  12. Jeff KingDec 30, 2009
  13. 1/6 run-command: add "use shell" optionJeff King, Dec 30, 2009
  14. Erik Faye-LundDec 30, 2009
  15. Johannes SixtJan 1, 2010
  16. 2/6 run-command: convert simple callsites to use_shellJeff King, Dec 30, 2009
  17. 3/6 run-command: optimize out useless shell callsJeff King, Dec 30, 2009
  18. Johannes SixtDec 31, 2009
  19. Junio C HamanoDec 31, 2009
  20. Johannes SixtDec 31, 2009
  21. Jeff KingDec 31, 2009
  22. Johannes SixtDec 31, 2009
  23. Jeff KingJan 1, 2010
  24. Johannes SixtJan 1, 2010
  25. 4/6 editor: use run_command's shell featureJeff King, Dec 30, 2009
  26. 5/6 textconv: use shell to run helperJeff King, Dec 30, 2009
  27. 6/6 diff: run external diff helper with shellJeff King, Dec 30, 2009
  28. 7/6 t0021: use $SHELL_PATH for the filter scriptJohannes Sixt, Jan 1, 2010
  29. 8/6 t4030, t4031: work around bogus MSYS bash path conversionJohannes Sixt, Jan 1, 2010
  30. Jeff KingJan 3, 2010
  31. Johannes SixtJan 4, 2010
  32. Jeff KingJan 4, 2010
  33. Johannes SixtJan 4, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.