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

[PATCH] rev-parse --sq bugfixes.

From
Junio C Hamano <junkio@cox.net>
Date
Jul 17, 2005, 08:06 UTC
Message-ID
<7vslyd3lhk.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vmzol29zm.fsf@assigned-by-dhcp.cox.net>

We expect --sq output to be used to construct a string to be "eval"ed in shell scripts, so we should not be separating the parameter with LF, which would cause the current command to be ended.

Also there was a silly thinko for doing the shell quoting.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---

*** This is a fix on top of the "git-rev-parse vs IFS" RFC *** patch.

 rev-parse.c |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)
bf5a2b2f3cd5693560ab72974f9956c76a8fd667
diff --git a/rev-parse.c b/rev-parse.c
--- a/rev-parse.c
+++ b/rev-parse.c
@@ -50,18 +50,6 @@ static int is_rev_argument(const char *a
 	}
 }
 
-static void show_rev(int type, const unsigned char *sha1)
-{
-	if (no_revs)
-		return;
-	output_revs++;
-
-	/* Hexadecimal string plus possibly a carret;
-	 * this does not have to be quoted even under output_sq.
-	 */
-	printf("%s%s\n", type == show_type ? "" : "^", sha1_to_hex(sha1));
-}
-
 static void show(const char *arg)
 {
 	if (output_sq) {
@@ -75,16 +63,31 @@ static void show(const char *arg)
 				fputs(arg, stdout);
 				break;
 			}
+			while (arg < next)
+				putchar(*arg++);
 			fputs("'\\''", stdout);
 			arg = next + 1;
 		}
 		putchar(sq);
-		putchar('\n');
+		putchar(' ');
 	}
 	else
 		puts(arg);
 }
 
+static void show_rev(int type, const unsigned char *sha1)
+{
+	if (no_revs)
+		return;
+	output_revs++;
+
+	/* Hexadecimal string plus possibly a carret;
+	 * this does not have to be quoted even under output_sq.
+	 */
+	printf("%s%s%c", type == show_type ? "" : "^", sha1_to_hex(sha1),
+	       output_sq ? ' ' : '\n');
+}
+
 static void show_rev_arg(char *rev)
 {
 	if (no_revs)
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 4 in “git-rev-parse vs IFS”
  1. git-rev-parse vs IFSJunio C Hamano, Jul 17, 2005
  2. rev-parse --sq bugfixes.Junio C Hamano, Jul 17, 2005
  3. Help scripts that use git-rev-parse to grok args with SP/TAB/LFJunio C Hamano, Jul 18, 2005
  4. Audit rev-parse users.Junio C Hamano, Jul 17, 2005

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.