git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] reflog: drop usage of global variables

From
Karthik Nayak <karthik.188@gmail.com>
Date
Mar 7, 2025, 11:17 UTC
Message-ID
<20250307-493-add-command-to-purge-reflog-entries-v1-1-84ab8529cf9e@gmail.com>
In-Reply-To
<20250307-493-add-command-to-purge-reflog-entries-v1-0-84ab8529cf9e@gmail.com>

The 'builtin/reflog.c' file uses the 'the_repository' global variable directly and also via 'git_config()'. Since this is a builtin command which has access to the 'struct repository', drop usage of the global variable and use the available repository struct.

With this, remove the 'USE_THE_REPOSITORY_VARIABLE' macro from the file.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 builtin/reflog.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 95f264989b..f92258f6b6 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "builtin.h"
 #include "config.h"
 #include "gettext.h"
@@ -236,7 +234,7 @@ static int expire_total_callback(const struct option *opt,
 }
 
 static int cmd_reflog_show(int argc, const char **argv, const char *prefix,
-			   struct repository *repo UNUSED)
+			   struct repository *repo)
 {
 	struct option options[] = {
 		OPT_END()
@@ -246,7 +244,7 @@ static int cmd_reflog_show(int argc, const char **argv, const char *prefix,
 		      PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 |
 		      PARSE_OPT_KEEP_UNKNOWN_OPT);
 
-	return cmd_log_reflog(argc, argv, prefix, the_repository);
+	return cmd_log_reflog(argc, argv, prefix, repo);
 }
 
 static int show_reflog(const char *refname, void *cb_data UNUSED)
@@ -256,7 +254,7 @@ static int show_reflog(const char *refname, void *cb_data UNUSED)
 }
 
 static int cmd_reflog_list(int argc, const char **argv, const char *prefix,
-			   struct repository *repo UNUSED)
+			   struct repository *repo)
 {
 	struct option options[] = {
 		OPT_END()
@@ -268,13 +266,13 @@ static int cmd_reflog_list(int argc, const char **argv, const char *prefix,
 		return error(_("%s does not accept arguments: '%s'"),
 			     "list", argv[0]);
 
-	ref_store = get_main_ref_store(the_repository);
+	ref_store = get_main_ref_store(repo);
 
 	return refs_for_each_reflog(ref_store, show_reflog, NULL);
 }
 
 static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
-			     struct repository *repo UNUSED)
+			     struct repository *repo)
 {
 	struct cmd_reflog_expire_cb cmd = { 0 };
 	timestamp_t now = time(NULL);
@@ -310,7 +308,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 
 	default_reflog_expire_unreachable = now - 30 * 24 * 3600;
 	default_reflog_expire = now - 90 * 24 * 3600;
-	git_config(reflog_expire_config, NULL);
+	repo_config(repo, reflog_expire_config, NULL);
 
 	save_commit_buffer = 0;
 	do_all = status = 0;
@@ -332,7 +330,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 	if (cmd.stalefix) {
 		struct rev_info revs;
 
-		repo_init_revisions(the_repository, &revs, prefix);
+		repo_init_revisions(repo, &revs, prefix);
 		revs.do_not_die_on_missing_objects = 1;
 		revs.ignore_missing = 1;
 		revs.ignore_missing_links = 1;
@@ -368,7 +366,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 			};
 
 			set_reflog_expiry_param(&cb.cmd,  item->string);
-			status |= refs_reflog_expire(get_main_ref_store(the_repository),
+			status |= refs_reflog_expire(get_main_ref_store(repo),
 						     item->string, flags,
 						     reflog_expiry_prepare,
 						     should_prune_fn,
@@ -382,12 +380,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 		char *ref;
 		struct expire_reflog_policy_cb cb = { .cmd = cmd };
 
-		if (!repo_dwim_log(the_repository, argv[i], strlen(argv[i]), NULL, &ref)) {
+		if (!repo_dwim_log(repo, argv[i], strlen(argv[i]), NULL, &ref)) {
 			status |= error(_("%s points nowhere!"), argv[i]);
 			continue;
 		}
 		set_reflog_expiry_param(&cb.cmd, ref);
-		status |= refs_reflog_expire(get_main_ref_store(the_repository),
+		status |= refs_reflog_expire(get_main_ref_store(repo),
 					     ref, flags,
 					     reflog_expiry_prepare,
 					     should_prune_fn,
@@ -430,7 +428,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix,
 }
 
 static int cmd_reflog_exists(int argc, const char **argv, const char *prefix,
-			     struct repository *repo UNUSED)
+			     struct repository *repo)
 {
 	struct option options[] = {
 		OPT_END()
@@ -445,7 +443,7 @@ static int cmd_reflog_exists(int argc, const char **argv, const char *prefix,
 	refname = argv[0];
 	if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
 		die(_("invalid ref format: %s"), refname);
-	return !refs_reflog_exists(get_main_ref_store(the_repository),
+	return !refs_reflog_exists(get_main_ref_store(repo),
 				   refname);
 }
 
-- 
2.48.1
Previous: Karthik NayakNext: Junio C Hamano
Message 2 of 30 in “EDITME: cover title for 493-add-command-to-purge-reflog-entries”
  1. 0/2 EDITME: cover title for 493-add-command-to-purge-reflog-entriesKarthik Nayak, Mar 7, 2025
  2. 1/2 reflog: drop usage of global variablesKarthik Nayak, Mar 7, 2025
  3. Junio C HamanoMar 7, 2025
  4. Karthik NayakMar 10, 2025
  5. Junio C HamanoMar 10, 2025
  6. Karthik NayakMar 13, 2025
  7. 2/2 reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 7, 2025
  8. Patrick SteinhardtMar 7, 2025
  9. Karthik NayakMar 7, 2025
  10. Patrick SteinhardtMar 7, 2025
  11. Karthik NayakMar 7, 2025
  12. Karthik NayakMar 7, 2025
  13. Junio C HamanoMar 7, 2025
  14. Karthik NayakMar 10, 2025
  15. Kristoffer HaugsbakkMar 10, 2025
  16. Karthik NayakMar 10, 2025
  17. Junio C HamanoMar 10, 2025
  18. reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 10, 2025
  19. Patrick SteinhardtMar 12, 2025
  20. Karthik NayakMar 13, 2025
  21. Patrick SteinhardtMar 13, 2025
  22. 0/2 reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 14, 2025
  23. 1/2 reflog: improve error for when reflog is not foundKarthik Nayak, Mar 14, 2025
  24. 2/2 reflog: implement subcommand to drop reflogsKarthik Nayak, Mar 14, 2025
  25. Christian CouderMar 18, 2025
  26. Junio C HamanoMar 18, 2025
  27. Christian CouderMar 19, 2025
  28. Karthik NayakMar 19, 2025
  29. Toon ClaesMar 18, 2025
  30. Karthik NayakMar 19, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.