From 6346f704a00a2fc94cc2ca26dbe872b446500bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Fri, 10 Sep 2021 22:25:50 +0200 Subject: index-pack: use xopen in init_thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support an arbitrary file descriptor expression in the semantic patch for replacing open+die_errno with xopen, not just an identifier, and apply it. This makes the error message at the single affected place more consistent and reduces code duplication. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 6cc4890..738a35c 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -187,9 +187,7 @@ static void init_thread(void) pthread_key_create(&key, NULL); CALLOC_ARRAY(thread_data, nr_threads); for (i = 0; i < nr_threads; i++) { - thread_data[i].pack_fd = open(curr_pack, O_RDONLY); - if (thread_data[i].pack_fd == -1) - die_errno(_("unable to open %s"), curr_pack); + thread_data[i].pack_fd = xopen(curr_pack, O_RDONLY); } threads_active = 1; diff --git a/contrib/coccinelle/xopen.cocci b/contrib/coccinelle/xopen.cocci index 814d7b8..b71db67 100644 --- a/contrib/coccinelle/xopen.cocci +++ b/contrib/coccinelle/xopen.cocci @@ -2,15 +2,18 @@ identifier fd; identifier die_fn =~ "^(die|die_errno)$"; @@ -( - fd = + int fd = - open + xopen (...); -| - int fd = +- if ( \( fd < 0 \| fd == -1 \) ) { die_fn(...); } + +@@ +expression fd; +identifier die_fn =~ "^(die|die_errno)$"; +@@ + fd = - open + xopen (...); -) - if ( \( fd < 0 \| fd == -1 \) ) { die_fn(...); } -- cgit v0.10.2-6-g49f6