quote_path: give flags parameter to quote_path()
The quote_path() function computes a path (relative to its base directory) and c-quotes the result if necessary. Teach it to take a flags parameter to allow its behaviour to be enriched later. No behaviour change intended. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Sep 10, 2020 at 10:01 UTC
88910c9939cee927a3ed1acca8d33a30c90b8fe5
5 files changed
+26
-26
builtin/clean.c
+11
-11
@@ -162,7 +162,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
162
if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
163
is_nonbare_repository_dir(path)) {
164
if (!quiet) {
165
- quote_path(path->buf, prefix, "ed);
165
+ quote_path(path->buf, prefix, "ed, 0);
166
printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir),
167
quoted.buf);
168
}
@@ -177,7 +177,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
177
res = dry_run ? 0 : rmdir(path->buf);
178
if (res) {
179
int saved_errno = errno;
180
- quote_path(path->buf, prefix, "ed);
180
+ quote_path(path->buf, prefix, "ed, 0);
181
errno = saved_errno;
182
warning_errno(_(msg_warn_remove_failed), quoted.buf);
183
*dir_gone = 0;
@@ -202,7 +202,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
202
if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
203
ret = 1;
204
if (gone) {
205
- quote_path(path->buf, prefix, "ed);
205
+ quote_path(path->buf, prefix, "ed, 0);
206
string_list_append(&dels, quoted.buf);
207
} else
208
*dir_gone = 0;
@@ -210,11 +210,11 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
210
} else {
211
res = dry_run ? 0 : unlink(path->buf);
212
if (!res) {
213
- quote_path(path->buf, prefix, "ed);
213
+ quote_path(path->buf, prefix, "ed, 0);
214
string_list_append(&dels, quoted.buf);
215
} else {
216
int saved_errno = errno;
217
- quote_path(path->buf, prefix, "ed);
217
+ quote_path(path->buf, prefix, "ed, 0);
218
errno = saved_errno;
219
warning_errno(_(msg_warn_remove_failed), quoted.buf);
220
*dir_gone = 0;
@@ -238,7 +238,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
238
*dir_gone = 1;
239
else {
240
int saved_errno = errno;
241
- quote_path(path->buf, prefix, "ed);
241
+ quote_path(path->buf, prefix, "ed, 0);
242
errno = saved_errno;
243
warning_errno(_(msg_warn_remove_failed), quoted.buf);
244
*dir_gone = 0;
@@ -266,7 +266,7 @@ static void pretty_print_dels(void)
266
struct column_options copts;
267
268
for_each_string_list_item(item, &del_list) {
269
- qname = quote_path(item->string, NULL, &buf);
269
+ qname = quote_path(item->string, NULL, &buf, 0);
270
string_list_append(&list, qname);
271
}
272
@@ -753,7 +753,7 @@ static int ask_each_cmd(void)
753
for_each_string_list_item(item, &del_list) {
754
/* Ctrl-D should stop removing files */
755
if (!eof) {
756
- qname = quote_path(item->string, NULL, &buf);
756
+ qname = quote_path(item->string, NULL, &buf, 0);
757
/* TRANSLATORS: Make sure to keep [y/N] as is */
758
printf(_("Remove %s [y/N]? "), qname);
759
if (git_read_line_interactively(&confirm) == EOF) {
@@ -1047,19 +1047,19 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
1047
if (remove_dirs(&abs_path, prefix, rm_flags, dry_run, quiet, &gone))
1048
errors++;
1049
if (gone && !quiet) {
1050
- qname = quote_path(item->string, NULL, &buf);
1050
+ qname = quote_path(item->string, NULL, &buf, 0);
1051
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
1052
}
1053
} else {
1054
res = dry_run ? 0 : unlink(abs_path.buf);
1055
if (res) {
1056
int saved_errno = errno;
1057
- qname = quote_path(item->string, NULL, &buf);
1057
+ qname = quote_path(item->string, NULL, &buf, 0);
1058
errno = saved_errno;
1059
warning_errno(_(msg_warn_remove_failed), qname);
1060
errors++;
1061
} else if (!quiet) {
1062
- qname = quote_path(item->string, NULL, &buf);
1062
+ qname = quote_path(item->string, NULL, &buf, 0);
1063
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
1064
}
1065
}
builtin/grep.c
+1
-1
@@ -319,7 +319,7 @@ static void grep_source_name(struct grep_opt *opt, const char *filename,
319
}
320
321
if (opt->relative && opt->prefix_length)
322
- quote_path(filename + tree_name_len, opt->prefix, out);
322
+ quote_path(filename + tree_name_len, opt->prefix, out, 0);
323
else
324
quote_c_style(filename + tree_name_len, out, NULL, 0);
325
quote.c
+1
-1
@@ -352,7 +352,7 @@ void write_name_quoted_relative(const char *name, const char *prefix,
352
}
353
354
/* quote path as relative to the given prefix */
355
-char *quote_path(const char *in, const char *prefix, struct strbuf *out)
355
+char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigned flags)
356
{
357
struct strbuf sb = STRBUF_INIT;
358
const char *rel = relative_path(in, prefix, &sb);
quote.h
+1
-1
@@ -72,7 +72,7 @@ void write_name_quoted_relative(const char *name, const char *prefix,
72
FILE *fp, int terminator);
73
74
/* quote path as relative to the given prefix */
75
-char *quote_path(const char *in, const char *prefix, struct strbuf *out);
75
+char *quote_path(const char *in, const char *prefix, struct strbuf *out, unsigned flags);
76
77
/* quoting as a string literal for other languages */
78
void perl_quote_buf(struct strbuf *sb, const char *src);
wt-status.c
+12
-12
@@ -336,7 +336,7 @@ static void wt_longstatus_print_unmerged_data(struct wt_status *s,
336
memset(padding, ' ', label_width);
337
}
338
339
- one = quote_path(it->string, s->prefix, &onebuf);
339
+ one = quote_path(it->string, s->prefix, &onebuf, 0);
340
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
341
342
how = wt_status_unmerged_status_string(d->stagemask);
@@ -402,8 +402,8 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
402
if (d->rename_status == status)
403
one_name = d->rename_source;
404
405
- one = quote_path(one_name, s->prefix, &onebuf);
406
- two = quote_path(two_name, s->prefix, &twobuf);
405
+ one = quote_path(one_name, s->prefix, &onebuf, 0);
406
+ two = quote_path(two_name, s->prefix, &twobuf, 0);
407
408
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
409
what = wt_status_diff_status_string(status);
@@ -964,7 +964,7 @@ static void wt_longstatus_print_other(struct wt_status *s,
964
struct string_list_item *it;
965
const char *path;
966
it = &(l->items[i]);
967
- path = quote_path(it->string, s->prefix, &buf);
967
+ path = quote_path(it->string, s->prefix, &buf, 0);
968
if (column_active(s->colopts)) {
969
string_list_append(&output, path);
970
continue;
@@ -1848,7 +1848,7 @@ static void wt_shortstatus_unmerged(struct string_list_item *it,
1848
} else {
1849
struct strbuf onebuf = STRBUF_INIT;
1850
const char *one;
1851
- one = quote_path(it->string, s->prefix, &onebuf);
1851
+ one = quote_path(it->string, s->prefix, &onebuf, 0);
1852
printf(" %s\n", one);
1853
strbuf_release(&onebuf);
1854
}
@@ -1877,7 +1877,7 @@ static void wt_shortstatus_status(struct string_list_item *it,
1877
const char *one;
1878
1879
if (d->rename_source) {
1880
- one = quote_path(d->rename_source, s->prefix, &onebuf);
1880
+ one = quote_path(d->rename_source, s->prefix, &onebuf, 0);
1881
if (*one != '"' && strchr(one, ' ') != NULL) {
1882
putchar('"');
1883
strbuf_addch(&onebuf, '"');
@@ -1886,7 +1886,7 @@ static void wt_shortstatus_status(struct string_list_item *it,
1886
printf("%s -> ", one);
1887
strbuf_release(&onebuf);
1888
}
1889
- one = quote_path(it->string, s->prefix, &onebuf);
1889
+ one = quote_path(it->string, s->prefix, &onebuf, 0);
1890
if (*one != '"' && strchr(one, ' ') != NULL) {
1891
putchar('"');
1892
strbuf_addch(&onebuf, '"');
@@ -1905,7 +1905,7 @@ static void wt_shortstatus_other(struct string_list_item *it,
1905
} else {
1906
struct strbuf onebuf = STRBUF_INIT;
1907
const char *one;
1908
- one = quote_path(it->string, s->prefix, &onebuf);
1908
+ one = quote_path(it->string, s->prefix, &onebuf, 0);
1909
color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign);
1910
printf(" %s\n", one);
1911
strbuf_release(&onebuf);
@@ -2222,9 +2222,9 @@ static void wt_porcelain_v2_print_changed_entry(
2222
*/
2223
sep_char = '\t';
2224
eol_char = '\n';
2225
- path = quote_path(it->string, s->prefix, &buf);
2225
+ path = quote_path(it->string, s->prefix, &buf, 0);
2226
if (d->rename_source)
2227
- path_from = quote_path(d->rename_source, s->prefix, &buf_from);
2227
+ path_from = quote_path(d->rename_source, s->prefix, &buf_from, 0);
2228
}
2229
2230
if (path_from)
@@ -2310,7 +2310,7 @@ static void wt_porcelain_v2_print_unmerged_entry(
2310
if (s->null_termination)
2311
path_index = it->string;
2312
else
2313
- path_index = quote_path(it->string, s->prefix, &buf_index);
2313
+ path_index = quote_path(it->string, s->prefix, &buf_index, 0);
2314
2315
fprintf(s->fp, "%c %s %s %06o %06o %06o %06o %s %s %s %s%c",
2316
unmerged_prefix, key, submodule_token,
@@ -2343,7 +2343,7 @@ static void wt_porcelain_v2_print_other(
2343
path = it->string;
2344
eol_char = '\0';
2345
} else {
2346
- path = quote_path(it->string, s->prefix, &buf);
2346
+ path = quote_path(it->string, s->prefix, &buf, 0);
2347
eol_char = '\n';
2348
}
2349