From patchwork Sun Aug 2 14:38:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 11696523 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 943DF138C for ; Sun, 2 Aug 2020 14:38:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B3752075A for ; Sun, 2 Aug 2020 14:38:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=web.de header.i=@web.de header.b="sEfDzvsE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725991AbgHBOik (ORCPT ); Sun, 2 Aug 2020 10:38:40 -0400 Received: from mout.web.de ([212.227.15.3]:55415 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725778AbgHBOik (ORCPT ); Sun, 2 Aug 2020 10:38:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1596379115; bh=lq7Z4jwUeQzkoG7f7pFwuP71q1bgsiTnuyZqRm/AME0=; h=X-UI-Sender-Class:To:Cc:From:Subject:Date; b=sEfDzvsEP3rT5sxTVps2SU/z0XB4mtit755z6wTUb7GZpXCsg5lhEUb/iPGQq4lbw HqiPu8wJHEjgeIseaAvmTF84ohNhHnhH7HNVQt+COo4RtSB7zZvKKJort80PIJB5/O Ull4YPOggEfn3IkBeKzIoZvSBTqgdBPDyB6b6nI8= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.26] ([79.203.26.151]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LotIZ-1khdIG1Tbv-00gmLq; Sun, 02 Aug 2020 16:38:35 +0200 To: Git Mailing List Cc: Junio C Hamano From: =?utf-8?q?Ren=C3=A9_Scharfe?= Subject: [PATCH] connected: use buffered I/O to talk to rev-list Message-ID: <2e2907ac-3be9-c0ed-830a-f8aa28b471aa@web.de> Date: Sun, 2 Aug 2020 16:38:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Language: en-US X-Provags-ID: V03:K1:HP71SYYm8o5rNPOCMI6ajVTvNAWRujEIyFrsTWoZBm85YswsIFs a8L+z0wXtuTILkiLSM0zloiiFN1XnuwLtpWESJ6pZhP2vYb2tjWD8Z/nFq5IE8lFuPv8obZ XwGpCQ6sh9HEjOXNR3q08CsDC+JiAKvDwJupM9engi1uc01d4mvPab/SCSQz5iDaxV9aGgi b/Y+rMhZpcKWbgHqbWcIg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:y89jtUOT54A=:KAAcyKAsitfEmdj99cBKT0 rtwJ6YIp1pEufyl/3Bb6u1I29E818Rpo1jaNTE8l2DqkfqHx8bDHhPwDsHGWG/tRpAs97SNJu zpZDua6ff76eAauVYwLRUBkjmhURhuXQ4IBL5LqWJtQv/L03z+QYLuuEAbh92sgRlOzOmD8Uk CrfKIYc7gxt4ErAKk5RpHgxjnAL1IYtDwCeOaQX1tRFVNaHMCTnNnRRMXSkyBqq0x3+ITSEip ujxTsSoViY7ziFCpjk+VJC1+LZ3bP9bcTVheeWMvTdiyvnbafaLnMZv0GsqTbdGh/eGqdP4pq HZeqjnK+7op3mBrPNqS0YuN6HjqLU3X453J2MnOKLCIxXM9blE3vQmssGhEOSo0oh7aYGQWZI TveALzXg6EaEAtMayv2XAOvtrojfD87R0V9LRZHNrAw8EsrAnyr1L04wD42G6//uFS6usi1DI dCGOLTAOn8/crUf9CO6bXl1ZyBWvuDOB5xbmzTV8C5/IXCsVkvtPb5UgU17gM+oicJO/30FWe +14bIjSo+JeKH1OaEDICVUhLlkKOsad1mK6uQrDrYDfeYFmDFMdHi1e1Aeq5aJnpuFmQCHp9j DI+IDf9pEtqcfrp3wTr6IEF5nNoI2u9eaRF/tOuR4ryhuIm3nyzjtC1YkxZdvZ9M4oFnvW0uw TVabQTZhLyURR8xsN0d3PzzCAK4sVNhQrBjzaLqyUZVOSlGBkuYHOHNWGB4qZpfs79yzjA7aX cb8lybhZutHiT14YzsqkKtpehGoA5ZLu1uLzmMMTvqwzQdmMktjei3atqDqHrID7Mh7shGJMK LqCkhyd+QjVW2j+/l9XjqNumz0VJTSNO5w0TT2qd04VpQxkVOC2aNcvwTnjBf5kh9gCbZSHRf cVS7r/naDUbSMQZd5PK800nUSn4p0359H4lD8ejZZi4xt6RDDi5gpcnkZTkC1dUm9qDAxyXNf DTBft10jo6FDi0+2ojV+V+U/u72Yl3N6wuA9bKD4yZoWerKIULKX6zFKTiEry90AgC4hslBiL FueqPwecQV61lkCJoAT90r9Z+rlICTXarKcnjhj8YRRWU7eZzoOouLj9FQsh3t0Tw0YVUhuig VCBuD801R2yhLUbqdDPbOi+pUaEbBydR7yvcR7lpHX8kONPREivIpPukswxCKZvp9fPmzKCfd hH0ites3u0HRXDHtVntzp8P+wK2WUch95UaKIJF2bZTe9NVsr6NDN5ACUe2Rhfxb7oJOFnGDC a3iTGVw+tF6YsPKt4 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Like f0bca72dc77 (send-pack: use buffered I/O to talk to pack-objects, 2016-06-08), significantly reduce the number of system calls and simplify the code for sending object IDs to rev-list by using stdio's buffering and handling errors after the loop. Signed-off-by: René Scharfe --- connected.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) -- 2.28.0 diff --git a/connected.c b/connected.c index 937b4bae387..05c2916f38d 100644 --- a/connected.c +++ b/connected.c @@ -22,14 +22,13 @@ int check_connected(oid_iterate_fn fn, void *cb_data, struct check_connected_options *opt) { struct child_process rev_list = CHILD_PROCESS_INIT; + FILE *rev_list_in; struct check_connected_options defaults = CHECK_CONNECTED_INIT; - char commit[GIT_MAX_HEXSZ + 1]; struct object_id oid; int err = 0; struct packed_git *new_pack = NULL; struct transport *transport; size_t base_len; - const unsigned hexsz = the_hash_algo->hexsz; if (!opt) opt = &defaults; @@ -122,7 +121,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data, sigchain_push(SIGPIPE, SIG_IGN); - commit[hexsz] = '\n'; + rev_list_in = xfdopen(rev_list.in, "w"); + do { /* * If index-pack already checked that: @@ -135,16 +135,10 @@ int check_connected(oid_iterate_fn fn, void *cb_data, if (new_pack && find_pack_entry_one(oid.hash, new_pack)) continue; - memcpy(commit, oid_to_hex(&oid), hexsz); - if (write_in_full(rev_list.in, commit, hexsz + 1) < 0) { - if (errno != EPIPE && errno != EINVAL) - error_errno(_("failed write to rev-list")); - err = -1; - break; - } + fprintf(rev_list_in, "%s\n", oid_to_hex(&oid)); } while (!fn(cb_data, &oid)); - if (close(rev_list.in)) + if (fclose(rev_list_in)) err = error_errno(_("failed to close rev-list's stdin")); sigchain_pop(SIGPIPE);