From patchwork Thu Mar 6 14:35:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14004610 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 593EB170A23 for ; Thu, 6 Mar 2025 14:36:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271800; cv=none; b=la4kYUg5Qgfon2ihly7Bd8CwC9q7PrEBVxiJxCZYJ5B+/oFDM1WJ6/MpRn4eGUcELdjYHIXDeqo3ADrLKEVQtEUoyRPx2Ckr6Ipk80hRfI6ay3sQSRp7YVxDEU1z4IsaynTQkD8z6DTIKwMXAAC5WmuvfXV2perjCxn3uruIxTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271800; c=relaxed/simple; bh=AwaaxAYt87FZHQCnDAzkqih66IySqenZOCdDZFOkilY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eJ3JaA5SX8rCUI4rc0U1fq4458+939BptvdyxzJla4gFOMrWc7suEdPPrwvXgjkqJIB0UXxCfIpRDsYScpko7AySeLBZf0t+3eGi9Dji51d0V/Yv3vHQFTEa0t173B63GJ8yrrtYP1FcO2+Z5iiPoQqHW2bT2aiDGBJ5XA54XF4= 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=ZlYPcARs; arc=none smtp.client-ip=209.85.216.51 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="ZlYPcARs" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2fce3b01efcso1118730a91.3 for ; Thu, 06 Mar 2025 06:36:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741271798; x=1741876598; 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=T0AZ4mEL8WspowItpDJ1/3XlhUBa1leXLVag5E4GWpI=; b=ZlYPcARsyf8jby3Xbpb0QsZ265/mwhR7CKbRj1p04qQXTgaNyc7HxeKMJC7T7L4YOS vZhJW3rXFT6aHcahAdvk3B9bxyHNySq2zKE1ZR7lMEij5Mm5ogdw0cTfCOo7JJTOJOhj 3bmmq6Ru4OsU2PoOr5skIBE9GFndQjgl/WtjsI/R/mTQMr+7uUypHJjuzGhml4WMRF8L IL+3WCT14ZaGwF7Y7Hi6ks1m3fCN+yHge3Wq9ftBr3/10NK9JETaUCbqsnO/y+BPmENY KZM7rp3U3fuSnsTXuShgKfgZrTm8Nn1yscoD/Fh3xnZPVOcsMQxpDV48FRXM6lutrqIb owlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271798; x=1741876598; 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=T0AZ4mEL8WspowItpDJ1/3XlhUBa1leXLVag5E4GWpI=; b=JDdJ3I0k3yxxlUHJjJHRwZ5JFrB5sTxUBtjO9r/VWoKVPPAQotPPJ4AQgbzgQZeBkH QlE1hqMz3IZgN30piFZdRjhECNAkTvsW8Q1JIh7G80nMLm2K3YIurGd8W4iD9z+E0dPH p6K3LDmkNrJPE09vB5ZoSw9hpY7L1FK03Oaxi8P0Npk5YbgtzupmlbESRGFPO1vhalhn gJ7EZjBmX4tKi/JjU1i/IZpfyUC0IASviCPcIB7nvlqzH7284CIf4ieQh6I3JQ/9cGtB pKmL4pW/EGO64Ec8AcakB0QAVQWY/cmUF84+Sr1bmao6tZ2V7FGAc6JcWUeD6F5bpDgC gNDg== X-Gm-Message-State: AOJu0YyboSJq7Xo6jgz/93NpKJkw63Se4IcoyCM783SuEco/ItGITlSz kI7Nrydw6V82SfliMtPGQVVgjKB4fJRA23lWZUbDExAvFkyxxIs0AXU60FJb X-Gm-Gg: ASbGncuZSSN/yAvDwUY/gZu1mg9y/GHJ8JhVc/3PZx0ZmDszpcUewd9hQgkyz1vMgGv mdsCEXLMzVXhgXlJWa9dck8Gvsuc8XyNi/0BNx58oWeLMG8ldVNwinCVrA3aKC4TTzRyoNnF5Wx QIyV8FftTpcAYKozr7XPbtA7B1Jm+4CLb6A8LD8D+NVeQPSIAuCH4cjqvZKXJiSIEgt2CBK6Nbp K3B10bthpdnLUN7JyOVadjTTw5ODkUygZsiGcLfT2oKXcNjxm193F/4dVy1cNiyVs0IY8fo13RM eDS5R5mlXvtpxF00EENlkY7D0zilNcicCERqB572VomXwiVjb8WVgu8MuhDsnG4T08E7/Q== X-Google-Smtp-Source: AGHT+IE9+MKNQkhdO6XdXm/NEFbbloBqHEeWMrO4c3jcrpp/I+NAenzarnWHWoVlbRBsTfdSQ6oiGg== X-Received: by 2002:a17:90b:2e42:b0:2ee:96a5:721c with SMTP id 98e67ed59e1d1-2ff497acb35mr10096547a91.21.1741271798277; Thu, 06 Mar 2025 06:36:38 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ff4e7ff944sm3561184a91.34.2025.03.06.06.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:36:37 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, ps@pks.im, shejialuo@gmail.com, Christian Couder Subject: [PATCH v3 1/8] config: teach repo_config to allow `repo` to be NULL Date: Thu, 6 Mar 2025 20:05:45 +0530 Message-ID: <20250306143629.1267358-2-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> References: <20250219203349.787173-1-usmanakinyemi202@gmail.com> <20250306143629.1267358-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The `repo` value can be NULL if a builtin command is run outside any repository. The current implementation of `repo_config()` will fail if `repo` is NULL. If the `repo` is NULL the `repo_config()` can ignore the repository configuration but it should read the other configuration sources like the system-side configuration instead of failing. Teach the `repo_config()` to allow `repo` to be NULL by calling the `read_very_early_config()` which read config but only enumerate system and global settings. This will be useful in the following commits. Suggested-by: Junio C Hamano Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- config.c | 4 ++++ config.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/config.c b/config.c index 36f76fafe5..c5181fd23b 100644 --- a/config.c +++ b/config.c @@ -2526,6 +2526,10 @@ void repo_config_clear(struct repository *repo) void repo_config(struct repository *repo, config_fn_t fn, void *data) { + if (!repo) { + read_very_early_config(fn, data); + return; + } git_config_check_init(repo); configset_iter(repo->config, fn, data); } diff --git a/config.h b/config.h index 5c730c4f89..1e5b22dfc4 100644 --- a/config.h +++ b/config.h @@ -219,6 +219,9 @@ void read_very_early_config(config_fn_t cb, void *data); * repo-specific one; by overwriting, the higher-priority repo-specific * value is left at the end). * + * In cases where the repository variable is NULL, repo_config() will + * call read_early_config(). + * * Unlike git_config_from_file(), this function respects includes. */ void repo_config(struct repository *r, config_fn_t fn, void *); From patchwork Thu Mar 6 14:35:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14004611 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 A648D188713 for ; Thu, 6 Mar 2025 14:36:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271804; cv=none; b=IERCbI27ytdjRcvVQwUccvzCqbXPceoiRv0KOA6vxxvLVpCxR3rMZTAQDWdIZXI81jjxI7UEAWIhjUcSLfSwshvOnjslKqtHCVWMrGCEQ6Tagic5rdk3GkfwmFMiOyebHVC7PWluxwVqBZWh1ODyd+h6NkW/Aw2TOTUF5FlSmtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271804; c=relaxed/simple; bh=JAJbSWuFJgB3UDNULyyBg5saO01KET8wLRD6PmDumWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LcFxU928IEi8xO/DzsotNYZWEXOY8uG7iLbjprY8Cjqirp3+Fq+S4pSVOl4zF1QYx6VGdZ8SJVenE4rFvgbvVqINxxkXEosIVJtg/XUOrbEjYeGX+0OqMsLk7jrW5IEDCcS37hFnyq58PuVk6DXaBKDAEDI9ODHgt6idMO1E2lY= 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=PUt/QQsZ; arc=none smtp.client-ip=209.85.216.51 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="PUt/QQsZ" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2f44353649aso1200275a91.0 for ; Thu, 06 Mar 2025 06:36:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741271802; x=1741876602; 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=YS369oUw4eRuRr2YFC8W8hxX9W24rD8Bi7rbrICFRVs=; b=PUt/QQsZyIHuSYDiin7Iinv1AOJJ8rlcU+vDrdWB2PFZY1yg4p8oTIURHLJLY0/o9w Ad1wzS81F9rDC+mytAEYFXjOlloODxoYg3ppQ9XE2zKr41/t1ttTTzcy9djyOwVi64+T QSJC3nEJGMSh5YPznWb7QmA7pn/JID87+NVAmQBWYe6TP8vqiNNVrBtkOtVYpbJcFzpF +4ep6+7SPaQssHoUrqGdxG8gWjBcW7uw40JF7qTARhEjY7igi/IdMpxBNkQDfN8VfYXd HFeHBV4m8dSV4z4rYOgty6uoHjwp/rlAb5ZkLTwgU9xzdnX3OxfDREGeaVNkYx5CQJq5 uxrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271802; x=1741876602; 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=YS369oUw4eRuRr2YFC8W8hxX9W24rD8Bi7rbrICFRVs=; b=Pwuazv7nPikDEdEikukJp0PTc6MjMbE+TPw+gPBU3BL92OpCqRuJ8aNSvmx8LM/91h kJ+g/QaCln+AxUwYvPTp8BIuDbTdJe6BSOJvp3DeoD2epK8UTXjkWa6azedT044m7ys8 9KBYXBcsHJGiBlYBNg88zczAeafK7Y6MRR3fQ5iKYaoHvZPNAS0IVWc6l8k/j2HnheiZ aA2Xfa2PxnIxLt4T/JyZyXia3NT0qcHpcOpaFX93BNy0/vK4Q8tYItO5LT4O2cSJtfoT H4ITFtC4v/mIqM6YOBT7/bwJjORT9e4bsddAUZ79qirMYuo1lEHbhVg/7BwVCXSkphhs 4fOg== X-Gm-Message-State: AOJu0Yxb8aUs1VH2Fo0udqv1pMjz/cop5NrPzUYNV1ZgXnizx5w/P7qh bqKJoJ8Y/UCI0FfdmD5pON8TOpTCuyOoweLney0XRVad5hDmQGFHYG24FXma X-Gm-Gg: ASbGncvqKps1dAy8zk2EAOhCqhEwOcqEDX1Oq4RlPzMzNJfPEGmF/ddFmYd6v2xVO5+ sWBS2olHu397uJA7zIfU5qXYAb6VRbQQjCl6T5Cq9B0H3668X9M9dEwQIxMXDoFC3vdfHb6w+IL kH+mkIl8Q04NKXxDQxScSiNJ2g3JuI2PfEoH8Wxp/IbNylB7qDQcTsC97q4/NDHiEWY/pWJPn8s CLbCHE1QTcWG6+hMj8/RmX3KVikr9QQVrPfIrdOiB3BqDHMeJ1W84TbuBV/Vc2J7/FuiIGQlsuZ tghBbAFNZSoxqDbP4iOIHgxkpLBpac4y7MbIPWpz3ICvmnWhg1UhVPMkTrMl3moWFevU9Q== X-Google-Smtp-Source: AGHT+IEKyIl5AEDk12ZQ3fGUY30IuNDwxeeVWjA2+9skiv1crgIcnxC5MsI+nruCUIagZ+PpjVO7ig== X-Received: by 2002:a17:90b:270d:b0:2fe:9e6c:add9 with SMTP id 98e67ed59e1d1-2ff4975343amr13214303a91.18.1741271801585; Thu, 06 Mar 2025 06:36:41 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ff4e7ff944sm3561184a91.34.2025.03.06.06.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:36:41 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, ps@pks.im, shejialuo@gmail.com, Christian Couder Subject: [PATCH v3 2/8] builtin/verify-tag: stop using `the_repository` Date: Thu, 6 Mar 2025 20:05:46 +0530 Message-ID: <20250306143629.1267358-3-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> References: <20250219203349.787173-1-usmanakinyemi202@gmail.com> <20250306143629.1267358-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/verify-tag.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_verify_tag()` function with `repo` set to NULL and then early in the function, `parse_options()` call will give the options help and exit. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/verify-tag.c | 7 +++---- t/t7030-verify-tag.sh | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index f6b97048a5..ed1c40338f 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -5,7 +5,6 @@ * * Based on git-verify-tag.sh */ -#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "config.h" #include "gettext.h" @@ -23,7 +22,7 @@ static const char * const verify_tag_usage[] = { int cmd_verify_tag(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { int i = 1, verbose = 0, had_error = 0; unsigned flags = 0; @@ -35,7 +34,7 @@ int cmd_verify_tag(int argc, OPT_END() }; - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); argc = parse_options(argc, argv, prefix, verify_tag_options, verify_tag_usage, PARSE_OPT_KEEP_ARGV0); @@ -56,7 +55,7 @@ int cmd_verify_tag(int argc, struct object_id oid; const char *name = argv[i++]; - if (repo_get_oid(the_repository, name, &oid)) { + if (repo_get_oid(repo, name, &oid)) { had_error = !!error("tag '%s' not found.", name); continue; } diff --git a/t/t7030-verify-tag.sh b/t/t7030-verify-tag.sh index 6f526c37c2..2c147072c1 100755 --- a/t/t7030-verify-tag.sh +++ b/t/t7030-verify-tag.sh @@ -7,6 +7,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh . "$TEST_DIRECTORY/lib-gpg.sh" +test_expect_success GPG 'verify-tag does not crash with -h' ' + test_expect_code 129 git verify-tag -h >usage && + test_grep "[Uu]sage: git verify-tag " usage && + test_expect_code 129 nongit git verify-tag -h >usage && + test_grep "[Uu]sage: git verify-tag " usage +' + test_expect_success GPG 'create signed tags' ' echo 1 >file && git add file && test_tick && git commit -m initial && From patchwork Thu Mar 6 14:35:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14004612 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 CBD62158DD9 for ; Thu, 6 Mar 2025 14:36:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271807; cv=none; b=Wrgeiv14IF8x93UPkKUZGzPJpg+WkflIZtq/XxwUpq2+wGCKmmE+qK3laGOzeeqA/nBpjCEgaRMnBGggRXfzO/4VLTOtyTiT9b5NGfHGEXc1dojlqZUJqj9Cea3JfUG9DwlTEkUk3dHnIp7pwMMHE/IJULeEwaoylQpfbZLjtYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271807; c=relaxed/simple; bh=U6cmTbxV4tCdvBmncexg+swheF19OVuQ+W1ra8DB9vQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zu+mpSOD0kl8sSThg/l5pWbMcJJUI0HrEUesnl0ogWdFFokcHXLxasgEB4LIEyI4EQnNbPMCQUPoKlaH4APnhIn2af03VpM2cPfqujK/w1XxO4jRTgzzCynQMOFNclPU7iLics2xNhuqAV+vKRn0uB67Xfk0fI9s1H5psvDLKR4= 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=BUackK6z; arc=none smtp.client-ip=209.85.216.54 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="BUackK6z" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2ff799d99dcso87431a91.1 for ; Thu, 06 Mar 2025 06:36:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741271805; x=1741876605; 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=PzH0GxcUvPZP2/UeP0dJFg2sRLWgXweOioqvjIfY+08=; b=BUackK6zuX+1eDVOLb/zmY4k+lNZRj7oTwNWa2VM8Of391R5SRJI/9aCVNyh4M1d4H gIJ10yrdCvpfbUGDUe5N/Uk+FlCDWp8lT78Z2qfaUADzjo1WyU1BLTClhlUEiNmjNjpe O2r2hBMZsifsnIpVIRb/lLiiPMlaMPDPz2tF1XZ7XRmc1fMirUiBY66KSlKtbzdi1u5I HbHY/46J+/MU6JGevkv2L/dWHHcixMq5gzL8JQprXCSqmTTxI0Xo42yQvpje/9l4C290 1RltRrUIJY9lC0MTOXYKvaira8QvQlPXaNwzzBrrOJV5W9plfvBuPB4pYtQxV1U8HOUy F9Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271805; x=1741876605; 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=PzH0GxcUvPZP2/UeP0dJFg2sRLWgXweOioqvjIfY+08=; b=CzDH5lpeVJ0v/R/xb9AGZNSH9OZRaP0HeANCCkjql5lcZWKnyc8qs69UHqiY4dKFVR zAnAwyGoca0rUgyKTBScsDDP7ZV6coAwwyrCdorvO6MPKMiYgN+NC2Q3ikpWaUE4cW9D 8ZZTrPtZNPi7kGTABLh4R8Yshh1yRmkDPzqyRZJUnApgDAlIqb3n+SyLgmUBtzhhEvnk yJcfa6QOtX3aidL1MxRQ/GULO5t1rZhuxMxIkc92VrnsBU5dD6YGKbcbmg/sxOykpn8S GoRWJ2Psxf57k6R665dHAFYNu6PkBkno6rzUPQiDSgRMHvJRw76bknfLKcnitxk8JDgP 3R4w== X-Gm-Message-State: AOJu0Yx/rwVeYDFAos62Kw3lLflavn8AWHErefhQVkYCQuJq1fZqzWAC o34vtXWxN4AjENAQJfTQyXETfi3sUhW3VXsk12Z8yWjQxoQICMH+k4aFgRT/ X-Gm-Gg: ASbGnct7wXpUqPvBazB93ed3ONt/fNPJ8f27AFB3BELHWjudmr6E74d2MgjnVyxGRKK hlu/2JOPc7dy9eUNnp7mH+RASql4BvixMgUCAC0HyCqOPHOgRedNEXaGDTe0YPlFSj6WAmuCwz+ 3RcQtwvfzAUo8j/zDIzWr4aLDFNapZZ8o9wnHdIap1Kqa19dHjFRNkoNGJ8hP10zfcFP/IhILJa jGTbRwzsej7EMv3ULUBpZZKyq9/97Nidn/62317PQ7oKaNKlv9eBwqUvhabSoTHPHT8SYht+XiS bjSGzFWqBycDl7IAHUTVARILfluy5CqPICa5ALCkEUB5RF2y9AbcNyHsEYITo7jzgn2oGg== X-Google-Smtp-Source: AGHT+IFgXlRR14MQAXps8Amim8qQ43onlzYUFwZMgaZ1w3f73rq3ufPn8TLGvnDXdcUlFIK6E3unnA== X-Received: by 2002:a17:90b:52c3:b0:2ff:69d4:6fe2 with SMTP id 98e67ed59e1d1-2ff69d470c9mr3951262a91.16.1741271804933; Thu, 06 Mar 2025 06:36:44 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ff4e7ff944sm3561184a91.34.2025.03.06.06.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:36:44 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, ps@pks.im, shejialuo@gmail.com, Christian Couder Subject: [PATCH v3 3/8] builtin/verify-commit: stop using `the_repository` Date: Thu, 6 Mar 2025 20:05:47 +0530 Message-ID: <20250306143629.1267358-4-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> References: <20250219203349.787173-1-usmanakinyemi202@gmail.com> <20250306143629.1267358-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/verify-commit.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_verify_commit()` function with `repo` set to NULL and then early in the function, `parse_options()` call will give the options help and exit. Pass the repository available in the calling context to `verify_commit()` to remove it's dependency on the global `the_repository` variable. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/verify-commit.c | 13 ++++++------- t/t7510-signed-commit.sh | 7 +++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 779b7988ca..5f749a30da 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -5,7 +5,6 @@ * * Based on git-verify-tag */ -#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "config.h" #include "gettext.h" @@ -33,15 +32,15 @@ static int run_gpg_verify(struct commit *commit, unsigned flags) return ret; } -static int verify_commit(const char *name, unsigned flags) +static int verify_commit(struct repository *repo, const char *name, unsigned flags) { struct object_id oid; struct object *obj; - if (repo_get_oid(the_repository, name, &oid)) + if (repo_get_oid(repo, name, &oid)) return error("commit '%s' not found.", name); - obj = parse_object(the_repository, &oid); + obj = parse_object(repo, &oid); if (!obj) return error("%s: unable to read file.", name); if (obj->type != OBJ_COMMIT) @@ -54,7 +53,7 @@ static int verify_commit(const char *name, unsigned flags) int cmd_verify_commit(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { int i = 1, verbose = 0, had_error = 0; unsigned flags = 0; @@ -64,7 +63,7 @@ int cmd_verify_commit(int argc, OPT_END() }; - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); argc = parse_options(argc, argv, prefix, verify_commit_options, verify_commit_usage, PARSE_OPT_KEEP_ARGV0); @@ -78,7 +77,7 @@ int cmd_verify_commit(int argc, * was received in the process of writing the gpg input: */ signal(SIGPIPE, SIG_IGN); while (i < argc) - if (verify_commit(argv[i++], flags)) + if (verify_commit(repo, argv[i++], flags)) had_error = 1; return had_error; } diff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh index 0d2dd29fe6..39677e859a 100755 --- a/t/t7510-signed-commit.sh +++ b/t/t7510-signed-commit.sh @@ -8,6 +8,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME GNUPGHOME_NOT_USED=$GNUPGHOME . "$TEST_DIRECTORY/lib-gpg.sh" +test_expect_success GPG 'verify-commit does not crash with -h' ' + test_expect_code 129 git verify-commit -h >usage && + test_grep "[Uu]sage: git verify-commit " usage && + test_expect_code 129 nongit git verify-commit -h >usage && + test_grep "[Uu]sage: git verify-commit " usage +' + test_expect_success GPG 'create signed commits' ' test_oid_cache <<-\EOF && header sha1:gpgsig From patchwork Thu Mar 6 14:35:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14004613 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 3989D158DD9 for ; Thu, 6 Mar 2025 14:36:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271810; cv=none; b=kn6MseLKhbUTa/VfRbH8VZb1XrvcKcvuOZcrjR5li37ILnHawqc2tzmuVcTeNQaE9C4c5jkvI8OXD1QRmpfu3cCGRhEx04JRyNC7hqamMJOxkiPACMZIpnhq2bVUbsCtCXth8Nj2Xu9mQWGXPMKxNYVxM7b066mUbDgM3+J/LNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271810; c=relaxed/simple; bh=6u2NuRnQfBqAIwfT9N+W2cLbTA8vrQV39JvWlFebs8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UtZqyGjtQUI/mho1Ka0CJw3ENjhrkJs2TA/ovRJOMbvu1wqtUQHg/PGUNm3nuZ+zxPrdDWZlNbpmOt8U1NGYIXa3c66WT0SvStmG6H4rFfqoZ8K8sdaULOad/DPxBaCH4Hal/hhurcahYFl2VLsvABaBbf0971i06dpwrZzhFjo= 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=UyDssLun; arc=none smtp.client-ip=209.85.216.53 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="UyDssLun" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2f9b9c0088fso1290346a91.0 for ; Thu, 06 Mar 2025 06:36:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741271808; x=1741876608; 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=3Rb3yS0CVOISQIr4Ol2n4ARfJ+e3EEivkK8XxzJZZK4=; b=UyDssLunzsV4gWSbXywODohY7H6cVDpGLBeHOEUnCFHcPGX8LC/aiBMhOHo6QIIJNy elXAhrmksFcuEUAaOG+u+VpKNhgfcTOK2bCJQ5SuALnC0J0zmyvF23fDfVEEIQZUW0pO ok90cHpJ3dyHKVV43RDT0c15fwZc4I0ujl19tDVw23n2mljwi7inB9NNJbkf5otxz9p+ 2+UuklNRmAsxlWK0qKfzDq+ESKMBEnJ7/q6p0ZnkayyUvsJjQ7p6nxwFrSjprOIhfdI/ zhdW+D5xjd2MGHNYRmcBdA7ePiUC3RtTDDywcb7XoZr4AVngsu6R7ky1Ubn9X2lmc02s Bw/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271808; x=1741876608; 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=3Rb3yS0CVOISQIr4Ol2n4ARfJ+e3EEivkK8XxzJZZK4=; b=BgcM1bhfXJphbTBNwAacecaYU1Zq/qrn45Yp6k0RhdyHOER8gL5hoTsW7SmHBgs0sw ncapQcvhjbNA73ZPEx3kFXciscKEFjScLskO4D+HuwaeRuzlJvb96VdhlEXyI4N51p2T YdXv6/0KtGaW/av/YRT3KqqCUcdhV7AyUUFC6PVtjQhF2VeUcEJG6IzFDLILaDQ7ROsu GPg+OqjaY+iGyhOVUyJZalG+AlD6cCoZsjZIOXNKU20LVgMqKVLewJ+aHadtrpGDh03e fDQk4yKUKU9hPL637EiZuAIF0QLb4TCSkLiXNlarPVANMXbQJLW/PAcBebge+gnbjgAR 23BQ== X-Gm-Message-State: AOJu0YxBDRkuyuZ4R9ZqA6MxAxvO2SlctPlzwKDRw1tuJTMj/NHf3xSe UpFZflxgxAAnzQKYdpDtygowTPPf57hxJBcHtNuiPL4arMuQQj+1PSYjuWU0 X-Gm-Gg: ASbGncuCJfv4C/rZvRq6cAkXthvdmSDM2RACuDnzZrXbbiGYJZUwe4srlGlvDJ+ENSB 269sEDdx8QwvzNunajUu3n70cGWvnfj8BxUfkwh6vzh4iRlDl9dmBt0Hc0OQPOIORGDtw87Zjl3 WcbPjRS3qG7E4gUipHtGVN7skS3MCA/xVZwVHrJ6gCvL38Px1lXi9eybz+e71fVzFWmrTRaWqlU dK7L+zgKXMaGUvMCi05rpbFZKUuCmHOfXOg/qx51TOBQ0+yUFKZOuJw942YRQ9lVg8S785+gXa5 x2B9hDnTGDgCvGkW7j/9990+N5RtOkyF7wO4t2jPJwxEAEzJZxltQNyCVbquGz7Np165fw== X-Google-Smtp-Source: AGHT+IGUONZ/5fiKo5pZpyv1VR43o3tPwWA6XlecsrFtOytVMPoegDoPqPljE/WUyod/rqUUPGZ/Ew== X-Received: by 2002:a17:90b:3ec5:b0:2ea:8aac:6ac1 with SMTP id 98e67ed59e1d1-2ff617b5145mr5482979a91.15.1741271808173; Thu, 06 Mar 2025 06:36:48 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ff4e7ff944sm3561184a91.34.2025.03.06.06.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:36:47 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, ps@pks.im, shejialuo@gmail.com, Christian Couder Subject: [PATCH v3 4/8] builtin/send-pack: stop using `the_repository` Date: Thu, 6 Mar 2025 20:05:48 +0530 Message-ID: <20250306143629.1267358-5-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> References: <20250219203349.787173-1-usmanakinyemi202@gmail.com> <20250306143629.1267358-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/send-pack.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_send_pack()` function with `repo` set to NULL and then early in the function, `parse_options()` call will give the options help and exit. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/send-pack.c | 7 +++---- t/t5400-send-pack.sh | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 8d461008e2..c6e0e9d051 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -1,4 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "config.h" #include "hex.h" @@ -151,7 +150,7 @@ static int send_pack_config(const char *k, const char *v, int cmd_send_pack(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { struct refspec rs = REFSPEC_INIT_PUSH; const char *remote_name = NULL; @@ -212,7 +211,7 @@ int cmd_send_pack(int argc, OPT_END() }; - git_config(send_pack_config, NULL); + repo_config(repo, send_pack_config, NULL); argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0); if (argc > 0) { dest = argv[0]; @@ -317,7 +316,7 @@ int cmd_send_pack(int argc, set_ref_status_for_push(remote_refs, args.send_mirror, args.force_update); - ret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have); + ret = send_pack(repo, &args, fd, conn, remote_refs, &extra_have); if (helper_status) print_helper_status(remote_refs); diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh index 3f81f16e13..8f018d2f23 100755 --- a/t/t5400-send-pack.sh +++ b/t/t5400-send-pack.sh @@ -55,6 +55,13 @@ test_expect_success setup ' echo Rebase && git log' +test_expect_success 'send-pack does not crash with -h' ' + test_expect_code 129 git send-pack -h >usage && + test_grep "[Uu]sage: git send-pack " usage && + test_expect_code 129 nongit git send-pack -h >usage && + test_grep "[Uu]sage: git send-pack " usage +' + test_expect_success 'pack the source repository' ' git repack -a -d && git prune From patchwork Thu Mar 6 14:35:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14004614 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 3BF5417BEBF for ; Thu, 6 Mar 2025 14:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271815; cv=none; b=K7RDP0v8Cxpb4PYyhJZEM2AqeCZTZlD2fJ/sMzT9VA+9OSSwJuGFXjR6jh3LtMaBt/qumhinu6DETvRrj7v+9eW8T5BSFXWEQxHQrhSAlQxAJaJHWl9tq67lTPJPzu+pX2u0FDGrv48+PoqLGGt4YTH1ip1y9YBhXSONbHyqRY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271815; c=relaxed/simple; bh=XTJrwl6lGzYH/UD6p2YmKN1G1LrAG9X5uWXZIigQmz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A8A8g39tG0YtH+g1U7GVsqM7f8g5htcehYJ593fG3Wp1ST2r8EpzgY6npaoF1YAoqciebV5lMKEf2n8vj5JwxsWc5Fsb0Ukn20UwJDT8ZJJBEvpHbLqpb9uUSL3/pNdUsJWZA9/kOF1QlJJ+a85OprvLAt7VXvQxWmPXofIEw9Y= 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=CogmgyFB; arc=none smtp.client-ip=209.85.216.52 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="CogmgyFB" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2fa8ac56891so1202052a91.2 for ; Thu, 06 Mar 2025 06:36:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741271812; x=1741876612; 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=odxIt6J5cAejMWvEFPdbwTynWI7WHeWNfI/TInK4QPk=; b=CogmgyFB9o3H622DZGFqek9QXbBs7KiQZRZAiTFPzQCyUHuV+HlFjPfPyRzNfvKD6u NrWtNYiBl4GZmmc+IvMkZPeCYwwq1ZDSjkc6PXv0Xx7afrWb0J61kIvHQR0lg0X/Bise Nny4BviBkdk9WbEOVNqbxjLeGMKTouU2EfDowMihAOtwNqNQbfrS+MyPwo2MFxXJvjC7 cskPDcOd/14oiBjrzRtoitjkOeHA52HEEr6W9TchWy4nhNQz2oObekPFqW+by5px7bST PLIlK9PuXC6qtLnLTNIETtWEWjI/IpYulY0hHEziXW7vDNRjtQULKl5TySweYp3nw+2E iX7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271812; x=1741876612; 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=odxIt6J5cAejMWvEFPdbwTynWI7WHeWNfI/TInK4QPk=; b=omcDH5Tx0+IKJdqFoJj3ikCHWcS1Xroyh7L59UeeSmRm8jYr0+sMyrcJMi3o1gcEXs JSckznzC6IUBCWGj+VchXaNvrjQ60Fjj9nTGBFGPjtgQHmPK5WE8FYM1V/deM3i9ccfA mWo9JcbSoaZspl934VR+pbV0d6L3hBkcTNFTlCbzUAtkzyKD0KmtZH+/99D1Mr2Q/jYz NX/QZ3S4CBRDD+eAAiC3ttzz1CKvGCMwAU2N2WIfZmgHZ3DMp0+DGzsB6M8O5i0+T148 vTrWQYETWmFWqAiNa3koLLxdPPv9JsjPIHQ7KZuwZBrc5IVfUb3PT5wM8thZ9gtGhe4D Gchw== X-Gm-Message-State: AOJu0YwOY8z0hz4+3b/q/VVgX78X6hUq/sxNRs3eu1khYLleZ402WPTn AaKjgahefGI9GGQRv9vE1TuI00R8Ris9GFwfP1ovpWdtfVoQvsRpHAZnowvU X-Gm-Gg: ASbGnctsKow4/dM0595MzczuRL+AcY7xFteyXKIDnl4YA3v7cLc80C2Gw61ezKPjMXu PVrCuKAtkGJHbd/1FwbHYEYbSV/K/yRXfVpXZKfSf0/Adrx1Zjg9a2TdK+Jqg1ijhUlXyiGyqVp kjVSQ6Eaze8pnw35w3RewMRXxN2jz6Bpjp5rFRPX7zvz28+RhMHOR9B2hnHR8Cg9ZZL9snZ4L51 kGxsNHQjK0m256NFD/7gs5Um38KX0zv+RmxK6nHdOI7i+oetYopeHT8H5Bkgg/ugEhP2R/2HcNS fmUEjmdz3bL6jcZ1NMKEEHxeefpFJl1T5xE9JJ4aOwXDfC2JKuWon8cfBC2w67n6381zGw== X-Google-Smtp-Source: AGHT+IHt0HvJ5M+fW0qF0nIKC7Chrm/H/Nk6f8KvYdST1QQ/j5GgfcfBS0T0+uRgnGuDJeg6A/c6nw== X-Received: by 2002:a17:90b:38c4:b0:2ff:693a:758d with SMTP id 98e67ed59e1d1-2ff693a76a4mr3558142a91.27.1741271811484; Thu, 06 Mar 2025 06:36:51 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ff4e7ff944sm3561184a91.34.2025.03.06.06.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:36:51 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, ps@pks.im, shejialuo@gmail.com, Christian Couder Subject: [PATCH v3 5/8] builtin/pack-refs: stop using `the_repository` Date: Thu, 6 Mar 2025 20:05:49 +0530 Message-ID: <20250306143629.1267358-6-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> References: <20250219203349.787173-1-usmanakinyemi202@gmail.com> <20250306143629.1267358-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/pack-refs.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_pack_refs()` function with `repo` set to NULL and then early in the function, `parse_options()` call will give the options help and exit. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/pack-refs.c | 8 +++----- t/t0610-reftable-basics.sh | 7 +++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c index 4fdd68880e..e47bae1c80 100644 --- a/builtin/pack-refs.c +++ b/builtin/pack-refs.c @@ -1,5 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "builtin.h" #include "config.h" #include "gettext.h" @@ -15,7 +13,7 @@ static char const * const pack_refs_usage[] = { int cmd_pack_refs(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { struct ref_exclusions excludes = REF_EXCLUSIONS_INIT; struct string_list included_refs = STRING_LIST_INIT_NODUP; @@ -39,7 +37,7 @@ int cmd_pack_refs(int argc, N_("references to exclude")), OPT_END(), }; - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0)) usage_with_options(pack_refs_usage, opts); @@ -52,7 +50,7 @@ int cmd_pack_refs(int argc, if (!pack_refs_opts.includes->nr) string_list_append(pack_refs_opts.includes, "refs/tags/*"); - ret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts); + ret = refs_pack_refs(get_main_ref_store(repo), &pack_refs_opts); clear_ref_exclusions(&excludes); string_list_clear(&included_refs, 0); diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh index 4618ffc108..002a75dee8 100755 --- a/t/t0610-reftable-basics.sh +++ b/t/t0610-reftable-basics.sh @@ -14,6 +14,13 @@ export GIT_TEST_DEFAULT_REF_FORMAT INVALID_OID=$(test_oid 001) +test_expect_success 'pack-refs does not crash with -h' ' + test_expect_code 129 git pack-refs -h >usage && + test_grep "[Uu]sage: git pack-refs " usage && + test_expect_code 129 nongit git pack-refs -h >usage && + test_grep "[Uu]sage: git pack-refs " usage +' + test_expect_success 'init: creates basic reftable structures' ' test_when_finished "rm -rf repo" && git init repo && From patchwork Thu Mar 6 14:35:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14004615 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D573B18BB9C for ; Thu, 6 Mar 2025 14:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271817; cv=none; b=Gj4OOfgZmefXLp/VIENl0gkDYZcm3NLCYRU0EBPwR5MwT8WeyCZRhoXJiKrDACl8BivT4JnuiIEsNQTnCFaXIrB0MSKdPbJyxEWLOzUiJ7yBznOrgqm59w8aYptDU1oigl+z0IJhkkojHx8alou7zsq4gIS1Jq+vHkuASEgdxrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271817; c=relaxed/simple; bh=uyPEZR42xGEUWWqABH7AINQb5hhX4uxPZN3aXjnIdLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uw0mCQey0ZFjBrvNIM8gmERcPto12725G2IdifFf8aNWGum5vQUwHMZfzG4+7GchdMaRrN9xqy8dW5SuT6snW9lmv5dfTi6gCOxrnvf0sMwJ6WNQXazPcssl3Qa+3wm5QxiOUh46gf9uOx2LvOgj4/SOvOWt8alKqGQpNZ3FEqk= 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=aWdtrSH6; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aWdtrSH6" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2ff187f027fso1270134a91.1 for ; Thu, 06 Mar 2025 06:36:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741271815; x=1741876615; 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=4mTtvDBKpgj+WV6qsVkiH+6irNu3ohNrVLzshn7Enuw=; b=aWdtrSH6tVuRviFmFzDCrzi7q1Ei7FKmbqBJOs1LFfODICUQLJ1U8z4G4BS9xBKoaL lfPvy7DFDEqxeVgM/l38xD8NzA6M/4Utp05TQa3sYb4sraMzMpFmGVxWjiqqe8b8xb1J 5XVkJDM5g47AGG3Hm1etHyvCVbUWmViAqoQw3RBZMLnnuOW/PcDvmypvOxLwYofSbw0R mkX5cfE66+Rlst/AzJKHwnJWRsc8Dgpl2u+GyPS/vc3cw5Z6KNfU6GCpXvqzBZqeHEpI J3GMARjPLVn1e+sIgrzYZjilrByAVe8qluk8OVRDNZEIb6LbxJbCYklpTJZNhc2VuY2J u/ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271815; x=1741876615; 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=4mTtvDBKpgj+WV6qsVkiH+6irNu3ohNrVLzshn7Enuw=; b=mENeMg2J8bQHvGMI/3Z4lfPC0+SvlVZdATU2l62arymghM1rFUlXUS/LqJt7al0uCN KMN26fyK79V+YoZbbO01yFFsS+Pk3QsJZlYM1yo/zHTIT+77vNLvCKliwLQYbzfT6/EF 0WJpChu+FnLsV4lsQNFK4528ozyBWORQMMsQKgATtT7WNYlW5yeFhQaLbaGnS60ZeYSL 2sKxs8PzHbzsUQSTz8yssHbz48JzJ7qOZL1LrzduJ4ZQVG2MxP1rbvz7SZFI4xD8/BhD UwheSxEHomp+QcHS4O7vmNPwx74TdO+vcNa5g8OFDWJMlb3N+ZIiu1ltzcNQqJRcQc9B RFsQ== X-Gm-Message-State: AOJu0YymONeqSgE7QoNQHh9cehZcyNx8rBGUfsi5uDWjrnf9nOVq+OOK I2Sp6D0H7F4Rc59eR0Xk/eF7zke63nFyEmUv589OCDvuqmFPJR9QRV332GD3 X-Gm-Gg: ASbGncs9PlNd2y0yM1SdLBBdiTimbx6Pq9K/W0L+1khtP1HrZVDF6KtXq5KG0osow2k pdimLL7U+2A1UooPdXEdaeh6/UqesPESjSbYUFiiqCwar4UOA4OWJJD2QgCeBq5yOFh0LZrVQsY WF71Tyu3wMyAmrggxFCx7MCWC45Onp1YfhpIHGhoNwPU9su9qQDK8D97/9bQodr0yBoL/AEKGba Wq6hsVC561O6R5RB/IwpqjNIE3HI8XMwchsULH+JnbONXgU088lvmia3j8tLR6az3TLd2cSU6qZ 343/5s2dEe3YFEWRxsCZZGw8jSsTJuztLRpw5SQZUF95RbQcUQMhWzcMhY1ykk0GX0L8OQ== X-Google-Smtp-Source: AGHT+IG25ViNEIdgmmnC6hwVU8GfR3dBpk+6m1Y0heqsGGHX4s7148gzSWctNkVHeP1amwwLbgvRfw== X-Received: by 2002:a17:90b:4a91:b0:2fa:3174:e344 with SMTP id 98e67ed59e1d1-2ff617d8290mr5966018a91.14.1741271814917; Thu, 06 Mar 2025 06:36:54 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ff4e7ff944sm3561184a91.34.2025.03.06.06.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:36:54 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, ps@pks.im, shejialuo@gmail.com, Christian Couder Subject: [PATCH v3 6/8] builtin/ls-files: stop using `the_repository` Date: Thu, 6 Mar 2025 20:05:50 +0530 Message-ID: <20250306143629.1267358-7-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> References: <20250219203349.787173-1-usmanakinyemi202@gmail.com> <20250306143629.1267358-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/ls-files.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_ls_files()` function with `repo` set to NULL and then early in the function, `show_usage_with_options_if_asked()` call will give the options help and exit. Pass the repository available in the calling context to both `expand_objectsize()` and `show_ru_info()` to remove their dependency on the global `the_repository` variable. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/ls-files.c | 32 ++++++++++++++++---------------- t/t3004-ls-files-basic.sh | 7 +++++++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index a4431429b7..70a377e9c0 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -6,7 +6,6 @@ * Copyright (C) Linus Torvalds, 2005 */ -#define USE_THE_REPOSITORY_VARIABLE #define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" @@ -245,12 +244,13 @@ static void show_submodule(struct repository *superproject, repo_clear(&subrepo); } -static void expand_objectsize(struct strbuf *line, const struct object_id *oid, +static void expand_objectsize(struct repository *repo, struct strbuf *line, + const struct object_id *oid, const enum object_type type, unsigned int padded) { if (type == OBJ_BLOB) { unsigned long size; - if (oid_object_info(the_repository, oid, &size) < 0) + if (oid_object_info(repo, oid, &size) < 0) die(_("could not get object info about '%s'"), oid_to_hex(oid)); if (padded) @@ -283,10 +283,10 @@ static void show_ce_fmt(struct repository *repo, const struct cache_entry *ce, else if (skip_prefix(format, "(objecttype)", &format)) strbuf_addstr(&sb, type_name(object_type(ce->ce_mode))); else if (skip_prefix(format, "(objectsize:padded)", &format)) - expand_objectsize(&sb, &ce->oid, + expand_objectsize(repo, &sb, &ce->oid, object_type(ce->ce_mode), 1); else if (skip_prefix(format, "(objectsize)", &format)) - expand_objectsize(&sb, &ce->oid, + expand_objectsize(repo, &sb, &ce->oid, object_type(ce->ce_mode), 0); else if (skip_prefix(format, "(stage)", &format)) strbuf_addf(&sb, "%d", ce_stage(ce)); @@ -348,7 +348,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir, } } -static void show_ru_info(struct index_state *istate) +static void show_ru_info(struct repository *repo, struct index_state *istate) { struct string_list_item *item; @@ -370,7 +370,7 @@ static void show_ru_info(struct index_state *istate) if (!ui->mode[i]) continue; printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i], - repo_find_unique_abbrev(the_repository, &ui->oid[i], abbrev), + repo_find_unique_abbrev(repo, &ui->oid[i], abbrev), i + 1); write_name(path); } @@ -567,7 +567,7 @@ static int option_parse_exclude_standard(const struct option *opt, int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix, - struct repository *repo UNUSED) + struct repository *repo) { int require_work_tree = 0, show_tag = 0, i; char *max_prefix; @@ -647,15 +647,15 @@ int cmd_ls_files(int argc, show_usage_with_options_if_asked(argc, argv, ls_files_usage, builtin_ls_files_options); - prepare_repo_settings(the_repository); - the_repository->settings.command_requires_full_index = 0; + prepare_repo_settings(repo); + repo->settings.command_requires_full_index = 0; prefix = cmd_prefix; if (prefix) prefix_len = strlen(prefix); - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); - if (repo_read_index(the_repository) < 0) + if (repo_read_index(repo) < 0) die("index file corrupt"); argc = parse_options(argc, argv, prefix, builtin_ls_files_options, @@ -724,7 +724,7 @@ int cmd_ls_files(int argc, max_prefix = common_prefix(&pathspec); max_prefix_len = get_common_prefix_len(max_prefix); - prune_index(the_repository->index, max_prefix, max_prefix_len); + prune_index(repo->index, max_prefix, max_prefix_len); /* Treat unmatching pathspec elements as errors */ if (pathspec.nr && error_unmatch) @@ -748,13 +748,13 @@ int cmd_ls_files(int argc, */ if (show_stage || show_unmerged) die(_("options '%s' and '%s' cannot be used together"), "ls-files --with-tree", "-s/-u"); - overlay_tree_on_index(the_repository->index, with_tree, max_prefix); + overlay_tree_on_index(repo->index, with_tree, max_prefix); } - show_files(the_repository, &dir); + show_files(repo, &dir); if (show_resolve_undo) - show_ru_info(the_repository->index); + show_ru_info(repo, repo->index); if (ps_matched && report_path_error(ps_matched, &pathspec)) { fprintf(stderr, "Did you forget to 'git add'?\n"); diff --git a/t/t3004-ls-files-basic.sh b/t/t3004-ls-files-basic.sh index a1078f8701..4034a5a59f 100755 --- a/t/t3004-ls-files-basic.sh +++ b/t/t3004-ls-files-basic.sh @@ -34,6 +34,13 @@ test_expect_success 'ls-files -h in corrupt repository' ' test_grep "[Uu]sage: git ls-files " broken/usage ' +test_expect_success 'ls-files does not crash with -h' ' + test_expect_code 129 git ls-files -h >usage && + test_grep "[Uu]sage: git ls-files " usage && + test_expect_code 129 nongit git ls-files -h >usage && + test_grep "[Uu]sage: git ls-files " usage +' + test_expect_success SYMLINKS 'ls-files with absolute paths to symlinks' ' mkdir subs && ln -s nosuch link && From patchwork Thu Mar 6 14:35:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14004616 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 5B4B018BB9C for ; Thu, 6 Mar 2025 14:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271820; cv=none; b=aGVD2rS2/hZj12fKpUil/3SDfB4tN2VwCs0Gz/inNNlOevZjMTEzO2JyJV7TCrB2gikO8ayNTBfB9w4BGDQb1iSd6bZjwM/LhBYBBuVoSwg82/3M3FY8R6DgUgpzB7uiGsmxA7AeQ3s1fQBWvW/DKkKjPRyCD1ZG8BiX03ZwsNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271820; c=relaxed/simple; bh=uW5bRQB4XXi6+E31aohFFA1T+pUDf31lBRQLmOnjdyE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bQ3CYgtQRj1l7x5CNgnAjLOt1LSvzf6QOvabeGNOxgD9CVaKrK/c7j96MdOb1rXEUyIxb+Dxx2NGhavenu3zsF3e9cl1h85g7Ia/aZev5wHYmKqUqEwUqvfzG1dAcM2vwtu3WNIhACZWo9D6KCsWfqP1BlJ1KidYx19RZ/MzTyc= 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=ZMKAIcOe; arc=none smtp.client-ip=209.85.216.49 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="ZMKAIcOe" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2feb96064e4so1608441a91.1 for ; Thu, 06 Mar 2025 06:36:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741271818; x=1741876618; 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=iK1MudTOOC0VXfUy+3wi28IDwRwjOzctrPukWuJ73aE=; b=ZMKAIcOeJH/Jnjy+0I6nEfCdvLvgiLLJuFLUkBOQd8SbcRzzta4nbFQssIeRR1/vb2 9T2RTUi3Is/nXIEsFh6xBXiMnbPaeHgggOdfqzynxVI29Y8CIF1i7B/UPHxHvYSKHKLK I7q+FFJV5NyDW7III3d3gQ+WYs3j+5iY1jx2cKmukucEFiq75ZPPE0C6zzBb1PtRiUBU 3kvFTACaJ8FryLVzlu8UdqZM0kQunTsgVzkrx/zRfw4sgPnSPUCPspdihhjIqGkrKExh Gk0rLTKA9/yYsRIumQkbUu3QgxyDi5ADrQdfinZRXNxc9LXpl1OtFaKNSaLZOhSEo0WT XooA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271818; x=1741876618; 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=iK1MudTOOC0VXfUy+3wi28IDwRwjOzctrPukWuJ73aE=; b=aAXM+WFX6JeP+qwVI9zS/AjpYAB6eu4JATSWhmthhlz0ZYeQHxo8EvddWXWDff+TOK /DkCe2m3vhcUnuCcXfeAHThFA9emRvz9E37VgHVPNKaSVVUeXw3bTbLELd7tH+nD5k3U XVN7PBLN0oi4X4mNZc3SMkj7oUP/2JMPGxC2w5eOKbrt5EhNUtzFUxE5d+6ZqH2peSQ6 XXSQn0h5pyNz7bIYOjLzPo2rdwf2BjRHxN9ku/O1mFLF0+Y2W3h50Y9dgWl3XWMyNo8N F9BcaL4Urh8TqdOiaMDH4YmOa7FOLKvchtd/Hl6/0vVoWMHyqIzCQjvpZh/sUONAI11P DUaQ== X-Gm-Message-State: AOJu0YxCYkiUeUZSZaYcoZwSL+XGSWEYrA6lhPEv8Zx/xDkvUiyn+Rq5 POBnm/A40kJTeKOUUtyBXVC27hvPyixCafqjdeFcR2QrYMaiQQLYc/eHN68u X-Gm-Gg: ASbGncs15FHuVTHiKv23un0UL/YmONqeRtO0bXPH2ZmPIzf1motcLMmrudZk3UPVEqo 5mpi8i6ocIrKjsUOU7WfKM9E1h3fLRtYlV1MCo3JWVXwKHy4EaxTkYJCHk6qi+V6Ec48JcEKxtP 99yqxYguIwjvlce0xs04cfU+l/IPsf2WusklXc2aiceWXj+9PKuszHvi95QfY0H4lBEg3GpJket zUn4lfXLyJQvLJF87sav2NmhzYIkVj3cObKxTtdyruN2SKIaJ+j+rsVRJeu1g5Wix7DC6MzFAsm o608aVNPh2RZ7uWgofOn+f9ON9eHWJ9/CuuYSfJ1bgPqDAZuc3Cn3cxozSyzo4l3pCcpkA== X-Google-Smtp-Source: AGHT+IECRxGOwLAHturm2xg/PmK8xT+vu5FxJEOI7WGFXftm/Lg2ZWmq6FoVSqoc8r1jQ0dLN6Fteg== X-Received: by 2002:a17:90b:2692:b0:2ff:58b8:5c46 with SMTP id 98e67ed59e1d1-2ff58b85d9cmr7657216a91.8.1741271818271; Thu, 06 Mar 2025 06:36:58 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ff4e7ff944sm3561184a91.34.2025.03.06.06.36.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:36:58 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, ps@pks.im, shejialuo@gmail.com, Christian Couder Subject: [PATCH v3 7/8] builtin/for-each-ref: stop using `the_repository` Date: Thu, 6 Mar 2025 20:05:51 +0530 Message-ID: <20250306143629.1267358-8-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> References: <20250219203349.787173-1-usmanakinyemi202@gmail.com> <20250306143629.1267358-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/for-each-ref.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_for_each_ref()` function with `repo` set to NULL and then early in the function, `parse_options()` call will give the options help and exit. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/for-each-ref.c | 5 ++--- t/t6300-for-each-ref.sh | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 8085ebd8fe..3d2207ec77 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -1,4 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "commit.h" #include "config.h" @@ -20,7 +19,7 @@ static char const * const for_each_ref_usage[] = { int cmd_for_each_ref(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { struct ref_sorting *sorting; struct string_list sorting_options = STRING_LIST_INIT_DUP; @@ -63,7 +62,7 @@ int cmd_for_each_ref(int argc, format.format = "%(objectname) %(objecttype)\t%(refname)"; - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); /* Set default (refname) sorting */ string_list_append(&sorting_options, "refname"); diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index a5c7794385..9b4f4306c4 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -292,6 +292,13 @@ test_expect_success 'Check invalid atoms names are errors' ' test_must_fail git for-each-ref --format="%(INVALID)" refs/heads ' +test_expect_success 'for-each-ref does not crash with -h' ' + test_expect_code 129 git for-each-ref -h >usage && + test_grep "[Uu]sage: git for-each-ref " usage && + test_expect_code 129 nongit git for-each-ref -h >usage && + test_grep "[Uu]sage: git for-each-ref " usage +' + test_expect_success 'Check format specifiers are ignored in naming date atoms' ' git for-each-ref --format="%(authordate)" refs/heads && git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && From patchwork Thu Mar 6 14:35:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14004617 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 93F43188A0E for ; Thu, 6 Mar 2025 14:37:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271824; cv=none; b=ZRXP8pP0qigXUlBK54xWsDNvJnpTEeRkn97CNjs+v9RcM6kYaq2CnssP6X/+wzRfY60Ldeg9TULhN+kRqEB9Fg+8XJFmcgttyZ9NVZ3xMtgTLQ7bl0c6nVE6ey2opvI/rMwi9zkiEMjAIk0Oupvgwb07Gty2FQuBikA69O2S5Lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741271824; c=relaxed/simple; bh=OOuocYm/o6iHxD4hH78Ud5/4/gAXbkbBxfgKp9NLIS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oBgyklSt7JRMHBG2iNSRuIB9liQ0UpU2W5unT0US3H6ZlwTCanlADhaADd0WioaW8c0MvSyJf9i8x06fFuCbl6RIA/9rICTGghQLYdK+x7PWGvFFpGwgzeLgHvzVlnxIEXLwls2rRtSTkrcKefXyYe1wwJv9JnLek3sPGy1Qc5w= 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=UIzlr15X; arc=none smtp.client-ip=209.85.216.45 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="UIzlr15X" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2feb867849fso1187109a91.3 for ; Thu, 06 Mar 2025 06:37:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741271821; x=1741876621; 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=P0TiMUI5l54jqyfeIJLHiEJvUTmL2bCQdsfSYZRn3RE=; b=UIzlr15XK6pTNcxiTZAr8nS8uqWyZfbYjNw9BKaqSNLIUtHoGArSnlARg6dcXPlbD6 DYPui+EoxN94kg1gTAGj8EIC0IE6ajkwPpdLwNSktWIYdtxYIkYV9VpXt+XLngIKiSpz 7FKJKK8pvPHsKPY5rNtZ9hETt/0zIOnea0n3VK5Nkcmy0cjLIkNtYkMKEuI4B0woJFe9 ZSmMqAACtWEddLODoxEDPestGnz3HG2lcJkARCsAqfbk5vZmwGfH3FIOJyBnQbwAGkxI pGwaTWF5s2wY1QjjNLF4FJlfziS3Yo1cZkdc26ft5QYJS+cVg0wPnxHpw3/uDC8SJSbl suww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741271821; x=1741876621; 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=P0TiMUI5l54jqyfeIJLHiEJvUTmL2bCQdsfSYZRn3RE=; b=K9UkcrXBznfiiqUcYE05kKX8TFYxom41fyToHK1K/3ZIfhTWFdEX/Q9/5VOup1kd9M 0s1b18UsQKCnkEyqMCbWWTDoSpfa+uV3rBWa0isPeLXNk1vkMGrhSPF3Z0+EgkpEfFie K6almxOYyhnw5hpEyD6L52ZqsI0RsMYYoO/Zm0kWPazEFLmIQKzv5NHCIJ48FqvebIhu 3YzIB2OHFA1g0wFmd9aAmqrYCROooO6sKGNir03wNWPt/pA9F4gIk6vJtj2Lch5MIbY2 9HgqkrXic5ITunPg+T8yR89pChlch+oCcC4tXXNANHDOAZbNVAD2mMjxtsbJhdI2bpV9 QWwA== X-Gm-Message-State: AOJu0YxhfVYH/T0gFdH27Q5yLlIMGr8P3CkmGwd2N/pGYphwn/7prCRX AB7DEQPrYK58aL/5Km5s79dKbPugyDGzfSj2JVR7OGyfDKJfrKjHuOqvTP2I X-Gm-Gg: ASbGncvnJbphWRrU5kjIULSUhNI/aoFlE3WrqWRHEEhWJHYB67l7c/Jfi+PH1Ll0EM8 73KbGxHXlLz2P7tMDqcpFx+5kKRE9Wk+8Hx1IvmSgjHyBS6PQLrqtco/DreCEWJ395ELs0OkWec Cj03A7zo4L+qVNGXr3nAAzg9D0hdaMcz3gxfzTbpzmtssyarnUnp6X4NXMcPU7acy4V+b6e+mSe XaYS1NuU7RoMi/y8QB7IQonU6jdE/eNMCO/WkvrWlokShJBSD5MckJ+uqtmK/pt3G6Ouh40EL7b HdOCBNkUGH5lPeCmU4i2zTtgq6J9H5dS4TkhxRssfA9PLRVlVeaaeisTfSuDQmXrHQUKaQ== X-Google-Smtp-Source: AGHT+IG/1FAvyWb2VjoorB0m4saqHiPvbDjTP4bDaxoYS+YaMjE7GTQG3qtgaJLUqkb0mwHxxeclDQ== X-Received: by 2002:a17:90b:498d:b0:2fa:15ab:4dff with SMTP id 98e67ed59e1d1-2ff497c418dmr10382221a91.31.1741271821567; Thu, 06 Mar 2025 06:37:01 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ff4e7ff944sm3561184a91.34.2025.03.06.06.36.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 06:37:01 -0800 (PST) From: Usman Akinyemi To: git@vger.kernel.org, christian.couder@gmail.com Cc: gitster@pobox.com, johncai86@gmail.com, me@ttaylorr.com, ps@pks.im, shejialuo@gmail.com, Christian Couder Subject: [PATCH v3 8/8] builtin/checkout-index: stop using `the_repository` Date: Thu, 6 Mar 2025 20:05:52 +0530 Message-ID: <20250306143629.1267358-9-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> References: <20250219203349.787173-1-usmanakinyemi202@gmail.com> <20250306143629.1267358-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/checkout-index.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_checkout_index()` function with `repo` set to NULL and then early in the function, `show_usage_with_options_if_asked()` call will give the options help and exit. Pass the repository available in the calling context to both `checkout_all()` and `checkout_file()` to remove their dependency on the global `the_repository` variable. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/checkout-index.c | 43 ++++++++++++++++----------------- t/t2006-checkout-index-basic.sh | 7 ++++++ 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index e30086c7d4..46035444eb 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -5,7 +5,6 @@ * */ -#define USE_THE_REPOSITORY_VARIABLE #define DISABLE_SIGN_COMPARE_WARNINGS #include "builtin.h" @@ -68,10 +67,10 @@ static void write_tempfile_record(const char *name, const char *prefix) } } -static int checkout_file(const char *name, const char *prefix) +static int checkout_file(struct repository *repo, const char *name, const char *prefix) { int namelen = strlen(name); - int pos = index_name_pos(the_repository->index, name, namelen); + int pos = index_name_pos(repo->index, name, namelen); int has_same_name = 0; int is_file = 0; int is_skipped = 1; @@ -81,8 +80,8 @@ static int checkout_file(const char *name, const char *prefix) if (pos < 0) pos = -pos - 1; - while (pos index->cache_nr) { - struct cache_entry *ce =the_repository->index->cache[pos]; + while (pos < repo->index->cache_nr) { + struct cache_entry *ce =repo->index->cache[pos]; if (ce_namelen(ce) != namelen || memcmp(ce->name, name, namelen)) break; @@ -137,13 +136,13 @@ static int checkout_file(const char *name, const char *prefix) return -1; } -static int checkout_all(const char *prefix, int prefix_length) +static int checkout_all(struct repository *repo, const char *prefix, int prefix_length) { int i, errs = 0; struct cache_entry *last_ce = NULL; - for (i = 0; i < the_repository->index->cache_nr ; i++) { - struct cache_entry *ce = the_repository->index->cache[i]; + for (i = 0; i < repo->index->cache_nr ; i++) { + struct cache_entry *ce = repo->index->cache[i]; if (S_ISSPARSEDIR(ce->ce_mode)) { if (!ce_skip_worktree(ce)) @@ -156,8 +155,8 @@ static int checkout_all(const char *prefix, int prefix_length) * first entry inside the expanded sparse directory). */ if (ignore_skip_worktree) { - ensure_full_index(the_repository->index); - ce = the_repository->index->cache[i]; + ensure_full_index(repo->index); + ce = repo->index->cache[i]; } } @@ -213,7 +212,7 @@ static int option_parse_stage(const struct option *opt, int cmd_checkout_index(int argc, const char **argv, const char *prefix, - struct repository *repo UNUSED) + struct repository *repo) { int i; struct lock_file lock_file = LOCK_INIT; @@ -253,19 +252,19 @@ int cmd_checkout_index(int argc, show_usage_with_options_if_asked(argc, argv, builtin_checkout_index_usage, builtin_checkout_index_options); - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); prefix_length = prefix ? strlen(prefix) : 0; - prepare_repo_settings(the_repository); - the_repository->settings.command_requires_full_index = 0; + prepare_repo_settings(repo); + repo->settings.command_requires_full_index = 0; - if (repo_read_index(the_repository) < 0) { + if (repo_read_index(repo) < 0) { die("invalid cache"); } argc = parse_options(argc, argv, prefix, builtin_checkout_index_options, builtin_checkout_index_usage, 0); - state.istate = the_repository->index; + state.istate = repo->index; state.force = force; state.quiet = quiet; state.not_new = not_new; @@ -285,8 +284,8 @@ int cmd_checkout_index(int argc, */ if (index_opt && !state.base_dir_len && !to_tempfile) { state.refresh_cache = 1; - state.istate = the_repository->index; - repo_hold_locked_index(the_repository, &lock_file, + state.istate = repo->index; + repo_hold_locked_index(repo, &lock_file, LOCK_DIE_ON_ERROR); } @@ -304,7 +303,7 @@ int cmd_checkout_index(int argc, if (read_from_stdin) die("git checkout-index: don't mix '--stdin' and explicit filenames"); p = prefix_path(prefix, prefix_length, arg); - err |= checkout_file(p, prefix); + err |= checkout_file(repo, p, prefix); free(p); } @@ -326,7 +325,7 @@ int cmd_checkout_index(int argc, strbuf_swap(&buf, &unquoted); } p = prefix_path(prefix, prefix_length, buf.buf); - err |= checkout_file(p, prefix); + err |= checkout_file(repo, p, prefix); free(p); } strbuf_release(&unquoted); @@ -334,7 +333,7 @@ int cmd_checkout_index(int argc, } if (all) - err |= checkout_all(prefix, prefix_length); + err |= checkout_all(repo, prefix, prefix_length); if (pc_workers > 1) err |= run_parallel_checkout(&state, pc_workers, pc_threshold, @@ -344,7 +343,7 @@ int cmd_checkout_index(int argc, return 1; if (is_lock_file_locked(&lock_file) && - write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK)) + write_locked_index(repo->index, &lock_file, COMMIT_LOCK)) die("Unable to write new index file"); return 0; } diff --git a/t/t2006-checkout-index-basic.sh b/t/t2006-checkout-index-basic.sh index bac231b167..fedd2cc097 100755 --- a/t/t2006-checkout-index-basic.sh +++ b/t/t2006-checkout-index-basic.sh @@ -21,6 +21,13 @@ test_expect_success 'checkout-index -h in broken repository' ' test_grep "[Uu]sage" broken/usage ' +test_expect_success 'checkout-index does not crash with -h' ' + test_expect_code 129 git checkout-index -h >usage && + test_grep "[Uu]sage: git checkout-index " usage && + test_expect_code 129 nongit git checkout-index -h >usage && + test_grep "[Uu]sage: git checkout-index " usage +' + test_expect_success 'checkout-index reports errors (cmdline)' ' test_must_fail git checkout-index -- does-not-exist 2>stderr && test_grep not.in.the.cache stderr