From: "Shashank S via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>,
Christian Couder <christian.couder@gmail.com>,
Siddharth Asthana <siddharthasthana31@gmail.com>,
Usman Akinyemi <usmanakinyemi202@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>, Shashank S <shashu8660@gmail.com>,
Shashank S <shashu8660@gmail.com>,
Shashank S Mogaveera <shashu8660@gmail.com>
Subject: [PATCH v3] prune-packed: remove USE_THE_REPOSITORY_VARIABLE
Date: Sat, 24 Oct 2026 09:22:21 +0000 [thread overview]
Message-ID: <pull.2266.v3.git.1792833741913.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2266.git.1792341073005.gitgitgadget@gmail.com>
From: Shashank S Mogaveera <shashu8660@gmail.com>
The prune_packed_objects() function uses the global
the_repository variable. To help with the libification effort,
change this function so it takes a 'struct repository' pointer
as an argument instead.
The function for_each_loose_file_in_source() uses a callback
that only takes a single 'void *data' pointer. This means we
cannot pass both the repository pointer and the 'opts' integer
at the same time. To fix this, create a new 'struct prune_data'
to hold both of them together, and update the prune_subdir() and
prune_object() callbacks to read from this new struct.
Update the builtins that call this function to pass their local 'repo'
variables. We can safely remove the UNUSED macro from them because
while 'repo' may be NULL if the command is invoked with "-h", the
call to parse_options() will give the short help and exit before the
dereference occurs.
Finally, drop the USE_THE_REPOSITORY_VARIABLE macro from
prune-packed.c.
Signed-off-by: Shashank S Mogaveera <shashu8660@gmail.com>
---
[Outreachy] prune-packed: remove use_the_repository_variable
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2266%2Fshashu8660%2Foutreachy2-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2266/shashu8660/outreachy2-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/2266
Range-diff vs v2:
1: 6b583e1d46 ! 1: 0b474e3433 [Outreachy Patch] prune-packed: remove USE_THE_REPOSITORY_VARIABLE
@@ Metadata
Author: Shashank S Mogaveera <shashu8660@gmail.com>
## Commit message ##
- [Outreachy Patch] prune-packed: remove USE_THE_REPOSITORY_VARIABLE
+ prune-packed: remove USE_THE_REPOSITORY_VARIABLE
The prune_packed_objects() function uses the global
the_repository variable. To help with the libification effort,
@@ Commit message
to hold both of them together, and update the prune_subdir() and
prune_object() callbacks to read from this new struct.
- Update the builtins that call this function (builtin/prune-packed.c,
- builtin/prune.c, and builtin/repack.c) to pass their local 'repo'
+ Update the builtins that call this function to pass their local 'repo'
variables. We can safely remove the UNUSED macro from them because
- these commands are all declared with the RUN_SETUP flag in git.c,
- which guarantees that the 'repo' pointer will never be NULL.
+ while 'repo' may be NULL if the command is invoked with "-h", the
+ call to parse_options() will give the short help and exit before the
+ dereference occurs.
Finally, drop the USE_THE_REPOSITORY_VARIABLE macro from
prune-packed.c.
@@ builtin/prune-packed.c: int cmd_prune_packed(int argc,
## builtin/prune.c ##
@@ builtin/prune.c: int cmd_prune(int argc,
- for_each_loose_file_in_source(repo->objects->sources,
+ for_each_loose_file_in_source(repo->objects->source,
prune_object, prune_cruft, prune_subdir, &revs);
- prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);
@@ prune-packed.c
-void prune_packed_objects(int opts)
+void prune_packed_objects(struct repository *r, int opts)
{
-+ struct prune_data cb_data = {
-+ .r = r,
-+ .opts = opts
-+ };
-+
- if (opts & PRUNE_PACKED_VERBOSE)
+- if (opts & PRUNE_PACKED_VERBOSE)
- progress = start_delayed_progress(the_repository,
-+ progress = start_delayed_progress(r,
- _("Removing duplicate objects"), 256);
+- _("Removing duplicate objects"), 256);
++ struct prune_data cb_data = {
++ .r = r,
++ .opts = opts
++ };
++
++ if (opts & PRUNE_PACKED_VERBOSE)
++ progress = start_delayed_progress(r,
++ _("Removing duplicate objects"), 256);
-- for_each_loose_file_in_source(the_repository->objects->sources,
+- for_each_loose_file_in_source(the_repository->objects->source,
- prune_object, NULL, prune_subdir, &opts);
-+ for_each_loose_file_in_source(r->objects->sources,
-+ prune_object, NULL, prune_subdir, &cb_data);
++ for_each_loose_file_in_source(r->objects->source,
++ prune_object, NULL, prune_subdir, &cb_data);
- /* Ensure we show 100% before finishing progress */
- display_progress(progress, 256);
+- /* Ensure we show 100% before finishing progress */
+- display_progress(progress, 256);
+- stop_progress(&progress);
++ /* Ensure we show 100% before finishing progress */
++ display_progress(progress, 256);
++ stop_progress(&progress);
+ }
## prune-packed.h ##
@@
builtin/prune-packed.c | 4 ++--
builtin/prune.c | 2 +-
builtin/repack.c | 2 +-
prune-packed.c | 42 +++++++++++++++++++++++++-----------------
prune-packed.h | 4 +++-
5 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/builtin/prune-packed.c b/builtin/prune-packed.c
index 4d63f26b0a..d44e7f81d4 100644
--- a/builtin/prune-packed.c
+++ b/builtin/prune-packed.c
@@ -11,7 +11,7 @@ static const char * const prune_packed_usage[] = {
int cmd_prune_packed(int argc,
const char **argv,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
int opts = isatty(2) ? PRUNE_PACKED_VERBOSE : 0;
const struct option prune_packed_options[] = {
@@ -30,6 +30,6 @@ int cmd_prune_packed(int argc,
prune_packed_usage,
prune_packed_options);
- prune_packed_objects(opts);
+ prune_packed_objects(repo, opts);
return 0;
}
diff --git a/builtin/prune.c b/builtin/prune.c
index 97f4c1418b..d543c3ad2d 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -201,7 +201,7 @@ int cmd_prune(int argc,
for_each_loose_file_in_source(repo->objects->source,
prune_object, prune_cruft, prune_subdir, &revs);
- prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);
+ prune_packed_objects(repo, show_only ? PRUNE_PACKED_DRY_RUN : 0);
remove_temporary_files(repo_get_object_directory(repo));
s = mkpathdup("%s/pack", repo_get_object_directory(repo));
remove_temporary_files(s);
diff --git a/builtin/repack.c b/builtin/repack.c
index 5d06872d77..585cdd3d1d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -757,7 +757,7 @@ int cmd_repack(int argc,
wrote_incremental_midx);
if (show_progress)
opts |= PRUNE_PACKED_VERBOSE;
- prune_packed_objects(opts);
+ prune_packed_objects(repo, opts);
if (!keep_unreachable &&
(!(pack_everything & LOOSEN_UNREACHABLE) ||
diff --git a/prune-packed.c b/prune-packed.c
index b6749b8d13..e02d5d7a01 100644
--- a/prune-packed.c
+++ b/prune-packed.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "gettext.h"
#include "object-file.h"
@@ -8,42 +6,52 @@
#include "prune-packed.h"
#include "repository.h"
+struct prune_data {
+ struct repository *r;
+ int opts;
+};
+
static struct progress *progress;
static int prune_subdir(unsigned int nr, const char *path, void *data)
{
- int *opts = data;
+ struct prune_data *d = data;
display_progress(progress, nr + 1);
- if (!(*opts & PRUNE_PACKED_DRY_RUN))
+ if (!(d->opts & PRUNE_PACKED_DRY_RUN))
rmdir(path);
return 0;
}
static int prune_object(const struct object_id *oid, const char *path,
- void *data)
+ void *data)
{
- int *opts = data;
+ struct prune_data *d = data;
- if (!has_object_pack(the_repository, oid))
+ if (!has_object_pack(d->r, oid))
return 0;
- if (*opts & PRUNE_PACKED_DRY_RUN)
+ if (d->opts & PRUNE_PACKED_DRY_RUN)
printf("rm -f %s\n", path);
else
unlink_or_warn(path);
return 0;
}
-void prune_packed_objects(int opts)
+void prune_packed_objects(struct repository *r, int opts)
{
- if (opts & PRUNE_PACKED_VERBOSE)
- progress = start_delayed_progress(the_repository,
- _("Removing duplicate objects"), 256);
+ struct prune_data cb_data = {
+ .r = r,
+ .opts = opts
+ };
+
+ if (opts & PRUNE_PACKED_VERBOSE)
+ progress = start_delayed_progress(r,
+ _("Removing duplicate objects"), 256);
- for_each_loose_file_in_source(the_repository->objects->source,
- prune_object, NULL, prune_subdir, &opts);
+ for_each_loose_file_in_source(r->objects->source,
+ prune_object, NULL, prune_subdir, &cb_data);
- /* Ensure we show 100% before finishing progress */
- display_progress(progress, 256);
- stop_progress(&progress);
+ /* Ensure we show 100% before finishing progress */
+ display_progress(progress, 256);
+ stop_progress(&progress);
}
diff --git a/prune-packed.h b/prune-packed.h
index 936fa9df23..9ec7ff0d60 100644
--- a/prune-packed.h
+++ b/prune-packed.h
@@ -1,9 +1,11 @@
#ifndef PRUNE_PACKED_H
#define PRUNE_PACKED_H
+struct repository;
+
#define PRUNE_PACKED_DRY_RUN 01
#define PRUNE_PACKED_VERBOSE 02
-void prune_packed_objects(int);
+void prune_packed_objects(struct repository *r, int opts);
#endif
base-commit: 7e34d8174dcda3435d1404c9a30bef46afe6c13e
--
gitgitgadget
next prev parent reply other threads:[~2026-10-24 9:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 16:31 [PATCH] prune-packed: remove USE_THE_REPOSITORY_VARIABLE Shashank S via GitGitGadget
2026-10-19 7:09 ` Patrick Steinhardt
2026-10-19 16:38 ` Shashank S
2026-10-19 21:05 ` Junio C Hamano
2026-10-20 16:27 ` Shashank S
2026-10-19 16:53 ` [PATCH v2] [Outreachy Patch] " Shashank S via GitGitGadget
2026-10-23 7:02 ` Patrick Steinhardt
2026-10-24 4:16 ` Shashank S
2026-10-24 9:22 ` Shashank S via GitGitGadget [this message]
2026-10-26 8:38 ` [PATCH v3] " Patrick Steinhardt
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=pull.2266.v3.git.1792833741913.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kaartic.sivaraam@gmail.com \
--cc=ps@pks.im \
--cc=shashu8660@gmail.com \
--cc=siddharthasthana31@gmail.com \
--cc=usmanakinyemi202@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