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 <worldhello.net@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jiang Xin committed Jun 25, 2013 at 23:53 UTC 39598f9983f759b5e38b9e762c695bad6c89a1b3
6 files changed +24 -29
builtin/clean.c
+9 -9
@@ -56,7 +56,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
56 if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
57 !resolve_gitlink_ref(path->buf, "HEAD", submodule_head)) {
58 if (!quiet) {
59 - quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
59 + quote_path_relative(path->buf, prefix, &quoted);
60 printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir),
61 quoted.buf);
62 }
@@ -70,7 +70,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
70 /* an empty dir could be removed even if it is unreadble */
71 res = dry_run ? 0 : rmdir(path->buf);
72 if (res) {
73 - quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
73 + quote_path_relative(path->buf, prefix, &quoted);
74 warning(_(msg_warn_remove_failed), quoted.buf);
75 *dir_gone = 0;
76 }
@@ -94,7 +94,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
94 if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone))
95 ret = 1;
96 if (gone) {
97 - quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
97 + quote_path_relative(path->buf, prefix, &quoted);
98 string_list_append(&dels, quoted.buf);
99 } else
100 *dir_gone = 0;
@@ -102,10 +102,10 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
102 } else {
103 res = dry_run ? 0 : unlink(path->buf);
104 if (!res) {
105 - quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
105 + quote_path_relative(path->buf, prefix, &quoted);
106 string_list_append(&dels, quoted.buf);
107 } else {
108 - quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
108 + quote_path_relative(path->buf, prefix, &quoted);
109 warning(_(msg_warn_remove_failed), quoted.buf);
110 *dir_gone = 0;
111 ret = 1;
@@ -127,7 +127,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
127 if (!res)
128 *dir_gone = 1;
129 else {
130 - quote_path_relative(path->buf, strlen(path->buf), &quoted, prefix);
130 + quote_path_relative(path->buf, prefix, &quoted);
131 warning(_(msg_warn_remove_failed), quoted.buf);
132 *dir_gone = 0;
133 ret = 1;
@@ -262,7 +262,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
262 if (remove_dirs(&directory, prefix, rm_flags, dry_run, quiet, &gone))
263 errors++;
264 if (gone && !quiet) {
265 - qname = quote_path_relative(directory.buf, directory.len, &buf, prefix);
265 + qname = quote_path_relative(directory.buf, prefix, &buf);
266 printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
267 }
268 }
@@ -272,11 +272,11 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
272 continue;
273 res = dry_run ? 0 : unlink(ent->name);
274 if (res) {
275 - qname = quote_path_relative(ent->name, -1, &buf, prefix);
275 + qname = quote_path_relative(ent->name, prefix, &buf);
276 warning(_(msg_warn_remove_failed), qname);
277 errors++;
278 } else if (!quiet) {
279 - qname = quote_path_relative(ent->name, -1, &buf, prefix);
279 + qname = quote_path_relative(ent->name, prefix, &buf);
280 printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname);
281 }
282 }
builtin/grep.c
+2 -3
@@ -286,8 +286,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
286 struct strbuf pathbuf = STRBUF_INIT;
287
288 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);
290 strbuf_insert(&pathbuf, 0, filename, tree_name_len);
291 } else {
292 strbuf_addstr(&pathbuf, filename);
@@ -318,7 +317,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
317 struct strbuf buf = STRBUF_INIT;
318
319 if (opt->relative && opt->prefix_length)
321 - quote_path_relative(filename, -1, &buf, opt->prefix);
320 + quote_path_relative(filename, opt->prefix, &buf);
321 else
322 strbuf_addstr(&buf, filename);
323
builtin/ls-files.c
+1 -1
@@ -394,7 +394,7 @@ int report_path_error(const char *ps_matched, const char **pathspec, const char
394 if (found_dup)
395 continue;
396
397 - name = quote_path_relative(pathspec[num], -1, &sb, prefix);
397 + name = quote_path_relative(pathspec[num], prefix, &sb);
398 error("pathspec '%s' did not match any file(s) known to git.",
399 name);
400 errors++;
quote.c
+2 -5
@@ -325,8 +325,8 @@ void write_name_quoted_relative(const char *name, size_t len,
325 }
326
327 /* 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)
330 {
331 struct strbuf sb = STRBUF_INIT;
332 const char *rel = relative_path(in, prefix, &sb);
@@ -334,9 +334,6 @@ char *quote_path_relative(const char *in, int len,
334 quote_c_style_counted(rel, strlen(rel), out, NULL, 0);
335 strbuf_release(&sb);
336
337 - if (!out->len)
338 - strbuf_addstr(out, "./");
339 -
337 return out->buf;
338 }
339
quote.h
+2 -2
@@ -65,8 +65,8 @@ extern void write_name_quoted_relative(const char *name, size_t len,
65 FILE *fp, int terminator);
66
67 /* 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);
70
71 /* quoting as a string literal for other languages */
72 extern void perl_quote_print(FILE *stream, const char *src);
wt-status.c
+8 -9
@@ -243,7 +243,7 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
243 struct strbuf onebuf = STRBUF_INIT;
244 const char *one, *how = _("bug");
245
246 - one = quote_path(it->string, -1, &onebuf, s->prefix);
246 + one = quote_path(it->string, s->prefix, &onebuf);
247 status_printf(s, color(WT_STATUS_HEADER, s), "\t");
248 switch (d->stagemask) {
249 case 1: how = _("both deleted:"); break;
@@ -297,8 +297,8 @@ static void wt_status_print_change_data(struct wt_status *s,
297 change_type);
298 }
299
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);
302
303 status_printf(s, color(WT_STATUS_HEADER, s), "\t");
304 switch (status) {
@@ -706,8 +706,7 @@ static void wt_status_print_other(struct wt_status *s,
706 struct string_list_item *it;
707 const char *path;
708 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);
710 if (column_active(s->colopts)) {
711 string_list_append(&output, path);
712 continue;
@@ -1289,7 +1288,7 @@ static void wt_shortstatus_unmerged(struct string_list_item *it,
1288 } else {
1289 struct strbuf onebuf = STRBUF_INIT;
1290 const char *one;
1292 - one = quote_path(it->string, -1, &onebuf, s->prefix);
1291 + one = quote_path(it->string, s->prefix, &onebuf);
1292 printf(" %s\n", one);
1293 strbuf_release(&onebuf);
1294 }
@@ -1317,7 +1316,7 @@ static void wt_shortstatus_status(struct string_list_item *it,
1316 struct strbuf onebuf = STRBUF_INIT;
1317 const char *one;
1318 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);
1320 if (*one != '"' && strchr(one, ' ') != NULL) {
1321 putchar('"');
1322 strbuf_addch(&onebuf, '"');
@@ -1326,7 +1325,7 @@ static void wt_shortstatus_status(struct string_list_item *it,
1325 printf("%s -> ", one);
1326 strbuf_release(&onebuf);
1327 }
1329 - one = quote_path(it->string, -1, &onebuf, s->prefix);
1328 + one = quote_path(it->string, s->prefix, &onebuf);
1329 if (*one != '"' && strchr(one, ' ') != NULL) {
1330 putchar('"');
1331 strbuf_addch(&onebuf, '"');
@@ -1345,7 +1344,7 @@ static void wt_shortstatus_other(struct string_list_item *it,
1344 } else {
1345 struct strbuf onebuf = STRBUF_INIT;
1346 const char *one;
1348 - one = quote_path(it->string, -1, &onebuf, s->prefix);
1347 + one = quote_path(it->string, s->prefix, &onebuf);
1348 color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign);
1349 printf(" %s\n", one);
1350 strbuf_release(&onebuf);