Junio C Hamano <gitster@xxxxxxxxx> writes: > Of course none of the above becomes unnecessary if we scan the whole > string for SP before the main loop in quote-c-style-counted, but the > function was written to process the input in a single pass and such > a change defeats its design. If we need to do it in two passes, we > can have the caller do so anyway, at least for now. That thinking > lead to the final organization of the series, with two steps that > used to be preparatory for passing the flag down thru to the bottom > layer rebased out as a discardable appendix at the end. Actually, this made me realize that another variant is possible. It might be easier to read, or it might not. Since I cannot tell without actually writing one, let's see ... Instead of scanning the output from quote-c-style-counted for SP in the caller, the caller can do something like this. /* quote path as relative to the given prefix */ char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigned flags) { struct strbuf sb = STRBUF_INIT; const char *rel = relative_path(in, prefix, &sb); int add_dq_ourselves = !!(flags & QUOTE_PATH_QUOTE_SP) && !!strchr(rel, ' '); strbuf_reset(out); if (add_dq_ourselves) strbuf_addch(out, '"'); quote_c_style_counted(rel, strlen(rel), out, NULL, add_dq_ourselves ? CQUOTE_NODQ : 0); if (add_dq_ourselves) strbuf_addch(out, '"'); strbuf_release(&sb); return out->buf; } That is, we tell quote-c-style-counted not to put dq-pair around its output whether it needs to do the backslash quoting, if we know we want the result inside dq-pair anyway (iow, when the caller wants us to treat SP specially and we do see SP in the input). I don't know if this is easier to follow or not. I do think so right now but that is only because it is still fresh in my brain.