From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH 1/2] reflog: drop usage of global variables
Date: Fri, 07 Mar 2025 12:17:25 +0100 [thread overview]
Message-ID: <20250307-493-add-command-to-purge-reflog-entries-v1-1-84ab8529cf9e@gmail.com> (raw)
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
next prev parent reply other threads:[~2025-03-07 11:17 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 11:17 [PATCH 0/2] EDITME: cover title for 493-add-command-to-purge-reflog-entries Karthik Nayak
2025-03-07 11:17 ` Karthik Nayak [this message]
2025-03-07 21:19 ` [PATCH 1/2] reflog: drop usage of global variables Junio C Hamano
2025-03-10 11:41 ` Karthik Nayak
2025-03-10 15:24 ` Junio C Hamano
2025-03-13 13:30 ` Karthik Nayak
2025-03-07 11:17 ` [PATCH 2/2] reflog: implement subcommand to drop reflogs Karthik Nayak
2025-03-07 11:50 ` Patrick Steinhardt
2025-03-07 12:53 ` Karthik Nayak
2025-03-07 12:59 ` Patrick Steinhardt
2025-03-07 13:28 ` Karthik Nayak
2025-03-07 13:28 ` Karthik Nayak
2025-03-07 21:28 ` Junio C Hamano
2025-03-10 11:28 ` Karthik Nayak
2025-03-10 7:39 ` [PATCH 0/2] EDITME: cover title for 493-add-command-to-purge-reflog-entries Kristoffer Haugsbakk
2025-03-10 12:34 ` Karthik Nayak
2025-03-10 15:28 ` Junio C Hamano
2025-03-10 12:36 ` [PATCH v2] reflog: implement subcommand to drop reflogs Karthik Nayak
2025-03-12 7:15 ` Patrick Steinhardt
2025-03-13 14:24 ` Karthik Nayak
2025-03-13 14:45 ` Patrick Steinhardt
2025-03-14 8:40 ` [PATCH v3 0/2] " Karthik Nayak
2025-03-14 8:40 ` [PATCH v3 1/2] reflog: improve error for when reflog is not found Karthik Nayak
2025-03-14 8:40 ` [PATCH v3 2/2] reflog: implement subcommand to drop reflogs Karthik Nayak
2025-03-18 14:01 ` Christian Couder
2025-03-18 17:44 ` Junio C Hamano
2025-03-19 8:17 ` Christian Couder
2025-03-19 9:06 ` Karthik Nayak
2025-03-18 15:56 ` Toon Claes
2025-03-19 9:16 ` Karthik Nayak
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=20250307-493-add-command-to-purge-reflog-entries-v1-1-84ab8529cf9e@gmail.com \
--to=karthik.188@gmail.com \
--cc=git@vger.kernel.org \
/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).