Skip to content

Commit 88910c9

Browse files
committed
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 <[email protected]>
1 parent c34d24b commit 88910c9

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

builtin/clean.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
162162
if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
163163
is_nonbare_repository_dir(path)) {
164164
if (!quiet) {
165-
quote_path(path->buf, prefix, &quoted);
165+
quote_path(path->buf, prefix, &quoted, 0);
166166
printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir),
167167
quoted.buf);
168168
}
@@ -177,7 +177,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
177177
res = dry_run ? 0 : rmdir(path->buf);
178178
if (res) {
179179
int saved_errno = errno;
180-
quote_path(path->buf, prefix, &quoted);
180+
quote_path(path->buf, prefix, &quoted, 0);
181181
errno = saved_errno;
182182
warning_errno(_(msg_warn_remove_failed), quoted.buf);
183183
*dir_gone = 0;
@@ -202,19 +202,19 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
202202
if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
203203
ret = 1;
204204
if (gone) {
205-
quote_path(path->buf, prefix, &quoted);
205+
quote_path(path->buf, prefix, &quoted, 0);
206206
string_list_append(&dels, quoted.buf);
207207
} else
208208
*dir_gone = 0;
209209
continue;
210210
} else {
211211
res = dry_run ? 0 : unlink(path->buf);
212212
if (!res) {
213-
quote_path(path->buf, prefix, &quoted);
213+
quote_path(path->buf, prefix, &quoted, 0);
214214
string_list_append(&dels, quoted.buf);
215215
} else {
216216
int saved_errno = errno;
217-
quote_path(path->buf, prefix, &quoted);
217+
quote_path(path->buf, prefix, &quoted, 0);
218218
errno = saved_errno;
219219
warning_errno(_(msg_warn_remove_failed), quoted.buf);
220220
*dir_gone = 0;
@@ -238,7 +238,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
238238
*dir_gone = 1;
239239
else {
240240
int saved_errno = errno;
241-
quote_path(path->buf, prefix, &quoted);
241+
quote_path(path->buf, prefix, &quoted, 0);
242242
errno = saved_errno;
243243
warning_errno(_(msg_warn_remove_failed), quoted.buf);
244244
*dir_gone = 0;
@@ -266,7 +266,7 @@ static void pretty_print_dels(void)
266266
struct column_options copts;
267267

268268
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);
270270
string_list_append(&list, qname);
271271
}
272272

@@ -753,7 +753,7 @@ static int ask_each_cmd(void)
753753
for_each_string_list_item(item, &del_list) {
754754
/* Ctrl-D should stop removing files */
755755
if (!eof) {
756-
qname = quote_path(item->string, NULL, &buf);
756+
qname = quote_path(item->string, NULL, &buf, 0);
757757
/* TRANSLATORS: Make sure to keep [y/N] as is */
758758
printf(_("Remove %s [y/N]? "), qname);
759759
if (git_read_line_interactively(&confirm) == EOF) {
@@ -1047,19 +1047,19 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
10471047
if (remove_dirs(&abs_path, prefix, rm_flags, dry_run, quiet, &gone))
10481048
errors++;
10491049
if (gone && !quiet) {
1050-
qname = quote_path(item->string, NULL, &buf);
1050+
qname = quote_path(item->string, NULL, &buf, 0);
10511051
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
10521052
}
10531053
} else {
10541054
res = dry_run ? 0 : unlink(abs_path.buf);
10551055
if (res) {
10561056
int saved_errno = errno;
1057-
qname = quote_path(item->string, NULL, &buf);
1057+
qname = quote_path(item->string, NULL, &buf, 0);
10581058
errno = saved_errno;
10591059
warning_errno(_(msg_warn_remove_failed), qname);
10601060
errors++;
10611061
} else if (!quiet) {
1062-
qname = quote_path(item->string, NULL, &buf);
1062+
qname = quote_path(item->string, NULL, &buf, 0);
10631063
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
10641064
}
10651065
}

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static void grep_source_name(struct grep_opt *opt, const char *filename,
319319
}
320320

321321
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);
323323
else
324324
quote_c_style(filename + tree_name_len, out, NULL, 0);
325325

quote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ void write_name_quoted_relative(const char *name, const char *prefix,
352352
}
353353

354354
/* 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)
356356
{
357357
struct strbuf sb = STRBUF_INIT;
358358
const char *rel = relative_path(in, prefix, &sb);

quote.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void write_name_quoted_relative(const char *name, const char *prefix,
7272
FILE *fp, int terminator);
7373

7474
/* 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);
7676

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

wt-status.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ static void wt_longstatus_print_unmerged_data(struct wt_status *s,
336336
memset(padding, ' ', label_width);
337337
}
338338

339-
one = quote_path(it->string, s->prefix, &onebuf);
339+
one = quote_path(it->string, s->prefix, &onebuf, 0);
340340
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
341341

342342
how = wt_status_unmerged_status_string(d->stagemask);
@@ -402,8 +402,8 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
402402
if (d->rename_status == status)
403403
one_name = d->rename_source;
404404

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);
407407

408408
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
409409
what = wt_status_diff_status_string(status);
@@ -964,7 +964,7 @@ static void wt_longstatus_print_other(struct wt_status *s,
964964
struct string_list_item *it;
965965
const char *path;
966966
it = &(l->items[i]);
967-
path = quote_path(it->string, s->prefix, &buf);
967+
path = quote_path(it->string, s->prefix, &buf, 0);
968968
if (column_active(s->colopts)) {
969969
string_list_append(&output, path);
970970
continue;
@@ -1848,7 +1848,7 @@ static void wt_shortstatus_unmerged(struct string_list_item *it,
18481848
} else {
18491849
struct strbuf onebuf = STRBUF_INIT;
18501850
const char *one;
1851-
one = quote_path(it->string, s->prefix, &onebuf);
1851+
one = quote_path(it->string, s->prefix, &onebuf, 0);
18521852
printf(" %s\n", one);
18531853
strbuf_release(&onebuf);
18541854
}
@@ -1877,7 +1877,7 @@ 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);
1880+
one = quote_path(d->rename_source, s->prefix, &onebuf, 0);
18811881
if (*one != '"' && strchr(one, ' ') != NULL) {
18821882
putchar('"');
18831883
strbuf_addch(&onebuf, '"');
@@ -1886,7 +1886,7 @@ static void wt_shortstatus_status(struct string_list_item *it,
18861886
printf("%s -> ", one);
18871887
strbuf_release(&onebuf);
18881888
}
1889-
one = quote_path(it->string, s->prefix, &onebuf);
1889+
one = quote_path(it->string, s->prefix, &onebuf, 0);
18901890
if (*one != '"' && strchr(one, ' ') != NULL) {
18911891
putchar('"');
18921892
strbuf_addch(&onebuf, '"');
@@ -1905,7 +1905,7 @@ static void wt_shortstatus_other(struct string_list_item *it,
19051905
} else {
19061906
struct strbuf onebuf = STRBUF_INIT;
19071907
const char *one;
1908-
one = quote_path(it->string, s->prefix, &onebuf);
1908+
one = quote_path(it->string, s->prefix, &onebuf, 0);
19091909
color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign);
19101910
printf(" %s\n", one);
19111911
strbuf_release(&onebuf);
@@ -2222,9 +2222,9 @@ static void wt_porcelain_v2_print_changed_entry(
22222222
*/
22232223
sep_char = '\t';
22242224
eol_char = '\n';
2225-
path = quote_path(it->string, s->prefix, &buf);
2225+
path = quote_path(it->string, s->prefix, &buf, 0);
22262226
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);
22282228
}
22292229

22302230
if (path_from)
@@ -2310,7 +2310,7 @@ static void wt_porcelain_v2_print_unmerged_entry(
23102310
if (s->null_termination)
23112311
path_index = it->string;
23122312
else
2313-
path_index = quote_path(it->string, s->prefix, &buf_index);
2313+
path_index = quote_path(it->string, s->prefix, &buf_index, 0);
23142314

23152315
fprintf(s->fp, "%c %s %s %06o %06o %06o %06o %s %s %s %s%c",
23162316
unmerged_prefix, key, submodule_token,
@@ -2343,7 +2343,7 @@ static void wt_porcelain_v2_print_other(
23432343
path = it->string;
23442344
eol_char = '\0';
23452345
} else {
2346-
path = quote_path(it->string, s->prefix, &buf);
2346+
path = quote_path(it->string, s->prefix, &buf, 0);
23472347
eol_char = '\n';
23482348
}
23492349

0 commit comments

Comments
 (0)