From patchwork Wed Feb 19 20:32: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: 13982872 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 EC3F122E3E7 for ; Wed, 19 Feb 2025 20:33:59 +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=1739997241; cv=none; b=fTcs2ctab3cWwuo15ExrDsOWXRgSZ8rYIgvS5WAWfBCX0sALcNEUAL3vzzv2F27ssQnd236zNRu/gxPMdcVf4yO+9lD2fZonAGOmiU7W6qLbIiGYYUNjTbZwtqwBjKN9Axw6tvmH1nFSCY+EhxaCLpzNxmSmhx5jypMlF0m1SuQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997241; c=relaxed/simple; bh=lmdrQ9vTlj4xW56z4iL7G8Rk96J8eay6EKznetfTDc8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AARNvLol999MHVmkeafh/iJJbVHZQCPTfUqaoiCFcH2hRvP1odpvfV0+tXR3FnXB58/XFwAzMGgieBJvA81RD1SdnhX5bXXE2pB3F5hNZ051fRW9Qk8+RycxGj3PzX7GzXKWj6ogBptvnlzGtQlCy7mceu6jVsjuA5Uk7no9k5o= 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=DP9tgkl2; 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="DP9tgkl2" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-220e6028214so3391405ad.0 for ; Wed, 19 Feb 2025 12:33:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997239; x=1740602039; 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=dU7o73/CRtObgslu50QcCkFZIY8xHmANhFXdxqsNHXY=; b=DP9tgkl2ApYTKdrCLa9f/YX/ycgwoTHGAk+ZVaAcf6Ahjttr76HazOVmceVA+MQz7V q7wDHDaCFkMTH1m37WfK0obyvhmg217junLq+YUskn855SJ4NTvJ2Lmy0AuSqFVYneEi qU39fjTyKzK+61aRiYqigUt5/5EX3mvr8z2dxE6fJMuvV4K/jEcC4n6q7FzMaiZ/BsoV 2m+4fyBEqx1AOiz1yMxVMwtTJNNMClD4tLA13UQ5Uc0PNFslX2KW+0mVKmIsZYu2EiSE tzKm/vmuvDQvA+6Ybeu/wLzFgVflLYh41NsoS5jRLsJVT3jb1gToMOSnaW0UdJ1X0KHi JvHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997239; x=1740602039; 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=dU7o73/CRtObgslu50QcCkFZIY8xHmANhFXdxqsNHXY=; b=Fio+hYkRj9oVK9B1e+4TKkB6OOD41pmPoUhP8f0CAYP3L6aYGFQbQMpTnkQ3iD2PXf zE/lJgJ/jn9l9Ytf9n/zg2KdCb2aOinSYc3B2gwE2pTz3Rjq2OFBeVxjeimAON+l7EU5 cRaiqMBJDPrCdZ5emHEWQ9CMJxRCbcYfEL5fZqeBghpzTSoU1odfy5mmW8GQOLPuCY4v PCcUyu53ke7P9jY6WY6YUUNe7PoAIt1sLRoYmE/ngPuJYoGKMwbw48Ztv6iZWzKdNVFB vBJeqCxVqjxeNp6IwCzUAXdTZcdsvpjlT8mSPS2lt0oUysxMnI1OeyGlRk3uYtodNTA+ GyzA== X-Forwarded-Encrypted: i=1; AJvYcCUY2oCeiC5KYtI6i83cNBT/tPpbHvdCz4V4BQ5Y8qSAsLe2u6jl6pAOoqBY2pXo7A7E4r4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6Gok4U+ZGSlU5L3fpTWJm4ndicXbJTznkH9WOo1h9I4IFyHI2 Xe7UjiqlV/gFokpHiIM0vYwh3RmLyRw5VHJi13C5G+RbWTmRrpMd X-Gm-Gg: ASbGnctCGylpsMc66qsoN5cTQj4zaVuhCJlzFiifF6uRBhxGEsE2mJ2T03+cirSEqIB SRniWxyJOtpDcv5O9OvoceCs2cW/vF854zraRe3DKNjk1J9MyibZCU54UTmy3I41x0dMGH+rS1B uEz6jREeDBCStrobd3lekFZcLp7DM6gdBwPv31lZwCH9hI85ETRlo2qMlX6HdCw+zM3lqoFKGHP pyscbF7rNOlauIjBRCLgUn6ootsSEY4R34WyvrO8h0eftHY0r76MbhC3d0ic4eepIY9FSLQglmR aRbUznyJRxXNlAzUTIyb86gjzHdG2v/3PgDvTJIU X-Google-Smtp-Source: AGHT+IF2avUkQPwRnqEFUn2LAJPzsuaZ7CWvkQvRmyXQT4zA76YeCNnBLF4Z6ffk5osLboicAxwdTw== X-Received: by 2002:a17:903:41c3:b0:220:eade:d77e with SMTP id d9443c01a7336-221040a8e2cmr328796965ad.40.1739997239107; Wed, 19 Feb 2025 12:33:59 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:33:58 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 01/12] builtin/verify-tag: refactor `cmd_verify_tag()` Date: Thu, 20 Feb 2025 02:02:49 +0530 Message-ID: <20250219203349.787173-2-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move `git_config()` call after `usage_with_options()` to avoid NULL `repo` check. When "-h" is passed to builtins using the RUN_SETUP macro, `repo` passed by `run_builtin()` will be NULL. If we use the `repo` instead of the global `the_repository` variable. We will have to switch from `git_config()` to `repo_config()` which takes in `repo`. We must check for NULL `repo` if `repo_config()` comes before `usage_with_options()`. Moving `git_config()` after `usage_with_options()` eliminates this need, as `usage_with_options()` exit before calling `repo_config()`. This will be useful in the following patch which remove `the_repository` global variable in favor of the `repo` passed by `run_builtin()`. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/verify-tag.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index f6b97048a5..f0e7c2a2b5 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -35,8 +35,6 @@ int cmd_verify_tag(int argc, OPT_END() }; - git_config(git_default_config, NULL); - argc = parse_options(argc, argv, prefix, verify_tag_options, verify_tag_usage, PARSE_OPT_KEEP_ARGV0); if (argc <= i) @@ -52,6 +50,8 @@ int cmd_verify_tag(int argc, flags |= GPG_VERIFY_OMIT_STATUS; } + git_config(git_default_config, NULL); + while (i < argc) { struct object_id oid; const char *name = argv[i++]; From patchwork Wed Feb 19 20:32: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: 13982873 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 3B8AB23CEE5 for ; Wed, 19 Feb 2025 20:34:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997244; cv=none; b=bd6VeFnJ4G+sLg8sf2v5TEwyFW2iyW8Ob7kPJMmOZkrY+4BptrjvS8a4f0luuoK3em0scdFcBlImnNXBfeXUCZ6YbIs0SmBYq6L75p+W3MNCSU8sp7htU/kPHP02340xWWQKitFrcXkGiGOGnxYk0Jkvl4w1S0VyhpwkF78upOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997244; c=relaxed/simple; bh=YdbQX8o/qRt4ey8bCprVUmna7+xu1Ip4LcuAbzL+U8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tHxQ7FshcV+X6SiyOAOa2OttoimuqeUN5eDU1jXhtR+kcYlpKsbUeeEpmc6gW3AzwnpOcxx8wEvWxBQWjGpwFOWDyTqeaq7dV2hgJO9EeuELuhy3I5zNDUXUY7bU0hsYIK3I4pjYKLgdrIQaEcN3VK8J2b70XkSP2bSXo5cWLHs= 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=fvl+JKDU; arc=none smtp.client-ip=209.85.214.182 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="fvl+JKDU" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-220d28c215eso2533685ad.1 for ; Wed, 19 Feb 2025 12:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997242; x=1740602042; 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=eqWghxS4GpQV0mu+vqf4BwXRzpu4pPkVyP0bFcj+00s=; b=fvl+JKDUG/MrW3sIjyv/2HdSy+jBCL4TOPv9Jm+qqeAs/ze4PhFbMeV7GNUOWa51v8 wLoZ+QZdbKK7ype1fFcl5z/FxeWDETBIYLeIxUJgRFcpKfNS66GZXOVkvcYeDSE0oBpr yzq24g52dpcdkWBjnuihhZsRcA7ta/b8Yw/OCI5QguRFzLW6A7bLS8Dd/MhPcbZEgqjg yRlD8m11mxuArSdwhXu9hD6NzlzWjZJooDt6YH2SO6neiXz2gwXlFvtdQvJsxAvyEGQw gm/mew16LbEKu8yx07oUzXjZW4MiCTrQJ7sfr+8EvajIIh05g/Ybz5z2/hX0pWLv3CPb XxPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997242; x=1740602042; 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=eqWghxS4GpQV0mu+vqf4BwXRzpu4pPkVyP0bFcj+00s=; b=AkmFs/QONb9l6V1S2NTsWfWsVGehhcR7DiN89BgR91PDos4LjV76Ugx/omnCCToSLA 99DP0H2WtNl+olMkV4db+6cO5wgr0BzsfD9Q9wmD8SviEhrHxLemZjT9ZMnxy+ZpV1Qb WK3fh/r2BvdEwDSi5wZcbqKnqqhXh1dvlfq7kvQ5sFMy7HSKYWzWbZzVxF41v354j23o q4Gt+LD+qsTiU8q+NaKd+c6maVDfKG4UksDrHbcOm29cMA8KJWE84wj7bb4qipFcTqLp EA49JcCW8yBKI///pI+ti4qxTefcMKQb3Qh6oG1cFUW59xvXNbrlEOLDnKxYTG3ji7pf /05Q== X-Forwarded-Encrypted: i=1; AJvYcCXJ+w5cuUUT/Rj3bPsY6xrs+m+D/CwYhr3Oi2xJFxJqWghEbpLzAzvSFOxf6MurP3EmcTM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9ZRe9nAXmBQO79IUKJTlO6yfXM1KubZTQu04sFp1MPOpzDTi/ qxvVdttvqhIrk8PAWcB0f6lpDrnjrybfeT4EqkzfpTI8zcosrZaw X-Gm-Gg: ASbGncuoDAJA/Q6tfS+vSa/dQd74kqwEZaKeF3BlcPz1cRoErLyh2RRqa6fn8QerOOB Y96lFV9ZstQGyd9VrmQGUfTy60dnosJygbOyk+msjvwNCTlrTiK3zzPXh52QT793ddAldELUSZ0 PkHqilgfuFbRroAf41/SUXGj01MpHYmighKUYZ6/CWaMHedf2aKmXTj6OIBmlRgSof8GcQubJVz fpnCF/x2GQlTZtnQgWbPLmKfLfcLJdqg2vn+BSKq3KuYZ0jw+Uwx4ZawXwDu40DV2QLkvzv2694 4wwmoG8M5xzEZlCXWQRQU5UXkJ2gCFXIqKVANZGG X-Google-Smtp-Source: AGHT+IF0s/uMZ2hvZNL7EYFAlNI/hcGMXTJYzmg5cOShqVK22VLePfThNSe+QBpN1X9K620tRpDAmA== X-Received: by 2002:a17:903:22c7:b0:215:5a53:edee with SMTP id d9443c01a7336-221040136afmr290063945ad.9.1739997242343; Wed, 19 Feb 2025 12:34:02 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:02 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 02/12] builtin/verify-tag: stop using `the_repository` Date: Thu, 20 Feb 2025 02:02:50 +0530 Message-ID: <20250219203349.787173-3-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-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, without having to consult much of the configuration file. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/verify-tag.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index f0e7c2a2b5..0acdb364dd 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; @@ -50,13 +49,13 @@ int cmd_verify_tag(int argc, flags |= GPG_VERIFY_OMIT_STATUS; } - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); while (i < 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; } From patchwork Wed Feb 19 20:32: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: 13982874 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 464DE23CEE5 for ; Wed, 19 Feb 2025 20:34:06 +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=1739997247; cv=none; b=rXruefP1XUDn33oHV1JQKF5khqPJnlZGZ9kBvyeqiaV14p7qbUqyUd53EF6ATjwy5/LFKfRUkQJCdL8wxB2CO9NjXaTqabW1pF1ygbayuE7nAUxwQ/+fdqGHkGL0RHE1hTJFZxbGPZ2pc8ZemqSG6bPv5aaGAdM5i3C5+HwW+bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997247; c=relaxed/simple; bh=8Y5qAmfAHj2xGohPG7roCX/TmrVPqnuJyxvgDjkp44I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IqVyLR5K3r/jAfJxddBwaOVAOIyGRoCkTKhk0yjCGssB0Eu+W81mAoQYr39ysihFFPhP86IZHZ7OqeaubEXasykwhOM6vIUkXwl39A1aj+wMFpOE6LzWwOo2nwO3wcqcPvtnoNdqfqD2njuMPJ3r+uwh50mmfeYLOBI95EUfafY= 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=FfndDZqC; 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="FfndDZqC" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-221050f3f00so3135365ad.2 for ; Wed, 19 Feb 2025 12:34:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997245; x=1740602045; 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=QJNmNL3sjFhLYsKKrH02VTj/a+jrK06hc/fki+sCs3M=; b=FfndDZqCCcCo0m3LvvS6U/7B1eDjJcrqSR0jeIZ6JIdDfJxmy0OBQE7hQwg47D8O0/ Df5OmrUlL7WRxxc8srJ2Uo178zYg40M9iw2dbO911OZxVmvslghUNXrhdX3YOJF/9LEB 9TlHT8905MqjAbbFWJZcwhANO+yjm2IBRZx2nbFQpHo8BmFWIaHx0cdQWQJRvazY8bpC YQ5RniKvkxA2vRGl/0dJMcBkChfLretDyiGxAbChhRZQcDqerGAbInsXaw4Oa/X8B3Fn LkfuAcgCZAHX+eA4BPPaqRRptBTwS0MpoPF1Lal18rUMY57z85TD2Pv7643aEBPecu3g +Kfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997245; x=1740602045; 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=QJNmNL3sjFhLYsKKrH02VTj/a+jrK06hc/fki+sCs3M=; b=QpT8rJT+FLboj7JDposWAOeHIp2eOXxiETAhIgiAJx2RU14sOXnVTjVkPFHCjJrwmZ nCuRZmF2AddImNaOCy/5L63Lf+pITC65w7/X5E+wRAw5h5Wg7iZIDwQyQNO7Tbkarlxe +PXZ0Uz3dZABRSuOPGpMvQ1kdG1wmfx73DtUGX6e/Y9y/mAOZrB74BSDD5NmvU2227f/ D/VnB4XBg1fpr7lRbdOjc8loqnQ4J+hjTjFwqZ/U8q8xvEnaoHHpyfj1V7aRgbiUMM3e TJpMBOWgiSeeSVI+RXBh/+pd4qMztkwyJW+tOws8SDJQah1iNROcuFexc7kxuT9nD1uN MQCA== X-Forwarded-Encrypted: i=1; AJvYcCUovgk+y3goiZGO9MnQPi3ISIPz39QvdC9/+SgS1Tz5tLn343aUB6V29EIvc2NQnk6n7Zs=@vger.kernel.org X-Gm-Message-State: AOJu0YypNx1xxu+ksRs9v6J2lYdaqqfGDV+MSgSFe1JuvtC7Pon+hlDB 9/2vNgvMSH5qUILi8p4dgG7hKfX8xz8uPrFPL4bPXV5Td49fxsDa X-Gm-Gg: ASbGncuEOEAnOcFJmjL+mz7Wn+ElcSnYV9TTjdjZQU5TleL46Cqh5XMb10ExVuRpKsN iR++glbQ7qucakLnB0FaMr/iYC1xunIT9Iwa8clxyqaKjTvVRtHfFV2l2mdl8hITZKN4ysUq15L TVyKs7GvWm5JlyaCrUrDE2T2Q54/VQ44iEHF+N63L8GCHKXW9TRdHpqOszj75d9OLA5PKX7G6b5 QS971FoVIIMEgLtqf0Lw+GAqwKTQzZRBog1Wh6vtxk7yPz4n7Tc3cs0nvQpJpSC755XUnl48gNR m5Ut+Of5fAFdhQScOFtUgqSLgjRjadwbq+fxSoUV X-Google-Smtp-Source: AGHT+IF01SpZSY+TeK0oQLIvPCCNUcDIL69Ivnltnsxt7pHJQs+F1yXemW7vyQ28tym2MYR9Nw8Ntw== X-Received: by 2002:a17:903:1ce:b0:220:d909:1734 with SMTP id d9443c01a7336-22103f16a3emr310560235ad.14.1739997245505; Wed, 19 Feb 2025 12:34:05 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:05 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 03/12] builtin/verify-commit: refactor `cmd_verify_commit()` Date: Thu, 20 Feb 2025 02:02:51 +0530 Message-ID: <20250219203349.787173-4-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move `git_config()` call after `usage_with_options()` to avoid NULL `repo` check. When "-h" is passed to builtins using the RUN_SETUP macro, `repo` passed by `run_builtin()` will be NULL. If we use the `repo` instead of the global `the_repository` variable. We will have to switch from `git_config()` to `repo_config()` which takes in `repo`. We must check for NULL `repo` if `repo_config()` comes before `usage_with_options()`. Moving `git_config()` after `usage_with_options()` eliminates this need, as `usage_with_options()` exit before calling `repo_config()`. This will be useful in the following patch which remove `the_repository` global variable in favor of the `repo` passed by `run_builtin()`. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/verify-commit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 779b7988ca..ae0c625777 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -64,8 +64,6 @@ int cmd_verify_commit(int argc, OPT_END() }; - git_config(git_default_config, NULL); - argc = parse_options(argc, argv, prefix, verify_commit_options, verify_commit_usage, PARSE_OPT_KEEP_ARGV0); if (argc <= i) @@ -74,6 +72,8 @@ int cmd_verify_commit(int argc, if (verbose) flags |= GPG_VERIFY_VERBOSE; + git_config(git_default_config, NULL); + /* sometimes the program was terminated because this signal * was received in the process of writing the gpg input: */ signal(SIGPIPE, SIG_IGN); From patchwork Wed Feb 19 20:32: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: 13982875 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 8B6E81E04BF for ; Wed, 19 Feb 2025 20:34:09 +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=1739997251; cv=none; b=gie/CYuF2+5+u3fU9TY1PnO5lP8kv4/qz2u0eVEi2rm5tmK/jLNpIBPDUd/tgNfY+ixAgwu4a3EHbJVf1eH7xU9pYej1HQMNOjQgNSM+ihycvhI75maQGlsAfjMP4rXpZX7OUHjKuPdgqvpWbSk3OI5PQWXcF6RHi8lYAOr19IE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997251; c=relaxed/simple; bh=kLPDFj4Ia9yzff1Oef1rinDP52YX/HKHujSIIM0fook=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PW6YbuNOmnsE26ycia9v5qux/y9WS0sSG3yz6HlKrsSXNCccP0AvS8tY1W+AtSWGr+Kkt2JthIA4PLxXdQcIOoRYcgd2SifBp9l60lRcdBBl1UhBspZJM2cUwW9LH/wD2pLzr3sjndMivNm0NrkhNQ00tzenFhM/Q8Os/l+mFLA= 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=UPiSMQ/R; 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="UPiSMQ/R" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-22113560c57so2661625ad.2 for ; Wed, 19 Feb 2025 12:34:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997249; x=1740602049; 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=sgSa/y+E/WevQ5WW9AJboIU3q8WEJMd2/SdLJ8g4mGs=; b=UPiSMQ/RwSe9rzmbbqmaM+CBxrfFlmtcSxIMFuvBgUOStsGeFL06NhnjTkTawwnhcn 3JUMVKoWpO9UriVp4dnqMcp/lUMuRB9TLWYNGPIuEbx6+Pziln10d8TYGe9XAnWlEgiV /kg1Bj0jxiGTEkV9BbZa/UCs1VLXC5kzbVdi4zCkpt2+cEKsAQ9n4RlSLTKfFTTyNgni 2jZIeyQfpdU6zC9J6O7a0CgD5464T7zju6ftMsVx9v0PqiDvj4N8U8CXZulgyUGpOyLL hzD/e0Da6XXpRhkw7bEATldyGiRstFVLbAWKh8yZyzFDNgCv2k7M/MOY8G9FZvQb+0fS jcug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997249; x=1740602049; 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=sgSa/y+E/WevQ5WW9AJboIU3q8WEJMd2/SdLJ8g4mGs=; b=iCPiDo90pnUK+Fp1KGwO2ay3LLi+5fW9fs5wDm7jyLRC9uu9V/449MsU1yuFeYnUL1 cj1Kwqn/fO2GSxhGRRemNGNABcZZAabO57CK/naceJx2Bum6f+CDmW08Cbr1YpEkuDAc cPoblqLGiH4oym2nUnR0Q2MQbtb6NGjkxfyqjzG+6dg6kZ8tYWvHDoaM5kM6QxdbJcbg 0WB9aDynqJVVfNT3W1tFSyNEL5zqHNS6IP9O+HGU+OOoXE2WVX0H2a7LX0B5KP7bs5L5 AZJ1/XnG+qAoMZMxQgMab5C5ecrstglyKaaNAaZIazqVshPyRKN+kLjpAlSPqJuAD+jy h2VQ== X-Forwarded-Encrypted: i=1; AJvYcCVXmS1m9sqfraqn6uGdDHQ1tzmFJN5m4W8DCCg39xjUnVnxoWPCTr2AlrIz8thjRRa0vj4=@vger.kernel.org X-Gm-Message-State: AOJu0YyHz38EZ2sHLAMTRRITA9HZFkClmh/TSwIQETNhnBPeNBAhyO9C Ecgx6J81TS0j7kMqhTXQxIwl0HLrhP4yAIwi8IZl+cm9CMyq+gGz X-Gm-Gg: ASbGncv8zXNP61XZirCYN5CFpUdzzecQPQdxC5jaRMcyHkOBnVaESTNWCs7W/3Q8NYA CR3bAvVwvYAXKyxvA2t7n6gNfIwMnuWNh4Vcg3UPTDlRNpwTclm/g2NsgintRYIDaVBMIUa7fwH fgj0RiwMmkox5pn5U4hP7DrwfXyRejIdFnctTgfSYUhkrhrhJCVez2DojATmg+6VXySmhFzYnqP qjx1lOK9q9Bqt3kCze2WW5kTCaGJrkqL267pgLN+RlJMkSrFKjIjsjvA5yaGkUaX0qkBcmg2bMR QjeD3NB8KvqhkBiydO87tgAd5T4yMjti1KQlE38o X-Google-Smtp-Source: AGHT+IGOgzbYzhleAIMZAMmec0OE5FwOFnVdvdrMYm1lxjFTWHAD/dLLJFdAQJwXf/440KaFsBZKZA== X-Received: by 2002:a17:902:e80b:b0:220:cd9a:a167 with SMTP id d9443c01a7336-22103ef5284mr332296635ad.4.1739997248732; Wed, 19 Feb 2025 12:34:08 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:08 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 04/12] builtin/verify-commit: stop using `the_repository` Date: Thu, 20 Feb 2025 02:02:52 +0530 Message-ID: <20250219203349.787173-5-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-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, without having to consult much of the configuration file. 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 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index ae0c625777..037032d15c 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; @@ -72,13 +71,13 @@ int cmd_verify_commit(int argc, if (verbose) flags |= GPG_VERIFY_VERBOSE; - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); /* sometimes the program was terminated because this signal * 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; } From patchwork Wed Feb 19 20:32:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13982876 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 B42811E04BF for ; Wed, 19 Feb 2025 20:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997254; cv=none; b=dysTwgYzTtK222XFHMiTQ8T2xab8mVXlghlIrpelDhXKdNvnjcKiEduoxKZQY3ADf3sSi/48Gg+q3JenNMhmum0Stj5CK1eA3SF4m1bCwI8oujHX09zHpeX7XDUcHNI1mSJbFnCqwpPapLkJNxWtkiBrolXmWxdgtZ8TUxOxdnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997254; c=relaxed/simple; bh=0Spg3KmYuHwAMzyAKisp3ZMckGL+Mh2IIYLqwFFFUas=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IteOGQwdtUq0ChpKO0fjsegPbDNOTWhr8irPy3CDBcGayYDCEOjnlo+8ldB7EwzRZmcB9li5rAuaHDEEiBzK7L5AQ43q5Z/vPa2D9HnJHZ/6xnlZo1EemAqvUeb/bn3vJfu/M+1NxrY43DMb0vAYjD8Dtpr2e10jPs7BZNtNYMw= 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=RpgnYxKg; arc=none smtp.client-ip=209.85.214.182 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="RpgnYxKg" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-219f8263ae0so3688195ad.0 for ; Wed, 19 Feb 2025 12:34:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997252; x=1740602052; 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=o/zYfYLxb8HB6W0rj50rAQ0zfF5Ar0AEk1JmVCN5YuE=; b=RpgnYxKgnbaOdpsqwOMolqqnAk67Bli5dpkZ8x2BStYlkMedFImuLLo/vFkjpkzkID yIU3W8KqS1g/x/u7P+ekaPMIpJal2ig8OE2tHLNSh6vCMSJVQ4IPp0CC3P1D2nkj1eNL NKzLgLP0e7T70W15mLd/CwQ0Vh6j22XU7nRQ7cVpxYZ83CqsSFsI45KmawV9z8VQ0s3o M+28mPC9HkS6nu/o/94XTY+ZuUowxAKYBrAXQHJhEqy2fW0+fTtEU1nDbzmDVObJOk02 F0xIFIr14kRrwDR9l15771MAPO+UZqqA4IXvURmc4XNhn9xToy8Y72U3fgLKnFUEf6P8 Jz0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997252; x=1740602052; 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=o/zYfYLxb8HB6W0rj50rAQ0zfF5Ar0AEk1JmVCN5YuE=; b=A8bDJXvb8OnyTG9+WdoaaorZB3B83Yzt4Ypg1mA4NvyNeIIYGYXxkkqEGf5PHUhn+u FONqoZOzu+0lMg6zp80FxdqV7SW2tz7AFF/I5rLE6Z9/Hwc3kLUzA/aG9Sef8oGq59Lx Xnlj9aUYAMGiNG2fw29lolOngwUH+S44aV3KgHziGqPktHIDkrjfwoiz35qnYtMnbhXV C4+1J0yo88VLzWw++QD3NYOSIvYLxGwd5Nhmfr0ZtXbai7aXWGdx3mEltRPZqVYUHtKr cfvRXtju61TD+5IV4NaXFtd79kWk2AuPVB9eJXFpEtihYWb/A0cezwJkGquBoQ9rB2Yx uq8w== X-Forwarded-Encrypted: i=1; AJvYcCVNYKxMhbb/B6NIqx27JfnssLz2bjqvHEVepiSH59b/wUXT/TiU0xRmb6GuAryu/8eEcZM=@vger.kernel.org X-Gm-Message-State: AOJu0YxVqqw2NYPEZ/DH27W6Xtzj7KrbS2mlbxFRwnNJKUimVr18VLh4 2VQxgB28tAVaup3oEemVs+U0YeUg5/Hrww5kBPF2D5cPUWOm36Lj X-Gm-Gg: ASbGncupo63EYC96y3etzgHBEFNlPzBwTFfTXRSJj9+25cPLaZboEFNh8AN4znzLuT3 8ISqoqH/xfd92esRJ6ahnRh7yFZOUnnZZ+srfVZTNhcywX4iMFW1aEnQ+Mkv/a12fRUDvYjrQgZ XxHZnZpG/yUM9/JxrgDMPUojjgW7IS/pldReSGnnXGLoH3h/OpQu9G2vhH64vizUYNx70LdLoZL 86o7yAIfVdFvRDqwArUwb5w6TIJ5gEAAk1vKfXe+24o1vFcogqcBleIn1QhCeomA8HHNG55mD5J KIOvY/MAONnxJSO3gyeobk2kS4+VYo/oo7CEbOsF X-Google-Smtp-Source: AGHT+IGJ0wpV1MSF5G5uj2qj3xiHcBLFeTiyGZsQQy1W7LuANQWTjwrJ9NXvsJUHDmGUfUOrTVDtdA== X-Received: by 2002:a17:902:dac4:b0:216:485f:bf90 with SMTP id d9443c01a7336-221040613admr254565585ad.27.1739997251875; Wed, 19 Feb 2025 12:34:11 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:11 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 05/12] builtin/send-pack: refactor `cmd_send_pack()` Date: Thu, 20 Feb 2025 02:02:53 +0530 Message-ID: <20250219203349.787173-6-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move `git_config()` call after `usage_with_options()` to avoid NULL `repo` check. When "-h" is passed to builtins using the RUN_SETUP macro, `repo` passed by `run_builtin()` will be NULL. If we use the `repo` instead of the global `the_repository` variable. We will have to switch from `git_config()` to `repo_config()` which takes in `repo`. We must check for NULL `repo` if `repo_config()` comes before `usage_with_options()`. Moving `git_config()` after `usage_with_options()` eliminates this need, as `usage_with_options()` exit before calling `repo_config()`. This will be useful in the following patch which remove `the_repository` global variable in favor of the `repo` passed by `run_builtin()`. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/send-pack.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 8d461008e2..0848d23171 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -212,7 +212,6 @@ int cmd_send_pack(int argc, OPT_END() }; - git_config(send_pack_config, NULL); argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0); if (argc > 0) { dest = argv[0]; @@ -222,6 +221,8 @@ int cmd_send_pack(int argc, if (!dest) usage_with_options(send_pack_usage, options); + git_config(send_pack_config, NULL); + args.verbose = verbose; args.dry_run = dry_run; args.send_mirror = send_mirror; From patchwork Wed Feb 19 20:32:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13982877 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 D8FC91E04BF for ; Wed, 19 Feb 2025 20:34:15 +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=1739997257; cv=none; b=jqSaQVFikFM+feIZhn+kaOnkbKy1TqRtqqNZSpva0+MLHzzNmDHJXFlE3G8IY0PAma1mtRNTyIPv5hDq8pVR7CvndLBh7eWIn62lRpg55WymgnbRa/xqbFO4ChSruNj8YmLNPxUk0gKExNsuHmV+svH1j7TQPP+Lw5b3To/KbVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997257; c=relaxed/simple; bh=yUsRVVynB8WUTVMHhlRlQW6RnOl4HaL8+LpyclczGXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FjaIOyHKkJGC8+IQUp3ut7757VTgM7XwsLSCiscThnsK5vFo8+zd+0WsgBbmVrSEeGQGPPvoUkUR7KE9fbYhzbm7200C6yKya4OWirenVNKqSTtIruBSB0JMdJtJJbW5Z1+FnIiB25p6+I/lHXYO/2Vj0nZ184Xl4/Gylosr8Jc= 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=dAC6Pr6w; 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="dAC6Pr6w" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-21c2f1b610dso4397645ad.0 for ; Wed, 19 Feb 2025 12:34:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997255; x=1740602055; 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=JJAwjPxYS3ZV1QhvQbMqgdWYuN3NUNCxW+1as9J/akQ=; b=dAC6Pr6wk176Qk817bciBAjXDjS9pocQgVzeSWGuQKLpiGPl7ZlUKQsvzUj3ppsFZ1 bmSqoOQhtWU1f3cvuLily7WUQfPA1+ZHCNCi5l0bG9KkhYxkcZfUFAJ16OU4l66AZQ62 B1VcfqIicLMzivXQfUhUwda+7mvKPJb5JOvlGcJ/0/oV/mqdXX0rd0JwFLhK+ChtvFra TEhUYtQwQOcPx5oRXZ+5XBYdTK+QjZ9HEkoBPk6f48pmvcHWnQGSD4mjliyO590zbHHc YnSYQzIWMkqNreQCP/xBlWjd9SRrSnT+XGrBfgGTD7UCLgq01CoPTSvS+XnnJGdg7/Yg i3cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997255; x=1740602055; 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=JJAwjPxYS3ZV1QhvQbMqgdWYuN3NUNCxW+1as9J/akQ=; b=hEZJphH3ZwVit7VgqqDJareWJ7VZe5ollkRYMZLWMr7bjCDBMtw4q7Znv1A5f9ywrL Fjzw2rzeQRhgRauL9Pbyy31UR0DQbDYp3VZukaaDNukP1pgrSN2bA8rj2Mi1ZBqN7tA6 +25Sx88BMpfrjcGjRK5lrZRbO/xW2lIX2j2CXi6HrfvTu7aFa8eKarZ39gTnLnA1bFrY 486e7gBOJAudmSYrmIe5aSwUVo2ErnbNwyelKMuoxN7Yk7hUWULTJggLlZPJQ7t3Ay8p b9i3jGXLXe7hdNBW06AGKEtyRhDA3xVyji+oBu7cubUO9QbQfD6N/mrOuUJNNPNDSoD9 vwsg== X-Forwarded-Encrypted: i=1; AJvYcCUj5f0TLdNkCdiFIDB1LIR53PWDASFuHwrva2tOPMiKw5Pb/i4D+Mj0XnP/bD4zT7wOjwI=@vger.kernel.org X-Gm-Message-State: AOJu0YwSRpa4Ya4pscu0xLEIznrHK8eeLVJy30j3wd8Ap0NvuvJhPD9i GIerz+GMKguUuJtCc9PJVr4WEtHa8pOwy+bm7s9iMkPl0L2c4j+a X-Gm-Gg: ASbGnculZOaEKhQaEdAJIOT43NjPeAymK2XFmRqH9NJyVzGDX5dKBYOQGIRZs5QcjFd 0j6wGvgr5U6e01ziZ0LX3Z0NWtYB6oVfS8efpvGhn81m6MdCY1CchrD2CvDWY1+D5PIKvtzRmum np72YUS/6vZScVZFfvGYzACjDU0zVjWp7uiYbSnFCkEZpZ1r9L+gr8ut5A6MMW/IojzdcMiOTAG JrSCZ/+SARhlk3rXKj0oW5Il85QdhGc1d97qUHn9hllJINAqk4WYhZs1TiO9YYqB5rxRk4XsGJe kF3vQ8HtyfnIQd5Z3dYPElucT9eNyT1UiD+V9cfp X-Google-Smtp-Source: AGHT+IGCJU1sD3Fwu1q2ZkqdBBdG1utTyjWnIf8KEjFnYM96gQOCCmT58a0YCuUK3eIACE1Qcu2hZQ== X-Received: by 2002:a17:903:1a0e:b0:220:f1a1:b6e1 with SMTP id d9443c01a7336-22104028854mr332391445ad.19.1739997255146; Wed, 19 Feb 2025 12:34:15 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:14 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 06/12] builtin/send-pack: stop using `the_repository` Date: Thu, 20 Feb 2025 02:02:54 +0530 Message-ID: <20250219203349.787173-7-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-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, without having to consult much of the configuration file. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/send-pack.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 0848d23171..0ebfc98317 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; @@ -221,7 +220,7 @@ int cmd_send_pack(int argc, if (!dest) usage_with_options(send_pack_usage, options); - git_config(send_pack_config, NULL); + repo_config(repo, send_pack_config, NULL); args.verbose = verbose; args.dry_run = dry_run; @@ -318,7 +317,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); From patchwork Wed Feb 19 20:32:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13982878 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 2C48C23ED40 for ; Wed, 19 Feb 2025 20:34:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997260; cv=none; b=GoQETWRVP5lf0p7wTAQb+w4/FhQWOdxlHV0ZpTwhuP7SyP4RbAhSjLKpE6LQCAtB+PuwCzPZkWtNoyslZPfM35VTU9vwV9zK3VCYSF9WjNX4BgIK1qRIOPc9gfkpTQ4Xyt9xYGF1NY2rVEVR8D4JlUIddVS2X/hOPX11VNmUz9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997260; c=relaxed/simple; bh=U7hxxSQ61EVylqutpUsj3GSWPgEB9M6Rf/qs0DFQLNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X+21boN6qaQYs1zb2Jny/E29W1B2IPzItra4k4GKRfBMHiloBW8/8vmC+YDrxfnq68WG6RWa54yYnkPwRuy8S1VTEErf5yyp6cvmfVDXL2DpXYnNRwyQtulVctpPPUNoPIpaP+0oYK5Boxj6mhsWjHJIpcUP9VPs4VaskQ4KPlI= 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=jkxe5gCJ; arc=none smtp.client-ip=209.85.214.176 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="jkxe5gCJ" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-220e989edb6so4032535ad.1 for ; Wed, 19 Feb 2025 12:34:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997258; x=1740602058; 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=x3zcETK7eZ2sts1H9XzlGGNw6Y/886v1blXgieinuwQ=; b=jkxe5gCJntaFs0bDzs7QuMNYR2dmHlzLJNGuqEBaG3qSZcqJUUOa6oO7lnc8ZtlSZH I2bCLvC/OYAR1b8PISrlWqImezgCZ44xh6al7Klof977mRj2kBVNKmbQOZyt92vaW4/I RXdBZ1GAJNYMJrfWTHNl/I2RaRF8ztZ1SzTDhUZWU0ZrFDld0HIk5qYEp3ajuzN9jPeU IpWY9YRgV/++LutkYL/4BBIJyrkLNqK5iqt9LqzMYp3DEKBbu3SmI5kM1VVfUntjgJya u3mnG3WwLX6koTXKT0B6mWnS1JtI0WH2koijdq7V3Pva7yZRrJzPMrP/GVxxKIJLCOli 6yIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997258; x=1740602058; 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=x3zcETK7eZ2sts1H9XzlGGNw6Y/886v1blXgieinuwQ=; b=X5La8DV1xnZuKuGvU4p7rEEaRMRQcGWaHqZ5VYFcdwTsSasW4F93pSAl962o0ubYn+ 9BX9PUjjpDFZ1KhlFlposIQ2B4EoYrCcLz1x1yWOIbCElwSnRMTk1M+Yit6VrRcYdf/f bqRbYAGqEu9N+KkMY0NpsXfIdfCgP33bDhkEsp3WDJA/uwhyzr43HK3POup4ZdGIExFW e4jtCcauElEOH0W1S312/SzP4589fzM2gXLe/kg5vhln8YPTntXI9OF+aiu7A9NQZEk2 YLkoFc4LiGeQq9j8nokr18P77LxJm8YEW2MWLIV3ff7LkYNITOGDSELZCCuAZpUkOLIm l8Qw== X-Forwarded-Encrypted: i=1; AJvYcCXDu65zFeQtsYadKd844bFhwnbaMMXLs81xjqkmwgCA3rg7DdkOOJy0OHr0NL/ULDiKZCs=@vger.kernel.org X-Gm-Message-State: AOJu0YyTKO8VzFzIQBZXa6hNDMRIKxnN20W/TmqUmPInQcL7EfT7YTYG F7DU2qkSSD5NpfwzTKkOV4mmVwOpQGpFsYYMBB+34XoWxsn7Eyqq X-Gm-Gg: ASbGncu4ARm4rAo+WeMFih1CZnEFED0JqaPF+J90ZQ++DS2nB9Cfp6UB+uMX7fOp5gO C1pmd6MEJkG0NHnMMucRkltOfU6MCWko7IqwUvg2EmdX+YsGBkriD3RuLopzb6o5D/80djZAaek 1iMM0gpuNG6HnkzwobWOCV6zPK+yeLgzATDL4bzFzlSBQJOI6GtIR+RCVt744sQQ6K0RP+NqkeW Wt6g8mpz7XxPQlok51PcN+gKIKRa5o8qK+Guk1GvHgrLfY0590b1xicxEuTQ7tzVvQm6n9Vefsk 6fIaHln3TWcoqx7p20qdPYpiMX05G2872uOZWG2p X-Google-Smtp-Source: AGHT+IE/CORsXkvkx7bJzwEvc051BaB28booLrfPGddzxwB9An14QTN6Kic7T62k4zxdi4N0YHcAdA== X-Received: by 2002:a17:903:240b:b0:216:3c36:69a7 with SMTP id d9443c01a7336-221040bdbefmr303814095ad.45.1739997258432; Wed, 19 Feb 2025 12:34:18 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.34.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:18 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 07/12] builtin/pack-refs: refactor `cmd_pack_refs()` Date: Thu, 20 Feb 2025 02:02:55 +0530 Message-ID: <20250219203349.787173-8-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move `git_config()` call after `usage_with_options()` to avoid NULL `repo` check. When "-h" is passed to builtins using the RUN_SETUP macro, `repo` passed by `run_builtin()` will be NULL. If we use the `repo` instead of the global `the_repository` variable. We will have to switch from `git_config()` to `repo_config()` which takes in `repo`. We must check for NULL `repo` if `repo_config()` comes before `usage_with_options()`. Moving `git_config()` after `usage_with_options()` eliminates this need, as `usage_with_options()` exit before calling `repo_config()`. This will be useful in the following patch which remove `the_repository` global variable in favor of the `repo` passed by `run_builtin()`. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/pack-refs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c index 4fdd68880e..bd09366738 100644 --- a/builtin/pack-refs.c +++ b/builtin/pack-refs.c @@ -39,10 +39,11 @@ int cmd_pack_refs(int argc, N_("references to exclude")), OPT_END(), }; - git_config(git_default_config, NULL); + if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0)) usage_with_options(pack_refs_usage, opts); + git_config(git_default_config, NULL); for_each_string_list_item(item, &option_excluded_refs) add_ref_exclusion(pack_refs_opts.exclusions, item->string); From patchwork Wed Feb 19 20:32:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13982879 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 709B01B0F33 for ; Wed, 19 Feb 2025 20:34:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997263; cv=none; b=AG3AsKIBO9bJFvSfbRd5PwcWtl+Z5EyfMX4dS0TRvjpDzCpRzGGAYEblTpVxHzrQ7j7m7qCvArguWKhMZVaAHBsRWdVP8mhlQvEZEiyKIImEGIV4pzxbdgxxZqv98iEyPU6cEtbSPvsrNR3jMzurN/ZpMa+p5vUuZFdpLeZhaKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997263; c=relaxed/simple; bh=Kl9+JlM83/Y+MKfhmGWpxD0SORHwQIvvp0xORW7zAd8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AK8AEIn3P4F9A+Qis7vXRVwhmPN0apAjJx5hNu16l78xtye+m6EPQYDZPYxpBEwC6mqhaCg1AXf4Hnn8OFpzc9EZEF/xgMIHUusSaMlnV8I6RFLxqAs42628CrvB7Dgga0aMETKhppg3PEznbR0HZ1z7qoQnMqGiI90YhxNPWaw= 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=Fh+xUUoa; arc=none smtp.client-ip=209.85.214.182 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="Fh+xUUoa" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-22100006bc8so2997825ad.0 for ; Wed, 19 Feb 2025 12:34:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997262; x=1740602062; 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=TLTlhuIq2yKCmU6R/jacEdYsxNWO4n5ZmA9gOb0FCAk=; b=Fh+xUUoak856aZwZmtF9g3ed5EESd/JgZmQCf7DuRZXQj30YaihCRNFB7cGUxxNUvb 6lKTiUOX8MlhWbnGDj8xec3FFVPmZRpNMV+oS4Z7fUMmcD7V2sqkkPAdGkS2ksAGMDj0 G9liAH9hUqmyIu9aEXzxzXuXkGRvuEZTt3QrdAU1igZ06aIxEO3MTl2Lq3rosKN7oeFB q5LLWY7PRRipg3jraEo94uCLolcaRjvccabDZvK8q4ULB3P1M1Jtw1zqhFjemrIES/ts SNNOjbzEpj3EdG9J+AZh4YmbI0CCA+p+jes7+AkHZv0QLQcP3oaz1mAJ9zj+qgWqPEYZ 6edA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997262; x=1740602062; 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=TLTlhuIq2yKCmU6R/jacEdYsxNWO4n5ZmA9gOb0FCAk=; b=vZaaAkGhsGjEOFkbOAz0kzeQX3FPP/ZWBkjW9pzrSDQ707gxYTIF0M1J/mLesl2nAn bTFd6kCWZQrwFgm1gvoOZgsJsE35X7n7pUER6+3cb7uz7n3ffad4oaqzR7kB/WnxdKvx wuJDBuUYfyy9Ullf0vVvzjzgsIQE5fS3O9Aqfyd2l6yBrc+Jeb5icKsWgyGXjI1gKMjl br2cBK9gSANpL6897A18yqQTDVINdsY8pXW7N/wuW71tO7zRqJCFXDVF5W5Ii+gaJxEb QW2/djp0ThUg8auKuuv6IROon6vQsD3e0anUbCl6zv10hFISsV1xbfB7q87Dr6lfV0M2 pw/Q== X-Forwarded-Encrypted: i=1; AJvYcCXsKxkeY348S7VSqdM2EChZdA5xWn7tvAsVPkfrVFXVZ+AIXqf4nDgdnUcJkZll+RRi0Ww=@vger.kernel.org X-Gm-Message-State: AOJu0YxU+S6kHgwePdlOjCcJAQNSCKSCUVnrugpynpol568Aye7hB5LD l1ozWnlZN49E3jdLfxp4toh/6QGKIv8ppb2vZlPenxkXeH5eXq2S X-Gm-Gg: ASbGncsJJ7J0Z31zESKFCRs5pDiXqq6s8hhSm5Yc5+JBZ6BuGG5pC3GnpQOL69boe9R HGmILOCrPol37nrxilOH4fDX6c/KsXVmSrkN85/fR2hV9U9pfcZWpCglmMN0yeL2KlQjyeMQWpZ gX5d4AAzs6upTfEt+sxV5CU1tYHhbLwNFGQj71ckxD/yk9BC04gWXen7Zf+BuOxBGajC92crIi0 jJqq4N2gmeq2XlzHJXRBaVyUwQPKpp0M/xsLUaDa2KHU8wLCwI1d3m81vV2yVwncd7icCCC0SwQ SxlwyulWh9J3UcNAZdXWZN7mD/o7GMFKXYPt+H0x X-Google-Smtp-Source: AGHT+IFTr1EK5YOKbRtU4h963h9N50pdQm3kDstyuJecg5IgfEaKygtTZHdZSBxb/2L25I1+652AbQ== X-Received: by 2002:a17:902:d58b:b0:21f:f02:4176 with SMTP id d9443c01a7336-221040b136emr331403935ad.33.1739997261660; Wed, 19 Feb 2025 12:34:21 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:21 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 08/12] builtin/pack-refs: stop using `the_repository` Date: Thu, 20 Feb 2025 02:02:56 +0530 Message-ID: <20250219203349.787173-9-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-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, without having to consult much of the configuration file. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/pack-refs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/builtin/pack-refs.c b/builtin/pack-refs.c index bd09366738..200a5516b1 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; @@ -43,7 +41,7 @@ int cmd_pack_refs(int argc, if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0)) usage_with_options(pack_refs_usage, opts); - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); for_each_string_list_item(item, &option_excluded_refs) add_ref_exclusion(pack_refs_opts.exclusions, item->string); @@ -53,7 +51,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); From patchwork Wed Feb 19 20:32:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13982880 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 64D5F23F262 for ; Wed, 19 Feb 2025 20:34:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997269; cv=none; b=MNbb45wzpVfoP2AdhyfO3QJdYhWMssJzPSidxanpOdHa9zKOYZTOGEudhMBRBedVPJCBlMPn8BFflnqvPr6clZw7fmueAPvq97UuPzWsWn3U/w37WJlCXBKULqgQaKFsf1WV9nn4JsIRIGbHBfmQ/NOVzHX/r87WytVHnRmUG2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997269; c=relaxed/simple; bh=kZjVe6dY+Cf5lPZfvjuehZJzBZ+oZA7HK2N5iUIMf2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bxVJKdV7Nic32957iDi/rsDOwaeCVeHLpJp1eF00Be3fQTfxAdUoxG94vdBeqD9e7Kz5sDSUSCMDZQExYhCpfqMwAZm8FZQPoRTDswoQt6kVwOQJ0OGazPAqtCH33dy39ADMy/ESaXPVE1E+43ZaHPdiA47Zt8Di9irn6Hs5D/g= 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=ltPQCdaj; arc=none smtp.client-ip=209.85.214.176 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="ltPQCdaj" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-220c2a87378so2349845ad.1 for ; Wed, 19 Feb 2025 12:34:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997266; x=1740602066; 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=PVsytE9dVt8lgyMho7rtHuedXymLlviG1CHSX3aqwv4=; b=ltPQCdajBfUYxkWaEdQwh/9Ma8EBkYaIDrYtDnTDnI876S1sHQqVpBw5laFY+ufcEv QN7zDqlG79GbAtQjtTXoXCihPAaEP16GegZ+MxGs6q9R42OWqIlFhsKcNYhxsYwx42rz OGdHzkG7RwHCG+tuKS03NP2RyAB4I9ZSp1y5bUq8dRs3WCJKHR/qA3+sLpDcshq8COfH daW2FkHygkOSohPUDi0VhZreF+79Z6a8OH9FhvrgxA1kRQQ6uRDX7sj9Od+iRy5pj/2U 8lH+cLgmwFb3CxQNvuXUQRAXJEXduFdEb55giV6VRAiNmQ2YvWV+0Li2nq4OropTG2mb 2++Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997266; x=1740602066; 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=PVsytE9dVt8lgyMho7rtHuedXymLlviG1CHSX3aqwv4=; b=ksIzVgxKQSeg3NqRElnjFmDQldCd1sWzsl3V//R0rBlrFS5Rn4pMF1VzYYp9iimeet rRx9E0kX0ahauD6YibBoU5ai0tIYV56uqNkO95ywzHpsoZbhkgaAGGn8nexzoQtxPxbM Wth4X29v8p+UrQRB0Dr68WddSx5QnW6+9FebUjWcZDuoOQdvVUxZyUSaC5KMKwmFYoZq kJrt4/PfVgNOq/l6rF0saf1lplfWuwrxiGeZ88wvzXWQ0dhdgsjGJA+mG0HUKTUGDO6P ER3RWpvdR/2brwnd9XBvGAxgVaburh/mCcegMnTbf0TLZ4LTjkiEpOev+tV/irDISvqP Errg== X-Forwarded-Encrypted: i=1; AJvYcCUFCfqqZvH7fdCol/AyWDcGmNVxw35LFTJKscNprR3c07OOXcgljYz4pKP6/i4foujC7XA=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0eUNWZvyF7CXHZ/HGjV87g6OCdyTX6fza245bREvGHRmbQgv7 IFeM419kHYFTz/oA/9HeM7/ubKcSRXNe8+XCseFN6LDlEffC4uWS X-Gm-Gg: ASbGncuYA7sJIP9Gcg/BsanoQIJFlvweM+GuuyvAwNX/J2q/APn6pqukohplrgMiBDe o1fL/nqZBxMglhMbame9PeJi1nawM6fowhhrWDyQd6a1Zr1FodH4iRy7nRb5lpGxkR5CEjBv8HB bSZt+egMG08WEvUTAMMDKCtjA1kzfIxCivC16OXS4DuNAdTbW8K+Zajjblrt5dA+DNcjVBdKqNa OV0BMVItNJi9XvITEajv72mHmmjEruYnko4HSvL8seFlpFOC2y2LnNU+v1Pxta59dLQZadhzOvf lqbn6x4/M6TVc9l4tWCdBf384m4hq3AbfeTn954i X-Google-Smtp-Source: AGHT+IEPsWGbG6sUoW3GIWntJeXj9lmwVTOQRgczEoP1RPmS/WQA1G18Jym/fMf5Al+OW36Etlt9QQ== X-Received: by 2002:a17:902:f54e:b0:220:c63b:d93c with SMTP id d9443c01a7336-221040d75a0mr338219435ad.44.1739997266511; Wed, 19 Feb 2025 12:34:26 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:26 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 09/12] builtin/ls-files: stop using `the_repository` Date: Thu, 20 Feb 2025 02:02:57 +0530 Message-ID: <20250219203349.787173-10-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-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, without having to consult much of the configuration file. 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 ++++++++++++++++---------------- 1 file changed, 16 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"); From patchwork Wed Feb 19 20:32:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13982881 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D12D23C8B3 for ; Wed, 19 Feb 2025 20:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997271; cv=none; b=BIUjn5zLpeLVgTAmxtnk2/T8kWgzMsXtDFX0KQPt5pZgFsQS0+jPI9wSo5iyYZaAaqkwbnTp3Z4cmlpxVGBiAD2XEKzRRDle3b4hnD3TL90xn6b9y/xiaWCS6Vqy8FPM2501h4CSNc7noWK5DG2KPuu1UqVqDJBLQmRmw8tXsG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997271; c=relaxed/simple; bh=r/dQdrA18FPS6wqf9HgMJ8hjxkc9IynhPHZcvS46bFc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bsnm79t15abGMDcNAzT/WoEa3fQGF33Vw0CFYGq9ipmPyUXnly0DWdlY2Quzx+90pPvD5arnzxhdOKD6hEGjiP6DA2XBKaOYxlx2k+8iYyTrV9VtC503X6PnLLhmd8GL9PJpto0JkqG27zSeQkIlz6/qOs45isAtK7Q93NCTO94= 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=mtSkm8ZB; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mtSkm8ZB" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-220d39a5627so2446245ad.1 for ; Wed, 19 Feb 2025 12:34:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997270; x=1740602070; 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=etws9vFdvPOXGxA4DQzZvLi6rQk0V++mAQK8vA0BNeM=; b=mtSkm8ZB3ETNvu+6QvADscWFDLYly/fcehFNNr4+dmgeoKnKJj8Mz3GjMroi/0Z2yb 6iPNU3vfPhNB9FewQzGpXXAiefPBt+gq4qhoPBT/G/5fufgM8iME/NUkauCgE9lg4Fn3 fAQc364seX5uyAzEdWwXxvLjIb909I+DsWc/8gm1Ay1jbKfJ1BYfbcQYgSSCd/5NPR6m CkeIYJLjOqHBJBVffy5i3gjLE2qhV8UX32wmCedz8AaBAqS3B8X58lidIUbDXEAZvhVn DjtR6/rrqHhAIv9iKj/fMpcFkBp3QVFOX5DY/XLHs8JrIz0LOtXQzaRRADzlO3deMwVR ZV9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997270; x=1740602070; 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=etws9vFdvPOXGxA4DQzZvLi6rQk0V++mAQK8vA0BNeM=; b=qQpGmWkHUidmdsQK+tcqv07FWL+OjqDmlh9+eghIIcRw2x+WV9oO/Ay13vCJ+vQV1b TWBN0Q0GxcUGKrWickKi9sk+roCyaeUmRrTPhHSzyMxxxwEyiS+LfIIZwBfatn/Hh5Ce YIJOftuhhRnvufRPiLVJjPT2sA2dImpl6pt3qz5x5HqRJZ7cIpJfoW2Fldducia8q5v/ 5i4wvrK4Gby9Oepc34LBxe703ot4DEPaN9NOaLwTyrqcqNVDQGZijEuHDiHA5Ds+5zV7 IBa+MQB7n7Ec5wxIPE78NZKknzXzIlsjp8i5QjRmGHW77NZJ46mklAaPGrbPICfN9IDU w6mg== X-Forwarded-Encrypted: i=1; AJvYcCUaat2+4LfTTFBPAUWR4fk7quoT2gAOVeiDFmN3iDLEKng+DcHQiZVLDd5Zpz6dOoFgmEs=@vger.kernel.org X-Gm-Message-State: AOJu0YzaSbQt9an2qIhQTePuJjTw0cAepk0cdbOcZ5OHNCZ6X6opWb7F yB521tZuJ3RNvj+gAgYeFgUxhhWrLU5g4fFLIuUqQXi0aspMtigJ X-Gm-Gg: ASbGncs9/WzhlqkOu3vXZx0vfJjuifykGH/ZSBez4P30F4M/YaTMNn6bbGkf4o7UUU2 8mnMhRRilcHeGc60ioaQo6pJBpghIqncZT0cEdzNzEmAU3k7XiYPuxc8s4hupBp9RMiYo5df1H5 tPkb1svjgurjdZQaD8gmgzyraJRjrCJbK0Je1wR/moQLG8RS4csINrNVYRaNQq/GB0wkjMkyi0a JaToQRvFZlm2CwCkGDGf+/7+sxcPWsANCsnoUPveLigESofGbDu9rcj9J07gUXejngchy8rZ9NM sj1XbbMEMuMyN186IiS2VqArY9xWdM/La46Oh0jr X-Google-Smtp-Source: AGHT+IFLtSU4s0iQhFVJZYJLNziRO/IBjvObxYQcsbrr4h2roSOKFM3p6KD0JO2KjhqlZD0IE3aeSA== X-Received: by 2002:a17:902:ec85:b0:220:c911:3f60 with SMTP id d9443c01a7336-221040bd357mr314775645ad.47.1739997269705; Wed, 19 Feb 2025 12:34:29 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:29 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 10/12] builtin/for-each-ref: refactor `cmd_for_each_ref()` Date: Thu, 20 Feb 2025 02:02:58 +0530 Message-ID: <20250219203349.787173-11-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-1-usmanakinyemi202@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move `git_config()` call after `usage_with_options()` to avoid NULL `repo` check. When "-h" is passed to builtins using the RUN_SETUP macro, `repo` passed by `run_builtin()` will be NULL. If we use the `repo` instead of the global `the_repository` variable. We will have to switch from `git_config()` to `repo_config()` which takes in `repo`. We must check for NULL `repo` if `repo_config()` comes before `usage_with_options()`. Moving `git_config()` after `usage_with_options()` eliminates this need, as `usage_with_options()` exit before calling `repo_config()`. This will be useful in the following patch which remove `the_repository` global variable in favor of the `repo` passed by `run_builtin()`. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/for-each-ref.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 8085ebd8fe..649689c92c 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -63,8 +63,6 @@ int cmd_for_each_ref(int argc, format.format = "%(objectname) %(objecttype)\t%(refname)"; - git_config(git_default_config, NULL); - /* Set default (refname) sorting */ string_list_append(&sorting_options, "refname"); @@ -80,6 +78,7 @@ int cmd_for_each_ref(int argc, if (verify_ref_format(&format)) usage_with_options(for_each_ref_usage, opts); + git_config(git_default_config, NULL); sorting = ref_sorting_options(&sorting_options); ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase); filter.ignore_case = icase; From patchwork Wed Feb 19 20:32:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usman Akinyemi X-Patchwork-Id: 13982882 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEAEC22F167 for ; Wed, 19 Feb 2025 20:34:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997275; cv=none; b=WLkSAbacYsiu5QnJ+fPUueHmrgVOnlimrd06rlyY8wRwURLBxuj6U9pm4n+0RSerWuMqKqv5+KMfNffPI1I9aP8soby5t083igjbkh3/eb55hHJickif3i8PwwOjCgZ2RbLDxR6Qx872Nee8AaUT+jZtGlXxxDxQUa3AHnGYpOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997275; c=relaxed/simple; bh=+8lhNbO8XPOdY5A43YAY7YE3kig8QN5Jq9lbPzOCfIs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z+EO36msfkxR8OCO1WMhu1Ad1p0R+thTY/gmaUrGbKvDpVpWFsQth4gzlOvYJpoerQPzZL6oBht4DDr7DxMzUUP31H/xP787aS3vfvyiLe+J41Kq2NxcEgxrDfNPCtEVtzRPKNzEizA0bDje31JQwxbgTcAja9SDbnMewHP00kA= 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=Xpdrrl8a; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xpdrrl8a" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-220f4dd756eso2761835ad.3 for ; Wed, 19 Feb 2025 12:34:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997273; x=1740602073; 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=/46wBVN4NTNuX5Jw8zskBcm1kjlaa9e2wbbYyQJRjro=; b=Xpdrrl8apRU+nKkUV6zuchVFD1SDjL0j+yrahIjGYmOIoGZKtAF01TtCpEbPJRAAOk H0wQRVwckBfaK7etRzLqmYnpUNj/MR/UeXIfqFWf+vXdvKIlR5sMN76Kwn45xQsHLxZX hjbm0vDueyi4vU0jVBvOvXSIw5egQuRycVjOA8bLeN6UfempKCqhyUvitxUhX+Qlff9d 25rDsiLYbYPz01ueFyGa8YHlJKLA3pqi6MHlIp0O1IohlWQ3CDKQFDOr5KTY2Vv+FJw5 Ub8FbF1nEkkoAqGIRUsbxruUCUqwtuAfOGkyM0bcCkLKZ2U6HKENHxVPpOU4tCilVwQq dOaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997273; x=1740602073; 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=/46wBVN4NTNuX5Jw8zskBcm1kjlaa9e2wbbYyQJRjro=; b=GMvhst/Q8MnrfzLtD7iycJpIHFoInvwHfjf7qPkBTg1Mk8DlBF+NXtpkIdqLCz30WF yTSvtyQJUJB619TVdNCZvfRntnGfy/yHKpD0DjSsdxX/ovUEIOgKI9GS9+koZM2H5jsc BfRZy0xSb01duM3skgnk/3Uh4CF60wM2UbvnKpRbDw91ezWFO4I2pfzSXzeVKAUAT+ti 4/ivq7nREmVK60ygX9Yl2PmQ6uQYz4LAnFQctmqJpdZMeQp0NSprNJ35/dI7rY7Ylc4O /YUJNMHDxOMx/aDKIXlEEownG07ehuqtJ3KF98aYcP41V3mmojugo52VTZAlZxW6iz0m U5GA== X-Forwarded-Encrypted: i=1; AJvYcCWGy5DDyj+5alqtI2nvrLQLGBcAuLMQ6bXqYcKRisMg7w4wiZhcJ6eae+E9U6UZ6bj4Kts=@vger.kernel.org X-Gm-Message-State: AOJu0YzV/t0yrqGxF7A+5ZWR+hL4z+xKkKUt1OgIgK7mscni2UsCGpNj 19ILOq7Gd9buiuU2ohhjS7BkQs2b52i3is93pnTPj8ktzXcQk0S9 X-Gm-Gg: ASbGncsifRnF9ZHfh4SLn9jcJRbwvtPLmVrbOA0oWBDBqipKC17KTcOAKyFXK/vRC/e LglKHFahPtNwRhV6o51kuktT/kVuVQv0UAt+zUOdKBcMJwJ4Dwj2cOgwyhbyphYVR83cdCP+MDA vsR7d7SP3tZFDfEHv3A0/alZNOVcJANGmlvKbVsH4802RSMiHWYTa83DUW3zqud5efYAEuohhPs 5v5wR4V/3lL6No8PA8dKCL9XysrbkaAbTtF/6xcsJ5ypI2S/g5lB/J044R9M7ZJHlXWJPA5D97B O6ErFNed4f75juiyc+NIHqj9aHIEJwNVU+Gl1IRj X-Google-Smtp-Source: AGHT+IEqcrRYaw4VtCjKX4lto5gSoiy5jyTugTIqe2xrgYTTCqcBOe8anht7cmXssnfAPAiC37u1zw== X-Received: by 2002:a17:902:ea11:b0:220:ea7a:8e63 with SMTP id d9443c01a7336-22103f19fc8mr296754705ad.17.1739997273006; Wed, 19 Feb 2025 12:34:33 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:32 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 11/12] builtin/for-each-ref: stop using `the_repository` Date: Thu, 20 Feb 2025 02:02:59 +0530 Message-ID: <20250219203349.787173-12-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-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, without having to consult much of the configuration file. Mentored-by: Christian Couder Signed-off-by: Usman Akinyemi --- builtin/for-each-ref.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 649689c92c..0f73f47fab 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; @@ -78,7 +77,7 @@ int cmd_for_each_ref(int argc, if (verify_ref_format(&format)) usage_with_options(for_each_ref_usage, opts); - git_config(git_default_config, NULL); + repo_config(repo, git_default_config, NULL); sorting = ref_sorting_options(&sorting_options); ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase); filter.ignore_case = icase; From patchwork Wed Feb 19 20:33: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: 13982883 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 D664322F167 for ; Wed, 19 Feb 2025 20:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997278; cv=none; b=EtNkZ0FHyIw6ewSq5N6kdAEn6vzXYJdvxyZfGJfQVcZhqN6ofNsfq+9vp+JrLHNM7KrQAbmHQTtFneZAY9+IaDTK03+LAUKQ+sHX0yUX6z27KPvg3DWnnXTeISTuxy4lcNxnU1BxqiBcRmveb0ZIfHCfbTBII19VYDvu+rkZAU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739997278; c=relaxed/simple; bh=q6T+HtPjuHyF2QaJdoltFUAyCmmFxMkZ4DVKyDRl5rM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XC8oj9MzZk4ueI7/RO34ki6TM5wOXGR2dhZ1uDo5V3k3f/XPlQFA8HhY6RmF0IBHf7Tj3YXFQdctNFKu1TidGpqSDxaZJFAHiLOgk5+lDpTrdqjZFuB5RoJmsXK5WUROpRHV9tqysbUL+sowKP5xVAjjPudam2CgF9yBsLSz47Y= 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=EQnaDgkf; arc=none smtp.client-ip=209.85.214.172 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="EQnaDgkf" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2212a930001so4352205ad.0 for ; Wed, 19 Feb 2025 12:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739997276; x=1740602076; 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=DQWzcKLc7oSM5BCdhcaEoI50j67Udj+50400HTzw0gI=; b=EQnaDgkfk0WRsSBUEEU+GNAfpCzLHo3t3yMTWtpEDdwInVbcl4QSCxx/09AySJBLJB /ZOfpQdZiY++dpx/EpnlCJ7m6GwnikbFDzX82tJi2YuOhuA8ai/QOiN/q2wbm+lrwieE xmGX1G1vKuKvgJaNAAmva5DKrKy/3pqKXlrjdYjTAuEpSxZSw+CBdJvudIqOHwgFQ0ZW pXiE5FcjiA4vtn/1f08VITdz4Y3/8jatJvj7QiPCihePZc+A+Mh4rUPapFFyiDQz8Xz0 Ca1JZqgZ6UaKI3bRPfe8RCwdbY2190rQV5f/TaiX+PYXGvtblWHeJqKcFEp69RSeLtKq n1oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739997276; x=1740602076; 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=DQWzcKLc7oSM5BCdhcaEoI50j67Udj+50400HTzw0gI=; b=X41el/7LEVNwSO78hTd+GkJtCc88e0FLRiOPIx5eHP2sqZZD4UD7H9ekAWyI0jMocc e7FqJkSTUhd3D867XZ2WyRyEBgJVMR5ydtSFUJQqSTl+zSYhHWocxt+EdB9C0DLH6fEh /GjGdSPNHSiGvSkWKlZXMuhE29LPnLuD0A9V1LVjS4CubTwYA1v45d/7sQABbMoIgL8X s7msDS3aq0n7AR4QO1iLT7pydwWKhhkIo+z8guKxg4SzfU3os4F3uR2U1DFE7ssX+8Uc B7CUSWkkY3BOpA3ZndgHcT9pQdBC0eLdcGr2fixLhRrWs1bwd/HldE5ArPlSoZKs6yB/ Ly1g== X-Forwarded-Encrypted: i=1; AJvYcCU2qxGNkDRoC/Nt7FMDOr1Z5LHujsKzP6ImqOlB2wtjUlX3diHvob2Xpsv9V8J2VL4SO8U=@vger.kernel.org X-Gm-Message-State: AOJu0YybdHz7Dssf5pWzujP1DSj2Ean+JrYKFlyU4YDJiLglKE2icchD KtKYBi3vcg5fSIIsskH6Wdi3N5dPLBa1g9UiTMOY/Sj5rWeOipZd X-Gm-Gg: ASbGncunDByhEBYjhab1TldRCjj7iULmUoaKqWCz7mCFU2udUnOkFG9CMBlo8bAUjG7 /7/wQ3J/vCcZtxTvpOX5XZQDkzaiwpOSwFY2gTg1EqxiS/CnHd71k0z9omS9uk9xNGF9XhNUl6p bMoRRPQ0IkSGHJvBxMk09tHyJ23MmaEoIrH3eUdlUxdeuQb+6Lz7bCwIHsaa00vY9hyzXJEb5BK dih102cnAHiDtnNcKYap+/5iHPqj7irPhLCTsLxMZrIh3KnsUge8G5PG7PeY5zKaVB7h9acFOU7 yUSXGbchQ+qs0SelmVQVi66PBJr0xQOPpHGHKqkL X-Google-Smtp-Source: AGHT+IHus3iBHNx6C5HYQTs40qef+rt1DCFieOONEipVYTphUELbObPfZzXGJwp41c7xJMAG7AhgwA== X-Received: by 2002:a17:902:e544:b0:220:ff3f:6cba with SMTP id d9443c01a7336-221040ab941mr335494065ad.38.1739997276219; Wed, 19 Feb 2025 12:34:36 -0800 (PST) Received: from archlinux.plaksha.edu.in ([202.164.41.66]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53499dasm107791355ad.12.2025.02.19.12.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 12:34:35 -0800 (PST) From: Usman Akinyemi To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com Subject: [PATCH v2 12/12] builtin/checkout-index: stop using `the_repository` Date: Thu, 20 Feb 2025 02:03:00 +0530 Message-ID: <20250219203349.787173-13-usmanakinyemi202@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219203349.787173-1-usmanakinyemi202@gmail.com> References: <20250214230210.1460111-1-usmanakinyemi202@gmail.com> <20250219203349.787173-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, without having to consult much of the configuration file. 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 ++++++++++++++++++++-------------------- 1 file changed, 21 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; }