{"thread":{"id":"56480","subject":"[PATCH] index-pack: use xopen in init_thread","startedAt":"2021-09-10T20:25:58Z","lastAt":"2021-09-10T20:25:58Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"435479","messageId":"4e9d7ac5-d922-006a-9123-5b5622024c4d@web.de","threadId":"56480","inReplyTo":null,"subject":"[PATCH] index-pack: use xopen in init_thread","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2021-09-10T20:25:50Z","receivedAt":"2021-09-10T20:25:58Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Support an arbitrary file descriptor expression in the semantic patch\nfor replacing open+die_errno with xopen, not just an identifier, and\napply it.  This makes the error message at the single affected place\nmore consistent and reduces code duplication.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\nThe semantic patch itself gains some duplicate lines in exchange,\nunfortunately, but I don't how to avoid that.\n\n builtin/index-pack.c           |  4 +---\n contrib/coccinelle/xopen.cocci | 13 ++++++++-----\n 2 files changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 6cc4890217..738a35c53c 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -187,9 +187,7 @@ static void init_thread(void)\n \tpthread_key_create(&key, NULL);\n \tCALLOC_ARRAY(thread_data, nr_threads);\n \tfor (i = 0; i < nr_threads; i++) {\n-\t\tthread_data[i].pack_fd = open(curr_pack, O_RDONLY);\n-\t\tif (thread_data[i].pack_fd == -1)\n-\t\t\tdie_errno(_(\"unable to open %s\"), curr_pack);\n+\t\tthread_data[i].pack_fd = xopen(curr_pack, O_RDONLY);\n \t}\n\n \tthreads_active = 1;\ndiff --git a/contrib/coccinelle/xopen.cocci b/contrib/coccinelle/xopen.cocci\nindex 814d7b8a1a..b71db67019 100644\n--- a/contrib/coccinelle/xopen.cocci\n+++ b/contrib/coccinelle/xopen.cocci\n@@ -2,15 +2,18 @@\n identifier fd;\n identifier die_fn =~ \"^(die|die_errno)$\";\n @@\n-(\n-  fd =\n+  int fd =\n - open\n + xopen\n   (...);\n-|\n-  int fd =\n+- if ( \\( fd < 0 \\| fd == -1 \\) ) { die_fn(...); }\n+\n+@@\n+expression fd;\n+identifier die_fn =~ \"^(die|die_errno)$\";\n+@@\n+  fd =\n - open\n + xopen\n   (...);\n-)\n - if ( \\( fd < 0 \\| fd == -1 \\) ) { die_fn(...); }\n--\n2.33.0\n"}]}