From patchwork Fri Feb 14 12:36:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13974830 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 CAFA8263F47 for ; Fri, 14 Feb 2025 12:37:45 +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=1739536671; cv=none; b=Iy6SxyMhkU8vbTgX6F0JFjMyB+VkQUOVZbGdxIw/MaTNuqaYPpLRH1Urb30GG9T9HYtyIDztSj2/5Qas0EBnBiY1rfKATtjlMWLFgdnGo3vNUQG9IYDwJ0V8xJCPy62JUoouAslkTgYI876H2QFBOLPdhyKLoDz3PIsoVzAGxDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536671; c=relaxed/simple; bh=fB80ASbecHtp4fGMlEVSHuxVoWUEiTfhiT/c1rpUQfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JNa98aL9JbL6OdN1DkJD+XcXQ5OpgKfSTebxVM+hQ+nfuTbjrFpH8UPeOByPoIqhtzPzdGY3t0S09EW/BLqh8aKFgOo8Jsgktl+wlrRBdUFvVk3XbZlc/jRp1i7/sTMzIpeMuN6+MoeUIUgiz9uqf7JdEcUEKQWffliLEeSRd4g= 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=BxH+aetW; 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="BxH+aetW" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-220e83d65e5so22284125ad.1 for ; Fri, 14 Feb 2025 04:37:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739536665; x=1740141465; 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=BxH+aetWTjBGzBQcZxB+Nv0CDZWHUCqt+N+LQDisnqrl/2lLNoEgoitDlE4B/E+vKS BId3UVX1Z86EJN7lQY/9E0MJy/xr59YzMI9hTcTynNanuLZpH0BaW6X9h2AwTaClLIEl kP6G0DULS+e2ms+lEkXfBVgGFV0oMXaYuWCD5gf07vYsxK81WHd2i8bp03JV3SKOXj9d OSyZRVV2un02pFi0sFz9y5+d+nGOu7whZdHnJlMNcTrdlq7d/SZ9KPk9xenhwLRnMQO5 duhnCv+eO2ztZsTymmeMXUzj2Qx5FEsXz/clgOXR/3v4TnKvpFkxD3xMZoBz8FF+je6Y wV8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739536665; x=1740141465; 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=jw/pz+pNSdcAHcEhSbntf9ozVNMNeTEC6md5y/IkGcIJXNgpS1bGCH7LmiQCo4rdGd Cp9+5ITCwdda7nCBW+yPJNvq+D0eT5nIfvnZoG3hLCpjWrazbuWfDSCoB2BJutr44OJ4 91K5lK57xvsffR1mRAlXqh0h1W9vcJi3uIJFl9ZgYPmYfF8P7hpo7XTHXT01a9mLYrwb 6nH90y3+l3DHm/sAO3Jui8x724y4pK4XXdFq8BvePT62lrCJ2ONryxRdjmnSmj2C8eV4 WrLkSrUOPuFZZTDSeBzL9Vk148xZhTHkCRpXu2HMsaSCLXXhMJn/nZzdTLK0tRKp7H7q el4A== X-Forwarded-Encrypted: i=1; AJvYcCXWdr4xh6rWjG+Bh1O0H+Zfh4wiLutgOVLKmK9YBni8tQStRvAUevu4XhLrOglSSn9n5q4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2vkh4aruexJXzI10tRu0txGCOjmIP8PhvgC/CZiCz2O7FQb2G /LGEMIZw4OwMLPhmB/ybwK40fcsYfhsxAE+dHEV6uH9xS5VDWeOQ X-Gm-Gg: ASbGncvbxNbyherNazuyuillAntDgdt8xcgOZvALQOgOeSU9hK3NiA2lRJ1/6UTE41d FNLbshCjy3elmgJV5oLy7KDFrYjYpCt0Q5dhzdgujYD1Cas0tbPneyu/uS/wAGCDgdZsm9toOy+ upzfOzlyGieU5E6EIfglhuGe3fsr9qdmqiuh+mv5edR1QvbzcvJ/froDOkjVQOBfYq2IJCr9uk4 eQA9mUgpfZOxgE25zrJUKXZQn+Z/L7vCts7WL88Qu7pC0214pPlRkuFTkgFio0xu3TSzUkQ/tmP N2pOqMGeEJGPr052laDxYBXmil2FEdQVkdM0xJag X-Google-Smtp-Source: AGHT+IEnuf/peGu51npdfaMPnCt8ocivzHyW1TOS64QRiUgdRD7Q4Wdwlqcr+vyNSO7b91Lpuc7avA== X-Received: by 2002:a17:902:d4d2:b0:21f:1ae1:dd26 with SMTP id d9443c01a7336-220bbcd0acbmr167342575ad.52.1739536664865; Fri, 14 Feb 2025 04:37:44 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545d09esm27814775ad.112.2025.02.14.04.37.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 04:37:44 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, git@vger.kernel.org Cc: Johannes.Schindelin@gmx.de, gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v5 1/6] version: replace manual ASCII checks with isprint() for clarity Date: Fri, 14 Feb 2025 18:06:11 +0530 Message-ID: <20250214123734.1403120-2-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> References: <20250205185246.111447-1-usmanakinyemi202@gmail.com> <20250214123734.1403120-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 Fri Feb 14 12:36:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13974831 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 2319C263F27 for ; Fri, 14 Feb 2025 12:37:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536672; cv=none; b=sYni8oS85KujlICLZxpgP5YrLHTQzmJlZckdsTouDGI9NveOPbzm16hjfgbO7F4sS2TeswscbRGYgZCgsDXQDCnY2+lc9svOjMNibnpUVG/HaNlkADZjSbiqP8L9O9G74T39o2xb/mm19cs4fDVE/UzSrayIGuM9pHYTxgRJKH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536672; c=relaxed/simple; bh=auT7Nq8j/Oj7j5e0/1qmYiFTBmU1qvLdasGT5WYJd5Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=atTZF2uW30dQ1uKRqsxuJAxOcj3JZwCDJiygHjmEWCPzZvBb+3LWGMD9dGLv3NKWFsd4C9dWFsOEEGDOpcBEOxQzwqkXZSP4ECBrJsHIO/ypvUFwhoQBbo93kmEUDJlW54FYdKHjUW8oFAeIHkcdO4cWsv6ZvZno03IT9JFT5pg= 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=OwjemjRo; arc=none smtp.client-ip=209.85.214.175 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="OwjemjRo" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-220d28c215eso26707625ad.1 for ; Fri, 14 Feb 2025 04:37:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739536669; x=1740141469; 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=OwjemjRoDHQuJbNczomAzyblZPTx01nIGVfCT/4WUfCOW9k8A4c0hJoSi0tG79Zy6C Sfob61ZYhqHFBLlC57E0XEoI6DtCn7RFk26w1fXZli8zRFzuVjSkC9z3aaMeycPEPvG5 DxN+7FJcGlZUZEkwVXmYxucZwbfSxX2eCVIecKww/NtxWMjsr2EXtMfoVWJLJZdyk5kI 3zf6LoWkSeTtnjin+FaQ6BI6VGIMSPiAdohuOZ6wKuxNxHHmZ1hcprZWfW2MqUVhZCsH bvRzlkaHjq0bxnVn3HCkLYTp/PeTHQ8fMPAJ6HvuEHCSafabf+zPDsWJBktFwiLr08Ag ImDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739536669; x=1740141469; 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=RkvsRroAwUIVRDMTkS4HC6/bdcTnUC6h/KYuw3b6rrWnOsWRQa+uzqZFJ8MyuTOypX GP9G7ZEj8tBoxV3w36uWPFxGVcmgO2VsBKwEKBYb/LBeqgNdxlEsS4hT338bKyjQg5HN ff8unO28oJBY1I+dl+R9MdB8RMNomuMCutSeXheUpxlhuY7kSlZABIx0zSBuD3aPcTx6 tc2qKORtyaQHPr3M6AQ0Gr0jD+V8W7loEGcHa34q6lZVzXj64+w56h7Yx/BhDPzB33Pn v87ANHzQtaiB9QQ5qF1ALTkuC93/EwXgr7c8sVwoUtfzx8GbT0oPCvIPhYaOYFN/cEHI t4Hw== X-Forwarded-Encrypted: i=1; AJvYcCVrT1Kyz5GbN4TFUQ5RXMwr1Qz9KAC8+XH8hx1G2jm3/LXmVu3Yp/tMC8q+sjmd5hXY92k=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9TVmDR1q6lexYwHuS/YpXwp3H6O41lXJWvEAOrBkeBjbxATw4 d0z6AaqeHIm+ar0uXS5AozMpxu4VTLThyoNUBlTqga1jXfEj59Qx X-Gm-Gg: ASbGncuv6OrFYVGF0qJlo+qh+3APsCFAuI0WyO5QQSjp4BhESPqcdq6UKq5Hez7jH1R sZgKGDGekVBXDDY7a0/vtElSHZWnlmnQB8sFs9Qmzcgpe9HGb1/bMJGAo+ed686mwmf8uS5f5F4 TPrQT+JMNERw1FfE+x7J1+fus0GyTm1qqPfuI4bExxO3ELLLk5/FlDThRfoPQT7E2wJ8l+HQuUZ h3Y5X2JuHtAN+ZCkKM13KcazMWzay0w+doGppNvnVueuTHodKvrHo4TbSJvW35vUTAadmAHg/Jd a1Pds4sU4abfNv9CKrdz3OxhDdKHQvBbLCEhGSCf X-Google-Smtp-Source: AGHT+IG7fUA8PD07KgJvDiF57aLbfmUowhYItlcxtoYZ1KyRnxEdXExvyx52+v4Y39zKERdO2h9dew== X-Received: by 2002:a17:902:db0c:b0:21f:5e9c:c349 with SMTP id d9443c01a7336-220d216b66dmr114637955ad.43.1739536669194; Fri, 14 Feb 2025 04:37:49 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545d09esm27814775ad.112.2025.02.14.04.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 04:37:48 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, git@vger.kernel.org Cc: Johannes.Schindelin@gmx.de, gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v5 2/6] version: refactor redact_non_printables() Date: Fri, 14 Feb 2025 18:06:12 +0530 Message-ID: <20250214123734.1403120-3-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> References: <20250205185246.111447-1-usmanakinyemi202@gmail.com> <20250214123734.1403120-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 Fri Feb 14 12:36:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13974832 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 1DBF5263F23 for ; Fri, 14 Feb 2025 12:37:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536675; cv=none; b=l2Me27bS5kDVT2xeQoF/HV/gEUodt0HrmX8rxOVSY+4VZApF6j6a9aSUneX56ZZneviIMv2iVsaO9MkazmYD+oUPGyrgfDdTYwoAeKCYQJHjYposS1zfnITefmhEDI9op1PmaQWgiuf37my18Co+TzNs9WsNmp2RK6ouyU2jHgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536675; c=relaxed/simple; bh=42i8PUdjyKs+NSwGtLcbj9v39QXr3Du2dpk4eqznw+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PKS5IABkqxRdu3VtOqQUFsAcHEwM0ZVyU40xuni3zKAqoA4uc5wwuqE49MwqiCDkCQVVQXp9tzgDZgr+qdPV863eoAoV6Z1Iqu8v9FJu+dlix5kX7AMZPUqXrAFRgJ3dsGsHXcl7SR0CJ5DQ0OGp9X6XiRn0tMc8hiN0ixHRkag= 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=SYCePan+; arc=none smtp.client-ip=209.85.214.181 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="SYCePan+" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-219f8263ae0so33322495ad.0 for ; Fri, 14 Feb 2025 04:37:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739536673; x=1740141473; 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=SYCePan+HYMypEattmEetFPSsRrEJZpgc9a9n9UVM4J78ebyv5rkI3uhW6NSvPbdgl 83ziCDK2onUY9Zb94peYv6tbHWCVWrrLiDlnUJKGtra7OBsx0GAe2VuXlKe9j+RibgN2 E9i79fIkU06R+UXDXupe4N/nVwG/d6DwVwwKapGPd4G41814+IOy1xyJqzrovZWg6wX1 1BNrxKVNqZRHd8I39PWCiQc/JWS666Gp/krhvSF45HBS5iU2zjPnUbEIF6D2oxLkzVyc OG+8uHuXMotenfm4mp7solimEnh9nJ7FUnrQ366uOdsR4DtFcjHBCbk6DoOnd9fkjdMW 85rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739536673; x=1740141473; 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=DNGKSNE1nUmgEFSZ6EqIXKtvalaLBuZ1CBKrpaZV7ajfTrBIhK5EiQo2SQDHP99RiS P70lPIyQL3rsEdndt3JzLLP6N9qACLb5UoK+Jy9d7uipBK6aVH/+PXb9tZQT+gbz5Rsa Fijukbt6tLP8WIcPZJ/WZZg+Av6ov6OUkx9H1hKFLVvhjQSaueE6n35k610Ejo1NLfmi f8QuHBcnykVUe1d4w1Hkpy0/Cvko79332TOJL9Zb/xntXqsGcSWTFNm/UWhPaMDha1en fEO2EWEuM7nl5dMKpqze/lcnA0y+45oxHiWPThNqVcBD0BM9ymUu07+7WOP4nhHeYNnk nghQ== X-Forwarded-Encrypted: i=1; AJvYcCWMbHV/t5eY6Ant+zA7ggC27Gw4LVPlFw30bMzGVmZTlE3/7W8la866ulw0ILjwsLqHFiw=@vger.kernel.org X-Gm-Message-State: AOJu0YyMnnkpUM0gLhYyZYyd/RHJESNR2znaE2rXS2BZAhiUv6cVxHpl pyZaq5MFu/CCjh0gI0eD7UsPU0uObxn8RvaSKtZolvrlNOpZOe8B X-Gm-Gg: ASbGncvE07Ld7trxmDMiNL7T9dtvNOtSmOAt61y33JqvuEWNKlSe9eiQ8uqJEhFVsst 3Ape8zYg/zZPXgjt2HIUu6HNPCqoc3KXQc+kgvDKJQbj3BaxN79aIEsKijz6xwzyzzMlFGr/u4w ROYwDevN/VNI25kvM8/QChJ55gu9Pqxxo+sy6Icwv3oixb52fehibIOSdya+o0U5/DaWZGshDOg jrxxkJpZvaXwd46w0PL34FmUkq5XoFDHIcnbIGiAAvzSVeh6luQCTbezpDFr7YEDT7VbNut8eRd BwOOm37BFegI4jWWGIgFBj32AaPTBrOGwfZtUmi8 X-Google-Smtp-Source: AGHT+IHkwkzIx8pcCSLAHTO4BNhhuJuK1PPDOfgbOIjM48czG1NLzt5a246xc4Mrd/4wpsq9z4lr9Q== X-Received: by 2002:a17:902:f54a:b0:21f:6dca:6932 with SMTP id d9443c01a7336-220bbc7f9bamr191186955ad.43.1739536673417; Fri, 14 Feb 2025 04:37:53 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545d09esm27814775ad.112.2025.02.14.04.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 04:37:53 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, git@vger.kernel.org Cc: Johannes.Schindelin@gmx.de, gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v5 3/6] version: refactor get_uname_info() Date: Fri, 14 Feb 2025 18:06:13 +0530 Message-ID: <20250214123734.1403120-4-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> References: <20250205185246.111447-1-usmanakinyemi202@gmail.com> <20250214123734.1403120-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 Fri Feb 14 12:36:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13974833 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 9B241263F49 for ; Fri, 14 Feb 2025 12:37:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536680; cv=none; b=iYoJhv2KeI2X0OfuC4DOXjJ6sJfF1uxyHY5j3k5g/pt4v8qevVe+iRiSfEUoyKKjSv52XuPjBiM8qcX7UU83iZH+LrWRFbz6XDszEvL2kabe4EP8khuHGqy0NxsGCE1D0CXAin0djzWgW96w60mEsAWXme5HxtZcBHUyFAAZPQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536680; c=relaxed/simple; bh=HVeukTMHNYer7qqxUJZvhIb+1eODx9LL40SC14YRDMY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ug1F0t1CEJrQkJuZjJ7KYL5bFA6lB4ALNV7ghi2wYLf21QO10A3kwp3wKDNoMgyyLhoPoRBFgdit10jUfpq1I7R+/KzHEWercLamWOw2aqc+T0r9gN7UDBXyiiLt2IMifKpz0B094hAkxZaSOpW6BC3R7m++hR4orktOcd/1f3A= 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=EoZ5WM+k; arc=none smtp.client-ip=209.85.216.41 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="EoZ5WM+k" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2fa4493a695so2959632a91.0 for ; Fri, 14 Feb 2025 04:37:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739536678; x=1740141478; 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=EoZ5WM+keK6bZBWv5jJNb61D9Jhdh4hxP+SEyBGnMlu8tNZ1ffI5OTaaUGjD0AMw6m JTFbY2gytqIRfypt9S/9U1cqKVWdBRhygFp7Kf59iCNAYlIK4ILHuIC5QEmdURh4y+Y2 5MnE9XP54OJe/NY8unBMsd0oZ+Xge3CuPI0G5/poXZvFfZDwFvy9SgaRn/Mz6gGQQW5G IKWPfGZvDmZZ07Kiq8Bzr9sB01B+oINdcPi2yk9VkWxD7wVu5eQ0zDQ7Rz7fc0Ji35xs rVpMVqYLVD8FSC59ipsAd2ET/8+DsffZEy0n2IXdcy6UVGNdpUtiHoNC5dwAiXgrP5WX Relw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739536678; x=1740141478; 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=bxMhDKD/tF7hVVZfJ7HsPP5E+nBSofVAmvZbKwsH98kB/3fcckyBab7caBuJVZRBST So0w466w7P0bF9GYMHjQr4J/C8yY+F+XoYNKvar3+CdL2q2COmhHh2J5TOllV4e3Ys8Q ft7+BbuBHqtaGF4o5pns0KNbhoflnAREcBoUgcorVnS1GKUu+G8TQopg+T99ny4DzlKh omdormdd1OaU9vF5b0JCZ+Bx/U3W+g7HNmOy334PmaiGiqhVEO2wIq101jNu35l4rEuT ftscecbP/fpXdenFY64H4qoEosoWEvy2f2hgK5Xv0HJA9bDJHrdMD0IWyGUKvfZmZijy +tZA== X-Forwarded-Encrypted: i=1; AJvYcCUIKNTWnkUgUfsa2RDrATfIQZFgMKQVcSWznV7pWEzW8UtjtZwGCQGg2dNVdhLpXW6VYjY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5rOrMXHDCHOO8+BfThUD7QzZsWpKUXsYrvI9WA5MQIC65ranq Qfh+m+bBSxRYJUALELUr44zLTIwds+UkYlx86IYSCv6D63MEy1xi X-Gm-Gg: ASbGncuajxHo5UH3WLX7AT6/I3Y4XHVhZpeCj9nfth3HZZwAjYDZDhf8K/U7d0B8yyJ fBRxz97kbdiCA0igt8CIrLsUFtAX6XjvRJraGeY4xOvw5oKgngxhXfWMigM9z9BIrwAcvGC1j5J nbUTfZKWVnFSwaYDRrdBLEBeXDk3KHW7xChiW4q15JegG68khdvPk29rpv24LSyLGQB9yfcisov IZ9wOk347kpEeGtXns191UQ1a8VreL5MateJ00oknDfYI3G3/mYpF9n+5mvSwrpkDkENYEry9kt Qvd4vXMnEaQJkNiphwNYdnMFDZQuWSR4w3gYx93k X-Google-Smtp-Source: AGHT+IFGXwUcB0PEOCFA4HbcHxi5f2EcLRmiVnLsJvGLmFKknAP4B4DdHNDbi/HKJ3A7ZknVnFaCLw== X-Received: by 2002:a17:90b:1d8e:b0:2ee:f440:53ed with SMTP id 98e67ed59e1d1-2fc0f0e4798mr9766756a91.31.1739536677798; Fri, 14 Feb 2025 04:37:57 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545d09esm27814775ad.112.2025.02.14.04.37.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 04:37:57 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, git@vger.kernel.org Cc: Johannes.Schindelin@gmx.de, gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v5 4/6] version: extend get_uname_info() to hide system details Date: Fri, 14 Feb 2025 18:06:14 +0530 Message-ID: <20250214123734.1403120-5-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> References: <20250205185246.111447-1-usmanakinyemi202@gmail.com> <20250214123734.1403120-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 Fri Feb 14 12:36:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13974834 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 E2733263F47 for ; Fri, 14 Feb 2025 12:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536684; cv=none; b=RKFG8fHNpoScS8XaWf1n6WoeW+ONlkCAEasQPByDtQE6Sq6W50mK4tcPHlG53t1KR+UdV93kmU/clYJkthdAZspDVT5XpdLVz3qQ6YvVRRu57NEcl3YKaA91p6zqpbzmVJvnKyZ7a1yVqTQuy2usTgiSim7JJE4TUhkMKur7/8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536684; c=relaxed/simple; bh=NgcdHkkLwudzQ35twlRCjU8htQPOSFjEU6KAQMFcIos=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ovc03uVXR7V9Sr2EOpaCQeQjRWYaEl+KDrP+1x0u33FrhtjxxcCarNmyTjMqabbc3nOtgqFePV/fp2cDZy7QlIaXv6Qsmf7FnLztIGY1cMH1QkBbnmU/nZIpatNTD5F5HXO3CBYCqGh5Nk++9y+SwJvojGpAndcZZXrEW4kX1EA= 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=AeqsDwMg; arc=none smtp.client-ip=209.85.214.179 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="AeqsDwMg" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-220e6028214so25125985ad.0 for ; Fri, 14 Feb 2025 04:38:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739536682; x=1740141482; 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=AeqsDwMgphFT7U9vMYqLvvIhV3LJNjC1Wb+cGhfWhyccBTfkRU4GqIR/ExY8wRvypn 9WahG5LHqksJ3FjH9vLwuN3ElI0j+XKfg/bCBobGwrKabu/Z8tcBZjGIKxQz/GkdmUMf Red49jE/9kPF5Cqaz6yfyhGpeW/brTKD2AOvlaGjU86vCKlk82FSHB7Ru+H4CwL/VbQa jYDWGEO7xnYhHbazNxc5gx3TrYHOmumrUzbEbfedgLViKcDYOhdBPMaYPat0/zKThA2q 22sqqeiRYrf8euNLJfVr4C1zGsJechnfSOeije9V51rP5kSJWMJv/Qbp5lHHTyb9NzHL TB2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739536682; x=1740141482; 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=PRrwYXCA9zYUckLgndpT12kUz8ywYI2g9PDB4cq6DhdLXFdvqmOGDGL38VIW67oUW0 HPi8nc2K/GKQmrpuxfa9EVEGTOUldsO/wk8I/W4ZUFEv/m5PXgMnDG6qioWKwGNEhc/Q UWnr1N1yjGENj4A31rXIEkOCEhGRpREvzBqJrAvb+QmEuRN9Mz1cCE2KRcTiL7/xsJxe xnE1INoFj4dIyanwzlqQ0PqQk8ZvwJ7S05SS8MDf9ugZN+em7Unn2M5vyVQenHqFQ0qn J9FqgynUlb+LkzKCUCBu/B2KFN3DlX+niGuCaHdbWiKC5QnqBQYlRABMBsIJ6lRUMO7k Xtpg== X-Forwarded-Encrypted: i=1; AJvYcCULArktHrkbCpOxgGCJVsz0SX1Zb+N57Nky5zREVosR6aYb4ysFT5d9MPJRyrA9TBxgzl0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5GCFmiPOeB1Q5dRB54uee0aQxRm58y1QNxK8ZmdeLGkNNn4x5 /IB6SgJaZgin0Ve/00mArZPQBWjKjEtL6T6AuVp6HQyo+dJwOu7t X-Gm-Gg: ASbGnctxUlKvvizlqW+3MgGPhnFCIFUxBe0r0Ke7NQQaq24oI0n0Ewc0DusiJyajO2C /7LC35XVjNYrCrRWaczRtHTNaH84JSHrXR5lvDaxpBNBEKdHscKMbkqI8sglE6NOQDxM4D7wokR Ig1Rzgqi1pTK3YuHdxOSD7Nh06Pt2rudpdCKlRgd89wFhiButPwZoI2iif/JQgq7empjbnUeLNZ i8ZdftKl9jt8o3lqoF8Mqz+Id1SWLnmBOD3GNxcjiCHg7JV+FqHhVw1if0QWj5DQYGkxN3B1/Ms BZmDd9apm30SHJTYRERavGNsnZvPT7JTEZRb0MVN X-Google-Smtp-Source: AGHT+IG1Pcaeiz25Bj6AZxThuTy1+t0HLWuIxg/Y/HGY0D/OmulofHWYMIk+IbU9ESyYGM2cvOxuHw== X-Received: by 2002:a17:902:ebc2:b0:216:3466:7414 with SMTP id d9443c01a7336-220be0035c3mr199839235ad.44.1739536682110; Fri, 14 Feb 2025 04:38:02 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545d09esm27814775ad.112.2025.02.14.04.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 04:38:01 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, git@vger.kernel.org Cc: Johannes.Schindelin@gmx.de, gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v5 5/6] t5701: add setup test to remove side-effect dependency Date: Fri, 14 Feb 2025 18:06:15 +0530 Message-ID: <20250214123734.1403120-6-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> References: <20250205185246.111447-1-usmanakinyemi202@gmail.com> <20250214123734.1403120-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 Fri Feb 14 12:36:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13974835 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 3B3BF261567 for ; Fri, 14 Feb 2025 12:38:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536688; cv=none; b=rGCOGsirXYuxdtpvRCc2A7jXIkz5JFv2RPVGqtKBXKcHoadd/8D4t4iyzuxyWsFIY8DAqhrcRbmBcW4HlB1JpKkshW6SdGgXHe6qJxaweRwwO1A+34yI8v+RmvnNy5k89RqJbXRU4Gbm41gB0gzPb9vdxS3WX5+a7y9pZ/59EM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739536688; c=relaxed/simple; bh=cZCsJbKV44wNeeDhMqFj7Ji/afYTEqUgmHdChGuznYA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FkXkMg7RybFypYL7L918JQg5wUHtEDHXd3n2wwkrnySe73EcqbU2+itQLP5sBK7jaMb30Dcg0Ek2TgE3Lz3GiTeCLMQxU9xtBS97rCyUvLsxt4aeM3vH2tN4ou6ZemmdUQwRLWa3roteT+u8jEZvEMZV9yTioTHG9JTH2qqT5eU= 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=byVpy/qH; arc=none smtp.client-ip=209.85.214.175 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="byVpy/qH" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-21f3c119fe6so46874865ad.0 for ; Fri, 14 Feb 2025 04:38:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739536686; x=1740141486; 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=LMhluq5TYdN6ZdVsPOcx2eT0BsU3zGlAUrHr/mRBZBQ=; b=byVpy/qHqsi/ozaUtNP13CwwZGEtuoQbzoj7LApfBePeZacBTHm/Nm44ukrrRXzqbm cE163Kxzl1THHWzkJ6w2+S598t53FE6mFz37zD0gvps81d7g7xlw9ljUQtD5dZCpZFjh nmM6ohTQwMTgAhMR77eg01cY5Z4wrd+pgoRuOFH90V9rWvIbkh8Sa2oeCkkEMDS0NvY6 F9hImcfi+FIHgjVkkod0Few6FV2A0Rk2OmxcekO7RTxyq75wNPqDejIm5mFH6fKS/G8J iGC9hsVZ1vfxe18WIaEjriX8IZKW+rhjsggjc/hNONexeCTQBwRxVofrr/HPWvbcXjIb pLTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739536686; x=1740141486; 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=LMhluq5TYdN6ZdVsPOcx2eT0BsU3zGlAUrHr/mRBZBQ=; b=GPnbGWr1Upxk9BIaCQgYG00xwD1OmHdpGi2K9IE5ewHguj52wKkyU4/bII98U1bXjL wN1dqFqZZN/P3Q9frwkFW5Tk9FpI11cwT9QmZbfOnMZGXvzUvRPWi5e62YpTe6FsXXaa QuAcNoYA83Y9yJsjP417rrFf3JuxInukABEf5b93G5zkKQUWmzReIQKa7FIHWfSTRP31 f00Vu8PzbGrmqH5xYUVoGvjWhJqt2cGHhJ8gfUrWG12BjzsS+Se6oXvEhMqRDPVpGa4o wN6jXrFooyaZ40Nw5aOm0yDzw6rMtlnG7HRSz2PfwK/alCChw5KO6t914fvqwQ+KvMSg IOCw== X-Forwarded-Encrypted: i=1; AJvYcCVbp0TCI83adEc7R+XVf56qIzOiVDUwSf09VWNfkvDmFXWOKzl+WqCG+nyPQCWcTQT+Swk=@vger.kernel.org X-Gm-Message-State: AOJu0Yzwdu9ei/V8OuXxG14X6xtFO9iNaHb8bcslU+g1QLQ33pvSXHu9 ckkTNpTzXZwVoYwdrN6lAHgwu0vKJqVmuB/CxDeFpZLK24j6pEj+ X-Gm-Gg: ASbGncvzzaf4+Lvrwx/+fXpK/ouV+uJB6A0F8kna//UAi5XJNDP8TKZFDqD1o9DDJPt 9PFvkKO/bD2UUO3ZfEG3gusUfcsSobH2fKzTvNHeSFzddi+8ep/h5atVXFXKhhuaGm/rnJqdn6M w0ly84HDhkmLHE+HDjM6aSn7BbbggYaTez/hW1puiu7EAqD9BuKXHXPmTNl9lXjac6IPrPtZhY8 8b8dg5QnRWuRb5+yMEfkNdHlXHNajxeI4qzWMt75Hs9m2KKWvL98EHgRFRoa7xsdICXe+tFVcZ1 1uADFolFXl4a5t9PeqhKUdYDJPpMa2AKOKksepys X-Google-Smtp-Source: AGHT+IE8v0YewJfC5ITCzURqq16A81VvJZA1hozGY9zvqtkIY3u/FZcX4p5rnjUK8s3nQgsZDFxaeQ== X-Received: by 2002:a17:902:e544:b0:220:f795:5f14 with SMTP id d9443c01a7336-220f7955fc0mr19092365ad.27.1739536686306; Fri, 14 Feb 2025 04:38:06 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545d09esm27814775ad.112.2025.02.14.04.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2025 04:38:05 -0800 (PST) From: Usman Akinyemi To: christian.couder@gmail.com, git@vger.kernel.org Cc: Johannes.Schindelin@gmx.de, gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, Christian Couder Subject: [PATCH v5 6/6] agent: advertise OS name via agent capability Date: Fri, 14 Feb 2025 18:06:16 +0530 Message-ID: <20250214123734.1403120-7-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250214123734.1403120-1-usmanakinyemi202@gmail.com> References: <20250205185246.111447-1-usmanakinyemi202@gmail.com> <20250214123734.1403120-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 ++++++++----- t/t5701-git-serve.sh | 16 +++++++++++++++- t/test-lib-functions.sh | 8 ++++++++ version.c | 29 ++++++++++++++++++++++++++++- version.h | 3 +++ 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/Documentation/gitprotocol-v2.txt b/Documentation/gitprotocol-v2.txt index 1652fef3ae..f4831a8787 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 31 < x < 127), 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/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index 4c24a188b9..4f0b053c4a 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..027ebc82b4 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; @@ -43,6 +65,11 @@ const char *git_user_agent_sanitized(void) strbuf_addstr(&buf, git_user_agent()); redact_non_printables(&buf); + + if (!getenv("GIT_USER_AGENT")) { + strbuf_addch(&buf, ' '); + strbuf_addstr(&buf, os_info()); + } 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 */