Re: [PATCH v2 4/7] quote_path: code clarification
- From
Jeff King <peff@peff.net>
- Date
- Sep 10, 2020, 18:08 UTC
- Message-ID
- <20200910180814.GA1917207@coredump.intra.peff.net>
- In-Reply-To
- <20200910170159.1278781-5-gitster@pobox.com>
On Thu, Sep 10, 2020 at 10:01:56AM -0700, Junio C Hamano wrote:
Show 7 quoted lines
> Instead we can scan the path upfront to see if the input has SP in > it. If so, we tell quote_c_style_counted() not to enclose its > output in a dq-pair, and we add a dq-pair ourselves. Whether the > input had bytes that quote_c_style_counted() uses backslash quoting, > this would give us a desired quoted string. If the input does not > have SP in it, we just let quote_c_style_counted() do its thing as > usual, which would enclose the result in a dq-pair only when needed.
Nice. I think the result is easier to follow than the original, not to mention more efficient. And the fact that we didn't need to touch quote_c_style_counted() is the cherry on top.
> + int force_dq = ((flags & QUOTE_PATH_QUOTE_SP) && strchr(rel, ' ')); > [...] > + quote_c_style_counted(rel, strlen(rel), out, NULL, !!force_dq);
I think force_dq is already normalized to 0/1 by the &&, so we wouldn't need the "!!" here.
-Peff