Skip to content

Commit 39598f9

Browse files
jiangxingitster
authored andcommitted
quote_path_relative(): remove redundant parameter
quote_path_relative() used to take a counted string as its parameter (the string to be quoted). With an earlier change, it now uses relative_path() that does not take a counted string, and we have been passing only the pointer to the string since then. Remove the length parameter from quote_path_relative() to show that this parameter was redundant. All the changed lines show that the caller passed either -1 (to ask the function run strlen() on the string), or the length of the string, so the earlier conversion was safe. All the callers of quote_path_relative() that used to take counted string have been audited to make sure that they are passing length of the actual string (or -1 to ask the callee run strlen()) Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad66df2 commit 39598f9

File tree

6 files changed

+24
-29
lines changed

6 files changed

+24
-29
lines changed

builtin/clean.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
5656
if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
5757
!resolve_gitlink_ref(path->buf, "HEAD", submodule_head)) {
5858
if (!quiet) {
59-
quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
59+
quote_path_relative(path->buf, prefix, &quoted);
6060
printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir),
6161
quoted.buf);
6262
}
@@ -70,7 +70,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
7070
/* an empty dir could be removed even if it is unreadble */
7171
res = dry_run ? 0 : rmdir(path->buf);
7272
if (res) {
73-
quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
73+
quote_path_relative(path->buf, prefix, &quoted);
7474
warning(_(msg_warn_remove_failed), quoted.buf);
7575
*dir_gone = 0;
7676
}
@@ -94,18 +94,18 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
9494
if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
9595
ret = 1;
9696
if (gone) {
97-
quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
97+
quote_path_relative(path->buf, prefix, &quoted);
9898
string_list_append(&dels, quoted.buf);
9999
} else
100100
*dir_gone = 0;
101101
continue;
102102
} else {
103103
res = dry_run ? 0 : unlink(path->buf);
104104
if (!res) {
105-
quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
105+
quote_path_relative(path->buf, prefix, &quoted);
106106
string_list_append(&dels, quoted.buf);
107107
} else {
108-
quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
108+
quote_path_relative(path->buf, prefix, &quoted);
109109
warning(_(msg_warn_remove_failed), quoted.buf);
110110
*dir_gone = 0;
111111
ret = 1;
@@ -127,7 +127,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
127127
if (!res)
128128
*dir_gone = 1;
129129
else {
130-
quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
130+
quote_path_relative(path->buf, prefix, &quoted);
131131
warning(_(msg_warn_remove_failed), quoted.buf);
132132
*dir_gone = 0;
133133
ret = 1;
@@ -262,7 +262,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
262262
if (remove_dirs(&directory, prefix, rm_flags, dry_run, quiet, &gone))
263263
errors++;
264264
if (gone && !quiet) {
265-
qname = quote_path_relative(directory.buf, directory.len, &buf, prefix);
265+
qname = quote_path_relative(directory.buf, prefix, &buf);
266266
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
267267
}
268268
}
@@ -272,11 +272,11 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
272272
continue;
273273
res = dry_run ? 0 : unlink(ent->name);
274274
if (res) {
275-
qname = quote_path_relative(ent->name, -1, &buf, prefix);
275+
qname = quote_path_relative(ent->name, prefix, &buf);
276276
warning(_(msg_warn_remove_failed), qname);
277277
errors++;
278278
} else if (!quiet) {
279-
qname = quote_path_relative(ent->name, -1, &buf, prefix);
279+
qname = quote_path_relative(ent->name, prefix, &buf);
280280
printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
281281
}
282282
}

builtin/grep.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
286286
struct strbuf pathbuf = STRBUF_INIT;
287287

288288
if (opt->relative && opt->prefix_length) {
289-
quote_path_relative(filename + tree_name_len, -1, &pathbuf,
290-
opt->prefix);
289+
quote_path_relative(filename + tree_name_len, opt->prefix, &pathbuf);
291290
strbuf_insert(&pathbuf, 0, filename, tree_name_len);
292291
} else {
293292
strbuf_addstr(&pathbuf, filename);
@@ -318,7 +317,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
318317
struct strbuf buf = STRBUF_INIT;
319318

320319
if (opt->relative && opt->prefix_length)
321-
quote_path_relative(filename, -1, &buf, opt->prefix);
320+
quote_path_relative(filename, opt->prefix, &buf);
322321
else
323322
strbuf_addstr(&buf, filename);
324323

builtin/ls-files.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ int report_path_error(const char *ps_matched, const char **pathspec, const char
394394
if (found_dup)
395395
continue;
396396

397-
name = quote_path_relative(pathspec[num], -1, &sb, prefix);
397+
name = quote_path_relative(pathspec[num], prefix, &sb);
398398
error("pathspec '%s' did not match any file(s) known to git.",
399399
name);
400400
errors++;

quote.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,15 @@ void write_name_quoted_relative(const char *name, size_t len,
325325
}
326326

327327
/* quote path as relative to the given prefix */
328-
char *quote_path_relative(const char *in, int len,
329-
struct strbuf *out, const char *prefix)
328+
char *quote_path_relative(const char *in, const char *prefix,
329+
struct strbuf *out)
330330
{
331331
struct strbuf sb = STRBUF_INIT;
332332
const char *rel = relative_path(in, prefix, &sb);
333333
strbuf_reset(out);
334334
quote_c_style_counted(rel, strlen(rel), out, NULL, 0);
335335
strbuf_release(&sb);
336336

337-
if (!out->len)
338-
strbuf_addstr(out, "./");
339-
340337
return out->buf;
341338
}
342339

quote.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ extern void write_name_quoted_relative(const char *name, size_t len,
6565
FILE *fp, int terminator);
6666

6767
/* quote path as relative to the given prefix */
68-
extern char *quote_path_relative(const char *in, int len,
69-
struct strbuf *out, const char *prefix);
68+
extern char *quote_path_relative(const char *in, const char *prefix,
69+
struct strbuf *out);
7070

7171
/* quoting as a string literal for other languages */
7272
extern void perl_quote_print(FILE *stream, const char *src);

wt-status.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
243243
struct strbuf onebuf = STRBUF_INIT;
244244
const char *one, *how = _("bug");
245245

246-
one = quote_path(it->string, -1, &onebuf, s->prefix);
246+
one = quote_path(it->string, s->prefix, &onebuf);
247247
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
248248
switch (d->stagemask) {
249249
case 1: how = _("both deleted:"); break;
@@ -297,8 +297,8 @@ static void wt_status_print_change_data(struct wt_status *s,
297297
change_type);
298298
}
299299

300-
one = quote_path(one_name, -1, &onebuf, s->prefix);
301-
two = quote_path(two_name, -1, &twobuf, s->prefix);
300+
one = quote_path(one_name, s->prefix, &onebuf);
301+
two = quote_path(two_name, s->prefix, &twobuf);
302302

303303
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
304304
switch (status) {
@@ -706,8 +706,7 @@ static void wt_status_print_other(struct wt_status *s,
706706
struct string_list_item *it;
707707
const char *path;
708708
it = &(l->items[i]);
709-
path = quote_path(it->string, strlen(it->string),
710-
&buf, s->prefix);
709+
path = quote_path(it->string, s->prefix, &buf);
711710
if (column_active(s->colopts)) {
712711
string_list_append(&output, path);
713712
continue;
@@ -1289,7 +1288,7 @@ static void wt_shortstatus_unmerged(struct string_list_item *it,
12891288
} else {
12901289
struct strbuf onebuf = STRBUF_INIT;
12911290
const char *one;
1292-
one = quote_path(it->string, -1, &onebuf, s->prefix);
1291+
one = quote_path(it->string, s->prefix, &onebuf);
12931292
printf(" %s\n", one);
12941293
strbuf_release(&onebuf);
12951294
}
@@ -1317,7 +1316,7 @@ static void wt_shortstatus_status(struct string_list_item *it,
13171316
struct strbuf onebuf = STRBUF_INIT;
13181317
const char *one;
13191318
if (d->head_path) {
1320-
one = quote_path(d->head_path, -1, &onebuf, s->prefix);
1319+
one = quote_path(d->head_path, s->prefix, &onebuf);
13211320
if (*one != '"' && strchr(one, ' ') != NULL) {
13221321
putchar('"');
13231322
strbuf_addch(&onebuf, '"');
@@ -1326,7 +1325,7 @@ static void wt_shortstatus_status(struct string_list_item *it,
13261325
printf("%s -> ", one);
13271326
strbuf_release(&onebuf);
13281327
}
1329-
one = quote_path(it->string, -1, &onebuf, s->prefix);
1328+
one = quote_path(it->string, s->prefix, &onebuf);
13301329
if (*one != '"' && strchr(one, ' ') != NULL) {
13311330
putchar('"');
13321331
strbuf_addch(&onebuf, '"');
@@ -1345,7 +1344,7 @@ static void wt_shortstatus_other(struct string_list_item *it,
13451344
} else {
13461345
struct strbuf onebuf = STRBUF_INIT;
13471346
const char *one;
1348-
one = quote_path(it->string, -1, &onebuf, s->prefix);
1347+
one = quote_path(it->string, s->prefix, &onebuf);
13491348
color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign);
13501349
printf(" %s\n", one);
13511350
strbuf_release(&onebuf);

0 commit comments

Comments
 (0)