diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-07-06 20:54:45 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-07-06 20:54:45 +0200 |
commit | da269af9207e38e820daad8aa993caa7d2fad76c (patch) | |
tree | 28567788ed00e6c037cb93684e95a473e3d2f412 /convert.c | |
parent | The seventh batch (diff) | |
parent | strbuf: simplify strbuf_expand_literal_cb() (diff) | |
download | git-da269af9207e38e820daad8aa993caa7d2fad76c.tar.xz git-da269af9207e38e820daad8aa993caa7d2fad76c.zip |
Merge branch 'rs/strbuf-expand-step'
Code clean-up around strbuf_expand() API.
* rs/strbuf-expand-step:
strbuf: simplify strbuf_expand_literal_cb()
replace strbuf_expand() with strbuf_expand_step()
replace strbuf_expand_dict_cb() with strbuf_expand_step()
strbuf: factor out strbuf_expand_step()
pretty: factor out expand_separator()
Diffstat (limited to 'convert.c')
-rw-r--r-- | convert.c | 22 |
1 files changed, 10 insertions, 12 deletions
@@ -634,23 +634,21 @@ static int filter_buffer_or_fd(int in UNUSED, int out, void *data) */ struct child_process child_process = CHILD_PROCESS_INIT; struct filter_params *params = (struct filter_params *)data; + const char *format = params->cmd; int write_err, status; /* 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); + /* expand all %f with the quoted path; quote to preserve space, etc. */ + while (strbuf_expand_step(&cmd, &format)) { + if (skip_prefix(format, "%", &format)) + strbuf_addch(&cmd, '%'); + else if (skip_prefix(format, "f", &format)) + sq_quote_buf(&cmd, params->path); + else + strbuf_addch(&cmd, '%'); + } strvec_push(&child_process.args, cmd.buf); child_process.use_shell = 1; |