Skip to content

Commit 6346f70

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66e905b commit 6346f70

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

builtin/index-pack.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ static void init_thread(void)
187187
pthread_key_create(&key, NULL);
188188
CALLOC_ARRAY(thread_data, nr_threads);
189189
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);
193191
}
194192

195193
threads_active = 1;

contrib/coccinelle/xopen.cocci

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
identifier fd;
33
identifier die_fn =~ "^(die|die_errno)$";
44
@@
5-
(
6-
fd =
5+
int fd =
76
- open
87
+ xopen
98
(...);
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 =
1216
- open
1317
+ xopen
1418
(...);
15-
)
1619
- if ( \( fd < 0 \| fd == -1 \) ) { die_fn(...); }

0 commit comments

Comments
 (0)