Skip to content

Commit 1f00ff4

Browse files
gitsterdscho
authored andcommitted
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 f6abad0 commit 1f00ff4

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) {
@@ -1051,19 +1051,19 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
10511051
if (remove_dirs(&abs_path, prefix, rm_flags, dry_run, quiet, &gone))
10521052
errors++;
10531053
if (gone && !quiet) {
1054-
qname = quote_path(item->string, NULL, &buf);
1054+
qname = quote_path(item->string, NULL, &buf, 0);
10551055
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
10561056
}
10571057
} else {
10581058
res = dry_run ? 0 : unlink(abs_path.buf);
10591059
if (res) {
10601060
int saved_errno = errno;
1061-
qname = quote_path(item->string, NULL, &buf);
1061+
qname = quote_path(item->string, NULL, &buf, 0);
10621062
errno = saved_errno;
10631063
warning_errno(_(msg_warn_remove_failed), qname);
10641064
errors++;
10651065
} else if (!quiet) {
1066-
qname = quote_path(item->string, NULL, &buf);
1066+
qname = quote_path(item->string, NULL, &buf, 0);
10671067
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
10681068
}
10691069
}

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);
@@ -969,7 +969,7 @@ static void wt_longstatus_print_other(struct wt_status *s,
969969
struct string_list_item *it;
970970
const char *path;
971971
it = &(l->items[i]);
972-
path = quote_path(it->string, s->prefix, &buf);
972+
path = quote_path(it->string, s->prefix, &buf, 0);
973973
if (column_active(s->colopts)) {
974974
string_list_append(&output, path);
975975
continue;
@@ -1853,7 +1853,7 @@ static void wt_shortstatus_unmerged(struct string_list_item *it,
18531853
} else {
18541854
struct strbuf onebuf = STRBUF_INIT;
18551855
const char *one;
1856-
one = quote_path(it->string, s->prefix, &onebuf);
1856+
one = quote_path(it->string, s->prefix, &onebuf, 0);
18571857
printf(" %s\n", one);
18581858
strbuf_release(&onebuf);
18591859
}
@@ -1882,7 +1882,7 @@ static void wt_shortstatus_status(struct string_list_item *it,
18821882
const char *one;
18831883

18841884
if (d->rename_source) {
1885-
one = quote_path(d->rename_source, s->prefix, &onebuf);
1885+
one = quote_path(d->rename_source, s->prefix, &onebuf, 0);
18861886
if (*one != '"' && strchr(one, ' ') != NULL) {
18871887
putchar('"');
18881888
strbuf_addch(&onebuf, '"');
@@ -1891,7 +1891,7 @@ static void wt_shortstatus_status(struct string_list_item *it,
18911891
printf("%s -> ", one);
18921892
strbuf_release(&onebuf);
18931893
}
1894-
one = quote_path(it->string, s->prefix, &onebuf);
1894+
one = quote_path(it->string, s->prefix, &onebuf, 0);
18951895
if (*one != '"' && strchr(one, ' ') != NULL) {
18961896
putchar('"');
18971897
strbuf_addch(&onebuf, '"');
@@ -1910,7 +1910,7 @@ static void wt_shortstatus_other(struct string_list_item *it,
19101910
} else {
19111911
struct strbuf onebuf = STRBUF_INIT;
19121912
const char *one;
1913-
one = quote_path(it->string, s->prefix, &onebuf);
1913+
one = quote_path(it->string, s->prefix, &onebuf, 0);
19141914
color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign);
19151915
printf(" %s\n", one);
19161916
strbuf_release(&onebuf);
@@ -2227,9 +2227,9 @@ static void wt_porcelain_v2_print_changed_entry(
22272227
*/
22282228
sep_char = '\t';
22292229
eol_char = '\n';
2230-
path = quote_path(it->string, s->prefix, &buf);
2230+
path = quote_path(it->string, s->prefix, &buf, 0);
22312231
if (d->rename_source)
2232-
path_from = quote_path(d->rename_source, s->prefix, &buf_from);
2232+
path_from = quote_path(d->rename_source, s->prefix, &buf_from, 0);
22332233
}
22342234

22352235
if (path_from)
@@ -2315,7 +2315,7 @@ static void wt_porcelain_v2_print_unmerged_entry(
23152315
if (s->null_termination)
23162316
path_index = it->string;
23172317
else
2318-
path_index = quote_path(it->string, s->prefix, &buf_index);
2318+
path_index = quote_path(it->string, s->prefix, &buf_index, 0);
23192319

23202320
fprintf(s->fp, "%c %s %s %06o %06o %06o %06o %s %s %s %s%c",
23212321
unmerged_prefix, key, submodule_token,
@@ -2348,7 +2348,7 @@ static void wt_porcelain_v2_print_other(
23482348
path = it->string;
23492349
eol_char = '\0';
23502350
} else {
2351-
path = quote_path(it->string, s->prefix, &buf);
2351+
path = quote_path(it->string, s->prefix, &buf, 0);
23522352
eol_char = '\n';
23532353
}
23542354

0 commit comments

Comments
 (0)