{"thread":{"id":"4110","subject":"[PATCH] apply: fix infinite loop with multiple patches with --index","startedAt":"2006-05-09T08:08:23Z","lastAt":"2006-05-09T08:08:23Z","messageCount":1,"participants":["Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"19774","messageId":"1147162103958-git-send-email-normalperson@yhbt.net","threadId":"4110","inReplyTo":null,"subject":"[PATCH] apply: fix infinite loop with multiple patches with --index","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-05-09T08:08:23Z","receivedAt":"2006-05-09T08:08:23Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"When multiple patches are passed to git-apply, it will attempt\nto open multiple file descriptors to an index, which means\nmultiple entries will be in the circular cache_file_list.\n\nThis change makes git-apply only open the index once and\nwrite the index at exit.\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n\n---\n\n apply.c |   18 +++++++++---------\n 1 files changed, 9 insertions(+), 9 deletions(-)\n\n1d0b15a178abaf7ba61085f0acc70521bd71a961\ndiff --git a/apply.c b/apply.c\nindex 269210a..ca36391 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -19,6 +19,7 @@ #include \"blob.h\"\n //\n static const char *prefix;\n static int prefix_length = -1;\n+static int newfd = -1;\n \n static int p_value = 1;\n static int allow_binary_replacement = 0;\n@@ -1873,7 +1874,6 @@ static int use_patch(struct patch *p)\n \n static int apply_patch(int fd, const char *filename)\n {\n-\tint newfd;\n \tunsigned long offset, size;\n \tchar *buffer = read_patch_file(fd, &size);\n \tstruct patch *list = NULL, **listp = &list;\n@@ -1904,12 +1904,11 @@ static int apply_patch(int fd, const cha\n \t\tsize -= nr;\n \t}\n \n-\tnewfd = -1;\n \tif (whitespace_error && (new_whitespace == error_on_whitespace))\n \t\tapply = 0;\n \n \twrite_index = check_index && apply;\n-\tif (write_index)\n+\tif (write_index && newfd < 0)\n \t\tnewfd = hold_index_file_for_update(&cache_file, get_index_file());\n \tif (check_index) {\n \t\tif (read_cache() < 0)\n@@ -1922,12 +1921,6 @@ static int apply_patch(int fd, const cha\n \tif (apply)\n \t\twrite_out_results(list, skipped_patch);\n \n-\tif (write_index) {\n-\t\tif (write_cache(newfd, active_cache, active_nr) ||\n-\t\t    commit_index_file(&cache_file))\n-\t\t\tdie(\"Unable to write new cachefile\");\n-\t}\n-\n \tif (show_index_info)\n \t\tshow_index_list(list);\n \n@@ -2085,5 +2078,12 @@ int main(int argc, char **argv)\n \t\t\t\twhitespace_error == 1 ? \"\" : \"s\",\n \t\t\t\twhitespace_error == 1 ? \"s\" : \"\");\n \t}\n+\n+\tif (write_index) {\n+\t\tif (write_cache(newfd, active_cache, active_nr) ||\n+\t\t    commit_index_file(&cache_file))\n+\t\t\tdie(\"Unable to write new cachefile\");\n+\t}\n+\n \treturn 0;\n }\n-- \n1.3.2.g45f7-dirty\n"}]}