diff options
author | Pete Wyckoff <pw@padd.com> | 2010-12-22 06:40:13 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-12-22 10:19:32 -0800 |
commit | a2b665de4b694b04959f6371f9887f7ad5cae404 (patch) | |
tree | 7b4329b53414d676d14c62cc225a88e7f9136e29 /convert.c | |
parent | 853563d7344ee532aa56f8a9aabcfdfb5c4fe2c3 (diff) | |
download | git-a2b665de4b694b04959f6371f9887f7ad5cae404.tar.gz |
convert filter: supply path to external driver
Filtering to support keyword expansion may need the name of
the file being filtered. In particular, to support p4 keywords
like
$File: //depot/product/dir/script.sh $
the smudge filter needs to know the name of the file it is
smudging.
Allow "%f" in the custom filter command line specified in the
configuration. This will be substituted by the filename
inside a single-quote pair to be passed to the shell.
Signed-off-by: Pete Wyckoff <pw@padd.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'convert.c')
-rw-r--r-- | convert.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -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)) |