From patchwork Wed Feb 5 18:52:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13961760 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 0D0CC1FF7B3 for ; Wed, 5 Feb 2025 18:52:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738781579; cv=none; b=sgP9vpd6XhxQES2jF6KJ7Ad99iQcTtl8bAy1enk7IquzD6o8ZlNiTi+A9vKdqjHSoyxqs2sXIKmv+PjdLw3jNpksqLjZlhf0LEyD6IT1DT0wIFcEYBpAgzWSkYMcTFDOIKXg/95TQCa/5hqymAvRSFYaG5Iqzl88szuJ2A3ufrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738781579; c=relaxed/simple; bh=fB80ASbecHtp4fGMlEVSHuxVoWUEiTfhiT/c1rpUQfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uNQMBpJpR2Sb+UKRAFEX2fu89Yxfg+nbS8XjVHqcZ5+cywXgbr+2NDux1cGZJnSd3tDs7qfOgpg7y8G8W4QTLTz4chiqloxsVo0FKtikL0INOClP7Dn6PwSORxQoB6Lfouedb4VWKKuvoMfr57onkgAlcLY5O/BjC5Rw/huIEXk= 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=i3AUX1O+; arc=none smtp.client-ip=209.85.214.173 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="i3AUX1O+" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-216728b1836so3161415ad.0 for ; Wed, 05 Feb 2025 10:52:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738781577; x=1739386377; 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=i3AUX1O+KBbU46M9tVqLhHJv/t+CZBFD5ovg/UBAoTdKhwNrBH4jLyePQiY4USYozo zkcD4dptBFppaGlKW35UITGHsX04yXuqX+73olwHEmOZPfeEBBLPGhuvwkmy497ZEud4 pDbuZlf4WX15vUxJTYczArrawlWwTi8GLBmyX7DGChWvcDDK/nBqju7PxT0agJI65nRm jl9grDBFFjqerOSGnugAjIj+SvzV9nHtt0BvMsEx6GYKXNXBS6CdkspaZTpqvKrgsTKM cQeuNTk/4WRX4zmMO3uW2butHmI3mKgh/QvVVgP56Sj9LcOef9YG+IXXvxbTzKb/o2iG VJqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738781577; x=1739386377; 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=vtHuXUBqsdlp7CLS77uIOkCWKKmcrnJmI5X008+zVs35J6Hino2vWe7sNMC9iF4HR1 5M5bYdwweFxNNJ/0T6d+c1x9jocam4l88E4ZW+3nJI4A3e9X+ZeS8N83Uv1z3+F6Oruu UPv2X0lCtkTDNZbTiagWVLKpFnUxGXHhdg7oOqFMWOrTo97lCqHYJwVDX+dJsciDBde9 r0/NWxPvfbeLEUWEAZUk7UyzfgD3ME3JoGxZK3WeYMth9lwLCAKuS6S2U53yFhb9Megh JflcIWcThiSaUSmcwzenjP47yQr2JyE2DkZV86fXF5n1ChgsRFPRpuwFbdnDtWHT3ZED +qQg== X-Gm-Message-State: AOJu0Yxgy3tFz9NiqLthRDwx8p54Dk558PK42TxxYPCo+zbnTi6wDB36 IMLjdKAX9wR37wEXrKrHog9nF7vPLc9Ow3b01ajzO1DLy6n2eAiadrqusmABk8A= X-Gm-Gg: ASbGnctU/qLkRBwFP8JQPEssDdxLZ12/zUVnF612bRWlTRK46rEyjdDXP+sigHBqY00 714/oLubKv2mEm1qDMprP0/wp3G5Du5ZjQ4DsZ4Mv64Wtw4GoOdyd5s7YUL0uZorb0sNBcoUq8P ulDjY3wTkmdiGhfbDt2WH8FpXi7GT+LCwPseBXEx+Hz5rRNTVNBe6oXtwttSqj3Jq1wjA2BZwBZ RLIvCBVhD44l8H7SSszaiZgcrfI/jSoeYA1Wf53xP1I5N3wfM6tLqeARsSL9OqVS1bDI6FdVW/n fIIzsQvAZHsbCnDhvZWafgE6m4ht5dB9cT7ZJOuA X-Google-Smtp-Source: AGHT+IF90ntoiAkUnT+yf3d0aMKc5lw81zxrZ5g1K8Rtmkcr4Ehh7eQrCdbe4wy98gxlNNLUAydEmw== X-Received: by 2002:a17:903:2d2:b0:215:acb3:3786 with SMTP id d9443c01a7336-21f17e46165mr74799645ad.19.1738781576854; Wed, 05 Feb 2025 10:52:56 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21f1e9f3ebbsm13754285ad.190.2025.02.05.10.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 10:52:56 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, =christian.couder@gmail.com Cc: gitster@pobox.com, Johannes.Schindelin@gmx.de, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, usmanakinyemi202@gmail.com, Christian Couder Subject: [PATCH v4 1/6] version: replace manual ASCII checks with isprint() for clarity Date: Thu, 6 Feb 2025 00:22:31 +0530 Message-ID: <20250205185246.111447-2-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205185246.111447-1-usmanakinyemi202@gmail.com> References: <20250124122217.250925-7-usmanakinyemi202@gmail.com> <20250205185246.111447-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 Wed Feb 5 18:52:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13961761 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 EDE371FECBF for ; Wed, 5 Feb 2025 18:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738781583; cv=none; b=bZE0gDGP48txoxNYaSYLii2TdpQruxQRVMnyJsm8ImTLfB/IfOOTsqo1A8JT9qBz+dHaCkbEQYXkH9PS80KI3X+JRlBQSeIKHHDPYo9TX4KoQZq1HPKxe7FH/sdQZ/E8WsdB2te1g+L6P4xbgC5R93tH99wU1Aq0tM+5HLoIJRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738781583; c=relaxed/simple; bh=auT7Nq8j/Oj7j5e0/1qmYiFTBmU1qvLdasGT5WYJd5Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CpZytTZZJMj4y5smFaF0yrGc4dCl94enSTVWpTqnEg38dy7kpvITv3i7BwXb3TM3TLsxS2dGKS/w5Vo85ANPomIMKuwj63U5xsBiKJVdE30qDRu3VtFDPg1Vvz0+RbJr6kfRaz8yUuLfgTmzZ0I8E7D+nOl/fyQyMST7Ztu+4Oo= 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=h2Omn+WP; arc=none smtp.client-ip=209.85.214.173 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="h2Omn+WP" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-21f169e9595so2354325ad.2 for ; Wed, 05 Feb 2025 10:53:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738781581; x=1739386381; 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=h2Omn+WPsTdRuL/MvtP74a5+OMS5gtpds8hs42aIkCZSCTqwPf3wNwtp4K5r1zB7FA fdqhDcBv2YhIIgCNv53A8iqdqnMtVAqzQjV0KAdb/FjikPMHEieoeiOXgDnPU2WFl3cB z/dUbhHX4JomGJRZNrcMyTkbk8YxYKav0yNSmWvoHtA/ttrEYJZtp20dfqc9toe+lfeh E4vN73LVEx39xzxSZ8SFCMljbsbRta9g9Mzlzf2mbK+cASS88/gOga84G6K9nOkGOVs6 eZFttH4OQKFusTXTHqX3qjarJMjp5n8nK+unBOtDflU4wvIxRVrb3sJoVk3MDlxJCJlw RGCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738781581; x=1739386381; 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=ay6S7r7zDXgNDxDrTDrhbPi0WyPQ1Nf4tLlymvGSuLiqjSJsyO2ITe8P2zK41bBlji FYM+eZb5KK2aHV/v48xTBaJAaUWi6m0ZocD08+wvPAnozLVmIFCOe4ZU4MfkY9zh/FFp AzzYXEKdo5GU6TrcWpOnT6CWeUYhtrdOoC2t3ge4nCMPXCg36y33RA4cWI/TFB/YB1xa kad/1YOAzdpZU4vvAC9GL7TLEUNvoHcXyXwkl+SDBZIeUee4f0rkhqRG1ZcvUukNiZI+ da0qwU3ipHloDi4zZ9+RKWvfui3wKdZF2zdXAAPsP94ttV9KM09tnArDJrjioB9MoIBc /z5Q== X-Gm-Message-State: AOJu0YyOsc4voBeoi/1QWfmqCXuPG3uzeVw2OL91C74vqVNTjvtV2DbT 6KP6BhL9DmNTYTcAL8yh6Ip/S2jGTaS1HV1BSlTHW9nLzRVTNcvpC6Joma4kPZg= X-Gm-Gg: ASbGncupdIcCMeQfKOQE0ru9CqY3Q5oUsWaf7FvbA99eau2UBBZnPHM3KsjY6eDrwRx zf17xX37sq5EYq7mIvSliu/P2nh1GAXBt9n+YV7I+PdfuY4UHUl4Cq07LKAr5sB81epsXe6BH1J gV5B7Jz3f6i+WSz+ftsHGAk/o4hHqnCRU90G8wgbpUhUURwfmU60J0GqFi8yCPbfrW8ZT0zVIMz t9pT3hwutSVGilSZLV7ZYWEyKrjbwt0IOhMcLpVXkhFdXXYoB5VQZCoUSBHTw7XG+Cm2V45r+JN h29Op6jpFQBSinX4+uUDS7wgXAOYolBMgaao9prV X-Google-Smtp-Source: AGHT+IG1lWe42mACnSh2PfMBmwVwr3vLBy2d3b3HfbvEZJtOTs9B54tE7NZG6QDU2C0rzErX/sFezQ== X-Received: by 2002:a17:903:292:b0:216:485f:bf90 with SMTP id d9443c01a7336-21f17e70242mr59308895ad.27.1738781580959; Wed, 05 Feb 2025 10:53:00 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21f1e9f3ebbsm13754285ad.190.2025.02.05.10.52.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 10:53:00 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, =christian.couder@gmail.com Cc: gitster@pobox.com, Johannes.Schindelin@gmx.de, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, usmanakinyemi202@gmail.com, Christian Couder Subject: [PATCH v4 2/6] version: refactor redact_non_printables() Date: Thu, 6 Feb 2025 00:22:32 +0530 Message-ID: <20250205185246.111447-3-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205185246.111447-1-usmanakinyemi202@gmail.com> References: <20250124122217.250925-7-usmanakinyemi202@gmail.com> <20250205185246.111447-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 Wed Feb 5 18:52:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13961762 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 679D0200B8A for ; Wed, 5 Feb 2025 18:53:06 +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=1738781587; cv=none; b=XchgP5pXiCzmy+1j7guTFKK77klJ2x640b6xAZ07WNstk5vmai/8kEKsYYK/KPXovmTIuYEuXZxViVfub7BhvLUD9A3571vq6qyvziuiU1Jv06K658sxyIQzuKrK0w6wbwi4zuolikc2xoVpU3GHVO8jIp73Y8qGyufKYLq0J/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738781587; c=relaxed/simple; bh=42i8PUdjyKs+NSwGtLcbj9v39QXr3Du2dpk4eqznw+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cb27RTjdBiYAt2HYQzhke2lNzYkl/q30VMb4bMIeQztZIzD2l003I6Gsr8YQNAxLHck9gWmO3AaUYmQiize/AyNx8bHHa+9eTeDxINrWE2145gBca/guT/6OuIbQlmqp87UC4ESXwYR8FwtR/y8aAElyJiGfRodon3d4gceeXoo= 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=U260/HDF; 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="U260/HDF" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-21effc750d2so2439865ad.3 for ; Wed, 05 Feb 2025 10:53:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738781585; x=1739386385; 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=U260/HDF5IMA/7Iw9dqn1UQSOvSwtkmdHyfWUC2I3eHyGsL58hhh/Jg4sKJpdXBIk+ HYjhwPwDMocvFX3ArqQr8bTgeolns0+MQaTfncWS9BgjOaUUL+7LIRrWas0OYhyIzcxE Psac2wEkVI9cS5rTSKVwnstPO2o5xNEjwvIWBVt5uMiUbXECDOx+pqRO7Kj2McM/mO2P YsN0JU0DmlQfwZrAvxl5ANLAhBRF6n4Q5ID8Leo/xJzLz+9WPTP2iX1b9YbiO+KiC2Wt U8Mx4S/zj98zZyWpj+8UsinUrq+P6idoGik45nLyjuO2OQBTEfvT+Ib49BPeHHw6glye ZLeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738781585; x=1739386385; 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=berAHq8a7XeafAabwDcETfwtNGdKYuxXfR1FVUIvkg8AEB1XEVKqIA3MFtPD+NzHQ+ ovioROtQs7BMd7lhaziqvLNt/Q+kpDstaU5oqREKuo89XRWKpwF5Ui11hhZdtowJsL+Q 7ed5eI3QYOVUobkjNG9Ho942ekhxTpW4vxlYjkkSFtPuMCCD1ZPHbvNreKDPz1cn/8L9 cPWohvXe86S30gzVQd1L/8BvcONSPCKU9M1IF9g0eUkFUOEa7HRNOAKrUpKNmkqnr5ME 3cEtv1GjF0SPSFL2Bm94kqQst5/o+7OkLmAX36Pnx92jCeYTlbI5eMUSGjLifapCvsTo PG1A== X-Gm-Message-State: AOJu0YxpZzGuAJfw7ZF9HvEO6YdRpdtALYr+JnRX8LD8ZEMhHzAohJvy ji62htlpXNeVe+mzl9amaqAABSDc0S57teBvsJG10Yb8jAqtIHHSLZyBddMtBRQ= X-Gm-Gg: ASbGnctQkwtWu4CtyT3illsh0SudiM0BnwQ6N3XbuRMuI/nvz497QGOsDzjsa5KS+Gb ece26hJLX7HuZ0jBxic9VZtHFst1Q1+lChw3kwt2lYOLXjby9tGVjnQ+RezXGhCslFgPoBxbam8 +2muvFlHzx0joPqbV42PQP+ACaZ/cwcemU6FkCO7R4veV9LTno3Ru1KGvu7/uWn5i0Encscsu6n f1wDulONwQr6qiutZFOFNoAeMzyPIxj4K4/s1GgoictFNpZczpj82D2bcb2QJ4qkGqB9DlRP9oy On0EVqTdn5m2ZbpUGGvZbThf8S7/DM2UHKu64xtS X-Google-Smtp-Source: AGHT+IG3FmRXhjfXm7gvhiIkyHyanNXRrGkjtXi5xBsOm3aozQ6cUyp/hCiR/4vAmvXygFQ97leRAA== X-Received: by 2002:a17:902:cec7:b0:21c:17b2:d345 with SMTP id d9443c01a7336-21f17dde0eamr68964225ad.3.1738781585406; Wed, 05 Feb 2025 10:53:05 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21f1e9f3ebbsm13754285ad.190.2025.02.05.10.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 10:53:05 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, =christian.couder@gmail.com Cc: gitster@pobox.com, Johannes.Schindelin@gmx.de, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, usmanakinyemi202@gmail.com, Christian Couder Subject: [PATCH v4 3/6] version: refactor get_uname_info() Date: Thu, 6 Feb 2025 00:22:33 +0530 Message-ID: <20250205185246.111447-4-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205185246.111447-1-usmanakinyemi202@gmail.com> References: <20250124122217.250925-7-usmanakinyemi202@gmail.com> <20250205185246.111447-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 Wed Feb 5 18:52:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13961763 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 B991E1FF1B4 for ; Wed, 5 Feb 2025 18:53:10 +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=1738781592; cv=none; b=pTxc9Ao42B+exyvRbQUvlYfc4tZcDjLqcHUGJ4t6/j9inBwtyNgwi5ijmsnSt+2fU2AbPhYeY52niuuEr++W6hhYRDhIMqEZ8kZB5rVJM65bKcYUJBTRL+e7dst0+I4IydAAlkuCUZuNyWVGCdzWRr59buKoPu7tFFHCRRPQ5Ig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738781592; c=relaxed/simple; bh=HVeukTMHNYer7qqxUJZvhIb+1eODx9LL40SC14YRDMY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bNMCg68n+tVYIR714avKyPO8Jw7Hbqda1JbjpjzWUyQV/SOF2dGT1IaGYsN91L9Fp9RtXQMHY5zoT+9hAEmhPvKROsJCwgL3uB6E5GeNzeK1wp//sN/Ah6KwT3go9JuL/FPEpu0MWiRqMMIlYK8XlKCQ0GaLusEmeKTvI8KuDWI= 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=O/AmduVt; 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="O/AmduVt" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-21f2339dcfdso1063755ad.1 for ; Wed, 05 Feb 2025 10:53:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738781590; x=1739386390; 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=O/AmduVtVC6I5frx8WggNFz5QfjN3B9m+AWr38ZbCMO/KapQsCRNLLrh316ooKuzNS hcF613tzgnBCnxXT0R7r2Sjr4ayLiHOfi8JvsueowDgAtUesc6bqns+QgTsA5m/X0a1B NTDRpQx3fI/8VeU9oh4EWGbpnOi+vSJq6PlJFoyGQEbgTbLMDfvqUyCFWLWfrL8VkeG6 Ra0KeP4c2/ZoXTL3RFwr6B9pugNhPblt/LjuJ3Rys0SQIxPntNHbxyxbMH5LLRDiTfv8 wCRGLDhbFBeVEX7QY4KDlBMaYVYBJ52sCUUrZutlvtHUypx4ZANuxM0DUBJUmrxwb36D VvCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738781590; x=1739386390; 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=Lls/XVdYGe2hJzWIAJEQ5X7gDj7iZBCHVR56EPfQyL47jYI8fzrC0PMKXjUSLKJKtH hIxqk6qcRwsH8KXyfDGG3HSUYy2fjZXKrWNL3PINNphQCcyPfNuElVdAaRlEOQlSGleU Yya6u3rur3KAa0fXgYQlMZxi8Q+ag3cekiBGXkQIJlMDdNVTvyesAToD6iEllhGy3UXt oIUKGxjxJdvc/kR8dchEff3Tes6YfcaLNMo6iiicfalQsZRAP3mJ8elhzecJsKwN0Q+4 EFEM9yFtHdQi4rNgS4UD5LUwjZ61pdJBBVJvBSI2kGaMlJl5V7bHxtuuclFqK3mkgshK R1wg== X-Gm-Message-State: AOJu0YzWjjN+92SBg6gGVctC2sDFh/qfj8X2hQ+LWlap3ktolicil7fW uUS3C+dA/m8LaDO9C7Le6n5o9OBrYQ4bRhJxXKeARNzS7W2lUAOAwZUYOH9spUk= X-Gm-Gg: ASbGncvD50ax819n4FFoVytGVNqrcPKG10Gx++LIW3K/rmq0ZU1OItXYz/sUwtwpL7Z 9ho7CQGuqyZa9kslGfJxayATzM7uEaHKRgPohau03Uzh85xmbnI+pEMTSAB0oaM1g8zlh13ENwk 9aJGw5ai9VNhP80brWocLScCMB0UnwMfRdJvneE9xEfI7suMWZILYigQNlo/pBV5tg/jrdeRuHJ QfkpfPXnfxx640/EWyZUrlEBFa7mvW8NStrh1Lhi+oxb7KKf9tQXApaWEuT9UrwkyaND7+maJUO BOasQaBTUCjCWGSd/jCyZzFxPs/huvnPu7daVJtt X-Google-Smtp-Source: AGHT+IHi1PxRIZGw0xOuRSmHaopoh34QdmRHz2bLudC1O5T4txTeWRgvP53aMI6n3/zL4lIs1NosFQ== X-Received: by 2002:a17:902:c946:b0:215:ba2b:cd55 with SMTP id d9443c01a7336-21f2f145833mr5122115ad.2.1738781589560; Wed, 05 Feb 2025 10:53:09 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21f1e9f3ebbsm13754285ad.190.2025.02.05.10.53.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 10:53:09 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, =christian.couder@gmail.com Cc: gitster@pobox.com, Johannes.Schindelin@gmx.de, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, usmanakinyemi202@gmail.com, Christian Couder Subject: [PATCH v4 4/6] version: extend get_uname_info() to hide system details Date: Thu, 6 Feb 2025 00:22:34 +0530 Message-ID: <20250205185246.111447-5-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205185246.111447-1-usmanakinyemi202@gmail.com> References: <20250124122217.250925-7-usmanakinyemi202@gmail.com> <20250205185246.111447-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 Wed Feb 5 18:52:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13961765 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 40AC01FF1DB for ; Wed, 5 Feb 2025 18:53:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738781602; cv=none; b=O10mB0866IlzLLwvtsdyzfCoL3RLVdqIGhDKb4wuic5Ron9gBZs9KwUtohmlYgaeqInK8bLYgGhSzu/y95XcvCPO29QKPzhQS2q5WdJiK4c0CKSFgMIsq8mx014avJW/MHB5RKxZAQzG7EJvbIDDgc64YefZEBTob2nwCYjdGHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738781602; c=relaxed/simple; bh=NgcdHkkLwudzQ35twlRCjU8htQPOSFjEU6KAQMFcIos=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CvU2q9TcBZLpoTpOsYfQgF02Z9hWNGdHArLSA1wF/NUpyV7lEAu9uBw3EPsHlzknKGHB6ps/VxMKUUERuZVlaly8SXjIGu3v9j+RACilSrm2qufyA6KlYr8ZoppDiF35s1XfzwFixaN1qMNqLHeJgHrVxyktta7D+tjtvUMfU2E= 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=GjqFoR07; arc=none smtp.client-ip=209.85.214.178 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="GjqFoR07" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-21f169e9595so2358995ad.2 for ; Wed, 05 Feb 2025 10:53:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738781600; x=1739386400; 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=GjqFoR07LXRzQ9tHR0XQ0z/8Ko1sFTvC2Opo+8PtJHi+hbiHKVjq0QmH6lkYi/NJ9+ 7bw4lsy80uBykswHq1c185z61FRPhc/t3m/o7XFYEUvYAO/j4tynS5D+CW3VyIU3comJ fwuJQ+GjcDCegUnNHLNd/ZcOlaFMsTd0JFzMElXFBp+JHJpcofnJGbuf91MVBDr3JXOR y6q4LGBN1Rj/gCCapHKp6Xqd2Fe0rcoo2bDvZZrEyA3G4m2y/EZ1dgL0f8CbKR1364kN DZ4vDgQaF6tVuO7OttyrSGKeOS8JA7OxN1+WYfbFRp1Tf6pSTAinaaWgoYaoL3yDNeT+ /nFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738781600; x=1739386400; 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=pp4aVjsVJyL42rcaBLHDakM+lVveHC9OKOL3rEhQrUwt6696p5iMpc2O8POJE2FxpE LjT1Jvw2NvrRt+mHSJENOUvkb0KZON4UDA5zGKgZLtWrxYZUgbNF91WO2GyzwXxXOHI6 XOTNq1uTFUULnCPaz2b4mTzayYgrmA2r2H2wwS/ZpjznBa87iN+VvKAcQuiHPphp4mFH baa+cBLd0f4xQl/1YeuWnGoZxWFP2vvMOSDuSJ3iHtkCVYDNFLyKLnP8dHEtiRbITCmD sGm0M8SJtGZSTdiZGwjxf6fOcjUeThmFY0P0TWHO/UgH2TmFLN0+GvvYxDb4qkCBN7JA AG0A== X-Gm-Message-State: AOJu0Yz5jJfOfo1NwPMWzzrKhBktB4ARc1o1g81cYLub8htQFITpWWfx ia3KTPXKLyH/Isdf+uJhy5quzVjOsSCHo0srkF8PwfQ/vQzMVugAfJMEp8FyYaw= X-Gm-Gg: ASbGncvZXujXQMShvyzRHhiAC3Oj1qm5OdyWo2z8sMcF7SMkv2Y1dsmtOfDEuSEzzQZ 3wbk+7jGAM3sEq1zpmcr9Gvzl7j9DpkXg1A5JcC4gzWJqoIdJ2sb2keztvnRD0W9Fzs0SoR80c4 KDTx6dnDLDruvxhE0XWQfn+r6nyLLOrEG27srQ14RozLD8iaT6t95bABY8WTzHD84J9U1dqQ/5+ VnoPm4UsEeGjezjwlJ2BF2GX6YKiC5MZk1gqFaPwWrI3jCzFaxsDz46lYHLgxwWxzjHc9XI3Zbx lTvNUykAOJOIjy6hHHwjkjjPUFNCHBjP5oKjLXVz X-Google-Smtp-Source: AGHT+IF4t2LzVwHA4WeTOy+RxRHhUCNUaz0fzq2o0S30k9tMgVc3mKpbyqqbz4MRrmnLQeJ/l809Mw== X-Received: by 2002:a17:902:ecc8:b0:21f:1bd:efd9 with SMTP id d9443c01a7336-21f17e4714emr74957525ad.12.1738781593806; Wed, 05 Feb 2025 10:53:13 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21f1e9f3ebbsm13754285ad.190.2025.02.05.10.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 10:53:13 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, =christian.couder@gmail.com Cc: gitster@pobox.com, Johannes.Schindelin@gmx.de, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, usmanakinyemi202@gmail.com, Christian Couder Subject: [PATCH v4 5/6] t5701: add setup test to remove side-effect dependency Date: Thu, 6 Feb 2025 00:22:35 +0530 Message-ID: <20250205185246.111447-6-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205185246.111447-1-usmanakinyemi202@gmail.com> References: <20250124122217.250925-7-usmanakinyemi202@gmail.com> <20250205185246.111447-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 Wed Feb 5 18:52:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13961764 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 230CB1FDE00 for ; Wed, 5 Feb 2025 18:53:18 +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=1738781600; cv=none; b=nVnzPKyUGhwAIulPCI0XllknV26mAvOmqJ1LN3T9AEou0Om856oSY+DNHE55BuUeF+KAeeUNyxGcjo+o3yB/F5UwWRLR/XK54c/z7FqI60eznKtJtM+xi/A4gRX9jDdHJgH8ARSLf1lN9DbzDlwElysa6WZiGMiEq+fOvJJkGFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738781600; c=relaxed/simple; bh=z82lKEABdhy/XVCM3hnGNlDTiAeNFAJQZK+zGRDQEDg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OE8EtUhJi2O8IU90vHQ7SgUUSvwvEGL/6BOVYkothHy6nrQQ2fBhjLH1c7g/WKY5YQHqXBpRGrMUwmPi68ArqlaOmyc/JzQhCkOo2F0+ZgibDA+pik6SGlPT7F+iHgZumbD75outDAjFxQI03WnWcKm9kRmE0Exws4vSSYI4XUs= 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=fkhI1ECY; 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="fkhI1ECY" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21634338cfdso3235215ad.2 for ; Wed, 05 Feb 2025 10:53:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738781598; x=1739386398; 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=DqjlURBI5cAHlJR/1iiawUI9AJRgNdM2yNlpAwRwcKA=; b=fkhI1ECY7e4A3E4WKEMyFD8kPMBdljOSnWSdc7Sup7HzyxXBlhQs3pociSvQR3zB58 wkH/Y1KiG3qg/1eFJf049N7tXYZ27dRxl/Q5UDfsgZ2xiTEY67iZrl24sVHUMh7uGlZX clBxUfveZWBxc41U6BlmFSppCpSBb02AMm0JbOaISf+hNuYtnNfRAa/mXgrTrI0jL0zz 4+PH6TxdHwqqRl+q3SaBJBjhX7ZIskVW5Wb1cCylW1kfAbFT9hq5nbwA1MPWZwb3Uu6A Wbat+s/nVVK7T50bMc7fQZlz3fhhoCPo1PG+Kgi0ROZMUGHmCl8Be2QtZYtTcj6tDjkd 1DsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738781598; x=1739386398; 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=DqjlURBI5cAHlJR/1iiawUI9AJRgNdM2yNlpAwRwcKA=; b=RpkDzEE3HNZ07EjjNhf5oObcZfgXjYeaW8Ibvl+nH0UP6sSJYc0DyFOmYNwun9+Ctn LIAD9QzsVjxiAzBbYj4AGDPpxr8fOQFsNREALsTF0T7Ublku/kKKTUCU626WZ2ymcHWf Hi51/vjQ1vSPW3jmdhfHXF9qu+Boy5GxtH6GEVsEkSmwZmwYDwGZuBhZZH1GVUI+NaVv Hkk0hHOJPsgP5NgDfgL3W9tTxJN26DO59+qzWSR+2vLMV7h5OforiBVBagvl+oP7H/5c BwSVxvA3etviebLg94LKfXfZmteCndWWS5Gs2pG2EPhZvn7X/4kSUACsFbZdskE4+FOT 4KGw== X-Gm-Message-State: AOJu0YxtFyEDNjAVeI5F1NIHo17dMdNAsoH/gc0EmwxHlFFIRVt+oKKB sQ0LK6UZYsLI7reZTrnyLNll6glzxYRKzNs4TD9u0hYPJtUjNNduQS3jWIT3LSk= X-Gm-Gg: ASbGncsW07foy1iq+zB367heoK4X2SXQf9Aun9unbHyVbOHPj677cR9lvFe+Mqm4cdx Eu98KrswI4V1JlFPgMkXl3Ip855uWxdaefP2ru78d58rAj0fOq8PP2EbuqH+8EmVVpOCQdB2nVw h6JFN8q7qF5a+P9ovs3E9tRAHpdfgS0/9f7VFbHu1pMh7ikYHileR3EnngXqHs6EglxMXrf1pX2 RJihIgFcuhQc3ONqL3QbBWHqmOXoIxRN0Hnkt+pyGv2bqr3vgEcBhNStk0+9/6fHyD3Whj32rw/ unP8RIaafiVxTEmX+2B4WlWsHFRHIhdRqIdyleOP X-Google-Smtp-Source: AGHT+IEZCfWPecKa1ibMb2pJPJJoElkcvGY/KDthnz4soj2+gkng3HPltpq0NBbE/EdzRizGF2KlUg== X-Received: by 2002:a17:902:f649:b0:215:6816:6345 with SMTP id d9443c01a7336-21f17e4d018mr67698895ad.16.1738781597928; Wed, 05 Feb 2025 10:53:17 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21f1e9f3ebbsm13754285ad.190.2025.02.05.10.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 10:53:17 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, =christian.couder@gmail.com Cc: gitster@pobox.com, Johannes.Schindelin@gmx.de, johncai86@gmail.com, me@ttaylorr.com, phillip.wood@dunelm.org.uk, ps@pks.im, rsbecker@nexbridge.com, sunshine@sunshineco.com, usmanakinyemi202@gmail.com, Christian Couder Subject: [PATCH v4 6/6] agent: advertise OS name via agent capability Date: Thu, 6 Feb 2025 00:22:36 +0530 Message-ID: <20250205185246.111447-7-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205185246.111447-1-usmanakinyemi202@gmail.com> References: <20250124122217.250925-7-usmanakinyemi202@gmail.com> <20250205185246.111447-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. Add the `transfer.advertiseOSInfo` config option to address privacy concerns. It defaults to `true` and can be changed to `false`. When `true`, both the client and server independently append their operating system name(os) to the `agent` capability value. The `agent` capability will now be in form of "package/version os" (e.g., "git/1.8.3.1 Linux"). When `false`, the `agent` capability will be in the form of "package/version" e.g "git/1.8.3.1". The server's configuration is independent of the client's. Defaults to `true`. 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/config/transfer.txt | 8 +++++++ Documentation/gitprotocol-v2.txt | 15 ++++++++----- t/t5555-http-smart-common.sh | 10 ++++++++- t/t5701-git-serve.sh | 9 +++++++- t/test-lib-functions.sh | 8 +++++++ version.c | 37 +++++++++++++++++++++++++++++++ version.h | 15 +++++++++++++ 7 files changed, 95 insertions(+), 7 deletions(-) diff --git a/Documentation/config/transfer.txt b/Documentation/config/transfer.txt index f1ce50f4a6..1e1dc849ef 100644 --- a/Documentation/config/transfer.txt +++ b/Documentation/config/transfer.txt @@ -125,3 +125,11 @@ transfer.bundleURI:: transfer.advertiseObjectInfo:: When `true`, the `object-info` capability is advertised by servers. Defaults to false. + +transfer.advertiseOSInfo:: + When `true`, both the client and server independently append their + operating system name (os) to the `agent` capability value. The `agent` + capability will now be in form of "package/version os" (e.g., + "git/1.8.3.1 Linux"). When `false`, the `agent` capability will be + in the form of "package/version" e.g "git/1.8.3.1". The server's + configuration is independent of the client's. Defaults to `true`. diff --git a/Documentation/gitprotocol-v2.txt b/Documentation/gitprotocol-v2.txt index 1652fef3ae..8fab7d7d52 100644 --- a/Documentation/gitprotocol-v2.txt +++ b/Documentation/gitprotocol-v2.txt @@ -184,11 +184,16 @@ 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 32 < 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. If `transfer.advertiseOSInfo` is `false` on the server, the server +omits the `os` from X. If it is `false` on the client, the client omits the +`os` from `Y`. 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/t5555-http-smart-common.sh b/t/t5555-http-smart-common.sh index e47ea1ad10..140a7f0ffb 100755 --- a/t/t5555-http-smart-common.sh +++ b/t/t5555-http-smart-common.sh @@ -123,9 +123,17 @@ test_expect_success 'git receive-pack --advertise-refs: v1' ' ' test_expect_success 'git upload-pack --advertise-refs: v2' ' + printf "agent=FAKE" >agent_capability && + if test_have_prereq WINDOWS + then + printf "\n" >>agent_capability && + git config transfer.advertiseOSInfo false + else + printf " %s\n" $(uname -s | test_redact_non_printables) >>agent_capability + fi && cat >expect <<-EOF && version 2 - agent=FAKE + $(cat agent_capability) ls-refs=unborn fetch=shallow wait-for-done server-option diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index 4c24a188b9..a4c12372f8 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -8,13 +8,20 @@ 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 "\n" >>agent_capability && + git config transfer.advertiseOSInfo false + else + printf " %s\n" $(uname -s | test_redact_non_printables) >>agent_capability + fi && cat >expect.base <<-EOF && version 2 $(cat agent_capability) 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..f0f936a75e 100644 --- a/version.c +++ b/version.c @@ -1,9 +1,12 @@ +#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" +#include "config.h" const char git_version_string[] = GIT_VERSION; const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; @@ -43,6 +46,12 @@ const char *git_user_agent_sanitized(void) strbuf_addstr(&buf, git_user_agent()); redact_non_printables(&buf); + /* Add os name if the transfer.advertiseosinfo config is true */ + if (advertise_os_info()) { + /* Add space to space character after git version string */ + strbuf_addch(&buf, ' '); + strbuf_addstr(&buf, os_info_sanitized()); + } agent = strbuf_detach(&buf, NULL); } @@ -69,3 +78,31 @@ int get_uname_info(struct strbuf *buf, unsigned int full) strbuf_addf(buf, "%s\n", uname_info.sysname); return 0; } + +const char *os_info_sanitized(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; +} + +int advertise_os_info(void) +{ + static int transfer_advertise_os_info= -1; + + if (transfer_advertise_os_info == -1) { + repo_config_get_bool(the_repository, "transfer.advertiseosinfo", &transfer_advertise_os_info); + /* enabled by default */ + transfer_advertise_os_info = !!transfer_advertise_os_info; + } + return transfer_advertise_os_info; +} diff --git a/version.h b/version.h index 5eb586c0bd..b2325865d7 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,17 @@ const char *git_user_agent_sanitized(void); */ int get_uname_info(struct strbuf *buf, unsigned int full); +/* + Retrieve, sanitize and cache operating system info for subsequent + calls. Return a pointer to the sanitized operating system info + string. +*/ +const char *os_info_sanitized(void); + +/* + Retrieve and cache transfer.advertiseosinfo config value. Return 1 + if true, 0 if false. +*/ +int advertise_os_info(void); + #endif /* VERSION_H */