From patchwork Sat Feb 15 15:50:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13976152 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C3AEB672 for ; Sat, 15 Feb 2025 15:51:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634704; cv=none; b=qm3tNTdKuh5Vb7QSZlATVoa7uKkV7PMCrHuVsFZULWjoOAIGyIc0GR/WEFbNMmbPSLaiogxivXnNOmkXb4vGxd9VjofA7bjANSg7dYYDnMTo0WJiKwsnwdf0v0QGHol7l4U0i491RSVF2XgvcXecAQWZGPVt5ZQYJnRur6rGBdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634704; c=relaxed/simple; bh=fB80ASbecHtp4fGMlEVSHuxVoWUEiTfhiT/c1rpUQfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A2RhgkNwer3eLO3B/uXsVz2rG8jfUL0kmbqSkSrjCdt5dLXYSrQQBhiMWtKLehrS/9JmntP/LeiexQd2dJoUe0OTqnk8zhC8HDuqu483mwwkw4P8SgX44BJ5AevXQkZpZnuQb1kPnLO32EO0BJebOiya/JIMg2kDHjjBk+0nyWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=N+fKuThb; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N+fKuThb" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2210d92292eso9572705ad.1 for ; Sat, 15 Feb 2025 07:51:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739634701; x=1740239501; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DUev6MBsFEBj9LcEfo26+7FRqWVh8ngUTgpXCvWBZ7M=; b=N+fKuThbyTICzXBQZ0tWbbZ0MxVXrgzDwsXmWTifvW/6YcJOIRTQfC+ruC+CFvKlV9 kE5T/c5edFQPFW3bREyHhEX0UwObT4FzGUMzhLXoHJZ+tJiFFkw/ucxbFQABqEwXn2Az rpHKGceSrc3iDRjAIyAisUSVx4ppZ6D3l2HjkVlS3Rk9ytCeIca8Greg8VwERDq2lpB6 yhkhfTORZsGRLaAS195hMk51YRa13l4KPd7DZIe2UXWnNydrsxum9f7W6kZvAgIzcb5z TggxPH+wmDxY6xHvc/cst0VsL/qt7c0me0Q9rNk0uQgomaRxFtb5cTtG3Vzi8wGzPcMl ckPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739634701; x=1740239501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DUev6MBsFEBj9LcEfo26+7FRqWVh8ngUTgpXCvWBZ7M=; b=G+vkkTD0CJ1ezOGtRzx1mELhO0jgXfSL1Fx2d+/yaOrfB1EWiRvOd7wIX3IJg3vZJg 0/gW8ho1UMp8jCX7EcAkU3AFomRS+y8ExdRJAUStzsTHjeblG0dLbdwvPbdQBHafpOY4 sMijjKch1hcE8SxxQjZj2gfCZR635GycYoH1CJztvizsDKaLaV+XYOyMwwdA+htmh86C OT7dmN2zeliNpUyC1PKHcYtswNKrl4VGwzPV8mR8yRM8OAut0SFb6ijtVqmUBHTjP0Zg H0fhBaRg6onyLcj1ri+E3VezYau7TPEwCNG0VwO3cBmcXmPfNSyAQZMW/y9Mm6Xs623o dOPg== X-Forwarded-Encrypted: i=1; AJvYcCU0kF3RCMSZvjNwU+8pcp+LICOX1gN954wzTOXSPePMQmvprJVOGJN2doQ/uVFEQsoiXu0=@vger.kernel.org X-Gm-Message-State: AOJu0YxZBJaorAt/mW0Xhh/Bq60Iu9J6MM2sNJ8aOgKQMlc1w+VzEZBi 7KkM87x+jqhQBHn1CKQR38miZzCpGHOUIa8EkI8IRVK/R3PoEOmNpEH3gx4t X-Gm-Gg: ASbGncsXr2jt0GlOzvMQZgalA5ApH9iXHG7cqtwIdm4e9VSGtVFConwXZQ4yksxQE3T IZeiDhNE8ZSxxrM9BFKwaEgktwgcSPbL+fhkrnZeM24H53NJCpUttS7n5BDpTVsKlawPDFTA9Uw 87c0DEb2UjnAEWqFXHPOEdMf8LPJ7LZ0gmcjKiI0WyEfxSwKKIwAZalVFEavXx78Krk7JhiyOKS P5lPmqYYwuhGfq+cBNmLZs6xBZ2lA1AAbQf6QOvaS0iv+rWZcaBVi7Q9YDK87KMCDUWa3oiEYD9 +j018yIjaH05aKJX3CF7vurxpu8A8eXNwaOINYVr X-Google-Smtp-Source: AGHT+IGthXiP+iEMxSwjr/OaiNpvMIrlwNHl7Oxh2zjY5rsHZqtaftAV1JoTb0+SUagToJEFoiXWEQ== X-Received: by 2002:a17:902:f54e:b0:220:d1c3:24d1 with SMTP id d9443c01a7336-221040d69d0mr57076955ad.46.1739634700832; Sat, 15 Feb 2025 07:51:40 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d559089asm45024285ad.241.2025.02.15.07.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Feb 2025 07:51:40 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, gitster@pobox.com Cc: Johannes.Schindelin@gmx.de, git@vger.kernel.org, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v6 1/6] version: replace manual ASCII checks with isprint() for clarity Date: Sat, 15 Feb 2025 21:20:47 +0530 Message-ID: <20250215155130.1756934-2-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250215155130.1756934-1-usmanakinyemi202@gmail.com> References: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> <20250215155130.1756934-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since the isprint() function checks for printable characters, let's replace the existing hardcoded ASCII checks with it. However, since the original checks also handled spaces, we need to account for spaces explicitly in the new check. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- version.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/version.c b/version.c index 4d763ab48d..6cfbb8ca56 100644 --- a/version.c +++ b/version.c @@ -2,6 +2,7 @@ #include "version.h" #include "version-def.h" #include "strbuf.h" +#include "sane-ctype.h" const char git_version_string[] = GIT_VERSION; const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; @@ -29,7 +30,7 @@ const char *git_user_agent_sanitized(void) strbuf_addstr(&buf, git_user_agent()); strbuf_trim(&buf); for (size_t i = 0; i < buf.len; i++) { - if (buf.buf[i] <= 32 || buf.buf[i] >= 127) + if (!isprint(buf.buf[i]) || buf.buf[i] == ' ') buf.buf[i] = '.'; } agent = buf.buf; From patchwork Sat Feb 15 15:50:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13976153 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0A4BB672 for ; Sat, 15 Feb 2025 15:51:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634707; cv=none; b=CW4yBgrMaoMmxJdVc9wrqZg0DlgH+VAMXHvpGrMLubOyONXCCLyhIFLpI9Mw1Ai4f3qhkCdr9LQM9vucYTvm9kwNUyuJfhjJMcgiZrSvkIRNW7QjxE4RcqG5giYDTW0KSBy1P2tJ6d+bL6epP2xJFKyEm82UTpfdd6pnHIItUmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634707; c=relaxed/simple; bh=auT7Nq8j/Oj7j5e0/1qmYiFTBmU1qvLdasGT5WYJd5Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uj24rFBB3pRnTJFJzpUhNqQ6zrhSfbGJ84yCMQCYL/6ja4wz/oahLeEhZe7FVp2lkMv7ZWKtXcuY4w1HwNvnC+HVXd8znUq/5GHJS25mB7l/OaEj2/jkjxq6pgVU0ufHMfs191WG77+PQHiia/q0RWMiR9O49iX64alaYsAhUF0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Es9IDGE9; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Es9IDGE9" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2210d92292eso9573525ad.1 for ; Sat, 15 Feb 2025 07:51:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739634705; x=1740239505; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TcvhFf9DLoHV/4B16FqnaOvirPJd2dOTFDpMtuyEBGY=; b=Es9IDGE9YfGDSPZtdZ2kQDEgWMUaO5TDNnD/PzM0hRH5FiPbPr1h7cMTkGort4xtkR W/AL4HSqGayAT3xv5SkJ3p4mI5f5oaOvI0xaGAo2an0v1Xje5LA687PoBP5xx9RImqXF 0vNHBHUq0lQKHiWXdiPbUKmXU2SD9IkM6g/ECj0KRedBoSgXBAVEv5qIoAUS+yQBQa9S zIRaBD7imu0f6LQrUOJO1bY+dRYdu26Iddn1+6xRJWPbZG1VSuHA0lBvKjzQaQulRN7y lH6d5nfDEDzF7GDyMYm29bgOEdtza3yrhIxd5a49spovJFSvSKbMD8n0yUscjGAJMIg7 ZIpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739634705; x=1740239505; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TcvhFf9DLoHV/4B16FqnaOvirPJd2dOTFDpMtuyEBGY=; b=jlOUrFr7RDMaHIHOeVfEedLQbpSiB7frRX157BjDp5meoXRlefd/ZePARCSndlvY7J JcJChcW6mh1QdTxmsSR9//6lq0nCNWx0pCUFJfcZ4l9+Ey2ij0LCYO+WbbQTWK6cHx5a ch6WcEPnxN61Ui3djHiRLnW4qltOA9fJtZeHGAt2Qwq+13klNe/ZNHY2O3XLOr8tLjAq gUkfUvE2e+ZTOAlRwvML5ZmMdxduEUQVsb6AQzPZSJ0y70ajEZZmBDkUYtVFTa3HDXYB LUm9RU+d10SYq1h5KORGj9v3QEZBY5a84vBjmjKAPAIhPNjMf70N2i0HmyvWR1sgKFc5 QzvQ== X-Forwarded-Encrypted: i=1; AJvYcCULPuZ4eLOH0q52SRQNvsBNon2fvBbaP+9HmWKYzXygIOsg6FjQcIUMXE5HMqOncKzlbTQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwB/uQQiYHZtzbpY7kVB5ptQc2CZtelerkHxHesm+ZXvwLglmdH F982G6Ggfrf2S21rslY1IMi9aIL5cn28GsB3IvFCR1ExW5wYsRza X-Gm-Gg: ASbGnctfrmx/c4o/4o8zhoDM0rZQS4VzrkT4+yyrmvriEaRrYVyJdy6Vn6D3KgSCjNQ h2TCcdgB3fPpmI0ZgIqGShJ5Dhu8pzfuBey9jKI2jeXypW/D+W1ZmoOSykADnNBIkfFLwRFEQRj Uh/HM/IlpAFxNfB024TMT/U9Pl/d61FF6ahXfZQomT6N/kDAfm2J4+8Tf1jM6zPND/w6Ey44iPh aG396FdRDwyE3zO9RsD1wE0ipA8uYAquFDrH1BMQNnCVa3PWnGxfc8dVRPeJTwaLATI+RmdjfnV 6ZEpq/5Shdhmd7zzkPWb/nqgfv/ZVqXdRD7URL6M X-Google-Smtp-Source: AGHT+IGZO5U5Lr3HRkh95veHwsd3A7XxxgE3BP9lvcyrbB1wv/LX3YYL5SX7IBrADEIG2xQqKGTl6Q== X-Received: by 2002:a17:903:1a07:b0:221:337:4862 with SMTP id d9443c01a7336-2211c55231bmr5054705ad.15.1739634704876; Sat, 15 Feb 2025 07:51:44 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d559089asm45024285ad.241.2025.02.15.07.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Feb 2025 07:51:44 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, gitster@pobox.com Cc: Johannes.Schindelin@gmx.de, git@vger.kernel.org, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v6 2/6] version: refactor redact_non_printables() Date: Sat, 15 Feb 2025 21:20:48 +0530 Message-ID: <20250215155130.1756934-3-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250215155130.1756934-1-usmanakinyemi202@gmail.com> References: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> <20250215155130.1756934-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The git_user_agent_sanitized() function performs some sanitizing to avoid special characters being sent over the line and possibly messing up with the protocol or with the parsing on the other side. Let's extract this sanitizing into a new redact_non_printables() function, as we will want to reuse it in a following patch. For now the new redact_non_printables() function is still static as it's only needed locally. While at it, let's use strbuf_detach() to explicitly detach the string contained by the 'buf' strbuf. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- version.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/version.c b/version.c index 6cfbb8ca56..60df71fd0e 100644 --- a/version.c +++ b/version.c @@ -7,6 +7,19 @@ const char git_version_string[] = GIT_VERSION; const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; +/* + * Trim and replace each character with ascii code below 32 or above + * 127 (included) using a dot '.' character. + */ +static void redact_non_printables(struct strbuf *buf) +{ + strbuf_trim(buf); + for (size_t i = 0; i < buf->len; i++) { + if (!isprint(buf->buf[i]) || buf->buf[i] == ' ') + buf->buf[i] = '.'; + } +} + const char *git_user_agent(void) { static const char *agent = NULL; @@ -28,12 +41,8 @@ const char *git_user_agent_sanitized(void) struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, git_user_agent()); - strbuf_trim(&buf); - for (size_t i = 0; i < buf.len; i++) { - if (!isprint(buf.buf[i]) || buf.buf[i] == ' ') - buf.buf[i] = '.'; - } - agent = buf.buf; + redact_non_printables(&buf); + agent = strbuf_detach(&buf, NULL); } return agent; From patchwork Sat Feb 15 15:50:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13976154 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DAC5B672 for ; Sat, 15 Feb 2025 15:51:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634711; cv=none; b=no9Feed/PMRBe+SlEc8ngX+hDb6JOq8Ol1sjw2d8CP0Vqx4u2p3oM9sEZYyqSYUEzleHKgHqXMjpCRLoDliT/1M8QUlaKF6vvKRdZf+b9SUMIc0gzOTQJAdmPRMQ5oCrr9fgAgaiH45s3bZFIep/pUEHIFZygkyjgvvoBQnLpho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634711; c=relaxed/simple; bh=42i8PUdjyKs+NSwGtLcbj9v39QXr3Du2dpk4eqznw+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JRFevWP46lF+27I7Y0qrkxgG8ZfOvdMIkl713iblBExNz0NyM4RMnVXo8DZuoxYPtcGWTS//MWWYdgE+t2h10VJM0ah0eHSZ+5XMhMacWnmBTDVILA52Dv7um+cI7WObg3hrPLeOdL1EbbEURIn7V+tbT+hCKOqHQi64o9y0m/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LCL+kGLU; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LCL+kGLU" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-220f048c038so29051245ad.2 for ; Sat, 15 Feb 2025 07:51:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739634709; x=1740239509; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ST9UH+tJO/KD1eiPpPYLssoj13nQqfVGYdBzpY/GozQ=; b=LCL+kGLU3lyNAelyD2awuMWvCR6RrbXaygP5dKgNcN3UqB2kBdYuwAF+qhv+T5vxpQ 95iq0YuBTKbn39nc4ausrnSEw/G/INOKAb0FCAf1svGA0Cih8qgYppHoHxrX6NKhCHor 4HZr3wDRlXxKXxg/AUJrmueGrUKKnnfevdReHOjpQKCrHdVUskvUkdEwsGImxYhc5DMz Nl8+qI/RGYDKKRftBE/2XOqKCkFwM37N3hHl7fHnnEX7LTuDCjzd8JTiG/cLB+2aDncY mRDyHo7Vr34Fo/OzvRFPUqj73c+633EVD7FKXtE4/bqU3rrEf7vjpHcl+lH+EcRXz9Eo tUtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739634709; x=1740239509; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ST9UH+tJO/KD1eiPpPYLssoj13nQqfVGYdBzpY/GozQ=; b=iObxdHJB+pdqjFXxp5g8mAfXOdBc4IckZoX+oiCu/x+jxHIfsV3PPYnAXiWd6x0tKL vkRJZUK09agY4rxWT1MZIFqAavDL7drVfrl1YSUKTyCKQCl02FyEm1HfWfZUq6STVZki KIbbrd5R4fYMQymsTu3X8rKNVTtvPH5SH1qr9lVVVphFzxph8ONgmIqN69hAHWjLC1aA 1D0Z0f+PWjwpMbRvjTBndRuuZ4f1WOiBA9zwLzn5eRApLGujyq9kefhrFMf+KFNSgny8 FS8ONcF8pjZSYLM5XzJNB5GItCxgl+twr34/dvSB1fzu37cB9z4XmbfKFXErH/95v0Uy ijwQ== X-Forwarded-Encrypted: i=1; AJvYcCUzI2RxMA723KT1GI2AugJqYOuGQTNARgR4eNH0I+T778J+dPrcAO4zD6GeJ9s7+p3FWNc=@vger.kernel.org X-Gm-Message-State: AOJu0YzPvRMYq9GxuslO9vv7Rbt4tCbtIv21CgrCMkwdqA5TBlOd7f4X iNYZzoKWtNqw3WKKVmbJvNrMHzR0J7eUwM0OHQ0O/x2c9yMz6Ge9 X-Gm-Gg: ASbGncvL/wyD5w8k9XfAHHLh0319/ET59FrrRuC6WVRWoIJXUsEQwrzSZvlMOoskmeH yD5y53HQQYrLgHR3J7pin6uXH7Me3O6+3YJf+gb6T/zePMHT7O4krBVn5wC3xA2k25EOm2M2VQF tUCxnmPV2HUmffOrrmpKo880SOccrMEf1cL35QX/pe5KtJyigLZbg3dJTLK8s/bLcbp5VLzicX3 oKPLs/aiVAju8OpP6QbGS9IEgHwvxSMXp40q/ItEQ8NYdJASVgBgGTcDLmpLI01WoTad2a8x63+ vE+kPlMgh6mucy/p7k3itc0Dqa0QV312oIwWufJZ X-Google-Smtp-Source: AGHT+IGAAjJby4V9mj/NPYxJZbV+BkdmjxKhnOheT1HhJRA+WBmDGKmUGCpy5ip7Dtn6WHOBxWkmNg== X-Received: by 2002:a17:902:fc4e:b0:220:ecf7:4b5c with SMTP id d9443c01a7336-22103f16d99mr56805365ad.14.1739634708864; Sat, 15 Feb 2025 07:51:48 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d559089asm45024285ad.241.2025.02.15.07.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Feb 2025 07:51:48 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, gitster@pobox.com Cc: Johannes.Schindelin@gmx.de, git@vger.kernel.org, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v6 3/6] version: refactor get_uname_info() Date: Sat, 15 Feb 2025 21:20:49 +0530 Message-ID: <20250215155130.1756934-4-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250215155130.1756934-1-usmanakinyemi202@gmail.com> References: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> <20250215155130.1756934-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some code from "builtin/bugreport.c" uses uname(2) to get system information. Let's refactor this code into a new get_uname_info() function, so that we can reuse it in a following commit. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/bugreport.c | 13 ++----------- version.c | 20 ++++++++++++++++++++ version.h | 7 +++++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 7c2df035c9..5e13d532a8 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -12,10 +12,10 @@ #include "diagnose.h" #include "object-file.h" #include "setup.h" +#include "version.h" static void get_system_info(struct strbuf *sys_info) { - struct utsname uname_info; char *shell = NULL; /* get git version from native cmd */ @@ -24,16 +24,7 @@ static void get_system_info(struct strbuf *sys_info) /* system call for other version info */ strbuf_addstr(sys_info, "uname: "); - if (uname(&uname_info)) - strbuf_addf(sys_info, _("uname() failed with error '%s' (%d)\n"), - strerror(errno), - errno); - else - strbuf_addf(sys_info, "%s %s %s %s\n", - uname_info.sysname, - uname_info.release, - uname_info.version, - uname_info.machine); + get_uname_info(sys_info); strbuf_addstr(sys_info, _("compiler info: ")); get_compiler_info(sys_info); diff --git a/version.c b/version.c index 60df71fd0e..3ec8b8243d 100644 --- a/version.c +++ b/version.c @@ -3,6 +3,7 @@ #include "version-def.h" #include "strbuf.h" #include "sane-ctype.h" +#include "gettext.h" const char git_version_string[] = GIT_VERSION; const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; @@ -47,3 +48,22 @@ const char *git_user_agent_sanitized(void) return agent; } + +int get_uname_info(struct strbuf *buf) +{ + struct utsname uname_info; + + if (uname(&uname_info)) { + strbuf_addf(buf, _("uname() failed with error '%s' (%d)\n"), + strerror(errno), + errno); + return -1; + } + + strbuf_addf(buf, "%s %s %s %s\n", + uname_info.sysname, + uname_info.release, + uname_info.version, + uname_info.machine); + return 0; +} diff --git a/version.h b/version.h index 7c62e80577..afe3dbbab7 100644 --- a/version.h +++ b/version.h @@ -7,4 +7,11 @@ extern const char git_built_from_commit_string[]; const char *git_user_agent(void); const char *git_user_agent_sanitized(void); +/* + Try to get information about the system using uname(2). + Return -1 and put an error message into 'buf' in case of uname() + error. Return 0 and put uname info into 'buf' otherwise. +*/ +int get_uname_info(struct strbuf *buf); + #endif /* VERSION_H */ From patchwork Sat Feb 15 15:50:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13976155 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88637B672 for ; Sat, 15 Feb 2025 15:51:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634715; cv=none; b=msyEPcIzaCXVO68sX/+PI2tfMjcq9p38h6AFSk6icdkyQZKNMr2+tix4RbJNI+b0oPeJ7RW8MGAI+6zGDrPCRQql8iyVX3hpzk5lT093/KjuNJAwyHiG7ftH8npSyQzLA7E/I2KD5h3ATY/arqqCAuID99DoWR9aOSlGH9V6ZwQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634715; c=relaxed/simple; bh=HVeukTMHNYer7qqxUJZvhIb+1eODx9LL40SC14YRDMY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RsD5+Z94stPJUxR/lWU1SGpTGrW/kv0GzSLXlRbM58xwyaBRdLVHzwUYCe6ecltceccA7qzvXxz69rxHisrkEoF/hzsw4y7dNqpoiahZ7JCD7ezdeIBO34FIY52j25FhSMkD6m+MTiDdHRo39R8kK80fjc/Ml7keoLEXl9pp5QA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mxuvXUsP; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mxuvXUsP" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-220d398bea9so42971715ad.3 for ; Sat, 15 Feb 2025 07:51:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739634713; x=1740239513; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BRekefwQgvdyI8vQ9EmJX5ETxl+wxhoojclqV8SCL8k=; b=mxuvXUsP/Wi60xZ31VnLRseNodI4k24gwyKWBSgNO8QebJllUdOVQs8W3m+JNeobPK U986uZVNJnrlB601K/0iPZMmvHysajcH+srZ3QMpEzc3Bs2FzpsrzyHzG9c2WxIADoal bKDVD3hCK9Gj7pffwQ7otFYaO7Xo7WTY892OlzlFL28uAT5mASjqVdb8aWcV2+bg0q2A +f85BlDnvle+rLICuZyUwbhg9C6f83aSSgGFQUdxdEIUziSmeRY3KWCY4g1qeC5WtabC g8X1vjC7FBcH9q4/LKSbdzZfQd9BJMLnFAS2mYv88iRi5R8M09affalJqWPlPonhI2ol TYqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739634713; x=1740239513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BRekefwQgvdyI8vQ9EmJX5ETxl+wxhoojclqV8SCL8k=; b=vsoKmo9FxHuzX9IDyNqFHWK1ZT+p3Xccol3JGrQa7tv5bA01jmcdxKR3BvlXy2XJt4 NNMF7z8Nu2VldF9oIGzW0IQX5CQYC0bzlD0thqTttUn+mcMnH96Z8e3D5fS/n3i6VbZ8 jvIllTZm1w/9MeGg0qsNyeAK7CW0sruZ4k83GiFWnV/PyC42T+riYokMZPWcam80l57G mFkf3td3ezu3vbUF/SW52MlDxOyyPoEzhvQhSUIgPLpiTWXQLPwhAAsXsCYLNm2NRG2a 2LFML1AX1I8w/DZc2vikRtU2XqJEwe5QPfRBsPiylflibzVwOv0hCVHlP81uS1jxazeE JRug== X-Forwarded-Encrypted: i=1; AJvYcCXe/jxeA5aFLYj4XhL/Oj4QZv06l1L0OSLo6EQjgEXCQKnqmi6XIbCIBoMsCH53f95xYFg=@vger.kernel.org X-Gm-Message-State: AOJu0YxSLR47FmWDP7UiOAWgtwG6sTUQ/zqrRET6t48/mYfVmyHTlejm yEp4kHZSiz5bZ69ULhB6Mq5TT2EEb3nqz6i0uMU0zyWqvjItNVNa X-Gm-Gg: ASbGncvRhsHE1Yx65kSDbIjMY/0g22YBGXHtOE/3MIcq9mPmg6YgrsXt1iDe3g0XYWm Gt151W+/Ww9HI6s4mkpjZ2xnVGY94svY8sblMXLjpNaNjiNkvhpDkhxsYT6nOoP7HQmePSOqp72 /faSkCXGggW6ofEvF8nnVuDniCz/xEoc2/bG/t9oZCdP0wz8/XGpEod74by7IRgdVZXP4TpjJ/2 YVfjH6NigjvIu3l1xEWvnUAQkvNib1DjBc8/9Bpk4rKtQdMNQBuB29ulCx9B1/Tdreofu4f6Ewe NJa60sx+cSvf/4PhMmOWAuBW4f8dfsx98t2I0C54 X-Google-Smtp-Source: AGHT+IGJN6wHqiovDq1/vyetYvFH64a/mIVW9N3L2s0cB8mNHvPfbLNbOVdVwpBJ3kpxmQjAK83Bxw== X-Received: by 2002:a17:902:e88a:b0:220:bf1d:41e9 with SMTP id d9443c01a7336-2210405f21fmr56334325ad.23.1739634712817; Sat, 15 Feb 2025 07:51:52 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d559089asm45024285ad.241.2025.02.15.07.51.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Feb 2025 07:51:52 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, gitster@pobox.com Cc: Johannes.Schindelin@gmx.de, git@vger.kernel.org, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v6 4/6] version: extend get_uname_info() to hide system details Date: Sat, 15 Feb 2025 21:20:50 +0530 Message-ID: <20250215155130.1756934-5-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250215155130.1756934-1-usmanakinyemi202@gmail.com> References: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> <20250215155130.1756934-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, get_uname_info() function provides the full OS information. In a following commit, we will need it to provide only the OS name. Let's extend it to accept a "full" flag that makes it switch between providing full OS information and providing only the OS name. We may need to refactor this function in the future if an `osVersion.format` is added. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/bugreport.c | 2 +- version.c | 16 +++++++++------- version.h | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/builtin/bugreport.c b/builtin/bugreport.c index 5e13d532a8..e3288a86c8 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -24,7 +24,7 @@ static void get_system_info(struct strbuf *sys_info) /* system call for other version info */ strbuf_addstr(sys_info, "uname: "); - get_uname_info(sys_info); + get_uname_info(sys_info, 1); strbuf_addstr(sys_info, _("compiler info: ")); get_compiler_info(sys_info); diff --git a/version.c b/version.c index 3ec8b8243d..d95221a72a 100644 --- a/version.c +++ b/version.c @@ -49,7 +49,7 @@ const char *git_user_agent_sanitized(void) return agent; } -int get_uname_info(struct strbuf *buf) +int get_uname_info(struct strbuf *buf, unsigned int full) { struct utsname uname_info; @@ -59,11 +59,13 @@ int get_uname_info(struct strbuf *buf) errno); return -1; } - - strbuf_addf(buf, "%s %s %s %s\n", - uname_info.sysname, - uname_info.release, - uname_info.version, - uname_info.machine); + if (full) + strbuf_addf(buf, "%s %s %s %s\n", + uname_info.sysname, + uname_info.release, + uname_info.version, + uname_info.machine); + else + strbuf_addf(buf, "%s\n", uname_info.sysname); return 0; } diff --git a/version.h b/version.h index afe3dbbab7..5eb586c0bd 100644 --- a/version.h +++ b/version.h @@ -12,6 +12,6 @@ const char *git_user_agent_sanitized(void); Return -1 and put an error message into 'buf' in case of uname() error. Return 0 and put uname info into 'buf' otherwise. */ -int get_uname_info(struct strbuf *buf); +int get_uname_info(struct strbuf *buf, unsigned int full); #endif /* VERSION_H */ From patchwork Sat Feb 15 15:50:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13976156 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CF3BB672 for ; Sat, 15 Feb 2025 15:51:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634719; cv=none; b=tH+omfR75jAQsxVCi7be2LgQ1DZrKrPxTqGR8K02RYIdDNRlqO95L9toLmBCvX3SnUHbsCwfumWmV7VIFCiGI3LtRGyYtAWVHvNpcao62G0FnuBr1aLFjmKmF1lePLWop2SqSTTnCVsP2qXmxqxWz+mNjWRKChE5xLfXaQdpmJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634719; c=relaxed/simple; bh=NgcdHkkLwudzQ35twlRCjU8htQPOSFjEU6KAQMFcIos=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KslCdagLj7LG61AAxgNxsBH5V8SQRjQDog6m8CUV7XO645uW6tpCILPgf5zW8XbBCo0n/nNRj7alN4SVutQThU3Jh4V11ukKPRiOOUnUgfMp3VaVJIiRI6WlFVBB3IEu/qYfIf+6qaXF7TGfc+XtPaUoy7a6CZBEAYsazXyx4kY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Em01Xz3t; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Em01Xz3t" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-220c4159f87so40875185ad.0 for ; Sat, 15 Feb 2025 07:51:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739634717; x=1740239517; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gpSXIfdbGTe6dt5KGY2+b6OJCQo7ccZYAQn8TcMKp38=; b=Em01Xz3t0oft0fVyhfKDVXc5fODp+OcipoB8PwNNJAS6aVPybwcNhHfXwkmX1fMpxY vr2Rn7vmD3b9U8dfMFmNapnjCG4A/hCS+E9kZhG+9cF0GSFjntyTNeR5JDPofHyy1fWr YHAk6/ii5v0rxl7TyC164pOQwp4nvfePLbTsHX848ia70nfqBxvpixGhJjQ6mq75gFwJ DgQx3+HOQAFxd89RV8kxlNImxQ82KTMujb6RMnTCtlHl1cEWCWdekDlW7uSYzt3i8iqf 9DtOhqprmwkWIyK5UyCMHfeD7o9zQbO9x38u3dai0ZseN/zsTg75HFy1E5fzNejndysc pLDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739634717; x=1740239517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gpSXIfdbGTe6dt5KGY2+b6OJCQo7ccZYAQn8TcMKp38=; b=ammXhXI1mnoEcDkLXKO6LMvfVLq2m/vBE11Ky1RHyOT9fD9X7EY++ZRNzHucuiiOAo BRSwwI0NOiCjb9DpivEmQwv4yV2/L1VmT8X34dPmXpins+VLGZbCFScH1yLbFFJ2/1FV MfUACj0CHcbVti5jDJEnOLM1CcqLLo6li6gBOJyfPaoUfJ/zOzWXNu+fAmEVGRIZFw+u f6ZcpIKI57aGti1urfRhHL64Ky5aTleeqZk1RuZT+f63iFU/t+GNie/o2AxdhG9LN8ON XvupoFPUVVPxN20tlQU24byt1NaJVecC64kf/+boJDirbvuCOogENAmlbuRxOgfbVwbV STqA== X-Forwarded-Encrypted: i=1; AJvYcCUCuQjUK7uAameiW1l06B+6BVMERSZOCuZQnfeZyyxmE/zvQ6DcjVPjV09PrbCdkR023+8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw6sT327YZLizzeU3L969qhvpHM9SyTxXEaFHb9Dpr60ywRTeMh drmc4lWfi/9JaaiD08Zrzd38sthxpzxZOSmT/An3o67xq5IBCooD X-Gm-Gg: ASbGncshvA6trInTmpLvPFwsT/RnaabuRcpte7mqJeMUSrgONYZKm/upqPZaNBzkYaG pwNQidiUx1pG8MqhYXE9i3aHwHxgSL8NbRzX+/EIYrz5axWLNjT2y37xJDddRm8SYodNtX4v6dL DyLx64qsGYKKdsCCf0oHHxw/OtTFKJx85fuIONZb23nasM4DwVdPY1ZS0FnI2B+ecGL+EacBwPB iZBaQ2YXoRc4JsOJTJd0s/SXkiRUKYeUEHflkuCxmOWka5/dEwm1U/IlDYuZymSfp9ivkbdU9eN VQKki099bB2CE5QgXI7nDFyhpOYG/1rUL/SmQQX0 X-Google-Smtp-Source: AGHT+IF4N/Zq3OnnhCiohsi6pRU2bQputA/3K+r+PFXLOAStK7cR+4Ro91kWK24ED3yRE7rlqasT3g== X-Received: by 2002:a17:902:f68c:b0:220:cd9f:a186 with SMTP id d9443c01a7336-22103c62dc3mr57144455ad.0.1739634716838; Sat, 15 Feb 2025 07:51:56 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d559089asm45024285ad.241.2025.02.15.07.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Feb 2025 07:51:56 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, gitster@pobox.com Cc: Johannes.Schindelin@gmx.de, git@vger.kernel.org, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v6 5/6] t5701: add setup test to remove side-effect dependency Date: Sat, 15 Feb 2025 21:20:51 +0530 Message-ID: <20250215155130.1756934-6-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250215155130.1756934-1-usmanakinyemi202@gmail.com> References: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> <20250215155130.1756934-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, the "test capability advertisement" test creates some files with expected content which are used by other tests below it. To remove that side-effect from this test, let's split up part of it into a "setup"-type test which creates the files with expected content which gets reused by multiple tests. This will be useful in a following commit. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- t/t5701-git-serve.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index de904c1655..4c24a188b9 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -7,22 +7,28 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh -test_expect_success 'test capability advertisement' ' +test_expect_success 'setup to generate files with expected content' ' + printf "agent=git/%s\n" "$(git version | cut -d" " -f3)" >agent_capability && + test_oid_cache <<-EOF && wrong_algo sha1:sha256 wrong_algo sha256:sha1 EOF + cat >expect.base <<-EOF && version 2 - agent=git/$(git version | cut -d" " -f3) + $(cat agent_capability) ls-refs=unborn fetch=shallow wait-for-done server-option object-format=$(test_oid algo) EOF - cat >expect.trailer <<-EOF && + cat >expect.trailer <<-EOF 0000 EOF +' + +test_expect_success 'test capability advertisement' ' cat expect.base expect.trailer >expect && GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ From patchwork Sat Feb 15 15:50:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13976157 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9712FB672 for ; Sat, 15 Feb 2025 15:52:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634723; cv=none; b=DqKP7ICZKcbhGVuZOdRV1GIWSmhKIqAcmbUdtPRq5+6lYoXVLuQxU0scMPaP0oK4Rb23FPMAVRn9fOO8n/HHo44sVBTWmrzDL8TsOwL09VEZ93/hNvZl/F2lbsTrPxUn0H0t381ANMDvNGwoBfnnNy88cbklCJNMIzFIdw38nTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739634723; c=relaxed/simple; bh=Nus5i8HAvRZpkHEYC8rjbLJKXBb+JtcQom4JdFjl9tM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BiL1oMTw1oQKWzwa5L0MAqPSIDY2kjIZfoiwP/74MJAE6rgarx0JH+TDTWo2VKNwxic2v6neoK3j9crkFr7otqPquYOwcqNs0PjAyrJtry/lg/F4laUXlaqBj56WdGEJvsVFPr1qK41VpnPTxwW5DB1cR5AyRL4vtBROmlJLInM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ex4ls2L/; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ex4ls2L/" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-220bff984a0so53557555ad.3 for ; Sat, 15 Feb 2025 07:52:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739634721; x=1740239521; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=02rixjac9xVj86b2mB98Aqwr8CO9Dz9kGZoiaq4BzUk=; b=ex4ls2L/jW3B1XR1bXSTa4g4+xVPMgUWiZboBZbnrS+GKmZTXi4w2RnTIHFdswhLdJ 26e/faozc0r0lYXXnpXKRaXRegLYF5qEop10BpsuFcbtK7Dd/tTzkFU9vey4KkoQu12Z zhUYbxo6MeVxkX1m0fxeksEeBAe+m0iyX10PSPLNjiRYaLG2/WDilkmU0R0voPCIdNLm 8ThbD83UXA47+sPoP2o4CnY0Ko/nLMydg8xZ0LkJ3lYXz66JpUzaWnznUGtDX4p++eI1 74iNNTDEg1nJ0Q9x+fIZ1Gk37WV5mIasGJKlPxytQEcI8ODB3zpr7abXw3T0M6MYzmEs knEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739634721; x=1740239521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=02rixjac9xVj86b2mB98Aqwr8CO9Dz9kGZoiaq4BzUk=; b=K3rwdEzq3EvbDNW2y2q30Y3I+tC7gOCURXSc87PZesNyIzzaEDB0q+AgpPHDR1frP5 4/NScibw5kVMhQ2W878lCqROIqSI5614tgAx49rn8FbfuchqcgIqpTjdJRO3SoM+LeGB Cl71aF/JRf265ex7LJfHxkD2kwJsBnq8VNt69FXkd7yLGcdPeZtfpoDiB9FVAjCXIR67 LFN6lf1LOJ5SURZH/ArfiQxX5DoY0ZyHc8W6PhsqloldNn5d3KH2v6+xPMCWQWPbBxDN o/685DAq1VZFoJDSFBQg7I8DfnwzEF3uoBzEJfLj3B9+xycfoi9xo7KrO50ErizHBxE8 Jwwg== X-Forwarded-Encrypted: i=1; AJvYcCWSn+7KjMyF+nBq4WJjx8JAsgylNn4VZR/MDuHElEynvs9NSHCuUp5wj4YoHbypxVTX4vM=@vger.kernel.org X-Gm-Message-State: AOJu0YxZMSxwzYExTQuva8vu4VzpysZoQ61ICM4r5Rkv9Me7lUB7FNYe JCTsu+eUGywZtk6SkODBPQ/xoovLIVVOJ6yMdVB0XhtuTsRq9U9r X-Gm-Gg: ASbGnctjIvUpo70y6tMU3GGR77cPSXqAvvxtO/268UnU4KY6tESzlSsn7JKiEITDO8P /HRcn7Erb2R7yge0l48UuPJztW6Wl+Fla51eo8AsYILf+m73jJj4+21IMQKhLDRFat+uFu/7hXJ bPoPTmAk0ZFFeEsl7QJiXR7EYwM0D1iBWZorp71kkKB9eh99949g4M/Z1LrbNCE6w+joWc6AmHp PXLCIbBMqVrrCdQtWjXpS0rf/88/AnSjM1OIhRZutUNIJIY63Lo8Qm1nC4V54Thz2R3LPVDo96h 4ROPsjodNzqaR7r8IC6eaRa+Kru16po3+JOvl8Kw X-Google-Smtp-Source: AGHT+IHAEmVRT4IU4IojGFPeUDZc8N12nV3VkneWAszgufETEpp/J6Au2/Gnd+MV5TMk2p3r3VHzMg== X-Received: by 2002:a17:903:2f88:b0:221:331:1d4e with SMTP id d9443c01a7336-22103efedc3mr54927905ad.7.1739634720823; Sat, 15 Feb 2025 07:52:00 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d559089asm45024285ad.241.2025.02.15.07.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Feb 2025 07:52:00 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, gitster@pobox.com Cc: Johannes.Schindelin@gmx.de, git@vger.kernel.org, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v6 6/6] agent: advertise OS name via agent capability Date: Sat, 15 Feb 2025 21:20:52 +0530 Message-ID: <20250215155130.1756934-7-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250215155130.1756934-1-usmanakinyemi202@gmail.com> References: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> <20250215155130.1756934-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As some issues that can happen with a Git client can be operating system specific, it can be useful for a server to know which OS a client is using. In the same way it can be useful for a client to know which OS a server is using. Our current agent capability is in the form of "package/version" (e.g., "git/1.8.3.1"). Let's extend it to include the operating system name (os) i.e in the form "package/version-os" (e.g., "git/1.8.3.1-Linux"). Including OS details in the agent capability simplifies implementation, maintains backward compatibility, avoids introducing a new capability, encourages adoption across Git-compatible software, and enhances debugging by providing complete environment information without affecting functionality. The operating system name is retrieved using the 'sysname' field of the `uname(2)` system call or its equivalent. However, there are differences between `uname(1)` (command-line utility) and `uname(2)` (system call) outputs on Windows. These discrepancies complicate testing on Windows platforms. For example: - `uname(1)` output: MINGW64_NT-10.0-20348.3.4.10-87d57229.x86_64\ .2024-02-14.20:17.UTC.x86_64 - `uname(2)` output: Windows.10.0.20348 On Windows, uname(2) is not actually system-supplied but is instead already faked up by Git itself. We could have overcome the test issue on Windows by implementing a new `uname` subcommand in `test-tool` using uname(2), but except uname(2), which would be tested against itself, there would be nothing platform specific, so it's just simpler to disable the tests on Windows. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- Documentation/gitprotocol-v2.txt | 13 ++++++++----- connect.c | 2 +- t/t5701-git-serve.sh | 16 +++++++++++++++- t/test-lib-functions.sh | 8 ++++++++ version.c | 29 ++++++++++++++++++++++++++++- version.h | 3 +++ 6 files changed, 63 insertions(+), 8 deletions(-) diff --git a/Documentation/gitprotocol-v2.txt b/Documentation/gitprotocol-v2.txt index 1652fef3ae..ce4a4e5e3b 100644 --- a/Documentation/gitprotocol-v2.txt +++ b/Documentation/gitprotocol-v2.txt @@ -184,11 +184,14 @@ form `agent=X`) to notify the client that the server is running version the `agent` capability with a value `Y` (in the form `agent=Y`) in its request to the server (but it MUST NOT do so if the server did not advertise the agent capability). The `X` and `Y` strings may contain any -printable ASCII characters except space (i.e., the byte range 32 < x < -127), and are typically of the form "package/version" (e.g., -"git/1.8.3.1"). The agent strings are purely informative for statistics -and debugging purposes, and MUST NOT be used to programmatically assume -the presence or absence of particular features. +printable ASCII characters (i.e., the byte range 33 <= x <= 126), and are +typically of the form "package/version-os" (e.g., "git/1.8.3.1-Linux") +where `os` is the operating system name (e.g., "Linux"). `X` and `Y` can +be configured using the GIT_USER_AGENT environment variable and it takes +priority. The `os` is retrieved using the 'sysname' field of the `uname(2)` +system call or its equivalent. The agent strings are purely informative for +statistics and debugging purposes, and MUST NOT be used to programmatically +assume the presence or absence of particular features. ls-refs ~~~~~~~ diff --git a/connect.c b/connect.c index 10fad43e98..4d85479075 100644 --- a/connect.c +++ b/connect.c @@ -625,7 +625,7 @@ const char *parse_feature_value(const char *feature_list, const char *feature, s *offset = found + len - orig_start; return value; } - /* feature with a value (e.g., "agent=git/1.2.3") */ + /* feature with a value (e.g., "agent=git/1.2.3-Linux") */ else if (*value == '=') { size_t end; diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index 4c24a188b9..678a346ed0 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -8,13 +8,19 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh test_expect_success 'setup to generate files with expected content' ' - printf "agent=git/%s\n" "$(git version | cut -d" " -f3)" >agent_capability && + printf "agent=git/%s" "$(git version | cut -d" " -f3)" >agent_capability && test_oid_cache <<-EOF && wrong_algo sha1:sha256 wrong_algo sha256:sha1 EOF + if test_have_prereq WINDOWS + then + printf "agent=FAKE\n" >agent_capability + else + printf -- "-%s\n" $(uname -s | test_redact_non_printables) >>agent_capability + fi && cat >expect.base <<-EOF && version 2 $(cat agent_capability) @@ -31,6 +37,10 @@ test_expect_success 'setup to generate files with expected content' ' test_expect_success 'test capability advertisement' ' cat expect.base expect.trailer >expect && + if test_have_prereq WINDOWS + then + GIT_USER_AGENT=FAKE && export GIT_USER_AGENT + fi && GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ --advertise-capabilities >out && test-tool pkt-line unpack actual && @@ -361,6 +371,10 @@ test_expect_success 'test capability advertisement with uploadpack.advertiseBund expect.extra \ expect.trailer >expect && + if test_have_prereq WINDOWS + then + GIT_USER_AGENT=FAKE && export GIT_USER_AGENT + fi && GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ --advertise-capabilities >out && test-tool pkt-line unpack actual && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 78e054ab50..3465904323 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -2007,3 +2007,11 @@ test_trailing_hash () { test-tool hexdump | sed "s/ //g" } + +# Trim and replace each character with ascii code below 32 or above +# 127 (included) using a dot '.' character. +# Octal intervals \001-\040 and \177-\377 +# correspond to decimal intervals 1-32 and 127-255 +test_redact_non_printables () { + tr -d "\n\r" | tr "[\001-\040][\177-\377]" "." +} diff --git a/version.c b/version.c index d95221a72a..8e927cf1eb 100644 --- a/version.c +++ b/version.c @@ -1,8 +1,9 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "version.h" #include "version-def.h" #include "strbuf.h" -#include "sane-ctype.h" #include "gettext.h" const char git_version_string[] = GIT_VERSION; @@ -34,6 +35,27 @@ const char *git_user_agent(void) return agent; } +/* + Retrieve, sanitize and cache operating system info for subsequent + calls. Return a pointer to the sanitized operating system info + string. +*/ +static const char *os_info(void) +{ + static const char *os = NULL; + + if (!os) { + struct strbuf buf = STRBUF_INIT; + + get_uname_info(&buf, 0); + /* Sanitize the os information immediately */ + redact_non_printables(&buf); + os = strbuf_detach(&buf, NULL); + } + + return os; +} + const char *git_user_agent_sanitized(void) { static const char *agent = NULL; @@ -42,6 +64,11 @@ const char *git_user_agent_sanitized(void) struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, git_user_agent()); + + if (!getenv("GIT_USER_AGENT")) { + strbuf_addch(&buf, '-'); + strbuf_addstr(&buf, os_info()); + } redact_non_printables(&buf); agent = strbuf_detach(&buf, NULL); } diff --git a/version.h b/version.h index 5eb586c0bd..bbde6d371a 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,8 @@ #ifndef VERSION_H #define VERSION_H +struct repository; + extern const char git_version_string[]; extern const char git_built_from_commit_string[]; @@ -14,4 +16,5 @@ const char *git_user_agent_sanitized(void); */ int get_uname_info(struct strbuf *buf, unsigned int full); + #endif /* VERSION_H */