{"thread":{"id":"43658","subject":"Re: [PATCH] git-mv: search more precisely for source directory in index","startedAt":"2006-12-03T13:57:25Z","lastAt":"2006-12-03T20:04:18Z","messageCount":3,"participants":["Sergey Vlasov","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"298578","messageId":"20061203135725.GA7971@procyon.home","threadId":"43658","inReplyTo":null,"subject":"[BUG] git-mv fails with \"source directory is empty\" when it should not","fromName":"Sergey Vlasov","fromEmail":"vsu@altlinux.ru","sentAt":"2006-12-03T13:57:25Z","receivedAt":"2006-12-03T13:57:25Z","isPatch":false,"sender":{"key":"vsu@altlinux.ru","avatar":"https://avatars.githubusercontent.com/u/616082?v=4"},"body":"Hello!\n\nIn some cases git-mv fails with \"source directory is empty\" when this\nis definitely not the case.\n\nExample (run in an empty directory):\n\n$ git init-db\ndefaulting to local storage area\n$ mkdir ab; touch ab.c; touch ab/d\n$ git add .\n$ git commit -m 'initial'\nCommitting initial tree f2dd231ec22a1d4376d4a6eadf49d87dd34ac2a0\n$ git mv ab a\nfatal: source directory is empty, source=ab, destination=a\n\nHowever, at this point the source directory is definitely not empty:\n\n$ git ls-tree -r HEAD\n100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391    ab.c\n100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391    ab/d\n$ ls -ogR\n.:\ntotal 4\ndrwxr-xr-x 2 4096 Dec  3 16:47 ab\n-rw-r--r-- 1    0 Dec  3 16:47 ab.c\n\n./ab:\ntotal 0\n-rw-r--r-- 1 0 Dec  3 16:47 d\n$ git status     \nnothing to commit\n\nThis happens both in v1.4.4.1 and in current 'master' (v1.4.4.1-g278fcd7).\n\n-- \nSergey Vlasov\n"},{"id":"297679","messageId":"Pine.LNX.4.63.0612032036030.28348@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43658","inReplyTo":"20061203135725.GA7971@procyon.home","subject":"[PATCH] git-mv: search more precisely for source directory in index","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-03T19:42:47Z","receivedAt":"2006-12-03T19:42:47Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nA move of a directory should find the entries in the index by\nsearching for the name _including_ the slash. Otherwise, the\ndirectory can be shadowed by a file when it matches the prefix\nand is lexicographically smaller, e.g. \"ab.c\" shadows \"ab/\".\n\nNoticed by Sergey Vlasov.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n---\n\n\tGood catch. Thanks!\n\n builtin-mv.c |   11 +++++++----\n 1 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-mv.c b/builtin-mv.c\nindex 54dd3bf..d14a4a7 100644\n--- a/builtin-mv.c\n+++ b/builtin-mv.c\n@@ -146,21 +146,24 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t\t&& lstat(dst, &st) == 0)\n \t\t\tbad = \"cannot move directory over file\";\n \t\telse if (src_is_dir) {\n+\t\t\tconst char *src_w_slash = add_slash(src);\n+\t\t\tint len_w_slash = length + 1;\n \t\t\tint first, last;\n \n \t\t\tmodes[i] = WORKING_DIRECTORY;\n \n-\t\t\tfirst = cache_name_pos(src, length);\n+\t\t\tfirst = cache_name_pos(src_w_slash, len_w_slash);\n \t\t\tif (first >= 0)\n-\t\t\t\tdie (\"Huh? %s/ is in index?\", src);\n+\t\t\t\tdie (\"Huh? %.*s is in index?\",\n+\t\t\t\t\t\tlen_w_slash, src_w_slash);\n \n \t\t\tfirst = -1 - first;\n \t\t\tfor (last = first; last < active_nr; last++) {\n \t\t\t\tconst char *path = active_cache[last]->name;\n-\t\t\t\tif (strncmp(path, src, length)\n-\t\t\t\t\t\t|| path[length] != '/')\n+\t\t\t\tif (strncmp(path, src_w_slash, len_w_slash))\n \t\t\t\t\tbreak;\n \t\t\t}\n+\t\t\tfree((char *)src_w_slash);\n \n \t\t\tif (last - first < 1)\n \t\t\t\tbad = \"source directory is empty\";\n-- \n1.4.4.1.g317bd\n"},{"id":"296383","messageId":"20061203200418.GC7971@procyon.home","threadId":"43658","inReplyTo":"Pine.LNX.4.63.0612032036030.28348@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] git-mv: search more precisely for source directory in index","fromName":"Sergey Vlasov","fromEmail":"vsu@altlinux.ru","sentAt":"2006-12-03T20:04:18Z","receivedAt":"2006-12-03T20:04:18Z","isPatch":true,"sender":{"key":"vsu@altlinux.ru","avatar":"https://avatars.githubusercontent.com/u/616082?v=4"},"body":"On Sun, Dec 03, 2006 at 08:42:47PM +0100, Johannes Schindelin wrote:\n> \n> A move of a directory should find the entries in the index by\n> searching for the name _including_ the slash. Otherwise, the\n> directory can be shadowed by a file when it matches the prefix\n> and is lexicographically smaller, e.g. \"ab.c\" shadows \"ab/\".\n\nThanks - seems to work now, and the existing tests are not broken.\n\n> Noticed by Sergey Vlasov.\n> \n> Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n> ---\n> \n> \tGood catch. Thanks!\n> \n>  builtin-mv.c |   11 +++++++----\n>  1 files changed, 7 insertions(+), 4 deletions(-)\n> \n> diff --git a/builtin-mv.c b/builtin-mv.c\n> index 54dd3bf..d14a4a7 100644\n> --- a/builtin-mv.c\n> +++ b/builtin-mv.c\n> @@ -146,21 +146,24 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n>  \t\t\t\t&& lstat(dst, &st) == 0)\n>  \t\t\tbad = \"cannot move directory over file\";\n>  \t\telse if (src_is_dir) {\n> +\t\t\tconst char *src_w_slash = add_slash(src);\n> +\t\t\tint len_w_slash = length + 1;\n>  \t\t\tint first, last;\n>  \n>  \t\t\tmodes[i] = WORKING_DIRECTORY;\n>  \n> -\t\t\tfirst = cache_name_pos(src, length);\n> +\t\t\tfirst = cache_name_pos(src_w_slash, len_w_slash);\n>  \t\t\tif (first >= 0)\n> -\t\t\t\tdie (\"Huh? %s/ is in index?\", src);\n> +\t\t\t\tdie (\"Huh? %.*s is in index?\",\n> +\t\t\t\t\t\tlen_w_slash, src_w_slash);\n>  \n>  \t\t\tfirst = -1 - first;\n>  \t\t\tfor (last = first; last < active_nr; last++) {\n>  \t\t\t\tconst char *path = active_cache[last]->name;\n> -\t\t\t\tif (strncmp(path, src, length)\n> -\t\t\t\t\t\t|| path[length] != '/')\n> +\t\t\t\tif (strncmp(path, src_w_slash, len_w_slash))\n>  \t\t\t\t\tbreak;\n>  \t\t\t}\n> +\t\t\tfree((char *)src_w_slash);\n>  \n>  \t\t\tif (last - first < 1)\n>  \t\t\t\tbad = \"source directory is empty\";\n"}]}