]> git.ipfire.org Git - thirdparty/git.git/commitdiff
index-pack: use xopen in init_thread
authorRené Scharfe <l.s.r@web.de>
Fri, 10 Sep 2021 20:25:50 +0000 (22:25 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Sep 2021 21:22:50 +0000 (14:22 -0700)
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>
builtin/index-pack.c
contrib/coccinelle/xopen.cocci

index 6cc48902170e32c578f50d27bba5af6ea8568ab8..738a35c53c886aba20d53776264e43188c5af8d6 100644 (file)
@@ -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;
index 814d7b8a1a1c75af49a1e648d96901587709329c..b71db670194c8025d5cb4c9c52a2c1faa90e342e 100644 (file)
@@ -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(...); }