summaryrefslogtreecommitdiff
path: root/convert.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-01-05 13:31:01 -0800
committerJunio C Hamano <gitster@pobox.com>2011-01-05 13:31:01 -0800
commit9e98354ab9717480e2e15b5ae56c10c3d5702a9b (patch)
tree716ed1df67e67bd8dccaca8909af135452806614 /convert.c
parent0c30ed0cb57988378d721d817c55f74a93dffb13 (diff)
parent4290f690676bc14c49c7cddbcda1c09017948718 (diff)
downloadgit-9e98354ab9717480e2e15b5ae56c10c3d5702a9b.tar.gz
Merge branch 'pw/convert-pathname-substitution'
* pw/convert-pathname-substitution: t0021: avoid getting filter killed with SIGPIPE convert filter: supply path to external driver
Diffstat (limited to 'convert.c')
-rw-r--r--convert.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/convert.c b/convert.c
index 01de9a84c2..d5aebed48d 100644
--- a/convert.c
+++ b/convert.c
@@ -1,6 +1,7 @@
#include "cache.h"
#include "attr.h"
#include "run-command.h"
+#include "quote.h"
/*
* convert.c - convert a file when checking it out and checking it in.
@@ -318,6 +319,7 @@ struct filter_params {
const char *src;
unsigned long size;
const char *cmd;
+ const char *path;
};
static int filter_buffer(int in, int out, void *data)
@@ -330,7 +332,23 @@ static int filter_buffer(int in, int out, void *data)
int write_err, status;
const char *argv[] = { NULL, NULL };
- argv[0] = params->cmd;
+ /* apply % substitution to cmd */
+ struct strbuf cmd = STRBUF_INIT;
+ struct strbuf path = STRBUF_INIT;
+ struct strbuf_expand_dict_entry dict[] = {
+ { "f", NULL, },
+ { NULL, NULL, },
+ };
+
+ /* quote the path to preserve spaces, etc. */
+ sq_quote_buf(&path, params->path);
+ dict[0].value = path.buf;
+
+ /* expand all %f with the quoted path */
+ strbuf_expand(&cmd, params->cmd, strbuf_expand_dict_cb, &dict);
+ strbuf_release(&path);
+
+ argv[0] = cmd.buf;
memset(&child_process, 0, sizeof(child_process));
child_process.argv = argv;
@@ -350,6 +368,8 @@ static int filter_buffer(int in, int out, void *data)
status = finish_command(&child_process);
if (status)
error("external filter %s failed %d", params->cmd, status);
+
+ strbuf_release(&cmd);
return (write_err || status);
}
@@ -377,6 +397,7 @@ static int apply_filter(const char *path, const char *src, size_t len,
params.src = src;
params.size = len;
params.cmd = cmd;
+ params.path = path;
fflush(NULL);
if (start_async(&async))