{"thread":{"id":"37313","subject":"[PATCH 0/8] builtin/mv.c cleanup","startedAt":"2014-08-08T13:10:54Z","lastAt":"2014-08-08T17:54:05Z","messageCount":11,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"247466","messageId":"1407503462-32632-1-git-send-email-pclouds@gmail.com","threadId":"37313","inReplyTo":null,"subject":"[PATCH 0/8] builtin/mv.c cleanup","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-08T13:10:54Z","receivedAt":"2014-08-08T13:10:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"I was looking at builtin/mv.c for pathspec support and ended up\ncleaning it up a bit. The first patch is definitely good. The rest\ncould be questionable. Although the output in the end looks better in\nmy opinion.\n\nNguyễn Thái Ngọc Duy (8):\n  mv: mark strings for translations\n  mv: no \"Huh?\" to the user\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\n builtin/mv.c | 168 +++++++++++++++++++++++++++++------------------------------\n 1 file changed, 84 insertions(+), 84 deletions(-)\n\n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247467","messageId":"1407503462-32632-2-git-send-email-pclouds@gmail.com","threadId":"37313","inReplyTo":"1407503462-32632-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 1/8] mv: mark strings for translations","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-08T13:10:55Z","receivedAt":"2014-08-08T13:10:55Z","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":"247468","messageId":"1407503462-32632-3-git-send-email-pclouds@gmail.com","threadId":"37313","inReplyTo":"1407503462-32632-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 2/8] mv: no \"Huh?\" to the user","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-08T13:10:56Z","receivedAt":"2014-08-08T13:10:56Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Although if we are frisky, this could do\n\n   static NORETURN void die_builtin(const char *err, va_list params)\n   {\n  -\tvreportf(\"fatal: \", err, params);\n  +\tvreportf(\"Huh? \", err, params);\n   \texit(128);\n   }\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/mv.c | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex b892f63..a7e02c0 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -135,7 +135,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\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\t\tdie (_(\"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@@ -153,8 +153,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\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+\t\t\t\t\tdie (_(\"%.*s is in index\"), len_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-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247469","messageId":"1407503462-32632-4-git-send-email-pclouds@gmail.com","threadId":"37313","inReplyTo":"1407503462-32632-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 3/8] mv: flatten error handling code block","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-08T13:10:57Z","receivedAt":"2014-08-08T13:10:57Z","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 | 35 +++++++++++++++++------------------\n 1 file changed, 17 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex a7e02c0..5c6f58f 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -58,6 +58,11 @@ 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@@ -224,24 +229,18 @@ 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\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\ti--;\n \t\t}\n \t}\n \n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247470","messageId":"1407503462-32632-5-git-send-email-pclouds@gmail.com","threadId":"37313","inReplyTo":"1407503462-32632-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 4/8] mv: split submodule move preparation code out","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-08T13:10:58Z","receivedAt":"2014-08-08T13:10:58Z","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 | 35 +++++++++++++++++++++--------------\n 1 file changed, 21 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 5c6f58f..e192f2d 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -66,6 +66,23 @@ static void move_up_one(void *p, int nmemb, int size)\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@@ -137,20 +154,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 (_(\"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":"247471","messageId":"1407503462-32632-6-git-send-email-pclouds@gmail.com","threadId":"37313","inReplyTo":"1407503462-32632-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 5/8] mv: remove an \"if\" that's always true","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-08T13:10:59Z","receivedAt":"2014-08-08T13:10:59Z","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 e192f2d..a45226e 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -179,22 +179,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":"247472","messageId":"1407503462-32632-7-git-send-email-pclouds@gmail.com","threadId":"37313","inReplyTo":"1407503462-32632-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 6/8] mv: move index search code out","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-08T13:11:00Z","receivedAt":"2014-08-08T13:11:00Z","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 | 41 +++++++++++++++++++++++++----------------\n 1 file changed, 25 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex a45226e..f8d65e2 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -83,6 +83,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@@ -158,24 +181,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 (_(\"%.*s is in index\"), len_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":"247473","messageId":"1407503462-32632-8-git-send-email-pclouds@gmail.com","threadId":"37313","inReplyTo":"1407503462-32632-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 7/8] mv: unindent one level for directory move code","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-08T13:11:01Z","receivedAt":"2014-08-08T13:11:01Z","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 f8d65e2..a2e33b5 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -176,42 +176,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":"247474","messageId":"1407503462-32632-9-git-send-email-pclouds@gmail.com","threadId":"37313","inReplyTo":"1407503462-32632-1-git-send-email-pclouds@gmail.com","subject":"[PATCH 8/8] mv: combine two if(s)","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2014-08-08T13:11:02Z","receivedAt":"2014-08-08T13:11:02Z","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 | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex a2e33b5..4eb420b 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -276,10 +276,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+\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}\n \n \treturn 0;\n }\n-- \n2.1.0.rc0.78.gc0d8480\n"},{"id":"247519","messageId":"xmqqfvh6kh2t.fsf@gitster.dls.corp.google.com","threadId":"37313","inReplyTo":"1407503462-32632-3-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 2/8] mv: no \"Huh?\" to the user","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-08-08T17:48:58Z","receivedAt":"2014-08-08T17:48:58Z","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> Although if we are frisky, this could do\n>\n>    static NORETURN void die_builtin(const char *err, va_list params)\n>    {\n>   -\tvreportf(\"fatal: \", err, params);\n>   +\tvreportf(\"Huh? \", err, params);\n>    \texit(128);\n>    }\n\n;-)\n\nWhile at it we may want to remove the extra SP between dies and\ntheir opening parentheses.\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  builtin/mv.c | 5 ++---\n>  1 file changed, 2 insertions(+), 3 deletions(-)\n>\n> diff --git a/builtin/mv.c b/builtin/mv.c\n> index b892f63..a7e02c0 100644\n> --- a/builtin/mv.c\n> +++ b/builtin/mv.c\n> @@ -135,7 +135,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\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\t\tdie (_(\"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> @@ -153,8 +153,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)\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> +\t\t\t\t\tdie (_(\"%.*s is in index\"), len_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"},{"id":"247520","messageId":"xmqqbnrukgua.fsf@gitster.dls.corp.google.com","threadId":"37313","inReplyTo":"1407503462-32632-4-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 3/8] mv: flatten error handling code block","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-08-08T17:54:05Z","receivedAt":"2014-08-08T17:54:05Z","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 | 35 +++++++++++++++++------------------\n>  1 file changed, 17 insertions(+), 18 deletions(-)\n>\n> diff --git a/builtin/mv.c b/builtin/mv.c\n> index a7e02c0..5c6f58f 100644\n> --- a/builtin/mv.c\n> +++ b/builtin/mv.c\n> @@ -58,6 +58,11 @@ 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> @@ -224,24 +229,18 @@ 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\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\ti--;\n\nThe resulting end-of-loop code structure certainly looks a lot\nbetter, even if the original memmove()s were left inline without the\nhelper.\n\nThe helper itself however looks a bit half-hearted.  It may be more\nappropriate to go one step further to have a macro whose use looks\nlike this, perhaps, to avoid the last remaining repetition?\n\n\tMOVE_UP_BY_ONE(source, i, n);\n\n\n>  \t\t}\n>  \t}\n"}]}