Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-07-06 21:54:45 +0300
committerJunio C Hamano <gitster@pobox.com>2023-07-06 21:54:45 +0300
commitda269af9207e38e820daad8aa993caa7d2fad76c (patch)
tree28567788ed00e6c037cb93684e95a473e3d2f412 /convert.c
parenta646b86cd10282de2ceb64ef33b5412e4fb2a54c (diff)
parent4416b86c6b34dad64b556bb1eb6711d5e6595a48 (diff)
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.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/convert.c b/convert.c
index 3d8325d49e..af87320471 100644
--- a/convert.c
+++ b/convert.c
@@ -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;