[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)