From: Usman Akinyemi <usmanakinyemi202@gmail.com>
To: git@vger.kernel.org
Cc: chriscool@tuxfamily.org, christian.couder@gmail.com,
johncai86@gmail.com, ps@pks.im, shejialuo@gmail.com
Subject: [PATCH 7/7] builtin/checkout-index.c: stop using `the_repository`
Date: Sat, 15 Feb 2025 04:27:23 +0530 [thread overview]
Message-ID: <20250214230210.1460111-8-usmanakinyemi202@gmail.com> (raw)
In-Reply-To: <20250214230210.1460111-1-usmanakinyemi202@gmail.com>
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.
Let's pass `repository` argument to `checkout_all()` and `checkout_file()`
functions to remove their dependency on the global `the_repository` variable.
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
---
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 <the_repository->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;
}
--
2.48.1
next prev parent reply other threads:[~2025-02-14 23:02 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 22:57 [PATCH 0/7][Outreachy] stop using the_repository global variable Usman Akinyemi
2025-02-14 22:57 ` [PATCH 1/7] builtin/verify-tag: stop using `the_repository` Usman Akinyemi
2025-02-17 6:55 ` Patrick Steinhardt
2025-02-17 10:05 ` Usman Akinyemi
2025-02-17 10:22 ` Patrick Steinhardt
2025-02-17 10:42 ` Usman Akinyemi
2025-02-17 15:47 ` Patrick Steinhardt
2025-02-14 22:57 ` [PATCH 2/7] builtin/verify-commit.c: " Usman Akinyemi
2025-02-16 5:32 ` shejialuo
2025-02-17 8:55 ` Usman Akinyemi
2025-02-14 22:57 ` [PATCH 3/7] builtin/send-pack.c: " Usman Akinyemi
2025-02-14 22:57 ` [PATCH 4/7] builtin/pack-refs: " Usman Akinyemi
2025-02-14 22:57 ` [PATCH 5/7] builtin/ls-files: " Usman Akinyemi
2025-02-17 6:55 ` Patrick Steinhardt
2025-02-17 8:57 ` Usman Akinyemi
2025-02-14 22:57 ` [PATCH 6/7] builtin/for-each-ref: " Usman Akinyemi
2025-02-14 22:57 ` Usman Akinyemi [this message]
2025-02-16 5:41 ` [PATCH 0/7][Outreachy] stop using the_repository global variable shejialuo
2025-02-17 8:56 ` Usman Akinyemi
2025-02-19 20:32 ` [PATCH v2 00/12][Outreachy] " Usman Akinyemi
2025-02-19 20:32 ` [PATCH v2 01/12] builtin/verify-tag: refactor `cmd_verify_tag()` Usman Akinyemi
2025-02-20 15:32 ` Junio C Hamano
2025-02-19 20:32 ` [PATCH v2 02/12] builtin/verify-tag: stop using `the_repository` Usman Akinyemi
2025-02-20 15:43 ` Junio C Hamano
2025-02-27 17:56 ` Usman Akinyemi
2025-02-27 22:39 ` Junio C Hamano
2025-02-19 20:32 ` [PATCH v2 03/12] builtin/verify-commit: refactor `cmd_verify_commit()` Usman Akinyemi
2025-02-19 20:32 ` [PATCH v2 04/12] builtin/verify-commit: stop using `the_repository` Usman Akinyemi
2025-02-19 20:32 ` [PATCH v2 05/12] builtin/send-pack: refactor `cmd_send_pack()` Usman Akinyemi
2025-02-19 20:32 ` [PATCH v2 06/12] builtin/send-pack: stop using `the_repository` Usman Akinyemi
2025-02-19 20:32 ` [PATCH v2 07/12] builtin/pack-refs: refactor `cmd_pack_refs()` Usman Akinyemi
2025-02-19 20:32 ` [PATCH v2 08/12] builtin/pack-refs: stop using `the_repository` Usman Akinyemi
2025-02-19 20:32 ` [PATCH v2 09/12] builtin/ls-files: " Usman Akinyemi
2025-02-19 20:32 ` [PATCH v2 10/12] builtin/for-each-ref: refactor `cmd_for_each_ref()` Usman Akinyemi
2025-02-19 20:32 ` [PATCH v2 11/12] builtin/for-each-ref: stop using `the_repository` Usman Akinyemi
2025-02-19 20:33 ` [PATCH v2 12/12] builtin/checkout-index: " Usman Akinyemi
2025-03-06 14:35 ` [Outreachy PATCH v3 0/8] stop using the_repository global variable Usman Akinyemi
2025-03-06 14:35 ` [PATCH v3 1/8] config: teach repo_config to allow `repo` to be NULL Usman Akinyemi
2025-03-06 17:53 ` Junio C Hamano
2025-03-07 1:33 ` Usman Akinyemi
2025-03-07 10:37 ` Phillip Wood
2025-03-06 14:35 ` [PATCH v3 2/8] builtin/verify-tag: stop using `the_repository` Usman Akinyemi
2025-03-06 17:56 ` Junio C Hamano
2025-03-06 14:35 ` [PATCH v3 3/8] builtin/verify-commit: " Usman Akinyemi
2025-03-06 14:35 ` [PATCH v3 4/8] builtin/send-pack: " Usman Akinyemi
2025-03-06 14:35 ` [PATCH v3 5/8] builtin/pack-refs: " Usman Akinyemi
2025-03-06 14:35 ` [PATCH v3 6/8] builtin/ls-files: " Usman Akinyemi
2025-03-06 17:59 ` Junio C Hamano
2025-03-06 14:35 ` [PATCH v3 7/8] builtin/for-each-ref: " Usman Akinyemi
2025-03-06 14:35 ` [PATCH v3 8/8] builtin/checkout-index: " Usman Akinyemi
2025-03-06 18:18 ` Junio C Hamano
2025-03-07 1:15 ` Usman Akinyemi
2025-03-07 14:15 ` Junio C Hamano
2025-03-07 19:41 ` Usman Akinyemi
2025-03-07 23:34 ` [Outreachy PATCH v4 0/8] stop using the_repository global variable Usman Akinyemi
2025-03-07 23:35 ` [PATCH v4 1/8] config: teach repo_config to allow `repo` to be NULL Usman Akinyemi
2025-03-07 23:35 ` [PATCH v4 2/8] builtin/verify-tag: stop using `the_repository` Usman Akinyemi
2025-03-07 23:35 ` [PATCH v4 3/8] builtin/verify-commit: " Usman Akinyemi
2025-03-07 23:35 ` [PATCH v4 4/8] builtin/send-pack: " Usman Akinyemi
2025-03-07 23:35 ` [PATCH v4 5/8] builtin/pack-refs: " Usman Akinyemi
2025-03-07 23:35 ` [PATCH v4 6/8] builtin/ls-files: " Usman Akinyemi
2025-03-07 23:35 ` [PATCH v4 7/8] builtin/for-each-ref: " Usman Akinyemi
2025-03-07 23:35 ` [PATCH v4 8/8] builtin/checkout-index: " Usman Akinyemi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250214230210.1460111-8-usmanakinyemi202@gmail.com \
--to=usmanakinyemi202@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=johncai86@gmail.com \
--cc=ps@pks.im \
--cc=shejialuo@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).