index-pack: use xopen in init_thread

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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Sep 10, 2021 at 22:25 UTC 6346f704a00a2fc94cc2ca26dbe872b446500bfd
2 files changed +9 -8
builtin/index-pack.c
+1 -3
@@ -187,9 +187,7 @@ static void init_thread(void)
187 pthread_key_create(&key, NULL);
188 CALLOC_ARRAY(thread_data, nr_threads);
189 for (i = 0; i < nr_threads; i++) {
190 - thread_data[i].pack_fd = open(curr_pack, O_RDONLY);
191 - if (thread_data[i].pack_fd == -1)
192 - die_errno(_("unable to open %s"), curr_pack);
190 + thread_data[i].pack_fd = xopen(curr_pack, O_RDONLY);
191 }
192
193 threads_active = 1;
contrib/coccinelle/xopen.cocci
+8 -5
@@ -2,15 +2,18 @@
2 identifier fd;
3 identifier die_fn =~ "^(die|die_errno)$";
4 @@
5 -(
6 - fd =
5 + int fd =
6 - open
7 + xopen
8 (...);
10 -|
11 - int fd =
9 +- if ( \( fd < 0 \| fd == -1 \) ) { die_fn(...); }
10 +
11 +@@
12 +expression fd;
13 +identifier die_fn =~ "^(die|die_errno)$";
14 +@@
15 + fd =
16 - open
17 + xopen
18 (...);
15 -)
19 - if ( \( fd < 0 \| fd == -1 \) ) { die_fn(...); }