{"thread":{"id":"12529","subject":"[PATCH v2] git-clean: correct printing relative path","startedAt":"2008-03-05T23:51:05Z","lastAt":"2008-03-05T23:51:05Z","messageCount":1,"participants":["Dmitry Potapov"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"71150","messageId":"20080305235105.GE11519@dpotapov.dyndns.org","threadId":"12529","inReplyTo":null,"subject":"[PATCH v2] git-clean: correct printing relative path","fromName":"Dmitry Potapov","fromEmail":"dpotapov@gmail.com","sentAt":"2008-03-05T23:51:05Z","receivedAt":"2008-03-05T23:51:05Z","isPatch":true,"sender":{"key":"dpotapov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6568595?v=4"},"body":"When the given path contains '..' then git-clean incorrectly printed names\nof files. This patch changes cmd_clean to use quote_path() from wt-status.\nAlso, \"failed to remove ...\" message used absolutely path, but not it is\ncorrected to use relative path.\n\nSigned-off-by: Dmitry Potapov <dpotapov@gmail.com>\n---\nAdd missing include \"wt-status.h\"\n\n builtin-clean.c |   32 ++++++++++++++------------------\n wt-status.c     |    4 ++--\n wt-status.h     |    2 ++\n 3 files changed, 18 insertions(+), 20 deletions(-)\n\ndiff --git a/builtin-clean.c b/builtin-clean.c\nindex 3b220d5..c3b29b9 100644\n--- a/builtin-clean.c\n+++ b/builtin-clean.c\n@@ -10,6 +10,7 @@\n #include \"cache.h\"\n #include \"dir.h\"\n #include \"parse-options.h\"\n+#include \"wt-status.h\"\n \n static int force = -1; /* unset */\n \n@@ -34,7 +35,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \tstruct dir_struct dir;\n \tconst char *path, *base;\n \tstatic const char **pathspec;\n-\tint prefix_offset = 0;\n+\tstruct strbuf buf;\n+\tconst char *qname;\n \tchar *seen = NULL;\n \tstruct option options[] = {\n \t\tOPT__QUIET(&quiet),\n@@ -56,6 +58,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \n \targc = parse_options(argc, argv, options, builtin_clean_usage, 0);\n \n+\tstrbuf_init(&buf, 0);\n \tmemset(&dir, 0, sizeof(dir));\n \tif (ignored_only)\n \t\tdir.show_ignored = 1;\n@@ -72,8 +75,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \tif (!ignored)\n \t\tsetup_standard_excludes(&dir);\n \n-\tif (prefix)\n-\t\tprefix_offset = strlen(prefix);\n \tpathspec = get_pathspec(prefix, argv);\n \tread_cache();\n \n@@ -133,40 +134,35 @@ int cmd_clean(int argc, const char **argv, const char *prefix)\n \t\t}\n \n \t\tif (S_ISDIR(st.st_mode)) {\n+\t\t\tqname = quote_path(directory.buf, -1, &buf, prefix);\n \t\t\tstrbuf_addstr(&directory, ent->name);\n \t\t\tif (show_only && (remove_directories || matches)) {\n-\t\t\t\tprintf(\"Would remove %s\\n\",\n-\t\t\t\t       directory.buf + prefix_offset);\n+\t\t\t\tprintf(\"Would remove %s\\n\", qname);\n \t\t\t} else if (remove_directories || matches) {\n \t\t\t\tif (!quiet)\n-\t\t\t\t\tprintf(\"Removing %s\\n\",\n-\t\t\t\t\t       directory.buf + prefix_offset);\n+\t\t\t\t\tprintf(\"Removing %s\\n\", qname);\n \t\t\t\tif (remove_dir_recursively(&directory, 0) != 0) {\n-\t\t\t\t\twarning(\"failed to remove '%s'\",\n-\t\t\t\t\t\tdirectory.buf + prefix_offset);\n+\t\t\t\t\twarning(\"failed to remove '%s'\", qname);\n \t\t\t\t\terrors++;\n \t\t\t\t}\n \t\t\t} else if (show_only) {\n-\t\t\t\tprintf(\"Would not remove %s\\n\",\n-\t\t\t\t       directory.buf + prefix_offset);\n+\t\t\t\tprintf(\"Would not remove %s\\n\", qname);\n \t\t\t} else {\n-\t\t\t\tprintf(\"Not removing %s\\n\",\n-\t\t\t\t       directory.buf + prefix_offset);\n+\t\t\t\tprintf(\"Not removing %s\\n\", qname);\n \t\t\t}\n \t\t\tstrbuf_reset(&directory);\n \t\t} else {\n \t\t\tif (pathspec && !matches)\n \t\t\t\tcontinue;\n+\t\t\tqname = quote_path(ent->name, -1, &buf, prefix);\n \t\t\tif (show_only) {\n-\t\t\t\tprintf(\"Would remove %s\\n\",\n-\t\t\t\t       ent->name + prefix_offset);\n+\t\t\t\tprintf(\"Would remove %s\\n\", qname);\n \t\t\t\tcontinue;\n \t\t\t} else if (!quiet) {\n-\t\t\t\tprintf(\"Removing %s\\n\",\n-\t\t\t\t       ent->name + prefix_offset);\n+\t\t\t\tprintf(\"Removing %s\\n\", qname);\n \t\t\t}\n \t\t\tif (unlink(ent->name) != 0) {\n-\t\t\t\twarning(\"failed to remove '%s'\", ent->name);\n+\t\t\t\twarning(\"failed to remove '%s'\", qname);\n \t\t\t\terrors++;\n \t\t\t}\n \t\t}\ndiff --git a/wt-status.c b/wt-status.c\nindex 32d780a..712fe91 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -82,8 +82,8 @@ static void wt_status_print_trailer(struct wt_status *s)\n \tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER), \"#\");\n }\n \n-static char *quote_path(const char *in, int len,\n-\t\t\tstruct strbuf *out, const char *prefix)\n+char *quote_path(const char *in, int len,\n+\t\tstruct strbuf *out, const char *prefix)\n {\n \tif (len < 0)\n \t\tlen = strlen(in);\ndiff --git a/wt-status.h b/wt-status.h\nindex 02afaa6..4b46dda 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -32,5 +32,7 @@ int wt_status_use_color;\n int wt_status_relative_paths;\n void wt_status_prepare(struct wt_status *s);\n void wt_status_print(struct wt_status *s);\n+char *quote_path(const char *in, int len,\n+\t\tstruct strbuf *out, const char *prefix);\n \n #endif /* STATUS_H */\n-- \n1.5.4.3.448.g0426d\n\n"}]}