{"thread":{"id":"37319","subject":"[PATCH v2 0/8] builtin/mv.c cleanup","startedAt":"2014-08-10T02:29:28Z","lastAt":"2014-08-12T17:56:37Z","messageCount":12,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano","Duy Nguyen"],"isPatch":true,"patchVersion":2,"patchTotal":8},"messages":[{"id":"247535","messageId":"1407637776-19794-1-git-send-email-pclouds@gmail.com","threadId":"37319","inReplyTo":null,"subject":"[PATCH v2 0/8] builtin/mv.c cleanup","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-10T02:29:28Z","receivedAt":"2014-08-10T02:29:28Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Interdiff on v1 below. I'm not going with MOVE_UP_BY_ONE because [1]\nseems to agree with the name CLOSE_GAP, but that should be a separate\ntopic (touching more than just mv.c)\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/243675/focus=244390\n\n-- 8< --\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 4eb420b..bf513e0 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -58,11 +58,6 @@ static const char *add_slash(const char *path)\n \treturn path;\n }\n \n-static void move_up_one(void *p, int nmemb, int size)\n-{\n-\tmemmove(p, (char*)p + size, nmemb * size);\n-}\n-\n static struct lock_file lock_file;\n #define SUBMODULE_WITH_GITDIR ((const char *)1)\n \n@@ -71,9 +66,9 @@ static void prepare_move_submodule(const char *src, int first,\n {\n \tstruct strbuf submodule_dotgit = STRBUF_INIT;\n \tif (!S_ISGITLINK(active_cache[first]->ce_mode))\n-\t\tdie (_(\"Directory %s is in index and no submodule?\"), src);\n+\t\tdie(_(\"Directory %s is in index and no submodule?\"), src);\n \tif (!is_staging_gitmodules_ok())\n-\t\tdie (_(\"Please, stage your changes to .gitmodules or stash them to proceed\"));\n+\t\tdie(_(\"Please stage your changes to .gitmodules or stash them to proceed\"));\n \tstrbuf_addf(&submodule_dotgit, \"%s/.git\", src);\n \t*submodule_gitfile = read_gitfile(submodule_dotgit.buf);\n \tif (*submodule_gitfile)\n@@ -91,7 +86,7 @@ static int index_range_of_same_dir(const char *src, int length,\n \n \tfirst = cache_name_pos(src_w_slash, len_w_slash);\n \tif (first >= 0)\n-\t\tdie (_(\"%.*s is in index\"), len_w_slash, src_w_slash);\n+\t\tdie(_(\"%.*s is in index\"), len_w_slash, src_w_slash);\n \n \tfirst = -1 - first;\n \tfor (last = first; last < active_nr; last++) {\n@@ -235,14 +230,18 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tif (!bad)\n \t\t\tcontinue;\n \t\tif (!ignore_errors)\n-\t\t\tdie (_(\"%s, source=%s, destination=%s\"),\n+\t\t\tdie(_(\"%s, source=%s, destination=%s\"),\n \t\t\t     bad, src, dst);\n \t\tif (--argc > 0) {\n \t\t\tint n = argc - i;\n-\t\t\tmove_up_one(source + i, n, sizeof(*source));\n-\t\t\tmove_up_one(destination + i, n, sizeof(*destination));\n-\t\t\tmove_up_one(modes + i, n, sizeof(*modes));\n-\t\t\tmove_up_one(submodule_gitfile + i, n, sizeof(*submodule_gitfile));\n+\t\t\tmemmove(source + i, source + i + 1,\n+\t\t\t\tn * sizeof(char *));\n+\t\t\tmemmove(destination + i, destination + i + 1,\n+\t\t\t\tn * sizeof(char *));\n+\t\t\tmemmove(modes + i, modes + i + 1,\n+\t\t\t\tn * sizeof(enum update_mode));\n+\t\t\tmemmove(submodule_gitfile + i, submodule_gitfile + i + 1,\n+\t\t\t\tn * sizeof(char *));\n \t\t\ti--;\n \t\t}\n \t}\n@@ -255,7 +254,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tprintf(_(\"Renaming %s to %s\\n\"), src, dst);\n \t\tif (!show_only && mode != INDEX) {\n \t\t\tif (rename(src, dst) < 0 && !ignore_errors)\n-\t\t\t\tdie_errno (_(\"renaming '%s' failed\"), src);\n+\t\t\t\tdie_errno(_(\"renaming '%s' failed\"), src);\n \t\t\tif (submodule_gitfile[i]) {\n \t\t\t\tif (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR)\n \t\t\t\t\tconnect_work_tree_and_git_dir(dst, submodule_gitfile[i]);\n@@ -278,7 +277,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \n \tif (active_cache_changed &&\n \t    write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n-\t\t\tdie(_(\"Unable to write new index file\"));\n+\t\tdie(_(\"Unable to write new index file\"));\n \n \treturn 0;\n }\n-- 8< --\n\nNguyễn Thái Ngọc Duy (8):\n  mv: mark strings for translations\n  mv: flatten error handling code block\n  mv: split submodule move preparation code out\n  mv: remove an \"if\" that's always true\n  mv: move index search code out\n  mv: unindent one level for directory move code\n  mv: combine two if(s)\n  mv: no SP between function name and the first opening parenthese\n\n builtin/mv.c | 171 +++++++++++++++++++++++++++++------------------------------\n 1 file changed, 85 insertions(+), 86 deletions(-)\n\n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247536","messageId":"1407637776-19794-2-git-send-email-pclouds@gmail.com","threadId":"37319","inReplyTo":"1407637776-19794-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 1/8] mv: mark strings for translations","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-10T02:29:29Z","receivedAt":"2014-08-10T02:29:29Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/mv.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 6ffe540..b892f63 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -108,7 +108,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tdestination = internal_copy_pathspec(dest_path[0], argv, argc, DUP_BASENAME);\n \t} else {\n \t\tif (argc != 1)\n-\t\t\tdie(\"destination '%s' is not a directory\", dest_path[0]);\n+\t\t\tdie(_(\"destination '%s' is not a directory\"), dest_path[0]);\n \t\tdestination = dest_path;\n \t}\n \n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247537","messageId":"1407637776-19794-3-git-send-email-pclouds@gmail.com","threadId":"37319","inReplyTo":"1407637776-19794-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 2/8] mv: flatten error handling code block","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-10T02:29:30Z","receivedAt":"2014-08-10T02:29:30Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/mv.c | 34 ++++++++++++++++------------------\n 1 file changed, 16 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex b892f63..c48129e 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -225,24 +225,22 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\telse\n \t\t\tstring_list_insert(&src_for_dst, dst);\n \n-\t\tif (bad) {\n-\t\t\tif (ignore_errors) {\n-\t\t\t\tif (--argc > 0) {\n-\t\t\t\t\tmemmove(source + i, source + i + 1,\n-\t\t\t\t\t\t(argc - i) * sizeof(char *));\n-\t\t\t\t\tmemmove(destination + i,\n-\t\t\t\t\t\tdestination + i + 1,\n-\t\t\t\t\t\t(argc - i) * sizeof(char *));\n-\t\t\t\t\tmemmove(modes + i, modes + i + 1,\n-\t\t\t\t\t\t(argc - i) * sizeof(enum update_mode));\n-\t\t\t\t\tmemmove(submodule_gitfile + i,\n-\t\t\t\t\t\tsubmodule_gitfile + i + 1,\n-\t\t\t\t\t\t(argc - i) * sizeof(char *));\n-\t\t\t\t\ti--;\n-\t\t\t\t}\n-\t\t\t} else\n-\t\t\t\tdie (_(\"%s, source=%s, destination=%s\"),\n-\t\t\t\t     bad, src, dst);\n+\t\tif (!bad)\n+\t\t\tcontinue;\n+\t\tif (!ignore_errors)\n+\t\t\tdie (_(\"%s, source=%s, destination=%s\"),\n+\t\t\t     bad, src, dst);\n+\t\tif (--argc > 0) {\n+\t\t\tint n = argc - i;\n+\t\t\tmemmove(source + i, source + i + 1,\n+\t\t\t\tn * sizeof(char *));\n+\t\t\tmemmove(destination + i, destination + i + 1,\n+\t\t\t\tn * sizeof(char *));\n+\t\t\tmemmove(modes + i, modes + i + 1,\n+\t\t\t\tn * sizeof(enum update_mode));\n+\t\t\tmemmove(submodule_gitfile + i, submodule_gitfile + i + 1,\n+\t\t\t\tn * sizeof(char *));\n+\t\t\ti--;\n \t\t}\n \t}\n \n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247538","messageId":"1407637776-19794-4-git-send-email-pclouds@gmail.com","threadId":"37319","inReplyTo":"1407637776-19794-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 3/8] mv: split submodule move preparation code out","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-10T02:29:31Z","receivedAt":"2014-08-10T02:29:31Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\"Huh?\" is removed from die() message.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/mv.c | 35 +++++++++++++++++++++--------------\n 1 file changed, 21 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex c48129e..524f4e5 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -61,6 +61,23 @@ static const char *add_slash(const char *path)\n static struct lock_file lock_file;\n #define SUBMODULE_WITH_GITDIR ((const char *)1)\n \n+static void prepare_move_submodule(const char *src, int first,\n+\t\t\t\t   const char **submodule_gitfile)\n+{\n+\tstruct strbuf submodule_dotgit = STRBUF_INIT;\n+\tif (!S_ISGITLINK(active_cache[first]->ce_mode))\n+\t\tdie(_(\"Directory %s is in index and no submodule?\"), src);\n+\tif (!is_staging_gitmodules_ok())\n+\t\tdie(_(\"Please stage your changes to .gitmodules or stash them to proceed\"));\n+\tstrbuf_addf(&submodule_dotgit, \"%s/.git\", src);\n+\t*submodule_gitfile = read_gitfile(submodule_dotgit.buf);\n+\tif (*submodule_gitfile)\n+\t\t*submodule_gitfile = xstrdup(*submodule_gitfile);\n+\telse\n+\t\t*submodule_gitfile = SUBMODULE_WITH_GITDIR;\n+\tstrbuf_release(&submodule_dotgit);\n+}\n+\n int cmd_mv(int argc, const char **argv, const char *prefix)\n {\n \tint i, gitmodules_modified = 0;\n@@ -132,20 +149,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tbad = _(\"cannot move directory over file\");\n \t\telse if (src_is_dir) {\n \t\t\tint first = cache_name_pos(src, length);\n-\t\t\tif (first >= 0) {\n-\t\t\t\tstruct strbuf submodule_dotgit = STRBUF_INIT;\n-\t\t\t\tif (!S_ISGITLINK(active_cache[first]->ce_mode))\n-\t\t\t\t\tdie (_(\"Huh? Directory %s is in index and no submodule?\"), src);\n-\t\t\t\tif (!is_staging_gitmodules_ok())\n-\t\t\t\t\tdie (_(\"Please, stage your changes to .gitmodules or stash them to proceed\"));\n-\t\t\t\tstrbuf_addf(&submodule_dotgit, \"%s/.git\", src);\n-\t\t\t\tsubmodule_gitfile[i] = read_gitfile(submodule_dotgit.buf);\n-\t\t\t\tif (submodule_gitfile[i])\n-\t\t\t\t\tsubmodule_gitfile[i] = xstrdup(submodule_gitfile[i]);\n-\t\t\t\telse\n-\t\t\t\t\tsubmodule_gitfile[i] = SUBMODULE_WITH_GITDIR;\n-\t\t\t\tstrbuf_release(&submodule_dotgit);\n-\t\t\t} else {\n+\t\t\tif (first >= 0)\n+\t\t\t\tprepare_move_submodule(src, first,\n+\t\t\t\t\t\t       submodule_gitfile + i);\n+\t\t\telse {\n \t\t\t\tconst char *src_w_slash = add_slash(src);\n \t\t\t\tint last, len_w_slash = length + 1;\n \n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247539","messageId":"1407637776-19794-5-git-send-email-pclouds@gmail.com","threadId":"37319","inReplyTo":"1407637776-19794-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 4/8] mv: remove an \"if\" that's always true","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-10T02:29:32Z","receivedAt":"2014-08-10T02:29:32Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This is inside an \"else\" block of \"if (last - first < 1)\", so we know\nthat \"last - first >= 1\" when we come here. No need to check\n\"last - first > 0\".\n\nWhile at there, save \"argc + last - first\" to a variable to shorten\nthe statements a bit.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/mv.c | 22 +++++++---------------\n 1 file changed, 7 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 524f4e5..0732355 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -175,22 +175,14 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t\tif (last - first < 1)\n \t\t\t\t\tbad = _(\"source directory is empty\");\n \t\t\t\telse {\n-\t\t\t\t\tint j, dst_len;\n+\t\t\t\t\tint j, dst_len, n;\n \n-\t\t\t\t\tif (last - first > 0) {\n-\t\t\t\t\t\tsource = xrealloc(source,\n-\t\t\t\t\t\t\t\t(argc + last - first)\n-\t\t\t\t\t\t\t\t* sizeof(char *));\n-\t\t\t\t\t\tdestination = xrealloc(destination,\n-\t\t\t\t\t\t\t\t(argc + last - first)\n-\t\t\t\t\t\t\t\t* sizeof(char *));\n-\t\t\t\t\t\tmodes = xrealloc(modes,\n-\t\t\t\t\t\t\t\t(argc + last - first)\n-\t\t\t\t\t\t\t\t* sizeof(enum update_mode));\n-\t\t\t\t\t\tsubmodule_gitfile = xrealloc(submodule_gitfile,\n-\t\t\t\t\t\t\t\t(argc + last - first)\n-\t\t\t\t\t\t\t\t* sizeof(char *));\n-\t\t\t\t\t}\n+\t\t\t\t\tn = argc + last - first;\n+\t\t\t\t\tsource = xrealloc(source, n * sizeof(char *));\n+\t\t\t\t\tdestination = xrealloc(destination, n * sizeof(char *));\n+\t\t\t\t\tmodes = xrealloc(modes, n * sizeof(enum update_mode));\n+\t\t\t\t\tsubmodule_gitfile =\n+\t\t\t\t\t\txrealloc(submodule_gitfile, n * sizeof(char *));\n \n \t\t\t\t\tdst = add_slash(dst);\n \t\t\t\t\tdst_len = strlen(dst);\n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247540","messageId":"1407637776-19794-6-git-send-email-pclouds@gmail.com","threadId":"37319","inReplyTo":"1407637776-19794-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 5/8] mv: move index search code out","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-10T02:29:33Z","receivedAt":"2014-08-10T02:29:33Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\"Huh?\" is removed from die() message.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/mv.c | 42 +++++++++++++++++++++++++-----------------\n 1 file changed, 25 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 0732355..dcfcb11 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -78,6 +78,29 @@ static void prepare_move_submodule(const char *src, int first,\n \tstrbuf_release(&submodule_dotgit);\n }\n \n+static int index_range_of_same_dir(const char *src, int length,\n+\t\t\t\t   int *first_p, int *last_p)\n+{\n+\tconst char *src_w_slash = add_slash(src);\n+\tint first, last, len_w_slash = length + 1;\n+\n+\tfirst = cache_name_pos(src_w_slash, len_w_slash);\n+\tif (first >= 0)\n+\t\tdie(_(\"%.*s is in index\"), len_w_slash, src_w_slash);\n+\n+\tfirst = -1 - first;\n+\tfor (last = first; last < active_nr; last++) {\n+\t\tconst char *path = active_cache[last]->name;\n+\t\tif (strncmp(path, src_w_slash, len_w_slash))\n+\t\t\tbreak;\n+\t}\n+\tif (src_w_slash != src)\n+\t\tfree((char *)src_w_slash);\n+\t*first_p = first;\n+\t*last_p = last;\n+\treturn last - first;\n+}\n+\n int cmd_mv(int argc, const char **argv, const char *prefix)\n {\n \tint i, gitmodules_modified = 0;\n@@ -153,25 +176,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\t\tprepare_move_submodule(src, first,\n \t\t\t\t\t\t       submodule_gitfile + i);\n \t\t\telse {\n-\t\t\t\tconst char *src_w_slash = add_slash(src);\n-\t\t\t\tint last, len_w_slash = length + 1;\n+\t\t\t\tint last;\n \n \t\t\t\tmodes[i] = WORKING_DIRECTORY;\n-\n-\t\t\t\tfirst = cache_name_pos(src_w_slash, len_w_slash);\n-\t\t\t\tif (first >= 0)\n-\t\t\t\t\tdie (_(\"Huh? %.*s is in index?\"),\n-\t\t\t\t\t\t\tlen_w_slash, src_w_slash);\n-\n-\t\t\t\tfirst = -1 - first;\n-\t\t\t\tfor (last = first; last < active_nr; last++) {\n-\t\t\t\t\tconst char *path = active_cache[last]->name;\n-\t\t\t\t\tif (strncmp(path, src_w_slash, len_w_slash))\n-\t\t\t\t\t\tbreak;\n-\t\t\t\t}\n-\t\t\t\tif (src_w_slash != src)\n-\t\t\t\t\tfree((char *)src_w_slash);\n-\n+\t\t\t\tindex_range_of_same_dir(src, length, &first, &last);\n \t\t\t\tif (last - first < 1)\n \t\t\t\t\tbad = _(\"source directory is empty\");\n \t\t\t\telse {\n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247541","messageId":"1407637776-19794-7-git-send-email-pclouds@gmail.com","threadId":"37319","inReplyTo":"1407637776-19794-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 6/8] mv: unindent one level for directory move code","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-10T02:29:34Z","receivedAt":"2014-08-10T02:29:34Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/mv.c | 47 +++++++++++++++++++++--------------------------\n 1 file changed, 21 insertions(+), 26 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex dcfcb11..988945c 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -171,42 +171,37 @@ 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\tint first = cache_name_pos(src, length);\n+\t\t\tint first = cache_name_pos(src, length), last;\n \t\t\tif (first >= 0)\n \t\t\t\tprepare_move_submodule(src, first,\n \t\t\t\t\t\t       submodule_gitfile + i);\n-\t\t\telse {\n-\t\t\t\tint last;\n-\n+\t\t\telse if (index_range_of_same_dir(src, length,\n+\t\t\t\t\t\t\t &first, &last) < 1) {\n \t\t\t\tmodes[i] = WORKING_DIRECTORY;\n-\t\t\t\tindex_range_of_same_dir(src, length, &first, &last);\n \t\t\t\tif (last - first < 1)\n \t\t\t\t\tbad = _(\"source directory is empty\");\n-\t\t\t\telse {\n-\t\t\t\t\tint j, dst_len, n;\n+\t\t\t} else { /* last - first >= 1 */\n+\t\t\t\tint j, dst_len, n;\n \n-\t\t\t\t\tn = argc + last - first;\n-\t\t\t\t\tsource = xrealloc(source, n * sizeof(char *));\n-\t\t\t\t\tdestination = xrealloc(destination, n * sizeof(char *));\n-\t\t\t\t\tmodes = xrealloc(modes, n * sizeof(enum update_mode));\n-\t\t\t\t\tsubmodule_gitfile =\n-\t\t\t\t\t\txrealloc(submodule_gitfile, n * sizeof(char *));\n+\t\t\t\tmodes[i] = WORKING_DIRECTORY;\n+\t\t\t\tn = argc + last - first;\n+\t\t\t\tsource = xrealloc(source, n * sizeof(char *));\n+\t\t\t\tdestination = xrealloc(destination, n * sizeof(char *));\n+\t\t\t\tmodes = xrealloc(modes, n * sizeof(enum update_mode));\n+\t\t\t\tsubmodule_gitfile = xrealloc(submodule_gitfile, n * sizeof(char *));\n \n-\t\t\t\t\tdst = add_slash(dst);\n-\t\t\t\t\tdst_len = strlen(dst);\n+\t\t\t\tdst = add_slash(dst);\n+\t\t\t\tdst_len = strlen(dst);\n \n-\t\t\t\t\tfor (j = 0; j < last - first; j++) {\n-\t\t\t\t\t\tconst char *path =\n-\t\t\t\t\t\t\tactive_cache[first + j]->name;\n-\t\t\t\t\t\tsource[argc + j] = path;\n-\t\t\t\t\t\tdestination[argc + j] =\n-\t\t\t\t\t\t\tprefix_path(dst, dst_len,\n-\t\t\t\t\t\t\t\tpath + length + 1);\n-\t\t\t\t\t\tmodes[argc + j] = INDEX;\n-\t\t\t\t\t\tsubmodule_gitfile[argc + j] = NULL;\n-\t\t\t\t\t}\n-\t\t\t\t\targc += last - first;\n+\t\t\t\tfor (j = 0; j < last - first; j++) {\n+\t\t\t\t\tconst char *path = active_cache[first + j]->name;\n+\t\t\t\t\tsource[argc + j] = path;\n+\t\t\t\t\tdestination[argc + j] =\n+\t\t\t\t\t\tprefix_path(dst, dst_len, path + length + 1);\n+\t\t\t\t\tmodes[argc + j] = INDEX;\n+\t\t\t\t\tsubmodule_gitfile[argc + j] = NULL;\n \t\t\t\t}\n+\t\t\t\targc += last - first;\n \t\t\t}\n \t\t} else if (cache_name_pos(src, length) < 0)\n \t\t\tbad = _(\"not under version control\");\n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247542","messageId":"1407637776-19794-8-git-send-email-pclouds@gmail.com","threadId":"37319","inReplyTo":"1407637776-19794-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 7/8] mv: combine two if(s)","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-10T02:29:35Z","receivedAt":"2014-08-10T02:29:35Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/mv.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 988945c..cbe220f 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -275,10 +275,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \tif (gitmodules_modified)\n \t\tstage_updated_gitmodules();\n \n-\tif (active_cache_changed) {\n-\t\tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n-\t\t\tdie(_(\"Unable to write new index file\"));\n-\t}\n+\tif (active_cache_changed &&\n+\t    write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n+\t\tdie(_(\"Unable to write new index file\"));\n \n \treturn 0;\n }\n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247543","messageId":"1407637776-19794-9-git-send-email-pclouds@gmail.com","threadId":"37319","inReplyTo":"1407637776-19794-1-git-send-email-pclouds@gmail.com","subject":"[PATCH v2 8/8] mv: no SP between function name and the first opening parenthese","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-10T02:29:36Z","receivedAt":"2014-08-10T02:29:36Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/mv.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex cbe220f..bf513e0 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -230,7 +230,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\tif (!bad)\n \t\t\tcontinue;\n \t\tif (!ignore_errors)\n-\t\t\tdie (_(\"%s, source=%s, destination=%s\"),\n+\t\t\tdie(_(\"%s, source=%s, destination=%s\"),\n \t\t\t     bad, src, dst);\n \t\tif (--argc > 0) {\n \t\t\tint n = argc - i;\n@@ -254,7 +254,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tprintf(_(\"Renaming %s to %s\\n\"), src, dst);\n \t\tif (!show_only && mode != INDEX) {\n \t\t\tif (rename(src, dst) < 0 && !ignore_errors)\n-\t\t\t\tdie_errno (_(\"renaming '%s' failed\"), src);\n+\t\t\t\tdie_errno(_(\"renaming '%s' failed\"), src);\n \t\t\tif (submodule_gitfile[i]) {\n \t\t\t\tif (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR)\n \t\t\t\t\tconnect_work_tree_and_git_dir(dst, submodule_gitfile[i]);\n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247588","messageId":"xmqq61hy7tii.fsf@gitster.dls.corp.google.com","threadId":"37319","inReplyTo":"1407637776-19794-7-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH v2 6/8] mv: unindent one level for directory move code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-08-11T18:47:49Z","receivedAt":"2014-08-11T18:47:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  builtin/mv.c | 47 +++++++++++++++++++++--------------------------\n>  1 file changed, 21 insertions(+), 26 deletions(-)\n>\n> diff --git a/builtin/mv.c b/builtin/mv.c\n> index dcfcb11..988945c 100644\n> --- a/builtin/mv.c\n> +++ b/builtin/mv.c\n> @@ -171,42 +171,37 @@ 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\tint first = cache_name_pos(src, length), last;\n>  \t\t\tif (first >= 0)\n>  \t\t\t\tprepare_move_submodule(src, first,\n>  \t\t\t\t\t\t       submodule_gitfile + i);\n> +\t\t\telse if (index_range_of_same_dir(src, length,\n> +\t\t\t\t\t\t\t &first, &last) < 1) {\n\nThe function returns (last - first), so (last - first) < 1 holds\ninside this block, right?\n\n>  \t\t\t\tmodes[i] = WORKING_DIRECTORY;\n>  \t\t\t\tif (last - first < 1)\n>  \t\t\t\t\tbad = _(\"source directory is empty\");\n\nThen do you need this conditional, or it is always bad here?\n\nIf it is always bad, then modes[i] do not need to be assigned to,\neither, I think.\n\nAm I missing something?\n\n> +\t\t\t} else { /* last - first >= 1 */\n> +\t\t\t\tint j, dst_len, n;\n\n> +\t\t\t\tmodes[i] = WORKING_DIRECTORY;\n> +\t\t\t\tn = argc + last - first;\n> ...\n\nOtherwise, perhaps squash this in?\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex bf513e0..bf784cb 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -172,15 +172,14 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n \t\t\tbad = _(\"cannot move directory over file\");\n \t\telse if (src_is_dir) {\n \t\t\tint first = cache_name_pos(src, length), last;\n+\n \t\t\tif (first >= 0)\n \t\t\t\tprepare_move_submodule(src, first,\n \t\t\t\t\t\t       submodule_gitfile + i);\n \t\t\telse if (index_range_of_same_dir(src, length,\n-\t\t\t\t\t\t\t &first, &last) < 1) {\n-\t\t\t\tmodes[i] = WORKING_DIRECTORY;\n-\t\t\t\tif (last - first < 1)\n-\t\t\t\t\tbad = _(\"source directory is empty\");\n-\t\t\t} else { /* last - first >= 1 */\n+\t\t\t\t\t\t\t &first, &last) < 1)\n+\t\t\t\tbad = _(\"source directory is empty\");\n+\t\t\telse { /* last - first >= 1 */\n \t\t\t\tint j, dst_len, n;\n \n \t\t\t\tmodes[i] = WORKING_DIRECTORY;\n"},{"id":"247605","messageId":"CACsJy8B2P-UMvbkW2HtyxrYPP8TyXnt25CYw9=ZZp6Ks+ed=yA@mail.gmail.com","threadId":"37319","inReplyTo":"xmqq61hy7tii.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v2 6/8] mv: unindent one level for directory move code","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-12T14:57:17Z","receivedAt":"2014-08-12T14:57:17Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Tue, Aug 12, 2014 at 1:47 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n>\n>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>> ---\n>>  builtin/mv.c | 47 +++++++++++++++++++++--------------------------\n>>  1 file changed, 21 insertions(+), 26 deletions(-)\n>>\n>> diff --git a/builtin/mv.c b/builtin/mv.c\n>> index dcfcb11..988945c 100644\n>> --- a/builtin/mv.c\n>> +++ b/builtin/mv.c\n>> @@ -171,42 +171,37 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\n>>                               && lstat(dst, &st) == 0)\n>>                       bad = _(\"cannot move directory over file\");\n>>               else if (src_is_dir) {\n>> +                     int first = cache_name_pos(src, length), last;\n>>                       if (first >= 0)\n>>                               prepare_move_submodule(src, first,\n>>                                                      submodule_gitfile + i);\n>> +                     else if (index_range_of_same_dir(src, length,\n>> +                                                      &first, &last) < 1) {\n>\n> The function returns (last - first), so (last - first) < 1 holds\n> inside this block, right?\n>\n>>                               modes[i] = WORKING_DIRECTORY;\n>>                               if (last - first < 1)\n>>                                       bad = _(\"source directory is empty\");\n>\n> Then do you need this conditional, or it is always bad here?\n>\n> If it is always bad, then modes[i] do not need to be assigned to,\n> either, I think.\n>\n> Am I missing something?\n\nNo you're right.\n\n>> +                     } else { /* last - first >= 1 */\n>> +                             int j, dst_len, n;\n>\n>> +                             modes[i] = WORKING_DIRECTORY;\n>> +                             n = argc + last - first;\n>> ...\n>\n> Otherwise, perhaps squash this in?\n\nSure. But I'm having second thought about this series.\n\nmv.c is centered around files on worktree, which makes it pretty hard\nif we want to make it more like rm.c where index and worktree entries\nare treated more equally and pathspec is applied. Doing that in mv.c\nwould require a lot more reorganization that makes this series\nobsolete. But on the other hand, I'm not even sure if I have time to\npursue that. So..\n-- \nDuy\n"},{"id":"247615","messageId":"xmqqlhqt617u.fsf@gitster.dls.corp.google.com","threadId":"37319","inReplyTo":"CACsJy8B2P-UMvbkW2HtyxrYPP8TyXnt25CYw9=ZZp6Ks+ed=yA@mail.gmail.com","subject":"Re: [PATCH v2 6/8] mv: unindent one level for directory move code","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-08-12T17:56:37Z","receivedAt":"2014-08-12T17:56:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Duy Nguyen <pclouds@gmail.com> writes:\n\n>> Otherwise, perhaps squash this in?\n>\n> Sure. But I'm having second thought about this series.\n>\n> mv.c is centered around files on worktree, which makes it pretty hard\n> if we want to make it more like rm.c where index and worktree entries\n> are treated more equally and pathspec is applied. Doing that in mv.c\n> would require a lot more reorganization that makes this series\n> obsolete.\n\nWell, you may have started these as preparatory clean-up, but taken\nalone these are purely making the result more readable without\nchanging any behaviour, so let's get them right first.\n\nThanks.\n"}]}