Thread (50 messages) 50 messages, 3 authors, 2025-03-07
STALE494d

[PATCH v2 10/12] builtin/for-each-ref: refactor `cmd_for_each_ref()`

From: Usman Akinyemi <hidden>
Date: 2025-02-19 20:34:30
Subsystem: the rest · Maintainer: Linus Torvalds

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 [off-list ref]
Signed-off-by: Usman Akinyemi <redacted>
---
 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;
-- 
2.48.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help