From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender4-op-o12.zoho.com (sender4-op-o12.zoho.com [136.143.188.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEBDC346A1F for ; Thu, 4 Dec 2025 14:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.12 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764857765; cv=pass; b=gix6KnCs845rY8n4UZ6Rr3Lhrur53a8OzIjNKWeU8ejfhqjcahlrsHtmIRoaSS8vNPbvNGNIT/0kFbwI2YNm/Y3JK+VioNOtuk8RvvIfpGon2AV8TNSOL8teF2QsQ5tYv8uOPOrFAQZ3z1I3AfUze1jVi4sTq34szos1S0P1IPY= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764857765; c=relaxed/simple; bh=k+LRIOIwrDQD4PHuI05LHYbWIvxPQGPNFrN7ceBjWig=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h+bkKlYsdqNUQXFXnd1zxc9fcYg6B5cYhfQJpyuEMrtt6NO1hORfQgGJcR6jDBEyl1zDM031P9hsanDNEa1NRgc8ZOzWFw1qKeP9i5B1GLWIrXnHBO/OgbWRHHWAM9rFcUBs6JpN8/pW4w7SbIc7ebedoX0JBsSXbUfWE3+Vs9E= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.ratiu@collabora.com header.b=PybFYme0; arc=pass smtp.client-ip=136.143.188.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=adrian.ratiu@collabora.com header.b="PybFYme0" ARC-Seal: i=1; a=rsa-sha256; t=1764857750; cv=none; d=zohomail.com; s=zohoarc; b=IZmDEDRzTP45UBN79j7AHMhk6zKdfWAXUTEb7njIvrtOYf8ikDiWJHvTkC2tTDsA7oJ6KfdozjlQKJHVLf2H1hYA0bf2p+ZRFh0DF501g7HPTrt74ZGnZ8JfPz+Nw5oeRMUwcKTp2TZbn2OcYzyLBMUOyk8N9eVFRM8IAKXtIws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764857750; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=x02/3GwYG57tooe+7B6KgkGtdO69dygR0rPY1d90GbU=; b=g6gUUXD5BTvaecXaeTux/3/L7uX6XBuVl6HkWMRzfcXr8ZLfsxAkeOZJMT4sPo4PV0KPbihahVnjQr5sG2JK9W0inoIDGaSeCNpp2gr24zDC6+1cBoqwlDOlc8EeGVgkyj96escF2Co/BlOBRntWzS5f1e+r/gpTP0HxhI6YrN0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=adrian.ratiu@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1764857750; s=zohomail; d=collabora.com; i=adrian.ratiu@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=x02/3GwYG57tooe+7B6KgkGtdO69dygR0rPY1d90GbU=; b=PybFYme0IYIF6L4eQyv+0paNGBwuvkfYrpTwvQrM1zXK6GJAnbGNXwQaa1V4rHuh Qw/LgHCMasoRpIkjB1rJxvGVYZu+x2SKq7TSekuaGvgfEg4UfnHIGoufBnX9JAgxmQA /jyOGnmLiOm+UQE7JNCsQGgtGwRxj8eAeS/aoJxo= Received: by mx.zohomail.com with SMTPS id 1764857749649688.223877421685; Thu, 4 Dec 2025 06:15:49 -0800 (PST) From: Adrian Ratiu To: git@vger.kernel.org Cc: Emily Shaffer , Rodrigo Damazio Bovendorp , Junio C Hamano , Patrick Steinhardt , Josh Steadmon , Ben Knoble , Phillip Wood , Kristoffer Haugsbakk , Adrian Ratiu Subject: [PATCH v4 01/11] run-command: add first helper for pp child states Date: Thu, 4 Dec 2025 16:15:25 +0200 Message-ID: <20251204141535.1986263-2-adrian.ratiu@collabora.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251204141535.1986263-1-adrian.ratiu@collabora.com> References: <20250925125352.1728840-1-adrian.ratiu@collabora.com> <20251204141535.1986263-1-adrian.ratiu@collabora.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-ZohoMailClient: External There is a recurring pattern of testing parallel process child states and file descriptors to determine if a child is running, receiving any input or if it's ready for cleanup. Name the pp_child structure and introduce a first helper to make these checks more readable. Next commits will add more helpers and checks. Suggested-by: Junio C Hamano Signed-off-by: Adrian Ratiu --- run-command.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/run-command.c b/run-command.c index ed9575bd6a..82eeac38bf 100644 --- a/run-command.c +++ b/run-command.c @@ -1478,15 +1478,22 @@ enum child_state { GIT_CP_WAIT_CLEANUP, }; +struct parallel_child { + enum child_state state; + struct child_process process; + struct strbuf err; + void *data; +}; + +static int child_is_working(const struct parallel_child *pp_child) +{ + return pp_child->state == GIT_CP_WORKING; +} + struct parallel_processes { size_t nr_processes; - struct { - enum child_state state; - struct child_process process; - struct strbuf err; - void *data; - } *children; + struct parallel_child *children; /* * The struct pollfd is logically part of *children, * but the system call expects it as its own array. @@ -1509,7 +1516,7 @@ static void kill_children(const struct parallel_processes *pp, int signo) { for (size_t i = 0; i < opts->processes; i++) - if (pp->children[i].state == GIT_CP_WORKING) + if (child_is_working(&pp->children[i])) kill(pp->children[i].process.pid, signo); } @@ -1665,7 +1672,7 @@ static void pp_buffer_stderr(struct parallel_processes *pp, /* Buffer output from all pipes. */ for (size_t i = 0; i < opts->processes; i++) { - if (pp->children[i].state == GIT_CP_WORKING && + if (child_is_working(&pp->children[i]) && pp->pfd[i].revents & (POLLIN | POLLHUP)) { int n = strbuf_read_once(&pp->children[i].err, pp->children[i].process.err, 0); @@ -1683,7 +1690,7 @@ static void pp_output(const struct parallel_processes *pp) { size_t i = pp->output_owner; - if (pp->children[i].state == GIT_CP_WORKING && + if (child_is_working(&pp->children[i]) && pp->children[i].err.len) { strbuf_write(&pp->children[i].err, stderr); strbuf_reset(&pp->children[i].err); @@ -1748,7 +1755,7 @@ static int pp_collect_finished(struct parallel_processes *pp, * running process time. */ for (i = 0; i < n; i++) - if (pp->children[(pp->output_owner + i) % n].state == GIT_CP_WORKING) + if (child_is_working(&pp->children[(pp->output_owner + i) % n])) break; pp->output_owner = (pp->output_owner + i) % n; } -- 2.51.0