From patchwork Fri Jan 17 10:46: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: 13943210 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E901A1FCFE5 for ; Fri, 17 Jan 2025 10:46:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110812; cv=none; b=rWrd/9sCng7dyUC6mJtsc9M0YlL8F9ggNgUaPRVHLkDWId01XbPf7JzMb6Vyk8VvQPz3/RXaXQk+Tc3pEQmIn5Fn5Lff10Nn9gfE6kv5GiThBW6jP1PSknmou6JHkNxM4odQxbG0dRujWlhLPLAm6AOjROQ1Cn4Clxf8OXH87pI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110812; c=relaxed/simple; bh=2kwipOWVsc1LH7GWNTDmhiwxrVtruFy42dP0QyaWJN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C6Leg8LSyNj+9rn7Dxazc/67aCAC82LxmAEzvUSO6SFgl2cs3vJ4mR2G2sR58YcqBBn09lLE6j8nXnvRVOEqzy8DSU0EnKzWsXQKCUM6JlRSmhAzlRm5WZYO1LUBLwIxlfw3cEV4oPhf+i9L+eyUyDyM3wM1o8V5ph1sf0lDxps= 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=NHbFfMgd; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NHbFfMgd" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-215770613dbso25675905ad.2 for ; Fri, 17 Jan 2025 02:46:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737110810; x=1737715610; 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=qQ08D5EYt9fGb8RdvwDS9a4fT7BarcYCl64xsCCFzEg=; b=NHbFfMgdYj5l+hiQ/322Q2+rKJ/qHNexMS3b/f6nn8tPycjBdaL65aEGUmOVdt0A0p dU0xkV6+chq77gbsefjebXpBzkEUYLdJUfFTAnx7Lmv4kFr5D9dHMsnJnWZPpb8K8TPh MKAS+zPJNGkUa/7wvH5FhZgJCMB4gM6ShTVIyXu5/uRj/QtA+N6BqZVB0rfuot/5YpSx 3ArIxDPmsYUa2reIuYKLs09H9QzwntLmGdchSFmmV2r18ceTQNnEmlCKiDX5cDjbrTnu IqmrRTNe2hRkZ+dfZhxLyu4qWZxnpqQV+79GVJvaMa1BXybB1DlqzXbCV9e7bk7oQ2ko n5Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737110810; x=1737715610; 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=qQ08D5EYt9fGb8RdvwDS9a4fT7BarcYCl64xsCCFzEg=; b=bAme5sEHf4CUwQ/jhLEfoBQ7KRl6+OYpq886AxD+r28Jv3wyIbvQj+YcTD+5PZq4W9 OTL0Pp1SPCCkLXuA3BRQqDUx5ieHc7gfYHMVDO9+jEZFUAdhiCsTrX0Oy8z8rkl6od7G 6KCEFxGGRbye/NjGHq6vg8ICQRfqwa+TuIkeOnPcib5iSn2Hep0jTAQNGddbUBd9yYyY I9KMB2hLYqqOcQNqxNZCaqJJGMkS3SCcQak1QhKdDJYJbyiiGlUmegvs/u/e8kqGWenU KlPQHIjI2sdbsCsD2hoCKybyUGI1t6UgcnDv/0UXSe1UsY7Y+tPN7d6im5NMz2l9Ey2N al/Q== X-Gm-Message-State: AOJu0YzZqNzSAKCKLz5vN3dTS1zeXhV8NzwIZKNH8pqkVCmf9MCuL0wB 7mzM1N+r2cKpLQFnxn0kIxbCEGef/WGcUBGSU/09uKFPf6Q0oE1QK3AH9h1DWes= X-Gm-Gg: ASbGncvgwJCJrzrc42icQh7qYvPsum4xdxYlEmu3yuU1mfamY9dyQzPbZeE6P/wbo4o R3M3w5uKoDJSVrYStF3ptRRFk7yZ2+2o69ERhBUvtbuEkFUvDPmSHtykHCJTS5B5kruexxIOu1v 2C4CENZtAH7haoSULMV2ISkQT0Es5X6KazxBFdAXfi+ly9S1oE5c5jHyFCRAUU70cV/+zzb2snl IMDpFxBA9XdBhaqUlydGbo7mQHcJBxK7ZR38qSO64LfS9DG27Sn8TwRy+Sm0HkgJ7c087bcgyA6 bjeKYg== X-Google-Smtp-Source: AGHT+IGgNl+TmCh5IpiSmH5mOQ4N2rSPOuj6PZ1/zcMAd8FD2I9AUZpuEeL/W3Att3i9Nbj7eAZhcg== X-Received: by 2002:a05:6a00:2917:b0:725:b201:2362 with SMTP id d2e1a72fcca58-72dafa409b5mr3663161b3a.11.1737110809916; Fri, 17 Jan 2025 02:46:49 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72daba48eb8sm1574985b3a.136.2025.01.17.02.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 02:46:49 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, sunshine@sunshineco.com, rsbecker@nexbridge.com, Christian Couder Subject: [PATCH v2 1/6] version: refactor redact_non_printables() Date: Fri, 17 Jan 2025 16:16:13 +0530 Message-ID: <20250117104639.65608-2-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250117104639.65608-1-usmanakinyemi202@gmail.com> References: <20250106103713.1452035-1-usmanakinyemi202@gmail.com> <20250117104639.65608-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 | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/version.c b/version.c index 4d763ab48d..78f025c808 100644 --- a/version.c +++ b/version.c @@ -6,6 +6,20 @@ 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. + * TODO: ensure consecutive non-printable characters are only replaced once +*/ +static void redact_non_printables(struct strbuf *buf) +{ + strbuf_trim(buf); + for (size_t i = 0; i < buf->len; i++) { + if (buf->buf[i] <= 32 || buf->buf[i] >= 127) + buf->buf[i] = '.'; + } +} + const char *git_user_agent(void) { static const char *agent = NULL; @@ -27,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 (buf.buf[i] <= 32 || buf.buf[i] >= 127) - buf.buf[i] = '.'; - } - agent = buf.buf; + redact_non_printables(&buf); + agent = strbuf_detach(&buf, NULL); } return agent; From patchwork Fri Jan 17 10:46: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: 13943211 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 C49C11FCCEB for ; Fri, 17 Jan 2025 10:46:54 +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=1737110818; cv=none; b=IKCeQyv0ANbMF6ZZLqtE9qa5aRK1QUenacFmKe57Xo+ql4yNUecR/Ef5HG9VJCQ/vuz1lG59Q8cAqIf/8Mi8Hb4EWretkYfKXb/OnJj+sifs5oZtgeMXQBGC+6ZsfQ5mb0F/7Rfj2mDKx5blXfmit7r6aEVcrQxgKIrlUNivMEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110818; c=relaxed/simple; bh=QnqlKGrccODNLeIcH6fq7yvva2SfFRsZTjppQIBuaz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oPA5xotmG7bBJ8vGzPawjKZJUp6J5UbuUrWlP6bZwgiWx1IvUmVuALIpnVbInygoabkj/uBWOLC08jS31tIroJLmwfiAqxlEMvEjydrhvQSyETdB6Bp7rd59b5kqidrVyn2ZYAM4es1tQHeSsYjWK6fwKLrsWw/egXx1xqGdkdU= 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=GMGCYF1t; 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="GMGCYF1t" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21c2f1b610dso20490485ad.0 for ; Fri, 17 Jan 2025 02:46:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737110814; x=1737715614; 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=LEOiK4Qu/cYqt0+j+Km/in7JQgblkIao7pkSH7kiHRI=; b=GMGCYF1tc8gGTa0hqJTybmu6fQpXBozAlkjNMCJI76dJC9x9QrVNZH0WWB44Q9Tg0l HIXms0vIuHmYe2dJdPDmLsW0UT1fiwMgYcAB9kxfMZUevdk2Fp5KcyepIXmcHbdneHsG LqmpEraV7/2QrAtlHh1W6OJ6GjlT3mJFIS2lkXJ0WMxIqtFcdBaeLuNNRppIJM4liPqX xqzGY1Uu/l5idNKOr3D+oiboWMG800KjPB3ql1m36QxMKB6q8d1lM0VWKmM6FFnCpTgw pY24zn5sp6IcwzMGkiuRZr4eTQEWqTWTBFnjOhVFeWAUfKLGCgSXHGJsPIBF+pNqIUwB alKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737110814; x=1737715614; 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=LEOiK4Qu/cYqt0+j+Km/in7JQgblkIao7pkSH7kiHRI=; b=ZomouY45XumpXsKfO6JXAJltU7hFmAv+6gJieCoXBQuBiBgviR+1A27ji5dPIgte5o oi4iJf4bEDd77shORtKkURzjecPErnN2OwbU/EQf1NFqwVD8cs0n9xUe5/klVKLtPXx3 QnLwCyOa9mRdj3WsnS4fMqiV8Hu7kpmepIniBX1Tv3dCarBTnbcsvJpkDg4P9sETkujC 70ldt9rxvCYBM6a/gSnJzGkyr91ujLD+NqV8RS+xfuyMfrbYYzYJzcpkTW+Z8Feksd7g zYc7g4tEghdDwCZbzXbQQ5t7KiMZUe2ufYlVRzSbpZMWggXFQPXW67RXVhFPe6x+bBSM BGwA== X-Gm-Message-State: AOJu0YzUdwYA3wU5h1IY6imRkeRTL2WO+Cj+Wrf9pGrrn22Zs19xxXp2 +F8lCztnq6QzyLNchyel26ZVXREot++1j5IncFEN+Sw5ICvDQDC1pzSM9cD/Zvk= X-Gm-Gg: ASbGncuwaS2GEPaC2KpaFBM/Q89SI2XFWxM2NS1pC6N3Nq80g/Ojx8ixyU1J1Xpmw2a 5EW/86sWR2vuEoajAZDvQ8GAarN1CqWIy+9/xtaPPdAKvObOXul+eIdD441exRBe654LI8W3zrj Vmi/j8hes6Eu47nnK3yPb8WWrY8N8Jc/on+aN/kSSIuJn3ERY2MLwPQMHsXZDLHhmsIjFAm1zP2 pCy8MGtaZW1KSr+gPJgiE1qT5X/hF8ctrXFXw3ee1jD8BjzgXOnoAuVTUobpiGYlHHC7/B/kKBb WxGnIg== X-Google-Smtp-Source: AGHT+IF7xp6Zcxoffs7Rq/xSufSB5QJmlzR63BofzH3c+Qq+qPxIe8PPkM6MDCd6NvedOmBxSQsA2Q== X-Received: by 2002:a05:6a20:394b:b0:1e1:d22d:cf38 with SMTP id adf61e73a8af0-1eb214f0f61mr3326169637.21.1737110813808; Fri, 17 Jan 2025 02:46:53 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72daba48eb8sm1574985b3a.136.2025.01.17.02.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 02:46:53 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, sunshine@sunshineco.com, rsbecker@nexbridge.com, Christian Couder Subject: [PATCH v2 2/6] version: refactor get_uname_info() Date: Fri, 17 Jan 2025 16:16:14 +0530 Message-ID: <20250117104639.65608-3-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250117104639.65608-1-usmanakinyemi202@gmail.com> References: <20250106103713.1452035-1-usmanakinyemi202@gmail.com> <20250117104639.65608-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 78f025c808..96f474c8e6 100644 --- a/version.c +++ b/version.c @@ -2,6 +2,7 @@ #include "version.h" #include "version-def.h" #include "strbuf.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 Jan 17 10:46: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: 13943212 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7180A1FCF5F for ; Fri, 17 Jan 2025 10:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110821; cv=none; b=OgJ4oUZye0qPuYkrY05Y68rgq0atD7FreUo9xxRQ+0tWF1QAcxdkO8NHKOtBSzc2PxPzjnjajtSpcQJOcAFpLrGYH0sdYR1s8CDduronuhajPvsnV/XkEsjce4eqxric5oHICPX8/O/tAREAFPlqqHifximjG3TYQSK9z1JbvGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110821; c=relaxed/simple; bh=uW/lQTkavtnsa1OWu9hrbkfka8oPmRobgYTtX264hjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g9Qy6/aehTMApQ3UMw4MZlbHjVzHs5c/ERvHGZkvFmS8JzgIA/hsEzPKg8iqAEWmvL5HdRst1tYzASRaeTEMZfOfLiINYpqY4x8r8c99SYoST8TxX2man6NG+s6h1MdU6gIBqmh/wns9NZGeNzY6NfPiDJ2jJ+o99nvIZt5ZN6Q= 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=nKU/fDf1; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nKU/fDf1" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2164b662090so35626745ad.1 for ; Fri, 17 Jan 2025 02:46:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737110817; x=1737715617; 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=3Z33A2SZFbMPHdEpR80wKv2/sMPf7sPRXmGeAYZpOP0=; b=nKU/fDf1swen/2lsjs+B8FG/i+i/kYelug5qSZ0bXdOg6ULs4HOUWG6vLZS/oB6HLa 3Xch06dF8wkUd9Eb86rJva+JA04ygcNdFZ3iKElJbHle4MqoxHSq4vyMQNL45oNYIexM UWu+AUjZU2lsj/w5Um5KnD+UhzyllIQbDgnwVPAZsNql0Inlmx5mJsWOvg6VlYPpaPmK yUbumGEkWJAapEAy8MXRKWHKdaFg1VekcXa9J+g42Qr1pwvpPnzTVhPKMKgppmJjFDRW tq9mO5sNAimjhK+t5VLkGDKOW3aJbNQt7fx5hg41TGs6efp9Hp/oCU7Aw8E2xrMToX0n d5cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737110817; x=1737715617; 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=3Z33A2SZFbMPHdEpR80wKv2/sMPf7sPRXmGeAYZpOP0=; b=ol8s7rpua7LA4bQDCNnyyA3abA40r6VHp7yytBbs+DuVhkArBInzw0MqRdzyVRqwaa aEHWnVsqJJiMv/toLUl3s01j1c5jyxnJhxTLfsTB6Ba1n2UFcetiwrUgBUX3jb1KS0u6 2q8Jk9dh1lMIJdpEAHxxiSH/Aun9GfTnwHFBnj3W54z3Sb8FOtxnTMS7KMiozFWqmpna D2ZgSaYSOZx+3Kpvdphlfq/RDrQT2n2q6DynNc44pFPLU6p4JXpqVHuTBPAVOkv1yNr3 zOr46nz4Pz+e9q9uSihEt7DlyYhDB72FIzaN88kozoj4ihmh3j31TQVoEgKd0k/lDR0L bCqg== X-Gm-Message-State: AOJu0YzHfO/5rzU5WC28y9KgdjkLiuNeBZ67Lt+xeEGAoYhv+xuzXhOV Bmna2ZFiZK2TDjjyqtxIcPH+oMdl4pdzggIlgjvqi5cS96t6LwCZ6UtKRghTFzI= X-Gm-Gg: ASbGnctUaXWNe0C4d+Mx/K9WNWRUyz1SNmEFJidAPVXx/Ec62xlrJ3srRJMmOeTddUl qs2zB25tGT+58FmeTcRc608bH8vjzADaHAZtFNhLQIli7KiSE/Q9uP9ua1ii9wEdcV2UZUVmjq8 w9hji5wrb98qn8yk1X0tSXVX+P6KmE3boTBv6QwAc3IQ1HjMFMr/mvGJh+1xI/bPI4NcNsqpd0X 5e3ku1AAk5qOZnseOpFp6DAJZ2Tdkv80YnNFs2Q+oVxhyFiuK0vMgJb74UnuNkxusqc5teP/yp8 0m4Lxg== X-Google-Smtp-Source: AGHT+IEFoACeKCH1uG9TvSiHedGws80/XzcYKniH42ZqB89cU7BjxLsH9jysnL5OKB1iIvi5/WWwPA== X-Received: by 2002:a05:6a00:1813:b0:729:cc5:fa42 with SMTP id d2e1a72fcca58-72dafbaa1c1mr4010673b3a.20.1737110817648; Fri, 17 Jan 2025 02:46:57 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72daba48eb8sm1574985b3a.136.2025.01.17.02.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 02:46:57 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, sunshine@sunshineco.com, rsbecker@nexbridge.com, Christian Couder Subject: [PATCH v2 3/6] version: extend get_uname_info() to hide system details Date: Fri, 17 Jan 2025 16:16:15 +0530 Message-ID: <20250117104639.65608-4-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250117104639.65608-1-usmanakinyemi202@gmail.com> References: <20250106103713.1452035-1-usmanakinyemi202@gmail.com> <20250117104639.65608-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 follwing 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 96f474c8e6..46835ec83f 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 Jan 17 10:46: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: 13943213 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 91CB91FDE0B for ; Fri, 17 Jan 2025 10:47:02 +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=1737110824; cv=none; b=aFlp8w9JwVviiz61MxVZJO5QsWneclsnwgnSv7I4mdMVsMnV74fmX5AgHLO8zhQAJIhcZp96sQr+od6yaN68q3ogql6kqgBihI7/RcrjOZ6mFmzOPraip0f+yTh5SN6sskb9v2XmGPeoJSr/XME9L5dO0mzb7UnRiZdUMDnAuuI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110824; c=relaxed/simple; bh=QQ7GUf0ktN7gLQiI5GvWRwmGffoeAeCpHGWKxF3Hxoo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UmYn8HsnyAxpOLF1BftOE1tI0ubReiOOM5YPr/zm4D4XqDFWhLJ7I9n2YEYh0ggRco7SrEJ/LsgEdhHcadoN+AjC3w+/ay+PJ8VCoybu20pMZXGUhgsX996MKBYkSj6vWUkRFWhNkoCN9BmWUTuHbre+LGoR1kduc+hNoJNbXew= 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=A+2CckOR; 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="A+2CckOR" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-21680814d42so30838675ad.2 for ; Fri, 17 Jan 2025 02:47:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737110821; x=1737715621; 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=ALFAAhPXG1sud+Hsk5Gb/byfBFcmg+Pt5vQNmyxcz9E=; b=A+2CckORcx+FSSoJihN2KDOSEpSQ+x7uP3aKysazZS6wKo1ZR+q4ZluO/Wn2MdjLvD gBusIv0h5/wKH5CN0+EJOSrvV4BboYj4dKY5Jeb5F77XBDlzzoIl2V6RI0nmywX931FX ALPba5pqFNj6RaAm6RFPl48Ad0EekK9do9uVR0C5nopXNAzUTr0qH3+j8+jI0PzpM5kf D01hDzbB4brY/MM4JjUTKN88ta4BM5qfdTXrAmoJ229Yb3GZ16HaOF/Q1dRHskz+q81k 7e1TduH7YVFbps6bijIDwOD0dE5iBwTefBXQU1/6pdW1/HW34hMDHzAcJWrpky7aEVdP lkgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737110821; x=1737715621; 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=ALFAAhPXG1sud+Hsk5Gb/byfBFcmg+Pt5vQNmyxcz9E=; b=p2Uwk1/L/J3XZWBNq77zeniUG9UO8mPmTotvuws3zFJDd1tHTA1e34wbouZzG0Uj7W TCHVFr84f3n9Y4h0gBBSYhV30FjaaFNSdEdA6HQyaDYLEFA6RuiRzUGmFH0t52z4XrXx 0kTw0BmTFtfvoZ+QFeoz+f0oIvT1NOXl2o9q7SyTX4wub0yHjlOQtC2o0F2zxUaKYfuc 5BFxdV66NEsYriI6WKszhmBd/na5b/bXZmuoKEqe8mEOv4WmhtJm1woFoyjvxKmD5Ed6 dGTtcZo0KFo9bnMDPFfCxXv2WJmvqSgF4gr1l+9IDx0T+TF3TRv2j4IN0iqeesn0Qy9F 6Tsw== X-Gm-Message-State: AOJu0YxfTtUVcme6ozHgtxO3uByDA7CikuUCjJ4k/zHythpaZqB9Shc+ GZp/XFEBDYE/xvBl9h3y4LM2Vi+1MGP0PJfuX+cbZVgMBFAWfKqN3SiD7j2Hrtw= X-Gm-Gg: ASbGncuY/0Zic7VD3/t4lpKttjWlGbh4VCXM0qnY1PSH+j6x3qz3YWxOiJhZLWAQtOW +dhNsEJnlpotNQ71xuSR9cdxWoq5IIeeLNl9wxdKU1EmQhasoaPxhRmCHovd2GfdaxP0/gwPLSl 6yHJlatGbjOUeodPbnrL6orX3mIzVrCA62HN1p3JG3DZjlgnrENDmiRGx6lhNI6hSaPIiPNypLE g6B7Zf7Jtvdy8UMzaIP3H4no58QW6wnvhaeVHMj3+6/DeBOTw/AYkb6rM5rX0dSyYfEjjy95Tde E1j5dA== X-Google-Smtp-Source: AGHT+IHc8OMGi1ykPM934p8Y3Y8Vi+/zv2qamYxMigmBtiDaqLMRczTG6DaTtqb16xyWiPWANq/EQg== X-Received: by 2002:a05:6a20:6a14:b0:1e0:cfc0:df34 with SMTP id adf61e73a8af0-1eb2149467cmr2927523637.16.1737110821430; Fri, 17 Jan 2025 02:47:01 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72daba48eb8sm1574985b3a.136.2025.01.17.02.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 02:47:01 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, sunshine@sunshineco.com, rsbecker@nexbridge.com, Christian Couder Subject: [PATCH v2 4/6] t5701: add setup test to remove side-effect dependency Date: Fri, 17 Jan 2025 16:16:16 +0530 Message-ID: <20250117104639.65608-5-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250117104639.65608-1-usmanakinyemi202@gmail.com> References: <20250106103713.1452035-1-usmanakinyemi202@gmail.com> <20250117104639.65608-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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index de904c1655..0c0a5b2aec 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -7,14 +7,17 @@ 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/$(git version | cut -d" " -f3)" >agent_and_osversion && + 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_and_osversion) ls-refs=unborn fetch=shallow wait-for-done server-option @@ -23,6 +26,9 @@ test_expect_success 'test capability advertisement' ' 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 Jan 17 10:46:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13943214 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 5D3C01FDE0B for ; Fri, 17 Jan 2025 10:47:06 +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=1737110829; cv=none; b=jIa7BQFUMd2SkEZAkICLpJIpOv8FW+P32wj7PXjaB65TRtegren95NooBRLxgpVczOdZ8HZ11ZBylGweZyn/jQzYfx0Pbbq3BR+aMkWuWtCtxZwgL0r2rSVtajpLNDviBfocHkRAPH1fDoitxKvtaNsP0PyOtCDmdU+9ONVWln8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110829; c=relaxed/simple; bh=GAhOsT2bW+1PFrxob92ZuOEB88boQLr8cM8qSfrSbjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P5U4MC5zZv3WDDBWxzVm9GRmyLbocNXcDhDeMf17djQeCt1Vo6qyxgbi7oKXQXW2TWjPlrGTRhcXNzrlXBpJCBc6/z1jDwZuNZXNgr23M8jRs6AAj9tQi9dQw+3ITVg1TKRQP/4AXkM3mizSjO5Io/IhRvdMUl8/HiEqbJk0jrc= 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=JVN5CPNn; 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="JVN5CPNn" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2162c0f6a39so59097605ad.0 for ; Fri, 17 Jan 2025 02:47:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737110825; x=1737715625; 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=y3qqpa/XSfr1Uhz/wwSwiMc7gnqhCsjeSCYz4F6Uu80=; b=JVN5CPNnmixuMEG4v3WnZXD/GWa8VDk6v+NUDJQjJZogTz5yne5Ps+dQtkBuUVxQWo J/sSBgYdy/J7yPb+/IxR5P1huzYY4vJttfYTyqTnrf3h0r0rynxmun/0FnN+azML68aJ Yc+fSUxfJkyi6tcPZE+HoM/glqhUQEYi/KZ/NR0k5jBE2RrUEz15PyDn7be1cxXh+Iip R6CaXuKEQdb3A8C8Uu+gzZrjOt94SK5toPNM3ZooWuF1laQql/m7L2j7u04QOZtyAknq XUTsCesA1P8LH6VZ6qhv/+l/oqqWlDiPVfBNapT99TC2uyesdl6dT9Y/D2mkQVMldRXU rwtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737110825; x=1737715625; 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=y3qqpa/XSfr1Uhz/wwSwiMc7gnqhCsjeSCYz4F6Uu80=; b=P+GS/zvTWvW7tf95/ylV8HBlUypI01EdE39mLSICdTDmtmbGoYUbTNb8gqcfyf0UPC dt07snfDsFjo7N+3+BrIEtLQ6hZPABK30o12Xz03VMoGLYZ7/CbhhnBMVgJuxkK2auOm np7JZnn5/+Y6TXflH9L4Zg8fuCQi9y3glH4Y4tZ9Wv7PEXleu+G0XHwRzBdcK67iK5ga aObvp1VLIbddUll86YfuXy3vdbgocswbA6Xj1GnyGlN0BzRqYyQOx2iPDElX9h/lSPjn SjetITSOh19rSiOhF2U1lHFNyMKKT0lO9UyCcFF3bbYeDfi0c7Hkq8myie19VjeI73Dq DmHw== X-Gm-Message-State: AOJu0Yyd3xT1mW8PTqdGNybAuMznVYmEhdWqKmI1m50JQiQc8evGjh/9 52ks2vVvYQ5u3iu2wa7ogRKV1ESl/+4U87h7eoPv68E6IIC2WRmygDkk1OF9RAE= X-Gm-Gg: ASbGncs6COfrG6xU7Q540IHElSv6H1Q9wKd/ugphpIObn5WQRvJqJSDioi/ofnUvuY5 /CojN/QbEnMHmfMjX3Ej8cBpb87s2ntaF87G0/y9tRpSATJCoq3qzLZvaz/sPxKJcsBnCUamJwD xc4N+PAvnOiAOYvCPmKp76Qh/txqLNTazlyff0ryvBzyVe911134Wel+1tBnmarNZTp+DIJezaB mc0Zq7w8TbsNkxgwLM7faXcP6nqFHvflusL/pmpMpTjEVHGJfws057c7AuJWg4F9uzorKaqmMvU fYJxgw== X-Google-Smtp-Source: AGHT+IEnAcHBRtjbfPy9pPoS4o6vxhlPtXBYpWKI+x178PAwGFwhel09NfZwis19UqprhLtsMWxGvg== X-Received: by 2002:a05:6a00:1d12:b0:728:15fd:dabb with SMTP id d2e1a72fcca58-72db1c5d820mr3316740b3a.8.1737110825303; Fri, 17 Jan 2025 02:47:05 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72daba48eb8sm1574985b3a.136.2025.01.17.02.47.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 02:47:05 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, sunshine@sunshineco.com, rsbecker@nexbridge.com, Christian Couder Subject: [PATCH v2 5/6] connect: advertise OS version Date: Fri, 17 Jan 2025 16:16:17 +0530 Message-ID: <20250117104639.65608-6-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250117104639.65608-1-usmanakinyemi202@gmail.com> References: <20250106103713.1452035-1-usmanakinyemi202@gmail.com> <20250117104639.65608-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. Let's introduce a new protocol (`os-version`) allowing Git clients and servers to exchange operating system information. The protocol is controlled by the new `transfer.advertiseOSVersion` config option. Add the `transfer.advertiseOSVersion` config option to address privacy concerns. It defaults to `true` and can be changed to `false`. When enabled, this option makes clients and servers send each other the OS name (e.g., "Linux" or "Windows"). The information is retrieved using the 'sysname' field of the `uname(2)` system call. 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 | 7 ++++++ Documentation/gitprotocol-v2.txt | 18 +++++++++++++ connect.c | 3 +++ serve.c | 14 +++++++++++ t/t5555-http-smart-common.sh | 10 +++++++- t/t5701-git-serve.sh | 20 +++++++++++++-- t/test-lib-functions.sh | 8 ++++++ version.c | 42 +++++++++++++++++++++++++++++++ version.h | 21 ++++++++++++++++ 9 files changed, 140 insertions(+), 3 deletions(-) diff --git a/Documentation/config/transfer.txt b/Documentation/config/transfer.txt index f1ce50f4a6..c368a893bd 100644 --- a/Documentation/config/transfer.txt +++ b/Documentation/config/transfer.txt @@ -125,3 +125,10 @@ transfer.bundleURI:: transfer.advertiseObjectInfo:: When `true`, the `object-info` capability is advertised by servers. Defaults to false. + +transfer.advertiseOSVersion:: + When `true`, the `os-version` capability is advertised by clients and + servers. It makes clients and servers send to each other a string + representing the operating system name, like "Linux" or "Windows". + This string is retrieved from the `sysname` field of the struct returned + by the uname(2) system call. Defaults to true. diff --git a/Documentation/gitprotocol-v2.txt b/Documentation/gitprotocol-v2.txt index 1652fef3ae..a332b55e4c 100644 --- a/Documentation/gitprotocol-v2.txt +++ b/Documentation/gitprotocol-v2.txt @@ -190,6 +190,24 @@ printable ASCII characters except space (i.e., the byte range 32 < x < and debugging purposes, and MUST NOT be used to programmatically assume the presence or absence of particular features. +os-version +~~~~~~~~~~ + +In the same way as the `agent` capability above, the server can +advertise the `os-version` capability to notify the client the +kind of operating system it is running on. The client may optionally +send its own `os-version` capability, to notify the server the kind of +operating system it is also running on in its request to the server +(but it MUST NOT do so if the server did not advertise the os-version +capability). The value of this capability may consist of ASCII printable +characters(from 33 to 126 inclusive) and are typically made from the result of +`uname -s`(OS name e.g Linux). The os-version capability can be disabled +entirely by setting the `transfer.advertiseOSVersion` config option +to `false`. The `os-version` strings are purely informative for +statistics and debugging purposes, and MUST NOT be used to +programmatically assume the presence or absence of particular +features. + ls-refs ~~~~~~~ diff --git a/connect.c b/connect.c index 10fad43e98..6d5792b63c 100644 --- a/connect.c +++ b/connect.c @@ -492,6 +492,9 @@ static void send_capabilities(int fd_out, struct packet_reader *reader) if (server_supports_v2("agent")) packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized()); + if (server_supports_v2("os-version") && advertise_os_version(the_repository)) + packet_write_fmt(fd_out, "os-version=%s", os_version_sanitized()); + if (server_feature_v2("object-format", &hash_name)) { int hash_algo = hash_algo_by_name(hash_name); if (hash_algo == GIT_HASH_UNKNOWN) diff --git a/serve.c b/serve.c index c8694e3751..5b0d54ae9a 100644 --- a/serve.c +++ b/serve.c @@ -31,6 +31,16 @@ static int agent_advertise(struct repository *r UNUSED, return 1; } +static int os_version_advertise(struct repository *r, + struct strbuf *value) +{ + if (!advertise_os_version(r)) + return 0; + if (value) + strbuf_addstr(value, os_version_sanitized()); + return 1; +} + static int object_format_advertise(struct repository *r, struct strbuf *value) { @@ -123,6 +133,10 @@ static struct protocol_capability capabilities[] = { .name = "agent", .advertise = agent_advertise, }, + { + .name = "os-version", + .advertise = os_version_advertise, + }, { .name = "ls-refs", .advertise = ls_refs_advertise, diff --git a/t/t5555-http-smart-common.sh b/t/t5555-http-smart-common.sh index e47ea1ad10..6f357a005a 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_and_osversion && + if test_have_prereq WINDOWS + then + git config transfer.advertiseOSVersion false + else + printf "\nos-version=%s\n" $(uname -s | test_redact_non_printables) >>agent_and_osversion + fi && + cat >expect <<-EOF && version 2 - agent=FAKE + $(cat agent_and_osversion) 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 0c0a5b2aec..8a783b3924 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -26,10 +26,26 @@ test_expect_success 'setup to generate files with expected content' ' cat >expect.trailer <<-EOF && 0000 EOF + + if test_have_prereq WINDOWS + then + git config transfer.advertiseOSVersion false + else + printf "\nos-version=%s\n" $(uname -s | test_redact_non_printables) >>agent_and_osversion + fi && + + cat >expect_osversion.base <<-EOF + version 2 + $(cat agent_and_osversion) + ls-refs=unborn + fetch=shallow wait-for-done + server-option + object-format=$(test_oid algo) + EOF ' test_expect_success 'test capability advertisement' ' - cat expect.base expect.trailer >expect && + cat expect_osversion.base expect.trailer >expect && GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ --advertise-capabilities >out && @@ -357,7 +373,7 @@ test_expect_success 'test capability advertisement with uploadpack.advertiseBund cat >expect.extra <<-EOF && bundle-uri EOF - cat expect.base \ + cat expect_osversion.base \ expect.extra \ expect.trailer >expect && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 78e054ab50..f7ff38521c 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 +# corresponds 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 46835ec83f..ea334c3e9c 100644 --- a/version.c +++ b/version.c @@ -3,6 +3,7 @@ #include "version-def.h" #include "strbuf.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; @@ -69,3 +70,44 @@ int get_uname_info(struct strbuf *buf, unsigned int full) strbuf_addf(buf, "%s\n", uname_info.sysname); return 0; } + +const char *os_version(void) +{ + static const char *os = NULL; + + if (!os) { + struct strbuf buf = STRBUF_INIT; + + get_uname_info(&buf, 0); + os = strbuf_detach(&buf, NULL); + } + + return os; +} + +const char *os_version_sanitized(void) +{ + static const char *os_sanitized = NULL; + + if (!os_sanitized) { + struct strbuf buf = STRBUF_INIT; + + strbuf_addstr(&buf, os_version()); + redact_non_printables(&buf); + os_sanitized = strbuf_detach(&buf, NULL); + } + + return os_sanitized; +} + +int advertise_os_version(struct repository *r) +{ + static int transfer_advertise_os_version = -1; + + if (transfer_advertise_os_version == -1) { + repo_config_get_bool(r, "transfer.advertiseosversion", &transfer_advertise_os_version); + /* enabled by default */ + transfer_advertise_os_version = !!transfer_advertise_os_version; + } + return transfer_advertise_os_version; +} diff --git a/version.h b/version.h index 5eb586c0bd..3e983bc623 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,23 @@ const char *git_user_agent_sanitized(void); */ int get_uname_info(struct strbuf *buf, unsigned int full); +/* + Retrieve and cache system information for subsequent calls. + Return a pointer to the cached system information string. +*/ +const char *os_version(void); + +/* + Retrieve system information string from os_version(). Then + sanitize and cache it. Return a pointer to the sanitized + system information string. +*/ +const char *os_version_sanitized(void); + +/* + Retrieve and cache whether os-version capability is enabled. + Return 1 if enabled, 0 if disabled. +*/ +int advertise_os_version(struct repository *r); + #endif /* VERSION_H */ From patchwork Fri Jan 17 10:46:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13943215 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DAE11FE45F for ; Fri, 17 Jan 2025 10:47:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110833; cv=none; b=HCb0/RhrwbXjdZ/W/lsyV5KNzuusD6TEoEld5Y9QxIIhr50/zGIodDcrVd4J1Xbl0yut/OTgQ1RyIFcC+UB233HAh/ZwbtdQAfB5meFCyGWm8pjkdZ5ziEpoOCEVnYXTVKcUWms6KqozsWG4XZfT65WO0UbbYlaZmGPVo+PTfzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737110833; c=relaxed/simple; bh=txFqAgWoxMb9+c/YDLVNHrSgvAu/TcuZ/0wLfr9hZGU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pSU6hQfEBYxNOq1U280Z5bYAlR0YPxrL+Gm/7EeYZ3FQUMlnFpWrFheM2yIurWZKy/7RxisaP6Hux4t0LnSuNCcdJ2kusdggxFklfEiOeFQVq/d70q0IbsXlSQtzimgr2g/9M+HYgnZhxy815yNlEaAUbwvIKSuxVoQA7NYAqWQ= 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=NkhlLCx0; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NkhlLCx0" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2165448243fso43889935ad.1 for ; Fri, 17 Jan 2025 02:47:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737110829; x=1737715629; 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=oJjCr56AkspfPUzAjUTbLKGGegoWBg6FQj9MU7c/c98=; b=NkhlLCx0AQ7PvRcgA91lPO7H83ceTEQguSZunhFz8nTyAhA4ttipilBtuDvwTJUJW3 ynoXICNgVTqaOtuTNHTCkB2tFL0fYx6j6es+JEoB1sUfg3iihVq/3Cr5ijdcTzYJnN68 0DwcKfmcK9S+PXsr6CM4VTF8kJK5CsmowHyybnK6MTu5uduaUMzj+iI8XY1sq9NGR33l 9NEtqgrGbNGljD+ByuKgiJMlfdS2XpCSpZXbh6b8gWzbEb5EByZxv/3ubUM57tptRAgv 6IKEU3BeQYwdzDwgcNnbhEuk4yUizDhHJgkyrbf93a95kr3QR+XUsSGf+kOGIypp3uGq RWHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737110829; x=1737715629; 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=oJjCr56AkspfPUzAjUTbLKGGegoWBg6FQj9MU7c/c98=; b=VIH6TjbLlsvF0mjCqL7y/JbBMB6taIQolIH/lOpF0pUi63t8GHdZRFCWhry6U1CzlE X/pQKguav1oM1CzXUYD6hcjHCVpnsPhH6mfmfY7TicAYKgVBPFypTFAyEnraeGHz29Rs YnOgdI59Ord8hKazNHicFuIg20YyQCCkl0qW/Gz7uIJLzkf94NpxVopg8NVooiMOrIbK HZ12/HFyx3JJaeImpHn207onlnKZh0idQ7uIrYgOYcqly7tLy7nU2s+57RD/w8MeEDm7 cLi8f3NV+evzsy658yEHjqmpA/J3X5m/1OCVHdafIuVF9TWuyzPs461tuCbRCPg4Ryui SSmQ== X-Gm-Message-State: AOJu0Yx6Un3DVfJGpdse/Xz22kA65Ifcp86kBD8z8KV6GDAFjwQrRAT9 yeMBBe6WRHXjJyreTiTQqpzZfZSUVwSp33wR6XKXmJbrF0P0ZKM7XCbU4r29yzc= X-Gm-Gg: ASbGncvEPESbbmk2qcwaVuqz05qFpnynOzOsPwkH/hT0bLAGlBoaNLnIEGld9QhdJh3 F44cqq/w+wi8Wiw8anL1X9WHbKeGxVI3ZMlpLYSVUc8xu0sImfTWRsnKo5FwF0VKjFTavetusg/ RbVN3BrWT0CQ4/I9gZoIxMg30Dg2dPB4sw/uK6IutsABjfS3XxUN2Kg4eG8Zsn20c3hqJl/yKGv lF+/GlTPf6SuG0U9+nIxtOoQ6+yyK9UzhOIsDWT5HaO4mumu1BQ0IPzjhbq7zfivxgV8UTjxwSk OVRAxg== X-Google-Smtp-Source: AGHT+IH3RnQf9snHzpyfrp/+/aL+IrOShafATxzGKtGsubZSxRWHvmFP/kXpVTalrX23/RtCWyTDTg== X-Received: by 2002:a05:6a00:340c:b0:728:e906:e446 with SMTP id d2e1a72fcca58-72dafbda6ddmr3798434b3a.24.1737110829204; Fri, 17 Jan 2025 02:47:09 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72daba48eb8sm1574985b3a.136.2025.01.17.02.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 02:47:08 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, ps@pks.im, johncai86@gmail.com, Johannes.Schindelin@gmx.de, me@ttaylorr.com, phillip.wood@dunelm.org.uk, sunshine@sunshineco.com, rsbecker@nexbridge.com, Christian Couder Subject: [PATCH v2 6/6] version: introduce osversion.command config for os-version output Date: Fri, 17 Jan 2025 16:16:18 +0530 Message-ID: <20250117104639.65608-7-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250117104639.65608-1-usmanakinyemi202@gmail.com> References: <20250106103713.1452035-1-usmanakinyemi202@gmail.com> <20250117104639.65608-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently by default, the new `os-version` capability only exchange the operating system name between servers and clients i.e "Linux" or "Windows". Let's introduce a new configuration option, `osversion.command`, to handle the string exchange between servers and clients. This option allows customization of the exchanged string by leveraging the output of the specified command. This customization might be especially useful on some quite uncommon platforms like NonStop where interesting OS information is available from other means than uname(2). If this new configuration option is not set, the `os-version` capability exchanges just the operating system name. Helped-by: Randall S. Becker Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- Documentation/config/transfer.txt | 11 ++++++- Documentation/gitprotocol-v2.txt | 25 ++++++++------- t/t5555-http-smart-common.sh | 28 +++++++++++++++++ t/t5701-git-serve.sh | 29 ++++++++++++++++++ version.c | 51 ++++++++++++++++++++++++++++++- 5 files changed, 129 insertions(+), 15 deletions(-) diff --git a/Documentation/config/transfer.txt b/Documentation/config/transfer.txt index c368a893bd..c9f38c5796 100644 --- a/Documentation/config/transfer.txt +++ b/Documentation/config/transfer.txt @@ -131,4 +131,13 @@ transfer.advertiseOSVersion:: servers. It makes clients and servers send to each other a string representing the operating system name, like "Linux" or "Windows". This string is retrieved from the `sysname` field of the struct returned - by the uname(2) system call. Defaults to true. + by the uname(2) system call. If the `osVersion.command` is set, the + output of the command specified will be the string exchanged by the clients + and the servers. Defaults to true. + +osVersion.command:: + If this variable is set, the specified command will be run and the output + will be used as the value `X` for `os-version` capability (in the form + `os-version=X`). `osVersion.command` is only used if `transfer.advertiseOSVersion` + is true. Refer to the linkgit:git-config[1] documentation to learn more about + `transfer.advertiseOSVersion` config option. diff --git a/Documentation/gitprotocol-v2.txt b/Documentation/gitprotocol-v2.txt index a332b55e4c..93a2e97ec0 100644 --- a/Documentation/gitprotocol-v2.txt +++ b/Documentation/gitprotocol-v2.txt @@ -193,20 +193,19 @@ the presence or absence of particular features. os-version ~~~~~~~~~~ -In the same way as the `agent` capability above, the server can -advertise the `os-version` capability to notify the client the -kind of operating system it is running on. The client may optionally -send its own `os-version` capability, to notify the server the kind of -operating system it is also running on in its request to the server -(but it MUST NOT do so if the server did not advertise the os-version -capability). The value of this capability may consist of ASCII printable +In the same way as the `agent` capability above, the server can advertise +the `os-version` capability to notify the client the kind of operating system +it is running on. The client may optionally send its own `os-version` capability, +to notify the server the kind of operating system it is also running on in its +request to the server (but it MUST NOT do so if the server did not advertise the +os-version capability). The value of this capability may consist of ASCII printable characters(from 33 to 126 inclusive) and are typically made from the result of -`uname -s`(OS name e.g Linux). The os-version capability can be disabled -entirely by setting the `transfer.advertiseOSVersion` config option -to `false`. The `os-version` strings are purely informative for -statistics and debugging purposes, and MUST NOT be used to -programmatically assume the presence or absence of particular -features. +`uname -s`(OS name e.g Linux). If the `osVersion.command` is set, the value of this +capability are made from the ouput of the command specified. The os-version capability +can be disabled entirely by setting the `transfer.advertiseOSVersion` config option +to `false`. The `os-version` 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 6f357a005a..1a3df3d090 100755 --- a/t/t5555-http-smart-common.sh +++ b/t/t5555-http-smart-common.sh @@ -150,6 +150,34 @@ test_expect_success 'git upload-pack --advertise-refs: v2' ' test_cmp actual expect ' +test_expect_success 'git upload-pack --advertise-refs: v2 with osVersion.command config set' ' + test_config osVersion.command "uname -srvm" && + printf "agent=FAKE" >agent_and_long_osversion && + + if test_have_prereq !WINDOWS + then + printf "\nos-version=%s\n" $(uname -srvm | test_redact_non_printables) >>agent_and_long_osversion + fi && + + cat >expect <<-EOF && + version 2 + $(cat agent_and_long_osversion) + ls-refs=unborn + fetch=shallow wait-for-done + server-option + object-format=$(test_oid algo) + 0000 + EOF + + GIT_PROTOCOL=version=2 \ + GIT_USER_AGENT=FAKE \ + git upload-pack --advertise-refs . >out 2>err && + + test-tool pkt-line unpack actual && + test_must_be_empty err && + test_cmp actual expect +' + test_expect_success 'git receive-pack --advertise-refs: v2' ' # There is no v2 yet for receive-pack, implicit v0 cat >expect <<-EOF && diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index 8a783b3924..1395ac4eba 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -53,6 +53,35 @@ test_expect_success 'test capability advertisement' ' test_cmp expect actual ' +test_expect_success 'test capability advertisement with osVersion.command config set' ' + test_config osVersion.command "uname -srvm" && + printf "agent=git/$(git version | cut -d" " -f3)" >agent_and_long_osversion && + + if test_have_prereq !WINDOWS + then + printf "\nos-version=%s\n" $(uname -srvm | test_redact_non_printables) >>agent_and_long_osversion + fi && + + test_oid_cache <<-EOF && + wrong_algo sha1:sha256 + wrong_algo sha256:sha1 + EOF + cat >expect_long.base <<-EOF && + version 2 + $(cat agent_and_long_osversion) + ls-refs=unborn + fetch=shallow wait-for-done + server-option + object-format=$(test_oid algo) + EOF + cat expect_long.base expect.trailer >expect && + + GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \ + --advertise-capabilities >out && + test-tool pkt-line unpack actual && + test_cmp expect actual +' + test_expect_success 'stateless-rpc flag does not list capabilities' ' # Empty request test-tool pkt-line pack >in <<-EOF && diff --git a/version.c b/version.c index ea334c3e9c..2aa55e56b5 100644 --- a/version.c +++ b/version.c @@ -1,9 +1,13 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "version.h" #include "version-def.h" #include "strbuf.h" #include "gettext.h" #include "config.h" +#include "run-command.h" +#include "alias.h" const char git_version_string[] = GIT_VERSION; const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT; @@ -71,6 +75,50 @@ int get_uname_info(struct strbuf *buf, unsigned int full) return 0; } +/* + * Return -1 if unable to retrieve the osversion.command config or + * if the command is malformed; otherwise, return 0 if successful. + */ +static int fill_os_version_command(struct child_process *cmd) +{ + const char *os_version_command; + const char **argv; + char *os_version_copy; + int n; + + if (git_config_get_string_tmp("osversion.command", &os_version_command)) + return -1; + + os_version_copy = xstrdup(os_version_command); + n = split_cmdline(os_version_copy, &argv); + + if (n < 0) { + warning(_("malformed osVersion.command config option: %s"), + _(split_cmdline_strerror(n))); + free(os_version_copy); + return -1; + } + + for (int i = 0; i < n; i++) + strvec_push(&cmd->args, argv[i]); + free(os_version_copy); + free(argv); + + return 0; +} + +static int capture_os_version(struct strbuf *buf) +{ + struct child_process cmd = CHILD_PROCESS_INIT; + + if (fill_os_version_command(&cmd)) + return -1; + if (capture_command(&cmd, buf, 0)) + return -1; + + return 0; +} + const char *os_version(void) { static const char *os = NULL; @@ -78,7 +126,8 @@ const char *os_version(void) if (!os) { struct strbuf buf = STRBUF_INIT; - get_uname_info(&buf, 0); + if (capture_os_version(&buf)) + get_uname_info(&buf, 0); os = strbuf_detach(&buf, NULL); }