diff options
-rw-r--r-- | Documentation/git-for-each-ref.txt | 4 | ||||
-rw-r--r-- | builtin-for-each-ref.c | 10 | ||||
-rw-r--r-- | quote.c | 34 | ||||
-rw-r--r-- | quote.h | 1 |
4 files changed, 47 insertions, 2 deletions
diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 06e7ab1ec..da52eba7b 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -7,7 +7,7 @@ git-for-each-ref - Output information on each ref SYNOPSIS -------- -'git-for-each-ref' [--count=<count>]\* [--shell|--perl|--python] [--sort=<key>]\* [--format=<format>] [<pattern>] +'git-for-each-ref' [--count=<count>]\* [--shell|--perl|--python|--tcl] [--sort=<key>]\* [--format=<format>] [<pattern>] DESCRIPTION ----------- @@ -49,7 +49,7 @@ OPTIONS using fnmatch(3). Refs that do not match the pattern are not shown. ---shell, --perl, --python:: +--shell, --perl, --python, --tcl:: If given, strings that substitute `%(fieldname)` placeholders are quoted as string literals suitable for the specified host language. This is meant to produce diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index af72a12a5..9d5f266dc 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -12,6 +12,7 @@ #define QUOTE_SHELL 1 #define QUOTE_PERL 2 #define QUOTE_PYTHON 3 +#define QUOTE_TCL 4 typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type; @@ -723,6 +724,9 @@ static void print_value(struct refinfo *ref, int atom, int quote_style) case QUOTE_PYTHON: python_quote_print(stdout, v->s); break; + case QUOTE_TCL: + tcl_quote_print(stdout, v->s); + break; } } @@ -834,6 +838,12 @@ int cmd_for_each_ref(int ac, const char **av, char *prefix) quote_style = QUOTE_PYTHON; continue; } + if (!strcmp(arg, "--tcl") ) { + if (0 <= quote_style) + die("more than one quoting style?"); + quote_style = QUOTE_TCL; + continue; + } if (!strncmp(arg, "--count=", 8)) { if (maxcount) die("more than one --count?"); @@ -387,3 +387,37 @@ void python_quote_print(FILE *stream, const char *src) } fputc(sq, stream); } + +void tcl_quote_print(FILE *stream, const char *src) +{ + char c; + + fputc('"', stream); + while ((c = *src++)) { + switch (c) { + case '[': case ']': + case '{': case '}': + case '$': case '\\': case '"': + fputc('\\', stream); + default: + fputc(c, stream); + break; + case '\f': + fputs("\\f", stream); + break; + case '\r': + fputs("\\r", stream); + break; + case '\n': + fputs("\\n", stream); + break; + case '\t': + fputs("\\t", stream); + break; + case '\v': + fputs("\\v", stream); + break; + } + } + fputc('"', stream); +} @@ -55,5 +55,6 @@ extern void write_name_quoted(const char *prefix, int prefix_len, /* quoting as a string literal for other languages */ extern void perl_quote_print(FILE *stream, const char *src); extern void python_quote_print(FILE *stream, const char *src); +extern void tcl_quote_print(FILE *stream, const char *src); #endif |