Re: [PATCH v14 04/16] Refactor quote_path_relative, remove unused params
2013/6/25 Junio C Hamano : > Jiang Xin writes: > >> After substitute path_relative() in quote.c with relative_path() from >> path.c, parameters (such as len and prefix_len) are obsolete in function >> quote_path_relative(). Remove unused parameters and change the order of >> parameters for quote_path_relative() function. >> ... >> diff --git a/builtin/clean.c b/builtin/clean.c >> index 04e39..f77f95 100644 >> --- a/builtin/clean.c >> +++ b/builtin/clean.c >> @@ -262,7 +262,7 @@ int cmd_clean(int argc, const char **argv, const char >> *prefix) >> if (remove_dirs(&directory, prefix, rm_flags, >> dry_run, quiet, &gone)) >> errors++; >> if (gone && !quiet) { >> - qname = >> quote_path_relative(directory.buf, directory.len, &buf, prefix); >> + qname = >> quote_path_relative(directory.buf, prefix, &buf); >> printf(dry_run ? _(msg_would_remove) : >> _(msg_remove), qname); > > This one needed a bit closer look to make sure directory.len is > already pointing at the end of directory.buf (it is) to verify that > this is a safe conversion. Everywhere else we lost either -1 or > strlen() of the string we feed quote_path() and quote_path_relative() > so they look fine. When tracking in "remove_dirs(&directory, prefix, rm_flags, dry_run, quiet, &gone)", there are some suspect strbuf_setlens, like: strbuf_setlen(path, len); strbuf_addstr(path, e->d_name); and at the end of remove_dirs, there is: strbuf_setlen(path, original_len); So both the but and len will be restored in the end, and directory.len always points to strlen of directory.buf. So it's safe for the following refactor: - qname = quote_path_relative(directory.buf, directory.len, &buf, prefix); + qname = quote_path_relative(directory.buf, prefix, &buf); -- Jiang Xin -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v14 04/16] Refactor quote_path_relative, remove unused params
Jiang Xin writes: > After substitute path_relative() in quote.c with relative_path() from > path.c, parameters (such as len and prefix_len) are obsolete in function > quote_path_relative(). Remove unused parameters and change the order of > parameters for quote_path_relative() function. > ... > diff --git a/builtin/clean.c b/builtin/clean.c > index 04e39..f77f95 100644 > --- a/builtin/clean.c > +++ b/builtin/clean.c > @@ -262,7 +262,7 @@ int cmd_clean(int argc, const char **argv, const char > *prefix) > if (remove_dirs(&directory, prefix, rm_flags, > dry_run, quiet, &gone)) > errors++; > if (gone && !quiet) { > - qname = > quote_path_relative(directory.buf, directory.len, &buf, prefix); > + qname = > quote_path_relative(directory.buf, prefix, &buf); > printf(dry_run ? _(msg_would_remove) : > _(msg_remove), qname); This one needed a bit closer look to make sure directory.len is already pointing at the end of directory.buf (it is) to verify that this is a safe conversion. Everywhere else we lost either -1 or strlen() of the string we feed quote_path() and quote_path_relative() so they look fine. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v14 04/16] Refactor quote_path_relative, remove unused params
After substitute path_relative() in quote.c with relative_path() from path.c, parameters (such as len and prefix_len) are obsolete in function quote_path_relative(). Remove unused parameters and change the order of parameters for quote_path_relative() function. Signed-off-by: Jiang Xin Signed-off-by: Junio C Hamano --- builtin/clean.c| 18 +- builtin/grep.c | 5 ++--- builtin/ls-files.c | 2 +- quote.c| 7 ++- quote.h| 4 ++-- wt-status.c| 17 - 6 files changed, 24 insertions(+), 29 deletions(-) diff --git a/builtin/clean.c b/builtin/clean.c index 04e39..f77f95 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -56,7 +56,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, if ((force_flag & REMOVE_DIR_KEEP_NESTED_GIT) && !resolve_gitlink_ref(path->buf, "HEAD", submodule_head)) { if (!quiet) { - quote_path_relative(path->buf, strlen(path->buf), "ed, prefix); + quote_path_relative(path->buf, prefix, "ed); printf(dry_run ? _(msg_would_skip_git_dir) : _(msg_skip_git_dir), quoted.buf); } @@ -70,7 +70,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, /* an empty dir could be removed even if it is unreadble */ res = dry_run ? 0 : rmdir(path->buf); if (res) { - quote_path_relative(path->buf, strlen(path->buf), "ed, prefix); + quote_path_relative(path->buf, prefix, "ed); warning(_(msg_warn_remove_failed), quoted.buf); *dir_gone = 0; } @@ -94,7 +94,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, if (remove_dirs(path, prefix, force_flag, dry_run, quiet, &gone)) ret = 1; if (gone) { - quote_path_relative(path->buf, strlen(path->buf), "ed, prefix); + quote_path_relative(path->buf, prefix, "ed); string_list_append(&dels, quoted.buf); } else *dir_gone = 0; @@ -102,10 +102,10 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, } else { res = dry_run ? 0 : unlink(path->buf); if (!res) { - quote_path_relative(path->buf, strlen(path->buf), "ed, prefix); + quote_path_relative(path->buf, prefix, "ed); string_list_append(&dels, quoted.buf); } else { - quote_path_relative(path->buf, strlen(path->buf), "ed, prefix); + quote_path_relative(path->buf, prefix, "ed); warning(_(msg_warn_remove_failed), quoted.buf); *dir_gone = 0; ret = 1; @@ -127,7 +127,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag, if (!res) *dir_gone = 1; else { - quote_path_relative(path->buf, strlen(path->buf), "ed, prefix); + quote_path_relative(path->buf, prefix, "ed); warning(_(msg_warn_remove_failed), quoted.buf); *dir_gone = 0; ret = 1; @@ -262,7 +262,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) if (remove_dirs(&directory, prefix, rm_flags, dry_run, quiet, &gone)) errors++; if (gone && !quiet) { - qname = quote_path_relative(directory.buf, directory.len, &buf, prefix); + qname = quote_path_relative(directory.buf, prefix, &buf); printf(dry_run ? _(msg_would_remove) : _(msg_remove), qname); } } @@ -272,11 +272,11 @@ int cmd_clean(int argc, const char **argv, const char *prefix) continue; res = dry_run ? 0 : unlink(ent->name); if (res) { - qname = quote_path_relative(ent->name, -1, &buf, prefix); + qname = quote_path_relative(ent->name, prefix, &buf); warning(_(msg_warn_remove_failed), qname); errors++; } else if (!quiet) {