summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cace16f)
raw | patch | inline | side by side (parent: cace16f)
author | Shawn O. Pearce <spearce@spearce.org> | |
Sun, 28 Jan 2007 07:39:13 +0000 (02:39 -0500) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 28 Jan 2007 21:00:26 +0000 (13:00 -0800) |
Love it or hate it, some people actually still program in Tcl. Some
of those programs are meant for interfacing with Git. Programs such as
gitk and git-gui. It may be useful to have Tcl-safe output available
from for-each-ref, just like shell, Perl and Python already enjoy.
Thanks to Sergey Vlasov for pointing out the horrible flaws in the
first and second version of this patch, and steering me in the right
direction for Tcl value quoting.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
of those programs are meant for interfacing with Git. Programs such as
gitk and git-gui. It may be useful to have Tcl-safe output available
from for-each-ref, just like shell, Perl and Python already enjoy.
Thanks to Sergey Vlasov for pointing out the horrible flaws in the
first and second version of this patch, and steering me in the right
direction for Tcl value quoting.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Documentation/git-for-each-ref.txt | patch | blob | history | |
builtin-for-each-ref.c | patch | blob | history | |
quote.c | patch | blob | history | |
quote.h | patch | blob | history |
index 06e7ab1ec127cb511e7d403ea3979b59893141ba..da52eba7b3619667537c1df3c58a927010f1c8ab 100644 (file)
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
-----------
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 af72a12a5798265cece6c7b72582fd3672421394..9d5f266dc4e06de99aa998c2ed3d220b246db812 100644 (file)
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
#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;
case QUOTE_PYTHON:
python_quote_print(stdout, v->s);
break;
+ case QUOTE_TCL:
+ tcl_quote_print(stdout, v->s);
+ break;
}
}
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?");
index a418a0f803f91d218b66ae89a1e8615a94ff27bc..fb9e4ca253ea9bcadbcb55dcdd62be614c66758f 100644 (file)
--- a/quote.c
+++ b/quote.c
}
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);
+}
index b55e69975091193f62b293f90a776ca9f6112ab4..bdc3610df51000baeda49da1eeaec20ccb2682fb 100644 (file)
--- a/quote.h
+++ b/quote.h
/* 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