{"thread":{"id":"4802","subject":"[PATCH] Close the index file between writing and committing","startedAt":"2006-07-08T08:56:28Z","lastAt":"2006-07-08T10:28:09Z","messageCount":2,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"23413","messageId":"Pine.LNX.4.63.0607081055520.29667@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4802","inReplyTo":null,"subject":"[PATCH] Close the index file between writing and committing","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-07-08T08:56:28Z","receivedAt":"2006-07-08T08:56:28Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tThis is just playing it safe.\n\n\tAlternatively, write_cache() could be taught to close the file\n\titself, but maybe there will be a user of write_cache() who wants\n\tto write something after the cache data?\n\n builtin-add.c          |    2 +-\n builtin-apply.c        |    2 +-\n builtin-read-tree.c    |    2 +-\n builtin-rm.c           |    2 +-\n builtin-update-index.c |    2 +-\n builtin-write-tree.c   |    3 ++-\n checkout-index.c       |    2 +-\n 7 files changed, 8 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin-add.c b/builtin-add.c\nindex bfbbb1b..2d25698 100644\n--- a/builtin-add.c\n+++ b/builtin-add.c\n@@ -181,7 +181,7 @@ int cmd_add(int argc, const char **argv,\n \n \tif (active_cache_changed) {\n \t\tif (write_cache(newfd, active_cache, active_nr) ||\n-\t\t    commit_lock_file(&lock_file))\n+\t\t    close(newfd) || commit_lock_file(&lock_file))\n \t\t\tdie(\"Unable to write new index file\");\n \t}\n \ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex e9ead00..c3af489 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -2323,7 +2323,7 @@ int cmd_apply(int argc, const char **arg\n \n \tif (write_index) {\n \t\tif (write_cache(newfd, active_cache, active_nr) ||\n-\t\t    commit_lock_file(&lock_file))\n+\t\t    close(newfd) || commit_lock_file(&lock_file))\n \t\t\tdie(\"Unable to write new index file\");\n \t}\n \ndiff --git a/builtin-read-tree.c b/builtin-read-tree.c\nindex 9a2099d..23a8d92 100644\n--- a/builtin-read-tree.c\n+++ b/builtin-read-tree.c\n@@ -1038,7 +1038,7 @@ int cmd_read_tree(int argc, const char *\n \t}\n \n \tif (write_cache(newfd, active_cache, active_nr) ||\n-\t    commit_lock_file(&lock_file))\n+\t    close(newfd) || commit_lock_file(&lock_file))\n \t\tdie(\"unable to write new index file\");\n \treturn 0;\n }\ndiff --git a/builtin-rm.c b/builtin-rm.c\nindex 4d56a1f..875d825 100644\n--- a/builtin-rm.c\n+++ b/builtin-rm.c\n@@ -147,7 +147,7 @@ int cmd_rm(int argc, const char **argv, \n \n \tif (active_cache_changed) {\n \t\tif (write_cache(newfd, active_cache, active_nr) ||\n-\t\t    commit_lock_file(&lock_file))\n+\t\t    close(newfd) || commit_lock_file(&lock_file))\n \t\t\tdie(\"Unable to write new index file\");\n \t}\n \ndiff --git a/builtin-update-index.c b/builtin-update-index.c\nindex ef50243..1a4200d 100644\n--- a/builtin-update-index.c\n+++ b/builtin-update-index.c\n@@ -648,7 +648,7 @@ int cmd_update_index(int argc, const cha\n  finish:\n \tif (active_cache_changed) {\n \t\tif (write_cache(newfd, active_cache, active_nr) ||\n-\t\t    commit_lock_file(lock_file))\n+\t\t    close(newfd) || commit_lock_file(lock_file))\n \t\t\tdie(\"Unable to write new index file\");\n \t}\n \ndiff --git a/builtin-write-tree.c b/builtin-write-tree.c\nindex 70e9b6f..449a4d1 100644\n--- a/builtin-write-tree.c\n+++ b/builtin-write-tree.c\n@@ -35,7 +35,8 @@ int write_tree(unsigned char *sha1, int \n \t\t\t\t      missing_ok, 0) < 0)\n \t\t\tdie(\"git-write-tree: error building trees\");\n \t\tif (0 <= newfd) {\n-\t\t\tif (!write_cache(newfd, active_cache, active_nr))\n+\t\t\tif (!write_cache(newfd, active_cache, active_nr)\n+\t\t\t\t\t&& !close(newfd))\n \t\t\t\tcommit_lock_file(lock_file);\n \t\t}\n \t\t/* Not being able to write is fine -- we are only interested\ndiff --git a/checkout-index.c b/checkout-index.c\nindex ea40bc2..2927955 100644\n--- a/checkout-index.c\n+++ b/checkout-index.c\n@@ -311,7 +311,7 @@ int main(int argc, char **argv)\n \n \tif (0 <= newfd &&\n \t    (write_cache(newfd, active_cache, active_nr) ||\n-\t     commit_lock_file(&lock_file)))\n+\t     close(newfd) || commit_lock_file(&lock_file)))\n \t\tdie(\"Unable to write new index file\");\n \treturn 0;\n }\n-- \n1.4.1.rc2.g5b68a\n"},{"id":"23414","messageId":"7vbqs0qtl2.fsf@assigned-by-dhcp.cox.net","threadId":"4802","inReplyTo":"Pine.LNX.4.63.0607081055520.29667@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Close the index file between writing and committing","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-07-08T10:28:09Z","receivedAt":"2006-07-08T10:28:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> \tAlternatively, write_cache() could be taught to close the file\n> \titself, but maybe there will be a user of write_cache() who wants\n> \tto write something after the cache data?\n\nCurrently I suspect nobody would want to append stuff to the\nindex file, because anybody who wants to add something to the\ncache can do so with the index extension mechanism.\n\nHowever, it is conceivable that later we might invent a new\nprogram that writes the index file and other things to a single\nstream, and closing the fd in write_cache() would inconvenience\nsuch a program.\n"}]}