Skip to content

Commit f3fc4a1

Browse files
committed
quote_path: optionally allow quoting a path with SP in it
Some code in wt-status.c special case a path with SP in it, which usually does not have to be c-quoted, and ensure that such a path does get quoted. Move the logic to quote_path() and give it a bit in the flags word, QUOTE_PATH_QUOTE_SP. No behaviour change intended. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 88910c9 commit f3fc4a1

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

quote.c

+7
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigne
360360
quote_c_style_counted(rel, strlen(rel), out, NULL, 0);
361361
strbuf_release(&sb);
362362

363+
if ((flags & QUOTE_PATH_QUOTE_SP) &&
364+
(out->buf[0] != '"' && strchr(out->buf, ' '))) {
365+
/* Ensure the whole thing is quoted if the path has SP in it */
366+
strbuf_insertstr(out, 0, "\"");
367+
strbuf_addch(out, '"');
368+
}
369+
363370
return out->buf;
364371
}
365372

quote.h

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void write_name_quoted_relative(const char *name, const char *prefix,
7373

7474
/* quote path as relative to the given prefix */
7575
char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigned flags);
76+
#define QUOTE_PATH_QUOTE_SP 01
7677

7778
/* quoting as a string literal for other languages */
7879
void perl_quote_buf(struct strbuf *sb, const char *src);

wt-status.c

+3-12
Original file line numberDiff line numberDiff line change
@@ -1877,21 +1877,12 @@ static void wt_shortstatus_status(struct string_list_item *it,
18771877
const char *one;
18781878

18791879
if (d->rename_source) {
1880-
one = quote_path(d->rename_source, s->prefix, &onebuf, 0);
1881-
if (*one != '"' && strchr(one, ' ') != NULL) {
1882-
putchar('"');
1883-
strbuf_addch(&onebuf, '"');
1884-
one = onebuf.buf;
1885-
}
1880+
one = quote_path(d->rename_source, s->prefix, &onebuf,
1881+
QUOTE_PATH_QUOTE_SP);
18861882
printf("%s -> ", one);
18871883
strbuf_release(&onebuf);
18881884
}
1889-
one = quote_path(it->string, s->prefix, &onebuf, 0);
1890-
if (*one != '"' && strchr(one, ' ') != NULL) {
1891-
putchar('"');
1892-
strbuf_addch(&onebuf, '"');
1893-
one = onebuf.buf;
1894-
}
1885+
one = quote_path(it->string, s->prefix, &onebuf, QUOTE_PATH_QUOTE_SP);
18951886
printf("%s\n", one);
18961887
strbuf_release(&onebuf);
18971888
}

0 commit comments

Comments
 (0)