{"thread":{"id":"3945","subject":"make update-index --chmod work with multiple files and --stdin","startedAt":"2006-04-22T20:46:42Z","lastAt":"2006-04-23T07:08:43Z","messageCount":4,"participants":["Alex Riesen","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"19007","messageId":"20060422204642.GA7676@steel.home","threadId":"3945","inReplyTo":null,"subject":"make update-index --chmod work with multiple files and --stdin","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-04-22T20:46:42Z","receivedAt":"2006-04-22T20:46:42Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"I had a project where lots of files were \"accidentally\" marked +x, and\ndoing plain \"git-update-index --chmod=-x\" for each file was too slow.\nBesides, it's somewhat inconsistent, that --chmod does work only for\none subsequent file.\n\n---\n\nYes, windows again.\n\n update-index.c |   16 ++++++++++++++--\n 1 files changed, 14 insertions(+), 2 deletions(-)\n\n5c7b9c2d187f36ba8b5632d2125f2bd19abb3564\ndiff --git a/update-index.c b/update-index.c\nindex 1efac27..c3c2000 100644\n--- a/update-index.c\n+++ b/update-index.c\n@@ -350,6 +350,7 @@ static int chmod_path(int flip, const ch\n \t\treturn -1;\n \t}\n \tactive_cache_changed = 1;\n+\treport(\"chmod %cx '%s'\", flip, path);\n \treturn 0;\n }\n \n@@ -478,6 +479,7 @@ int main(int argc, const char **argv)\n \tint read_from_stdin = 0;\n \tconst char *prefix = setup_git_directory();\n \tint prefix_length = prefix ? strlen(prefix) : 0;\n+\tchar chmod_mode = 0;\n \n \tgit_config(git_default_config);\n \n@@ -544,8 +546,7 @@ int main(int argc, const char **argv)\n \t\t\t    !strcmp(path, \"--chmod=+x\")) {\n \t\t\t\tif (argc <= i+1)\n \t\t\t\t\tdie(\"git-update-index: %s <path>\", path);\n-\t\t\t\tif (chmod_path(path[8], argv[++i]))\n-\t\t\t\t\tdie(\"git-update-index: %s cannot chmod %s\", path, argv[i]);\n+\t\t\t\tchmod_mode = path[8];\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(path, \"--assume-unchanged\")) {\n@@ -594,6 +595,11 @@ int main(int argc, const char **argv)\n \t\t\tdie(\"unknown option %s\", path);\n \t\t}\n \t\tupdate_one(path, prefix, prefix_length);\n+\t\tif ( chmod_mode ) {\n+\t\t\tif (chmod_path(chmod_mode, path))\n+\t\t\t\tdie(\"git-update-index: cannot chmod %cx %s\",\n+\t\t\t\t    chmod_mode, path);\n+\t\t}\n \t}\n \tif (read_from_stdin) {\n \t\tstruct strbuf buf;\n@@ -608,6 +614,12 @@ int main(int argc, const char **argv)\n \t\t\telse\n \t\t\t\tpath_name = buf.buf;\n \t\t\tupdate_one(path_name, prefix, prefix_length);\n+\t\t\tif ( chmod_mode ) {\n+\t\t\t\tconst char *p = prefix_path(prefix, prefix_length, path_name);\n+\t\t\t\tif (chmod_path(chmod_mode, p))\n+\t\t\t\t\tdie(\"git-update-index: cannot chmod %cx %s\",\n+\t\t\t\t\t    chmod_mode, p);\n+\t\t\t}\n \t\t\tif (path_name != buf.buf)\n \t\t\t\tfree(path_name);\n \t\t}\n-- \n1.3.0.gc2941\n"},{"id":"19012","messageId":"7v1wvpi010.fsf@assigned-by-dhcp.cox.net","threadId":"3945","inReplyTo":"20060422204642.GA7676@steel.home","subject":"Re: make update-index --chmod work with multiple files and --stdin","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-23T00:54:51Z","receivedAt":"2006-04-23T00:54:51Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> I had a project where lots of files were \"accidentally\" marked +x, and\n> doing plain \"git-update-index --chmod=-x\" for each file was too slow.\n> Besides, it's somewhat inconsistent, that --chmod does work only for\n> one subsequent file.\n\nIf you are doing that on the command line, people may want to\nhave a way to mean \"from here on do not do chmod, just do normal\nupdate-index and nothing else\" by resetting the chmod_mode thing\nback to zero.  Nothing major, and we do not do that to allow_add\nand allow_remove either, but just a thought.\n\n> +\tchar chmod_mode = 0;\n\nPerhaps \"set_executable_bit\"?\n\n> +\t\tif ( chmod_mode ) {\n\nPlease lose ( extra ) whitespaces around parentheses.\n\n> +\t\t\tif ( chmod_mode ) {\n\nLikewise.\n\n> +\t\t\t\tif (chmod_path(chmod_mode, p))\n> +\t\t\t\t\tdie(\"git-update-index: cannot chmod %cx %s\",\n> +\t\t\t\t\t    chmod_mode, p);\n> +\t\t\t}\n\nMight make sense to die inside chmod_path() instead of repeating\nthe if () { die() } sequence twice?  I dunno.\n"},{"id":"19015","messageId":"20060423070129.GA5802@steel.home","threadId":"3945","inReplyTo":"7v1wvpi010.fsf@assigned-by-dhcp.cox.net","subject":"Re: make update-index --chmod work with multiple files and --stdin","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-04-23T07:01:29Z","receivedAt":"2006-04-23T07:01:29Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Junio C Hamano, Sun, Apr 23, 2006 02:54:51 +0200:\n> > I had a project where lots of files were \"accidentally\" marked +x, and\n> > doing plain \"git-update-index --chmod=-x\" for each file was too slow.\n> > Besides, it's somewhat inconsistent, that --chmod does work only for\n> > one subsequent file.\n> \n> If you are doing that on the command line, people may want to\n> have a way to mean \"from here on do not do chmod, just do normal\n> update-index and nothing else\" by resetting the chmod_mode thing\n> back to zero.  Nothing major, and we do not do that to allow_add\n> and allow_remove either, but just a thought.\n\nNot sure about that, but did it anyway (as separate patches).\n\nI updated the patch with the other remarks regarding\nset_executable_bit, whitespaces and die in chmod_path (thought about\nthis one myself, but was lazy).\n\n---\n\n update-index.c |   23 ++++++++++++++++-------\n 1 files changed, 16 insertions(+), 7 deletions(-)\n\n92d1372fd0358811a5f2670b99a6a304dadb7864\ndiff --git a/update-index.c b/update-index.c\nindex 1efac27..a8582ea 100644\n--- a/update-index.c\n+++ b/update-index.c\n@@ -328,7 +328,7 @@ static int add_cacheinfo(unsigned int mo\n \treturn 0;\n }\n \n-static int chmod_path(int flip, const char *path)\n+static void chmod_path(int flip, const char *path)\n {\n \tint pos;\n \tstruct cache_entry *ce;\n@@ -336,21 +336,24 @@ static int chmod_path(int flip, const ch\n \n \tpos = cache_name_pos(path, strlen(path));\n \tif (pos < 0)\n-\t\treturn -1;\n+\t\tgoto _fail;\n \tce = active_cache[pos];\n \tmode = ntohl(ce->ce_mode);\n \tif (!S_ISREG(mode))\n-\t\treturn -1;\n+\t\tgoto _fail;\n \tswitch (flip) {\n \tcase '+':\n \t\tce->ce_mode |= htonl(0111); break;\n \tcase '-':\n \t\tce->ce_mode &= htonl(~0111); break;\n \tdefault:\n-\t\treturn -1;\n+\t\tgoto _fail;\n \t}\n \tactive_cache_changed = 1;\n-\treturn 0;\n+\treport(\"chmod %cx '%s'\", flip, path);\n+\treturn;\n+_fail:\n+\tdie(\"git-update-index: cannot chmod %cx '%s'\", flip, path);\n }\n \n static struct cache_file cache_file;\n@@ -478,6 +481,7 @@ int main(int argc, const char **argv)\n \tint read_from_stdin = 0;\n \tconst char *prefix = setup_git_directory();\n \tint prefix_length = prefix ? strlen(prefix) : 0;\n+\tchar set_executable_bit = 0;\n \n \tgit_config(git_default_config);\n \n@@ -544,8 +548,7 @@ int main(int argc, const char **argv)\n \t\t\t    !strcmp(path, \"--chmod=+x\")) {\n \t\t\t\tif (argc <= i+1)\n \t\t\t\t\tdie(\"git-update-index: %s <path>\", path);\n-\t\t\t\tif (chmod_path(path[8], argv[++i]))\n-\t\t\t\t\tdie(\"git-update-index: %s cannot chmod %s\", path, argv[i]);\n+\t\t\t\tset_executable_bit = path[8];\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(path, \"--assume-unchanged\")) {\n@@ -594,6 +597,8 @@ int main(int argc, const char **argv)\n \t\t\tdie(\"unknown option %s\", path);\n \t\t}\n \t\tupdate_one(path, prefix, prefix_length);\n+\t\tif (set_executable_bit)\n+\t\t\tchmod_path(set_executable_bit, path);\n \t}\n \tif (read_from_stdin) {\n \t\tstruct strbuf buf;\n@@ -608,6 +613,10 @@ int main(int argc, const char **argv)\n \t\t\telse\n \t\t\t\tpath_name = buf.buf;\n \t\t\tupdate_one(path_name, prefix, prefix_length);\n+\t\t\tif (set_executable_bit) {\n+\t\t\t\tconst char *p = prefix_path(prefix, prefix_length, path_name);\n+\t\t\t\tchmod_path(set_executable_bit, p);\n+\t\t\t}\n \t\t\tif (path_name != buf.buf)\n \t\t\t\tfree(path_name);\n \t\t}\n-- \n1.3.0.gc2941\n"},{"id":"19016","messageId":"20060423070843.GB5802@steel.home","threadId":"3945","inReplyTo":"7v1wvpi010.fsf@assigned-by-dhcp.cox.net","subject":"Re: make update-index --chmod work with multiple files and --stdin","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2006-04-23T07:08:43Z","receivedAt":"2006-04-23T07:08:43Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Junio C Hamano, Sun, Apr 23, 2006 02:54:51 +0200:\n> Alex Riesen <raa.lkml@gmail.com> writes:\n> \n> > I had a project where lots of files were \"accidentally\" marked +x, and\n> > doing plain \"git-update-index --chmod=-x\" for each file was too slow.\n> > Besides, it's somewhat inconsistent, that --chmod does work only for\n> > one subsequent file.\n> \n> If you are doing that on the command line, people may want to\n> have a way to mean \"from here on do not do chmod, just do normal\n> update-index and nothing else\" by resetting the chmod_mode thing\n> back to zero.  Nothing major, and we do not do that to allow_add\n> and allow_remove either, but just a thought.\n\nI am unsure about this. I'm even attaching instead of inlining the\npatches, to make it clear how unsure I am :)\n\nI have a feeling that it's more understandable to just use two\nseparate commands. Besides, the reset switch makes it impossible to\nuse pathname disambiguation (\"--\"). Unsure...\n\n\n\n>From nobody Mon Sep 17 00:00:00 2001\nFrom: Junio C Hamano <junkio@cox.net>\nDate: Sun Apr 23 08:38:04 2006 +0200\nSubject: git-update-index --no-chmod\n\nMessage-ID: <7v1wvpi010.fsf@assigned-by-dhcp.cox.net>\n\nAlex Riesen <raa.lkml@gmail.com> writes:\n\n> I had a project where lots of files were \"accidentally\" marked +x, and\n> doing plain \"git-update-index --chmod=-x\" for each file was too slow.\n> Besides, it's somewhat inconsistent, that --chmod does work only for\n> one subsequent file.\n\nIf you are doing that on the command line, people may want to\nhave a way to mean \"from here on do not do chmod, just do normal\nupdate-index and nothing else\" by resetting the chmod_mode thing\nback to zero.  Nothing major, and we do not do that to allow_add\nand allow_remove either, but just a thought.\n\n---\n\n update-index.c |    4 ++++\n 1 files changed, 4 insertions(+), 0 deletions(-)\n\n2972ef33fa4b04f07d4f4dbb9e13d5b9b2d593b4\ndiff --git a/update-index.c b/update-index.c\nindex a8582ea..1ed36fa 100644\n--- a/update-index.c\n+++ b/update-index.c\n@@ -551,6 +551,10 @@ int main(int argc, const char **argv)\n \t\t\t\tset_executable_bit = path[8];\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(path, \"--no-chmod\")) {\n+\t\t\t\tset_executable_bit = 0;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(path, \"--assume-unchanged\")) {\n \t\t\t\tmark_valid_only = MARK_VALID;\n \t\t\t\tcontinue;\n-- \n1.3.0.gc2941\n\n\n\n>From nobody Mon Sep 17 00:00:00 2001\nFrom: Junio C Hamano <junkio@cox.net>\nDate: Sun Apr 23 08:43:42 2006 +0200\nSubject: git-update-index: add --no-add and --no-remove\n\nMessage-ID: <7v1wvpi010.fsf@assigned-by-dhcp.cox.net>\n\nAlex Riesen <raa.lkml@gmail.com> writes:\n\n> I had a project where lots of files were \"accidentally\" marked +x, and\n> doing plain \"git-update-index --chmod=-x\" for each file was too slow.\n> Besides, it's somewhat inconsistent, that --chmod does work only for\n> one subsequent file.\n\nIf you are doing that on the command line, people may want to\nhave a way to mean \"from here on do not do chmod, just do normal\nupdate-index and nothing else\" by resetting the chmod_mode thing\nback to zero.  Nothing major, and we do not do that to allow_add\nand allow_remove either, but just a thought.\n\n---\n\n update-index.c |    8 ++++++++\n 1 files changed, 8 insertions(+), 0 deletions(-)\n\n89bceee48996f366a779b0c95ba230ec24fea340\ndiff --git a/update-index.c b/update-index.c\nindex 1ed36fa..cbee859 100644\n--- a/update-index.c\n+++ b/update-index.c\n@@ -509,6 +509,10 @@ int main(int argc, const char **argv)\n \t\t\t\tallow_add = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(path, \"--no-add\")) {\n+\t\t\t\tallow_add = 0;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(path, \"--replace\")) {\n \t\t\t\tallow_replace = 1;\n \t\t\t\tcontinue;\n@@ -517,6 +521,10 @@ int main(int argc, const char **argv)\n \t\t\t\tallow_remove = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(path, \"--no-remove\")) {\n+\t\t\t\tallow_remove = 0;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(path, \"--unmerged\")) {\n \t\t\t\tallow_unmerged = 1;\n \t\t\t\tcontinue;\n-- \n1.3.0.gc2941\n\n"}]}