From patchwork Fri Mar 7 23:35:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14007277 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 1C4FF33DF for ; Fri, 7 Mar 2025 23:35:52 +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=1741390554; cv=none; b=oHoClpArM4WxGpopHHSokBM3WwGPJ7MPi8giKJH9iwkEK7AupaNYdPmCJknEuFAmWVjpMSpVtd8j69RzEoTsv2FHpOuucdVgXqLEMtnx4rZ5r5fcOYBl4ooD1/GPwMJ1KRY5Celrs79GiZ4ACoqg+ltdFZTt534nmMI/7hkxrOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390554; c=relaxed/simple; bh=KMSjCfMurk5zS0ItXmb9jPpI2hx+UmRLmWLn26kY+go=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pephZMkgWyb2P0GCGCjVL7bMrE8DkX3SE18GT5Ek2qq62ZYvcaxN5o+L6O8YrvBCPdWQpTGiE6BiTlDtDJaLkWuXD/i/iVaY7sPLUtkf+LLVpkbIlA8Dx2QngO4E2RnJ4Nwezr5eJxYPXqKVOmbkRt+QWA1PhaTLuMeS01TNAWo= 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=d9FH07oJ; 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="d9FH07oJ" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-22398e09e39so45370525ad.3 for ; Fri, 07 Mar 2025 15:35:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390552; x=1741995352; 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=HaVIBUR2+3LQOqSFdcyd8jdcIr31CphUIj7XI2Ih8lM=; b=d9FH07oJEDOx5lTl9mJc16TVtE+7Fm0be8GrQwhN9z5ni2RNK40L7wLH98mOf8RLhy TozCwmuXXrzjPA8v2m1GJ7E5zmrc1DA7SaY4PLhpMztdNJ8vxWRxLztfi7xDTHZ3jP5F GBhQSAU8xKUkV9Lkkq5xwt7AB+VaE809vShzdhDoHauJRhRyrZ2oc5rDtsK5SmP0bWZ4 6WzCwGBHxvHfH/xeGIgVSRVDlYTghjXlDTQX9QWZPBsaFcSYKBpSRvermgJa8S102vG0 tTGq2+tvIrmtRdu3jh4z19ruo9VNv0RWcUcToGuKGGrfM2FrCDipqXT7vSuGeSEyOPvb yD8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390552; x=1741995352; 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=HaVIBUR2+3LQOqSFdcyd8jdcIr31CphUIj7XI2Ih8lM=; b=kX+PNysInehH9Bfu480AOXCDVqw4cwH+iJyqACKk4TMUhZp62SraFXySul8YJ31JzP p++/oGFkT5w0QsMCLhw9GjimtyOOuanEagQGIoEf505JBe/v0sQYUz99PQTHggKygVRq APy9Mof9g6Wd6WFLonXbkqiAOXtbQU/jR1nFOnJPlW10tTl1TNzLTjmD1uWx76YII4f9 BYeUfPHVYr3W+YZKSV6e8HahKO6LwWdarJxrfuoKawMvnFyRSUUJ2Q8YmfaIRsARRcmH FQgipbcbaXDV9wbT85+25e0D5YjRK0bYrdWKI5YPS2ihXZsBFD+vPsjkYy2ve8VPVZdX gOZQ== X-Gm-Message-State: AOJu0Yya2q7rrmhu2qbJSGcUO/vjrpgfup740+8U1ez1NYZ6uCQlhYnw I+c5gTWhPBZqKqPjFodifmENO6ktnTbG2p3fEw+QTjytgZ2BwRUcKOL1sf6bhy8= X-Gm-Gg: ASbGnctfZqoofcnUTCrIsLnc/HTovjo6CfMDowMaseQtqP8evlC6/VPC1nJX2vTXXz2 FxuYBDC751TwdXhARBqluNjYA8p+2UIXXUxiC4RNxZRkYHbZdS/C8o5/XaRMrZEd0a1V8IRCLJl dk7AC625h4p5fBsb4Nfnllt2SdLXec6SWLQm4WSnicV4MO0Sfz15aNcnKFN032bhG8CZpzuJjU3 ooc9R2T6qNRAQVp4lf+NSn8s9VpmvjkNi7CJx/w5zJJ9srOSKO7DjfVQge8eRFxTcnxWXL/OAuA zPzV4EbVcHDy1uJ2EoR5Y0oSJ460vEmxRuUIu9NTqbDDviwVUB+DOKxiEKP5EpI9Yww6nQ== X-Google-Smtp-Source: AGHT+IF9zq7of6t3GaMAYPhbzVp0GDuO7+yNK3agJ7Hy7GfQ66ovP1ONBwrC6diSzWRg0K7mL2JqLA== X-Received: by 2002:a05:6a00:194b:b0:732:5611:cbb5 with SMTP id d2e1a72fcca58-736aaa56ddemr6149106b3a.11.1741390552060; Fri, 07 Mar 2025 15:35:52 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736bcb8de04sm423880b3a.154.2025.03.07.15.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:35: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, phillip.wood123@gmail.com, Christian Couder Subject: [PATCH v4 1/8] config: teach repo_config to allow `repo` to be NULL Date: Sat, 8 Mar 2025 05:05:00 +0530 Message-ID: <20250307233543.1721552-2-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250307233543.1721552-1-usmanakinyemi202@gmail.com> References: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> <20250307233543.1721552-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 | 9 +++++++++ 2 files changed, 13 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..29a0277483 100644 --- a/config.h +++ b/config.h @@ -219,6 +219,15 @@ 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 + * skip the per-repository config but retain system and global configs + * by calling read_very_early_config() which also ignores one-time + * overrides like "git -c var=val". This is to support handling "git foo -h" + * (which lets git.c:run_builtin() to pass NULL and have the cmd_foo() + * call repo_config() before calling parse_options() to notice "-h", give + * help and exit) for a command that ordinarily require a repository + * so this limitation may be OK (but if needed you are welcome to fix it). + * * Unlike git_config_from_file(), this function respects includes. */ void repo_config(struct repository *r, config_fn_t fn, void *); From patchwork Fri Mar 7 23:35:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14007278 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 7283F33DF for ; Fri, 7 Mar 2025 23:35:56 +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=1741390557; cv=none; b=RS4TBt9ehWf7TGqsOE7SxwsOyRA+sgqgFzPWuiJ2Fo6z5/F0RLv2+8SmyKDNcYWq8m0SUp2gfrNGcIN0qgyLyUqgP04sFq4lCgIzvIPg1/Srj0InFTqNPTyxonmCd3gH9XTB1PYZRZWKpiF62jZv90lMVII4yqrBl4D+mTn808c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390557; c=relaxed/simple; bh=JAJbSWuFJgB3UDNULyyBg5saO01KET8wLRD6PmDumWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J8hmIrl6ZLdMrd2+Ss2hy8HbIsM0byYIOicSjO/kO7TMnXBbw8fjxdQdxkmuHGdu2TmeWIJq5TlUM8hamlyK1laZEA332cdzTUgl0zQdMMumhBFMqKblqaUnfWK/77KwTVKe9IG/T9EJijQ8vYEbZXcePScagzjHdyUAWXUCcRY= 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=ezq3e5Fg; 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="ezq3e5Fg" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-224341bbc1dso17082005ad.3 for ; Fri, 07 Mar 2025 15:35:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390555; x=1741995355; 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=ezq3e5Fgc+Eov+nrIxl6+H3XfZnJSIkE+sYix3naYhFoRg05cDMfzSsgFnOEWkcMqd ORXOORa2VCZSWZd9mOW0jCFCc6kfNwco5xLVfZ6njYtHRaXCjgoF02cKhAvULYy5eysT 511mTJSOPi2YF1EohkMkdiVBNJhyFceyTJlTtZB7by0yaFPYN4TKoDAg5e4j03fvS+ZR pFfV4oMmVn00RO6DU4VY3G3YIrwGS04zjC1UMBjXnkzJJdtkiTL4osJhVW3iaPY74A9l Tj011WksPqANstwxoBPH3F1AjRCALA6kOV4Hw4BLAMFEb2Dr1dX6TcnZBtDJfI5yJLGu 02dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390555; x=1741995355; 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=volApn9N3Pr73SDQPvveft/qlWjVq+0q1yvOQLxuaLC6uC/CGdIxLdAmaKCS4LE+fm HoM/Kq0dCYXMz9S84mHLVotj6QErpCAntXPHwq/a6NivlrvbHGVGYx0XJYnjBQbLETlo 6ttr+vTZowegDLIt9h50XONU6pdSp7LQVOqnw6CvC0Cc/HePfYT3PasyaFNLexP8v7Kt isCzaQVEqD+az+xSZSUTuKvHf4csOFfuLqxeshIU+O6YxpHbRJ+Yqbc/UOwcWHfEHkNx fUnC2RKZRr/rUPFtEq4SXkbLi6i1eesHwR8NmTlyPKYVTRFUlje4cf5ZadKGlioJR5Cf J/GA== X-Gm-Message-State: AOJu0YycdvdAB24NsZZ42Btemf5KgtVXQ+8DadVUEuRUEdTbFrI5cIqC 5rQCk3rTJmeb+fAM8k8ZSZFatgmcJWFTziPb/fBNb123bh0OUAuPJ/HMZfTVmD4= X-Gm-Gg: ASbGncvk9qVcQLmwKYJJ6klipXjqGjEIsng26C+dnPDcErSHxqynSRNdQgnbCGq3cQ+ HqyO57V0u8IN/SWTTo52PzZAW9XMHHTIAPMP8FNqxF4DNjMv3HrbXoFxv/AfmAtzhGsNCf2xTXw UkWNpe+yDe3ug5HTgJqk43AXjukfhPBORgH1Z+zlDuxst+FuSymcyzCFMKBrvDFFVQGZ1tHOvR2 O5zX1cZM4CL7W4RKQzv35s/tp45hjFMPO/M6Ce2XS5xTeC7cefSRLSoVR8mqTG2xMREarWquSEQ K+PuGod8PDs7sbwtwM8kpM5jxIPMIJArifEYuB5BkrqoaKGwpvvVN6krzRZbV+Z1pQdjAg== X-Google-Smtp-Source: AGHT+IGGd7XKJiFQyYHqm4XMXZ1d8xCHMYMDfIYuB7x7x3QdwDBBAz5T02ki8I7yt0ZPhdEhQHVZ4w== X-Received: by 2002:a17:903:19ee:b0:224:1943:c65 with SMTP id d9443c01a7336-224288874b9mr91862555ad.14.1741390555451; Fri, 07 Mar 2025 15:35:55 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736bcb8de04sm423880b3a.154.2025.03.07.15.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:35:55 -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, phillip.wood123@gmail.com, Christian Couder Subject: [PATCH v4 2/8] builtin/verify-tag: stop using `the_repository` Date: Sat, 8 Mar 2025 05:05:01 +0530 Message-ID: <20250307233543.1721552-3-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250307233543.1721552-1-usmanakinyemi202@gmail.com> References: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> <20250307233543.1721552-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 Fri Mar 7 23:35:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14007279 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0DE633DF for ; Fri, 7 Mar 2025 23:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390561; cv=none; b=NMgobBz452LBi2yKmBbcIIe4MGdJ5TP4fKVSbBp4MVPjmzTizqUmrpl+IaTmXVYjHmpx2SshDxAziXNYjQIo/XxyRd17six1FJxEfZjn9po5mkXshS4eEaJXhdfCgb+pb+EGJ3rOk8dxBx7gb/cQhjdVW5xnYl/2kjV7BCj6iNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390561; c=relaxed/simple; bh=U6cmTbxV4tCdvBmncexg+swheF19OVuQ+W1ra8DB9vQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qpJp4IuNLs8J065q8Vkbk+HmuiyFbvgu/IqkQV4ztN189CUIGkOqO9eHPufKPqnAqM94Q6hxPd3FP6EeURXbGFli66bDWSJBKrZWPNJSGwZx65bSLGVVVOMJ04U/PHIHd1IQsGCWqc5wG2nqzH9QBfw2yaPcSeDqifAEzI5s6T8= 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=S1hdlVe4; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S1hdlVe4" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2240b4de12bso23619645ad.2 for ; Fri, 07 Mar 2025 15:35:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390559; x=1741995359; 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=S1hdlVe4qkiFpNN7Z7tT8q2i8N7+hGN8FSOZUzsp2KuvEUCYRZsBYZ7JW8/ywA3Z1a whUVqcRfhwRBIw6kDWRMHZ/9ioWDAWoH+S1YaFAO2fHHJ/euFpfOxNmeIwk8ltbLYWQE uLea2UojUkVY7A5DHjNyLCYXaSiYiuXILr+2LsFI4jKq7CkSlHfAKCOpeFd/8JwMS7W6 X9YA/xC85VgWWplOMP33OMrj/helXGN0VTcFSDRlS1EvnWfaSFuyTA1NmvC9zncneMxN DYxO/ogyPCFd9qBpi9BHZ1PIs8R3g9yksxMFa9TxypQ3aT3OC6buwTUpG5K6c5+OYEro h9Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390559; x=1741995359; 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=Fy5D8BFw8iXRYLassyShulx00/WN36qBLYhlqXNJEejWrVIUYgLSapasA+gvXygAaA IFDsmBX7y0BKdcg+P4g1wULHY8vzYGaJAGhVmnbNsJmh7HdvRDblLxmk6fT224pCR7ht d0p7OLmKsmZj/eRMpSnqCm+txiCT16ZV+4w5eoQoOXlwQVK0Lx/VV9ni1xq88dIr3QrT 0ph3O383eENPTptbjSBWz/OjqfPkaR/fHkvUGYYucrGs+s9DtoBFVDzwc4MogOcrxEyh nwOBQq7rEKdNXzfgvx19dNHpvPPDRnXHUffkmXwysTkfqScUnmXqnjwCwMYFif0Fq+iK 7qzw== X-Gm-Message-State: AOJu0YyL1zB+bCU/jMmo3bv9QwHshdkfuZ4biMdlYN20e6AqfI43Qz4i nI3cZHgik1lwgbRMAXb/RS2FxK/0ArT1COnzvzvRj9W0CQ2R0pFeCPjRpEHsQOI= X-Gm-Gg: ASbGncuiORv9gu06g1q6y8PP4iMWSZOEij1GZVP46zOZITVzJsryMqu0GDdzpIAVIsc Ao2lfJ0XpvwqcvOmwsk0ID48mmpWbRENzYJSuwSwdN/RPDYkWNp5pNbu0e3xq0L5k90WB56SB3x M/H7g+nYckBx3UFQaA+wFo52e53Ogy3XJL7Uaz+8FRw42yA+/+OU4VQ29TIamv5oA0EPeGN5nHb bQHSLWZKXJA9OvPc9+W8QUUOO06I6RpQihotahPZeAzXW7MnabKFhz5E7pcHl4tiBWbDzujvWaX 5GN9fc5Ddr6k/rf4GY8qKI4gH+TW4EMRBvZ8EJlsTYb1NMMvta0+qAKPLKW/eejgufCd0Q== X-Google-Smtp-Source: AGHT+IFREfuW3WgdtUyIbWfKFzWk/RP6oWrLjot0vjzzygvCHkvWUd75iHecBDy7xp2OB7Cmpv/NBw== X-Received: by 2002:a17:903:32ce:b0:224:1acc:14db with SMTP id d9443c01a7336-22428993912mr82522345ad.29.1741390558836; Fri, 07 Mar 2025 15:35:58 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736bcb8de04sm423880b3a.154.2025.03.07.15.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:35: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, phillip.wood123@gmail.com, Christian Couder Subject: [PATCH v4 3/8] builtin/verify-commit: stop using `the_repository` Date: Sat, 8 Mar 2025 05:05:02 +0530 Message-ID: <20250307233543.1721552-4-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250307233543.1721552-1-usmanakinyemi202@gmail.com> References: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> <20250307233543.1721552-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 Fri Mar 7 23:35:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14007280 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37F1133DF for ; Fri, 7 Mar 2025 23:36:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390564; cv=none; b=B8t0rK6XiL5JW1dLi27Tc2tmShn+vRGLtC/g9hwfevSjzH5GWQ1Peqf/QRw+eQX64f4JF9hUshqpnmN17B7YMSwXsSsIzhrZjKlW3BUuiXFrlYE/MMxEQZEZdoCoq/BOA3s6+/+85dMybXo20W/rwo77scaI3aUpqkeAJpmDbGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390564; c=relaxed/simple; bh=6u2NuRnQfBqAIwfT9N+W2cLbTA8vrQV39JvWlFebs8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fUAtOOcwvndqgozkLFQFbS7rrATaoOnXJfG8BvKMjaaUtdwiOJRk/JkodjIAfdkBeHHPG88fE+WTj/MLsuZRRdLbaTrR0Y6M8ayqeEX0Ey2/CWqofT3S25y9SXVU/wipLvx25M3TLO0zQsS6FJEMxKy80k3PMBCSgkG1HKwwJ60= 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=PRT/3M97; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PRT/3M97" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-224100e9a5cso46588375ad.2 for ; Fri, 07 Mar 2025 15:36:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390562; x=1741995362; 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=PRT/3M973S94nNuVy4iGdBLbBWEyrAjQb0bGktzqr7iXp80rNJH+OKMatGxVo/6aEI NHfYEKIq4m++hnba5Vlj1SkE19f+mCAUuOBREBZu6DvsGAX3/KEKeVnNysfag5+0Pkor SFstlNORbhw5p9m/HK0tvz4uUvZ3Z7GYfe3VFKePlR+Q+VWyk9vGABnIP1yHTmBslBue vu/Ol2gLyTvp2pXVLXQEem334Z34Vd8IjdjAOdG/eY/wTG8NI+5dwW08BYLLuweNdGC7 yr1OPuYVrzEl3SEDqdFZ8sk0HhInKjdoq3qzMYGLLkyiksaFp5175Jf7yzMsmxy3jCAX z6mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390562; x=1741995362; 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=ItjjGmlqrEZFGQJaDadM6vxuAcMByfycwkaMq/nkPEZOLJNwEk5F1PhmhIDQawgPiy jS8KW8muPkHAGC5rtc2FlaSXcj05TKteJDCuVD8YToHtOXoPHR/Iv90bZ6bqPmgBqRJZ TKkh7sL0fJE8fxoz9ql8vxsZB9rnWYtvcWdwYlgQNiWWApGHgdAmk6TLP0tL+Zkov4/D 5ns6KCDXLqn9Thp7BA/rc+wa5AQxF00cDGQu47lpDrhdxpx2Xd8qRXIXnzhgK2U9nCMa zKbwWueNxxkGheDdzBUA8lkOwCgRaaQWDEX4usgzz6bL39NgRkRayt46IVi2zzUsnWMB dv9w== X-Gm-Message-State: AOJu0Yz3ybMbVApx5gIxWgtQarv4hghPRXN0wGBNojpUuQ5XYHDJcoL5 iYjO1yUyYNBzYyhQpVJTtXaB/hhWzh0Pp2JsKjXjvAxaaicR063m2G4Wc0CCDZI= X-Gm-Gg: ASbGncvHHP9CrWWNjmhd8D581ejo6TmPZfIyLujAjQNrtLjREBq8TTSzLv+uTcVv0Gk 7/BkFMyEnlZ7swFju8kA15qJUkXfO9KASlL7SqKhMHTcXF7d+ztClDF5pLFmvKqwtU/H6LFFOwO teUJHp8SnhN6H9E8RSoklj+w2BSPqnE+GZUMGDy1YIuAb21xJGEtuFtmiyFR3T656P4odAdNij2 b6+PHdAoU2m33EbalqNUhCX/NaqPhEA5T8R0YafIvzlXIF/CKQeqoYaw76hDjmcLpE84ys4hrVu w2ODvx0sOYjUlr3Rw+5p1KMtqFmEi8kHJCXw0pmrRK47CjsbpDw5DiP1sPMH3kbrURlMeA== X-Google-Smtp-Source: AGHT+IEttNnfgLp/m+5p0HFSRlYzxZy4+TSiroF+oac18WQ9WXzgnoJnEdpbEVVMfm5oyJMIWvTQ9w== X-Received: by 2002:a05:6a00:c8f:b0:736:69aa:112c with SMTP id d2e1a72fcca58-736aaa1df1emr6152541b3a.9.1741390562250; Fri, 07 Mar 2025 15:36:02 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736bcb8de04sm423880b3a.154.2025.03.07.15.35.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:36: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, phillip.wood123@gmail.com, Christian Couder Subject: [PATCH v4 4/8] builtin/send-pack: stop using `the_repository` Date: Sat, 8 Mar 2025 05:05:03 +0530 Message-ID: <20250307233543.1721552-5-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250307233543.1721552-1-usmanakinyemi202@gmail.com> References: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> <20250307233543.1721552-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 Fri Mar 7 23:35:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14007286 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 0DCC233DF for ; Fri, 7 Mar 2025 23:36: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=1741390568; cv=none; b=KdVm6so+76IUcvBiBhRKb0SJaXSdsVl46pCd93my9dvYhv79EOERY6UD+cQ2aXExYQGN3rdwzxgScm0lLfE3cYfIOmSp/sa+oTGcBiJ7YawnGNgTd+Vd0jeJQvrLYKRRn1B9yDtAkoQOYFLZchSCZkZ3r8VuCbMhErYFgVu3+8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390568; c=relaxed/simple; bh=XTJrwl6lGzYH/UD6p2YmKN1G1LrAG9X5uWXZIigQmz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oUz1qxiTP9kzBDuP2oXtRb7vFLC3anvPgOXaZFs0VRz9YElwqTULmB1MfToz3ftAe5vCCIS4wNPsczBeo9hiM224Al0p7GDBcRMHRKuQDbTiV8q6+YU5PfsQOCpZv0Il2Fm6BLZxXG3pFeELADTiX7UR5Fo6OxrrU016e//iuxQ= 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=e0RTTRBl; 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="e0RTTRBl" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-22548a28d0cso1251725ad.3 for ; Fri, 07 Mar 2025 15:36:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390566; x=1741995366; 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=e0RTTRBllDORQRodq+SAhi8G5RBcMgZzEscoKUbpuEiJtNxOhnHkjdAU9wfuPLAlMd yFuDhFOvu5BV+X1hNz5r4CkUerZBJLHBeIIw2ZzED+r4e3NcVC/6YYo5DZa0Ib2UOu0r WxSnuluoowA1s2/4bHmYalDnbk4Jx/zVpDwithTvtIHZQWjDe7OmMDhxDfFCzhFq9h3F +qygxz4iz2i2AHNDsJ7Axp0tgNT6z9RVarLVXPwZtWU8yJMWmtGzhmLDnBvG0qPlHimj iPLnyMPvd5e7cqUJG7SVZV6gCF8PpGpl5HjslRGQHQjW3S78jJn8DPR5SaoWfbxZwE2s i+oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390566; x=1741995366; 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=g4Kg428LJYUXkgWL6TO2G1b4Ifbm2H/clsYQubeHXTGj6flTOxVYBe/QYReMlmdgt+ gQoBxhyW5r1GM0Fil0sqQJNeX6kE24d5JDsSIBYZLS4Kye8sn0F7GeYgHBZMCIjRuEZU GaTChjuIhOizIpnNVTujIZZUmKpBgvGkA1RTKF6NCP5LhyhwtpWHYufaoQxw8PjzFsTw PHNDqd19OjzY/GAY72N7JqIrU3DvEjDfZbzOxujCt2jjxqthkxLXJ+gE6MLfFiBmU+DE A7E7N1rS3KZ6x5hvAq9M1Q/3gTPfnTACfDzHs0eHRT60udqKDfSHH/2AXhaLpEBYm2XA KKCw== X-Gm-Message-State: AOJu0YzbK93DfQ60yjgxJRbfhNt6dHdiCLbSEXmFYE2g+/S5rmHSDGIm VvO2hzz17Dnw9BAGs3/CLxWl8LcVdyKkJUMgYIyMJZKMnEWTxqGGKCfjrAGyr18= X-Gm-Gg: ASbGnctDR1W0092EuLOULNRcC65pcL0SPXERYOOVfSX2ANHBYBeQcVYWAgqW16Mla7Q 0L3SbbA+5a5VVbVKoous29eQa0877NDvnR2o9V7lSErIAH2pCTI1AVArQwFRvSA/iyWfOncEQT5 IRB60NjVzTZDfTBafj/XTvp7qmT2687RMGTgrbMHrgncFCYJeoRIrq1kuDL2Zlcs2/kiUjfbunc PG4fC+QLVGf9hF+/qU3qDYLHxF/mYqJLW3suxATH2Jfn+lJ8pLSvFTND6liOQrZrENGsymBnmBc BQ4QTstE+w6SldOWjY5I8rzB3MhZznLXgmtvWJm2deAjpMcJNedoXsqXSH1KjECTqB7yeg== X-Google-Smtp-Source: AGHT+IG8sqpqxK6s442ZRfhZC4mD+NW9vfmqY5Sk5h1DpbqfaYHLDfm7oAPaou5RbfQ3s0m4vupT8g== X-Received: by 2002:a17:902:ea07:b0:21d:dfae:300c with SMTP id d9443c01a7336-22428880270mr79316145ad.3.1741390565989; Fri, 07 Mar 2025 15:36:05 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736bcb8de04sm423880b3a.154.2025.03.07.15.36.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:36:05 -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, phillip.wood123@gmail.com, Christian Couder Subject: [PATCH v4 5/8] builtin/pack-refs: stop using `the_repository` Date: Sat, 8 Mar 2025 05:05:04 +0530 Message-ID: <20250307233543.1721552-6-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250307233543.1721552-1-usmanakinyemi202@gmail.com> References: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> <20250307233543.1721552-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 Fri Mar 7 23:35:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14007287 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6509333DF for ; Fri, 7 Mar 2025 23:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390571; cv=none; b=WCUEjxa+9XqI1/QNtCYZCSx3We+P2NrnJ2VziwFSOoU7YkOYjr9McRkm2p2CCptbGDgWvGrbBQtaoFkILaYmPooWxXHPFV/0JpzEKDNQ+T0EJMCM/OFmPf/OodHE07LChiFDPwT5/SONN7+fhmt7bxV5mWygiNjU1CtVdMe0PVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390571; c=relaxed/simple; bh=uyPEZR42xGEUWWqABH7AINQb5hhX4uxPZN3aXjnIdLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rtPYJNCnXZNsVByOwIDppGrE4FNqC2NFhW/Bp7gyRorXve7IP3p8IxoaBvDLBIT0PlE9b2m8BNkJLJJKk5JCbJ4zPpNcFJWqaQqxz+CYy4ESvEVbwVchzhTY5KG2vSEBXMCYvefOEeFsRN0TOlpoJkoGZlI8A8MWsZueiD+rG+0= 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=bT+vdvAv; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bT+vdvAv" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-223594b3c6dso45197365ad.2 for ; Fri, 07 Mar 2025 15:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390569; x=1741995369; 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=bT+vdvAv5a+gX9zSwZ4i76V3u5R8fDYxycD1F1W1XTFXKWIDwQBmjXg2WsGLzKA2Do 5JYzhU44jCRm08E2YVLVMhJttzEvs/iMZCsxKh8HtK3gIUawtyIy+V+2gTANXaGGKhyZ mJdNVdGniqJ1lkKBU5IK1FcqSiWWCPIrj89nvTzaOTwC814cryKNNfCp99MoyIDD1B7c IZj2QVdRudiNTj5QQF2hK3CGEdI7NDki+ypCeFglSdVd/OeDqejZrUA5gdeaM5Qtu7bs gGOdOxU2KhU/072Tnl+FZzparFoIjtdUmmjBds54p3GCvRc5YuQBunlc3/dbJIUanv7d u/JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390569; x=1741995369; 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=opuNQrY2GsDLoxtyElQCKy0RUvimWiFYeog0Ik0hwOgoAb20vpIN555dylFDSo8v3Q dRpK0rFDNGnoUymw37H6rffxr/xMiyL/SWGEQ9Hw3v0BEV/ujYlffZsSIBJvuEZcsuIQ 0D3tESzv+WMNZTM4dFDRTycom/GM4WfpfYXLagIXEPURsFqurnxzqDZWb+AXFbL68r11 cVcCHNnUg7aHoB7rMgO0iYsQPbrtW8hpSe2ULu704uu4EKXFvOcsCaaSKWY5K1o9TksR iRc/Khaa5doGanTw1lvMOhecVaIUZc/YsJ0jb9se7TIaEeHzI3vh8KtTExUky7aLgD92 W6WA== X-Gm-Message-State: AOJu0Yyr7xeS9SR9bE7qRc76ojJFtf4WaOLATOnrchvA2VkHoTOoD6Ke 3wZuogsTwE65KVrsMN223ZzQPq38uPwZStNiA43YtpQWlxuMPhX9mB4qbfzmvis= X-Gm-Gg: ASbGncu165wxsKJrR8cv7/gkfJ0ranSaktPltfdru49ujZ67WqGD5Srac8ZsfZed2VT mmbd1YC/ynzHKJ8OklvaQITXq7hC+cHSjPlqLw142HmELiilsBqBqOeM1DSY3gqG2mBEiWgD0xK oi9MfDxZm4oPc974sqif/veCLiJQfRVgy/VAkuzoiaw2Tmr8h3qGcK/aE7AeeoGlK4jtxfT6suP 7bAB9MtpKMuOUkpHqqh2v1v+SiXCUqcEcADrnfKs5maRN1TbatqC6tGEBZVEnT0campcWcfOsk1 +CNb53GOmoMAbtbIRXhN+Y7/9DJMgV5xBL/M5bu1Q8z5lydCeQPdUajE9eziPXKa+4alRQ== X-Google-Smtp-Source: AGHT+IGFF+6dglBl1ANx6ZQ88DhFfWq//VkwVagRfAuJRZBbSX2JaIxxEhDAR8FAr/2hprN9e66guQ== X-Received: by 2002:a05:6a00:987:b0:736:5725:59b4 with SMTP id d2e1a72fcca58-736aa9c1adbmr9860846b3a.3.1741390569402; Fri, 07 Mar 2025 15:36:09 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736bcb8de04sm423880b3a.154.2025.03.07.15.36.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:36:09 -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, phillip.wood123@gmail.com, Christian Couder Subject: [PATCH v4 6/8] builtin/ls-files: stop using `the_repository` Date: Sat, 8 Mar 2025 05:05:05 +0530 Message-ID: <20250307233543.1721552-7-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250307233543.1721552-1-usmanakinyemi202@gmail.com> References: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> <20250307233543.1721552-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 Fri Mar 7 23:35:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14007288 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 AB3C233DF for ; Fri, 7 Mar 2025 23:36:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390575; cv=none; b=mCtOQGpMnrNoQuKnlrEtIHEKr8dONSZBvr78Hfi08VVBBWyskQ8hNwdRDyH+qgiexxzHDrx50UtqSlxNk593BluE08lS1fpgFUP0T3nfiyYWgx+0tAbHM1KpKHmWb4COzT4dh7ORscCYFjJEl0CQwThv2ke2hu2LjuVMd89OT8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390575; c=relaxed/simple; bh=uW5bRQB4XXi6+E31aohFFA1T+pUDf31lBRQLmOnjdyE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BwukbG3Cks4t3nZazO8/WMG32aE87ZJx34Uc8LfOiO13z9dt2NvCawjradLvX6gMdPbdaiGuYJEMY9lLgDTQK7CQjkRml3BjWNIyjjgjVpx1iVvanFX8yswdQFWLqHfa94ApBxBjarEKufVzJAAvgeVedeZtW0yZhn9RCBE3pyM= 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=aX7Fk2Im; arc=none smtp.client-ip=209.85.214.180 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="aX7Fk2Im" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-22409077c06so19400405ad.1 for ; Fri, 07 Mar 2025 15:36:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390573; x=1741995373; 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=aX7Fk2ImlqOgU1oY5Yt5LKbaSlr0qe3xmnjIyNXH4uxwRZT+jOrlwtafeZ95svuoVh sWgMQ3j5JPu4UdW+lX0slgdPXFIK4LvdL3qs7V5/1Lragezmn5vBje4SSZVF5YLWt54x cZH4WsuEhEhKGLLaKLNMQrbQ8AHrKMiqDdte/B2KPqoamxAZmpGxYHiZX6iSB92WZO4I 85vFya6kyi2k7moD4twlouY3GQMRpwCqlapLkgSRvDkZzh8eu7ylpsMt78on8m40x3Ak R5GKPNdKbhQ9IAnnFPp7KwL2Acj5ku/MldCRmysY2btldlotqavKQBy4OOWH5ShCLK0C 10Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390573; x=1741995373; 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=cXh1gQ/tODM1uPAuCEGPm6b/VrDg3KJqCRaYZxYXbXwGZrkGAa83iSdmYB2P8AVupu sgsAooeqjrreIdKp+r9uDt5LY1vk2tZsCSQmZ4ORsbnEExFaozk1Ku+w/BKVde5s4wQt w0inb1NoYCffaQN96/8IpK/+lgqPcU5I6ZjYD/PTVv+jd1aXq7senrEHDWmyg758aeoP qQ+zP5hSPRNsSPvCkFYb4fA9GVgGqfjxjzn9Z6n9SuJcrfXBlsiRS6beSurTIMQtxCBD iZ64uKpU6Drz/GKMe6FvCCGktBEkMa7qFbwcSrjSpF+kP3Up6QABPNGrUhQD9IiHKfHk ptDA== X-Gm-Message-State: AOJu0YyumK0X/EywhhBp8/KIQ4/5fl9QCXB82JAFM2QvhyTHL00edQW8 5ytRYy0eAjl/OKuKyVoUFLtvoDOtsQ9+ynwgIgE/Sr/BWpeYqpFqogBNYS6x X-Gm-Gg: ASbGncv7/evcvBdOzkuSxWVogpA1Xmo3fGY0ah0d0HhQQ+9vqtFCnRTxXkRKg2eDzZB KELnxFaMzlq8i88S/XsdTEmgMmjtm2UolQ3b/5kKqyg9tqNdLTqG36bpybWcbH4dUaH6RO2sMP3 MayGtBgxjti79SIi9x8KgVb/DT8PsS+GTG1WTnZAg2cnd2KC8l9sCtE6fWlx7chhUK7X/gFDhE3 jy7Tqo8mg+PWA5CG7cl4+FufQcmmiUTPsuEhhB0tRz45Un8zeRLKVaJ87hBj9N73CFQ1Mbkd7+s 0YGxswpeTHMxuVYKYn2RhnRJ6mlWbThCyVAe+Qi1c/r2CzEne/tOhErAzBtSyVTk+FjUBA== X-Google-Smtp-Source: AGHT+IH5+9EkV1w5gHg3d39f59ONzbZ4gu0o7GYI1kgDJdGEJ7fr+vvSO9dRhBhnWERJ0NS838GZug== X-Received: by 2002:a05:6a00:928b:b0:731:737c:3224 with SMTP id d2e1a72fcca58-736aaa1e02emr7356755b3a.10.1741390572772; Fri, 07 Mar 2025 15:36:12 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736bcb8de04sm423880b3a.154.2025.03.07.15.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:36:12 -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, phillip.wood123@gmail.com, Christian Couder Subject: [PATCH v4 7/8] builtin/for-each-ref: stop using `the_repository` Date: Sat, 8 Mar 2025 05:05:06 +0530 Message-ID: <20250307233543.1721552-8-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250307233543.1721552-1-usmanakinyemi202@gmail.com> References: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> <20250307233543.1721552-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 Fri Mar 7 23:35:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 14007289 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 2010433DF for ; Fri, 7 Mar 2025 23:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390578; cv=none; b=sM5JWaFtdZ2nDh/CnIRG3sFquoKljgWX9mGYEiN5EvegqlyfdlNIortcKINzwnpUL4W6SsRNLvJ6uVscDid+9pWhtqTFcCRqUfHmjqFRdVp4MpyHaKmq/DAnxX+20H9S1Uw80ALvIhWnPduFEoQQCwxYMCcgNDVIhmxngDlGIds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741390578; c=relaxed/simple; bh=TG99l56WB7uG4AXm/m6Glul8x/2FBo3QBSFbry78VAQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UahCE5E9NfQty1+0NnqnNOZp9NhY3oPJ7l3bDchgBUHRmJr8MMhmtrk74HeRvopW5apoUp4rKF14d3ydDeBMUkLO0XKLGqvxFpJ9tP5TgBKMNc6hSbdf2HntX/QFDo7qvZirzs43nxXuUmw8+HMdk0CEIafWRwnR32kZgDISAv8= 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=NKFrYSGJ; arc=none smtp.client-ip=209.85.214.180 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="NKFrYSGJ" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-224100e9a5cso46590315ad.2 for ; Fri, 07 Mar 2025 15:36:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741390576; x=1741995376; 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=5ZagCCvp4BrHRFQq8PkN50cz/wHDlWnYErUpQ8WNHbY=; b=NKFrYSGJ2UV28FwwvR0Y/JkTs6KwZQFnCsIBBHBEVEanRSQ27MAn675nWBMtdCs8xz mosTlN6DL+++z/kefi3oRxghVP7R5GSWTnLAnAcv/ZV9u1Og/FV80twI7BOxxX5GijnR tEfqT9x9ASc0M+zF9NDmUJsw6V4R3pO/3W3cCEWW0F+nhLNgMbKK9sJcuyvn5I9ekRJi tbnXw7Z5PZBi0GPIYnJ+L0wsudh1TH37sx7kvCF/HZzm1ABPvizUbu0L/9cuRkxezg3t ET6YfN2ocr2s2rAdxsuB5Y50YUkezOaMoZYtWKupCrqk5BXXjhnT5//UIInPPkffuA7K Hs4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741390576; x=1741995376; 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=5ZagCCvp4BrHRFQq8PkN50cz/wHDlWnYErUpQ8WNHbY=; b=OXCYMp21OfYDT/beIVzQsAwe7CRRPbnUyo95+hhsVCXwG5WkjhKXFj8gfLZgv/u8/3 MpgUJPNW3VBaZYlf1c9C6pV8r77UYZyiX6j946efpE0dZ8Es/mMPPbc21eXE3JedroAD ql9c3ldAhgJlhOiZWHDyPJcIHnrazpUK7yiNesIiSxLWVQnjVYIyc75/dAQlRNqEda5J maMFFyVwMfbcSJ4/tQG0t4HY8o4iTeDS4iQW6UzH5B5oa4l37NIrIu0tUCKpLcxFXip5 N4CXTs1XVUFgNfOYnNXKWrL6CkmB/349gZKaRwiAobnUH1HmI0meDc0plIspjZs8NBcA aPxQ== X-Gm-Message-State: AOJu0YwJetNWon4kYL7FbE7dWeEznmjA9xml3ioSre+uJkE5yOcunr9n Gt1dlWp9BeYPi9BYd/cGMI55WpnHwoZVgU929mCWdFbTWtGMfLUSGgSnxw0D X-Gm-Gg: ASbGnctbOeMGu+yYHJV/bdKJTT6SMjDrtLgaty3Vj/5ZlTDmrt5CThhdpHndLCgr/Bm vWFmmFtwHCfwAEg4hxHgFZ5JjqYnaF5UBQQIIvxI22zcDQjUCUVJJStkK+DjTwXpOLaeiGf4XCi 3KwlbCNi0ITRBY7zjGmpgh7qANgXoaFEoIoZQXqKB7/CJnBadkELXMFVMa4uQoowL0EARSxvmGv Uuy708MK7IgqcwYqsfTKAX2Gl8DdSXPAT8FKAx3lwWhYzL5D0Y56v6dh5hW8I/neUkaeVPVyqbj f02OFCfgB8Me9tJ9nNcLAhS6+rMxA3G6C1ZBaqlwG9mJTYDGS5N56eLEiNmUNz1vOKqSGw== X-Google-Smtp-Source: AGHT+IHO/WR87B5wT7jLYJdrZ6VISR7H5XD++4XM1X4p7+flwi1AFDhI4IJlbesH51oPkpJOEG42Dg== X-Received: by 2002:a05:6a00:194b:b0:732:5611:cbb5 with SMTP id d2e1a72fcca58-736aaa56ddemr6150539b3a.11.1741390576099; Fri, 07 Mar 2025 15:36:16 -0800 (PST) Received: from archlinux.plaksha.edu.in ([182.75.25.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-736bcb8de04sm423880b3a.154.2025.03.07.15.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 15:36:15 -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, phillip.wood123@gmail.com, Christian Couder Subject: [PATCH v4 8/8] builtin/checkout-index: stop using `the_repository` Date: Sat, 8 Mar 2025 05:05:07 +0530 Message-ID: <20250307233543.1721552-9-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250307233543.1721552-1-usmanakinyemi202@gmail.com> References: <20250306143629.1267358-1-usmanakinyemi202@gmail.com> <20250307233543.1721552-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 an instance of "struct index_state" 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..7f74bc702f 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 index_state *index, 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(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 < index->cache_nr) { + struct cache_entry *ce = 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 index_state *index, 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 < index->cache_nr ; i++) { + struct cache_entry *ce = 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(index); + ce = 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->index, 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->index, 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->index, 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