{"thread":{"id":"63600","subject":"[GSOC PATCH 0/2] builtin/prune: remove dependency on global variables and 'the_repository'","startedAt":"2025-06-08T01:07:29Z","lastAt":"2025-07-08T13:52:26Z","messageCount":29,"participants":["Ayush Chandekar","shejialuo","Patrick Steinhardt","Junio C Hamano","Usman Akinyemi","Ben Knoble"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"519899","messageId":"cover.1749343601.git.ayu.chandekar@gmail.com","threadId":"63600","inReplyTo":null,"subject":"[GSOC PATCH 0/2] builtin/prune: remove dependency on global variables and 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-08T01:06:33Z","receivedAt":"2025-06-08T01:07:29Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"The aim of this patch series is to remove the definition '#define USE_THE_REPOSITORY_VARIABLE' \nfrom \"builtin/prune.c\" by removing global variables and the global 'the_repository'.\n\nThis patch series contains two patches:\n\n1 - Move the global variable 'repository_format_precious_objects' into 'struct repository' \nand update all affected code paths accordingly.\n\n2 - Remove the dependency of 'the_repository' in \"builtin/prunce.c\", allowing the removal of \nthe definition.\n\nAyush Chandekar (2):\n  repository: move 'repository_format_precious_objects' to repo scope\n  builtin/prune: stop depending on 'the_repository'\n\n builtin/gc.c     |  2 +-\n builtin/prune.c  | 25 ++++++++++++-------------\n builtin/repack.c |  2 +-\n environment.c    |  1 -\n environment.h    |  2 --\n repository.c     |  1 +\n repository.h     |  1 +\n setup.c          |  5 ++++-\n 8 files changed, 20 insertions(+), 19 deletions(-)\n\n-- \n2.49.0\n\n"},{"id":"519900","messageId":"6ffb071295272a1d5311f52d8d2015d0aec7e71f.1749343601.git.ayu.chandekar@gmail.com","threadId":"63600","inReplyTo":"cover.1749343601.git.ayu.chandekar@gmail.com","subject":"[GSOC PATCH 1/2] repository: move 'repository_format_precious_objects' to repo scope","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-08T01:06:34Z","receivedAt":"2025-06-08T01:07:37Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"The 'extensions.preciousObjects' settings when set true, prevents\noperations that might drop objects from the object storage.\nThis setting is populated in the global variable\n'repository_format_precious_objects'.\nMove this global variable to repo scope by adding it to 'struct\nrepository' and also refactor all the occurences accordingly.\n\nThis change is part of an ongoing effort to eliminate global variables,\nimprove modularity and help libify the codebase.\n\nSigned-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n---\n builtin/gc.c     | 2 +-\n builtin/prune.c  | 2 +-\n builtin/repack.c | 2 +-\n environment.c    | 1 -\n environment.h    | 2 --\n repository.c     | 1 +\n repository.h     | 1 +\n setup.c          | 5 ++++-\n 8 files changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex e33ba946e4..764f123b1c 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -976,7 +976,7 @@ int cmd_gc(int argc,\n \n \tgc_before_repack(&opts, &cfg);\n \n-\tif (!repository_format_precious_objects) {\n+\tif (!the_repository->repository_format_precious_objects) {\n \t\tstruct child_process repack_cmd = CHILD_PROCESS_INIT;\n \n \t\trepack_cmd.git_cmd = 1;\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex e930caa0c0..dab3c19b6f 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -177,7 +177,7 @@ int cmd_prune(int argc,\n \n \targc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n \n-\tif (repository_format_precious_objects)\n+\tif (the_repository->repository_format_precious_objects)\n \t\tdie(_(\"cannot prune in a precious-objects repo\"));\n \n \twhile (argc--) {\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 59214dbdfd..e1174a7a53 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -1235,7 +1235,7 @@ int cmd_repack(int argc,\n \tpo_args.depth = xstrdup_or_null(opt_depth);\n \tpo_args.threads = xstrdup_or_null(opt_threads);\n \n-\tif (delete_redundant && repository_format_precious_objects)\n+\tif (delete_redundant && the_repository->repository_format_precious_objects)\n \t\tdie(_(\"cannot delete packs in a precious-objects repo\"));\n \n \tdie_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), \"-A\",\ndiff --git a/environment.c b/environment.c\nindex c61d773e7e..f3d318f1a0 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -37,7 +37,6 @@ int ignore_case;\n int assume_unchanged;\n int is_bare_repository_cfg = -1; /* unspecified */\n int warn_on_object_refname_ambiguity = 1;\n-int repository_format_precious_objects;\n char *git_commit_encoding;\n char *git_log_output_encoding;\n char *apply_default_whitespace;\ndiff --git a/environment.h b/environment.h\nindex 3d98461a06..bee1ffb91d 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -190,8 +190,6 @@ extern enum object_creation_mode object_creation_mode;\n \n extern int grafts_keep_true_parents;\n \n-extern int repository_format_precious_objects;\n-\n const char *get_log_output_encoding(void);\n const char *get_commit_output_encoding(void);\n \ndiff --git a/repository.c b/repository.c\nindex 9b3d6665fc..62709d1c91 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -284,6 +284,7 @@ int repo_init(struct repository *repo,\n \trepo_set_ref_storage_format(repo, format.ref_storage_format);\n \trepo->repository_format_worktree_config = format.worktree_config;\n \trepo->repository_format_relative_worktrees = format.relative_worktrees;\n+\trepo->repository_format_precious_objects = format.precious_objects;\n \n \t/* take ownership of format.partial_clone */\n \trepo->repository_format_partial_clone = format.partial_clone;\ndiff --git a/repository.h b/repository.h\nindex c4c92b2ab9..ad23a243c6 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -151,6 +151,7 @@ struct repository {\n \t/* Configurations */\n \tint repository_format_worktree_config;\n \tint repository_format_relative_worktrees;\n+\tint repository_format_precious_objects;\n \n \t/* Indicate if a repository has a different 'commondir' from 'gitdir' */\n \tunsigned different_commondir:1;\ndiff --git a/setup.c b/setup.c\nindex f93bd6a24a..3ea01e9331 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -753,7 +753,8 @@ static int check_repository_format_gently(const char *gitdir, struct repository_\n \t\tdie(\"%s\", err.buf);\n \t}\n \n-\trepository_format_precious_objects = candidate->precious_objects;\n+\tthe_repository->repository_format_precious_objects = candidate->precious_objects;\n+\n \tstring_list_clear(&candidate->unknown_extensions, 0);\n \tstring_list_clear(&candidate->v1_only_extensions, 0);\n \n@@ -1864,6 +1865,8 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\tthe_repository->repository_format_partial_clone =\n \t\t\t\trepo_fmt.partial_clone;\n \t\t\trepo_fmt.partial_clone = NULL;\n+\t\t\tthe_repository->repository_format_precious_objects =\n+\t\t\t\trepo_fmt.precious_objects;\n \t\t}\n \t}\n \t/*\n-- \n2.49.0\n\n"},{"id":"519901","messageId":"9b274efd7dfde90990ace66bfbe5f7e3b6ce30d1.1749343601.git.ayu.chandekar@gmail.com","threadId":"63600","inReplyTo":"cover.1749343601.git.ayu.chandekar@gmail.com","subject":"[GSOC PATCH 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-08T01:06:35Z","receivedAt":"2025-06-08T01:07:46Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"Refactor builtin/prune.c to remove the dependency on the global\n'the_repository'. Replace all the occurrences of 'the_repository' with\nrepo and thus remove the definition '#define\nUSE_THE_REPOSITORY_VARIABLE'\n\nSigned-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n---\n builtin/prune.c | 25 ++++++++++++-------------\n 1 file changed, 12 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex dab3c19b6f..2c584a6e0e 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -64,7 +63,7 @@ static void perform_reachability_traversal(struct rev_info *revs)\n \t\treturn;\n \n \tif (show_progress)\n-\t\tprogress = start_delayed_progress(the_repository,\n+\t\tprogress = start_delayed_progress(revs->repo,\n \t\t\t\t\t\t  _(\"Checking connectivity\"), 0);\n \tmark_reachable_objects(revs, 1, expire, progress);\n \tstop_progress(&progress);\n@@ -78,7 +77,7 @@ static int is_object_reachable(const struct object_id *oid,\n \n \tperform_reachability_traversal(revs);\n \n-\tobj = lookup_object(the_repository, oid);\n+\tobj = lookup_object(revs->repo, oid);\n \treturn obj && (obj->flags & SEEN);\n }\n \n@@ -99,7 +98,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,\n \tif (st.st_mtime > expire)\n \t\treturn 0;\n \tif (show_only || verbose) {\n-\t\tenum object_type type = oid_object_info(the_repository, oid,\n+\t\tenum object_type type = oid_object_info(revs->repo, oid,\n \t\t\t\t\t\t\tNULL);\n \t\tprintf(\"%s %s\\n\", oid_to_hex(oid),\n \t\t       (type > 0) ? type_name(type) : \"unknown\");\n@@ -154,7 +153,7 @@ static void remove_temporary_files(const char *path)\n int cmd_prune(int argc,\n \t      const char **argv,\n \t      const char *prefix,\n-\t      struct repository *repo UNUSED)\n+\t      struct repository *repo)\n {\n \tstruct rev_info revs;\n \tint exclude_promisor_objects = 0;\n@@ -173,19 +172,19 @@ int cmd_prune(int argc,\n \texpire = TIME_MAX;\n \tsave_commit_buffer = 0;\n \tdisable_replace_refs();\n-\trepo_init_revisions(the_repository, &revs, prefix);\n+\trepo_init_revisions(repo, &revs, prefix);\n \n \targc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n \n-\tif (the_repository->repository_format_precious_objects)\n+\tif (repo->repository_format_precious_objects)\n \t\tdie(_(\"cannot prune in a precious-objects repo\"));\n \n \twhile (argc--) {\n \t\tstruct object_id oid;\n \t\tconst char *name = *argv++;\n \n-\t\tif (!repo_get_oid(the_repository, name, &oid)) {\n-\t\t\tstruct object *object = parse_object_or_die(the_repository, &oid,\n+\t\tif (!repo_get_oid(repo, name, &oid)) {\n+\t\t\tstruct object *object = parse_object_or_die(repo, &oid,\n \t\t\t\t\t\t\t\t    name);\n \t\t\tadd_pending_object(&revs, object, \"\");\n \t\t}\n@@ -200,16 +199,16 @@ int cmd_prune(int argc,\n \t\trevs.exclude_promisor_objects = 1;\n \t}\n \n-\tfor_each_loose_file_in_objdir(repo_get_object_directory(the_repository),\n+\tfor_each_loose_file_in_objdir(repo_get_object_directory(repo),\n \t\t\t\t      prune_object, prune_cruft, prune_subdir, &revs);\n \n \tprune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);\n-\tremove_temporary_files(repo_get_object_directory(the_repository));\n-\ts = mkpathdup(\"%s/pack\", repo_get_object_directory(the_repository));\n+\tremove_temporary_files(repo_get_object_directory(repo));\n+\ts = mkpathdup(\"%s/pack\", repo_get_object_directory(repo));\n \tremove_temporary_files(s);\n \tfree(s);\n \n-\tif (is_repository_shallow(the_repository)) {\n+\tif (is_repository_shallow(repo)) {\n \t\tperform_reachability_traversal(&revs);\n \t\tprune_shallow(show_only ? PRUNE_SHOW_ONLY : 0);\n \t}\n-- \n2.49.0\n\n"},{"id":"520706","messageId":"CAE7as+aJS7qaqoRTZsiL87m_L8KMYe=EE=-uB40jh6yGXDKO_Q@mail.gmail.com","threadId":"63600","inReplyTo":"cover.1749343601.git.ayu.chandekar@gmail.com","subject":"Re: [GSOC PATCH 0/2] builtin/prune: remove dependency on global variables and 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-25T15:59:06Z","receivedAt":"2025-06-25T15:59:18Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"On Sun, Jun 8, 2025 at 6:37 AM Ayush Chandekar <ayu.chandekar@gmail.com> wrote:\n>\n> The aim of this patch series is to remove the definition '#define USE_THE_REPOSITORY_VARIABLE'\n> from \"builtin/prune.c\" by removing global variables and the global 'the_repository'.\n>\n> This patch series contains two patches:\n>\n> 1 - Move the global variable 'repository_format_precious_objects' into 'struct repository'\n> and update all affected code paths accordingly.\n>\n> 2 - Remove the dependency of 'the_repository' in \"builtin/prunce.c\", allowing the removal of\n> the definition.\n>\n> Ayush Chandekar (2):\n>   repository: move 'repository_format_precious_objects' to repo scope\n>   builtin/prune: stop depending on 'the_repository'\n>\n>  builtin/gc.c     |  2 +-\n>  builtin/prune.c  | 25 ++++++++++++-------------\n>  builtin/repack.c |  2 +-\n>  environment.c    |  1 -\n>  environment.h    |  2 --\n>  repository.c     |  1 +\n>  repository.h     |  1 +\n>  setup.c          |  5 ++++-\n>  8 files changed, 20 insertions(+), 19 deletions(-)\n>\n> --\n> 2.49.0\n>\n\nThis patch appears to have gone unnoticed as it hasn't seen any\nreviews yet. Resurfacing it in case it got overlooked.\n"},{"id":"520839","messageId":"aF-ZLbf8rBHrHOXb@ArchLinux","threadId":"63600","inReplyTo":"6ffb071295272a1d5311f52d8d2015d0aec7e71f.1749343601.git.ayu.chandekar@gmail.com","subject":"Re: [GSOC PATCH 1/2] repository: move 'repository_format_precious_objects' to repo scope","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2025-06-28T07:26:37Z","receivedAt":"2025-06-28T07:26:28Z","isPatch":true,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Sun, Jun 08, 2025 at 06:36:34AM +0530, Ayush Chandekar wrote:\n> The 'extensions.preciousObjects' settings when set true, prevents\n\nShould \"settings\" be \"setting\"?\n\n> operations that might drop objects from the object storage.\n> This setting is populated in the global variable\n> 'repository_format_precious_objects'.\n> Move this global variable to repo scope by adding it to 'struct\n> repository' and also refactor all the occurences accordingly.\n> \n> This change is part of an ongoing effort to eliminate global variables,\n> improve modularity and help libify the codebase.\n> \n> Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n\nMaybe you should add the following things before \"Signed-off-by\":\n\n    Mentored-by: ...\n    Mentored-by: ...\n\nThanks,\nJialuo\n"},{"id":"520840","messageId":"aF-asGE-cX8IpAae@ArchLinux","threadId":"63600","inReplyTo":"9b274efd7dfde90990ace66bfbe5f7e3b6ce30d1.1749343601.git.ayu.chandekar@gmail.com","subject":"Re: [GSOC PATCH 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"shejialuo","fromEmail":"shejialuo@gmail.com","sentAt":"2025-06-28T07:33:04Z","receivedAt":"2025-06-28T07:32:54Z","isPatch":true,"sender":{"key":"shejialuo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/56911263?v=4"},"body":"On Sun, Jun 08, 2025 at 06:36:35AM +0530, Ayush Chandekar wrote:\n\n[snip]\n\n> @@ -99,7 +98,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,\n>  \tif (st.st_mtime > expire)\n>  \t\treturn 0;\n>  \tif (show_only || verbose) {\n> -\t\tenum object_type type = oid_object_info(the_repository, oid,\n> +\t\tenum object_type type = oid_object_info(revs->repo, oid,\n>  \t\t\t\t\t\t\tNULL);\n\nCould we simply make `NULL` in the same line by the way? The readability\nwould be better.\n\n>  \t\tprintf(\"%s %s\\n\", oid_to_hex(oid),\n>  \t\t       (type > 0) ? type_name(type) : \"unknown\");\n> @@ -154,7 +153,7 @@ static void remove_temporary_files(const char *path)\n>  int cmd_prune(int argc,\n>  \t      const char **argv,\n>  \t      const char *prefix,\n> -\t      struct repository *repo UNUSED)\n> +\t      struct repository *repo)\n>  {\n>  \tstruct rev_info revs;\n>  \tint exclude_promisor_objects = 0;\n> @@ -173,19 +172,19 @@ int cmd_prune(int argc,\n>  \texpire = TIME_MAX;\n>  \tsave_commit_buffer = 0;\n>  \tdisable_replace_refs();\n> -\trepo_init_revisions(the_repository, &revs, prefix);\n> +\trepo_init_revisions(repo, &revs, prefix);\n>  \n>  \targc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n>  \n> -\tif (the_repository->repository_format_precious_objects)\n> +\tif (repo->repository_format_precious_objects)\n>  \t\tdie(_(\"cannot prune in a precious-objects repo\"));\n>  \n>  \twhile (argc--) {\n>  \t\tstruct object_id oid;\n>  \t\tconst char *name = *argv++;\n>  \n> -\t\tif (!repo_get_oid(the_repository, name, &oid)) {\n> -\t\t\tstruct object *object = parse_object_or_die(the_repository, &oid,\n> +\t\tif (!repo_get_oid(repo, name, &oid)) {\n> +\t\t\tstruct object *object = parse_object_or_die(repo, &oid,\n>  \t\t\t\t\t\t\t\t    name);\n\nSame, could we just make `name` in the same line. There is no need for\nthe newline right now as we change \"the_repository\" to \"repo\" which\nwould reduce some columns.\n\nThanks,\nJialuo\n"},{"id":"520844","messageId":"CAE7as+ZF3o=vbS3o4RXfRiQJNXEb+0UHQ1tt7v13NX2rDcO0ow@mail.gmail.com","threadId":"63600","inReplyTo":"aF-ZLbf8rBHrHOXb@ArchLinux","subject":"Re: [GSOC PATCH 1/2] repository: move 'repository_format_precious_objects' to repo scope","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-28T13:14:32Z","receivedAt":"2025-06-28T13:14:44Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"On Sat, Jun 28, 2025 at 12:56 PM shejialuo <shejialuo@gmail.com> wrote:\n>\n> On Sun, Jun 08, 2025 at 06:36:34AM +0530, Ayush Chandekar wrote:\n> > The 'extensions.preciousObjects' settings when set true, prevents\n>\n> Should \"settings\" be \"setting\"?\n>\n\nYeah, thanks for correcting!\n\n> > operations that might drop objects from the object storage.\n> > This setting is populated in the global variable\n> > 'repository_format_precious_objects'.\n> > Move this global variable to repo scope by adding it to 'struct\n> > repository' and also refactor all the occurences accordingly.\n> >\n> > This change is part of an ongoing effort to eliminate global variables,\n> > improve modularity and help libify the codebase.\n> >\n> > Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n>\n> Maybe you should add the following things before \"Signed-off-by\":\n>\n>     Mentored-by: ...\n>     Mentored-by: ...\n>\n\nOh, I missed it on this patch series, apologies, I'll update it.\n\n> Thanks,\n> Jialuo\n\nThanks:)\n"},{"id":"520845","messageId":"CAE7as+a-uvbOGrA_QCGitWj8fsAbe88UmP4AyywxkWk=nhjihw@mail.gmail.com","threadId":"63600","inReplyTo":"aF-asGE-cX8IpAae@ArchLinux","subject":"Re: [GSOC PATCH 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-28T13:21:52Z","receivedAt":"2025-06-28T13:22:04Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"On Sat, Jun 28, 2025 at 1:02 PM shejialuo <shejialuo@gmail.com> wrote:\n>\n> On Sun, Jun 08, 2025 at 06:36:35AM +0530, Ayush Chandekar wrote:\n>\n> [snip]\n>\n> > @@ -99,7 +98,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,\n> >       if (st.st_mtime > expire)\n> >               return 0;\n> >       if (show_only || verbose) {\n> > -             enum object_type type = oid_object_info(the_repository, oid,\n> > +             enum object_type type = oid_object_info(revs->repo, oid,\n> >                                                       NULL);\n>\n> Could we simply make `NULL` in the same line by the way? The readability\n> would be better.\n>\n\nYeah, I agree, will do that.\n\n> >               printf(\"%s %s\\n\", oid_to_hex(oid),\n> >                      (type > 0) ? type_name(type) : \"unknown\");\n> > @@ -154,7 +153,7 @@ static void remove_temporary_files(const char *path)\n> >  int cmd_prune(int argc,\n> >             const char **argv,\n> >             const char *prefix,\n> > -           struct repository *repo UNUSED)\n> > +           struct repository *repo)\n> >  {\n> >       struct rev_info revs;\n> >       int exclude_promisor_objects = 0;\n> > @@ -173,19 +172,19 @@ int cmd_prune(int argc,\n> >       expire = TIME_MAX;\n> >       save_commit_buffer = 0;\n> >       disable_replace_refs();\n> > -     repo_init_revisions(the_repository, &revs, prefix);\n> > +     repo_init_revisions(repo, &revs, prefix);\n> >\n> >       argc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n> >\n> > -     if (the_repository->repository_format_precious_objects)\n> > +     if (repo->repository_format_precious_objects)\n> >               die(_(\"cannot prune in a precious-objects repo\"));\n> >\n> >       while (argc--) {\n> >               struct object_id oid;\n> >               const char *name = *argv++;\n> >\n> > -             if (!repo_get_oid(the_repository, name, &oid)) {\n> > -                     struct object *object = parse_object_or_die(the_repository, &oid,\n> > +             if (!repo_get_oid(repo, name, &oid)) {\n> > +                     struct object *object = parse_object_or_die(repo, &oid,\n> >                                                                   name);\n>\n> Same, could we just make `name` in the same line. There is no need for\n> the newline right now as we change \"the_repository\" to \"repo\" which\n> would reduce some columns.\n>\n\nYeah, got it.\n\n> Thanks,\n> Jialuo\n\nThanks:)\n"},{"id":"520934","messageId":"cover.1751296633.git.ayu.chandekar@gmail.com","threadId":"63600","inReplyTo":"cover.1749343601.git.ayu.chandekar@gmail.com","subject":"[GSOC PATCH v2 0/2] builtin/prune: remove dependency on global variables and 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-30T16:41:03Z","receivedAt":"2025-06-30T16:41:26Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"The aim of this patch series is to remove the definition '#define USE_THE_REPOSITORY_VARIABLE' \nfrom \"builtin/prune.c\" by removing global variables and the global 'the_repository'.\n\nThis patch series contains two patches:\n\n1 - Move the global variable 'repository_format_precious_objects' into 'struct repository' \nand update all affected code paths accordingly.\n\n2 - Remove the dependency of 'the_repository' in \"builtin/prunce.c\", allowing the removal of \nthe definition.\n\nAyush Chandekar (2):\n  repository: move 'repository_format_precious_objects' to repo scope\n  builtin/prune: stop depending on 'the_repository'\n\n builtin/gc.c     |  2 +-\n builtin/prune.c  | 27 ++++++++++++---------------\n builtin/repack.c |  2 +-\n environment.c    |  1 -\n environment.h    |  2 --\n repository.c     |  1 +\n repository.h     |  1 +\n setup.c          |  5 ++++-\n 8 files changed, 20 insertions(+), 21 deletions(-)\n\n-- \n\nSummary of the range-diff:\n* Changed the commit message of 1/2 to use \"setting\" instead of \"settings\" since it refers to just one.\n* Added \"Mentored-by\" tags in both 1/2 and 2/2.\n* Fixed line formatting in builtin/prune.c in 2/2.\n\nRange-diff:\n1:  699f9a947d ! 1:  995389d622 repository: move 'repository_format_precious_objects' to repo scope\n    @@ Metadata\n      ## Commit message ##\n         repository: move 'repository_format_precious_objects' to repo scope\n     \n    -    The 'extensions.preciousObjects' settings when set true, prevents\n    +    The 'extensions.preciousObjects' setting when set true, prevents\n         operations that might drop objects from the object storage.\n         This setting is populated in the global variable\n         'repository_format_precious_objects'.\n    @@ Commit message\n         This change is part of an ongoing effort to eliminate global variables,\n         improve modularity and help libify the codebase.\n     \n    +    Mentored-by: Christian Couder <christian.couder@gmail.com>\n    +    Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>\n         Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n     \n      ## builtin/gc.c ##\n2:  f22cc88e9f ! 2:  f70de9d549 builtin/prune: stop depending on 'the_repository'\n    @@ Commit message\n         repo and thus remove the definition '#define\n         USE_THE_REPOSITORY_VARIABLE'\n     \n    +    Mentored-by: Christian Couder <christian.couder@gmail.com>\n    +    Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>\n         Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n     \n      ## builtin/prune.c ##\n    @@ builtin/prune.c: static int prune_object(const struct object_id *oid, const char\n      \t\treturn 0;\n      \tif (show_only || verbose) {\n     -\t\tenum object_type type = oid_object_info(the_repository, oid,\n    -+\t\tenum object_type type = oid_object_info(revs->repo, oid,\n    - \t\t\t\t\t\t\tNULL);\n    +-\t\t\t\t\t\t\tNULL);\n    ++\t\tenum object_type type = oid_object_info(revs->repo, oid, NULL);\n      \t\tprintf(\"%s %s\\n\", oid_to_hex(oid),\n      \t\t       (type > 0) ? type_name(type) : \"unknown\");\n    + \t}\n     @@ builtin/prune.c: static void remove_temporary_files(const char *path)\n      int cmd_prune(int argc,\n      \t      const char **argv,\n    @@ builtin/prune.c: int cmd_prune(int argc,\n      \n     -\t\tif (!repo_get_oid(the_repository, name, &oid)) {\n     -\t\t\tstruct object *object = parse_object_or_die(the_repository, &oid,\n    +-\t\t\t\t\t\t\t\t    name);\n     +\t\tif (!repo_get_oid(repo, name, &oid)) {\n    -+\t\t\tstruct object *object = parse_object_or_die(repo, &oid,\n    - \t\t\t\t\t\t\t\t    name);\n    ++\t\t\tstruct object *object = parse_object_or_die(repo, &oid, name);\n      \t\t\tadd_pending_object(&revs, object, \"\");\n      \t\t}\n    + \t\telse\n     @@ builtin/prune.c: int cmd_prune(int argc,\n      \t\trevs.exclude_promisor_objects = 1;\n      \t}\n\n2.49.0\n\n"},{"id":"520935","messageId":"995389d6229df0c2a76ee4ba57e663a43abb4540.1751296633.git.ayu.chandekar@gmail.com","threadId":"63600","inReplyTo":"cover.1751296633.git.ayu.chandekar@gmail.com","subject":"[GSOC PATCH v2 1/2] repository: move 'repository_format_precious_objects' to repo scope","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-30T16:41:04Z","receivedAt":"2025-06-30T16:41:31Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"The 'extensions.preciousObjects' setting when set true, prevents\noperations that might drop objects from the object storage.\nThis setting is populated in the global variable\n'repository_format_precious_objects'.\nMove this global variable to repo scope by adding it to struct\n`repository` and also refactor all the occurences accordingly.\n\nThis change is part of an ongoing effort to eliminate global variables,\nimprove modularity and help libify the codebase.\n\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>\nSigned-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n---\n builtin/gc.c     | 2 +-\n builtin/prune.c  | 2 +-\n builtin/repack.c | 2 +-\n environment.c    | 1 -\n environment.h    | 2 --\n repository.c     | 1 +\n repository.h     | 1 +\n setup.c          | 5 ++++-\n 8 files changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 845876ff02..ec10b81dcc 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -998,7 +998,7 @@ int cmd_gc(int argc,\n \tif (opts.detach <= 0 && !skip_foreground_tasks)\n \t\tgc_foreground_tasks(&opts, &cfg);\n \n-\tif (!repository_format_precious_objects) {\n+\tif (!the_repository->repository_format_precious_objects) {\n \t\tstruct child_process repack_cmd = CHILD_PROCESS_INIT;\n \n \t\trepack_cmd.git_cmd = 1;\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex e930caa0c0..dab3c19b6f 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -177,7 +177,7 @@ int cmd_prune(int argc,\n \n \targc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n \n-\tif (repository_format_precious_objects)\n+\tif (the_repository->repository_format_precious_objects)\n \t\tdie(_(\"cannot prune in a precious-objects repo\"));\n \n \twhile (argc--) {\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 5ddc6e7f95..d0e4fa6bed 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -1240,7 +1240,7 @@ int cmd_repack(int argc,\n \tpo_args.depth = xstrdup_or_null(opt_depth);\n \tpo_args.threads = xstrdup_or_null(opt_threads);\n \n-\tif (delete_redundant && repository_format_precious_objects)\n+\tif (delete_redundant && the_repository->repository_format_precious_objects)\n \t\tdie(_(\"cannot delete packs in a precious-objects repo\"));\n \n \tdie_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), \"-A\",\ndiff --git a/environment.c b/environment.c\nindex 7bf0390a33..7c2480b22e 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -37,7 +37,6 @@ int ignore_case;\n int assume_unchanged;\n int is_bare_repository_cfg = -1; /* unspecified */\n int warn_on_object_refname_ambiguity = 1;\n-int repository_format_precious_objects;\n char *git_commit_encoding;\n char *git_log_output_encoding;\n char *apply_default_whitespace;\ndiff --git a/environment.h b/environment.h\nindex 9a3d05d414..3d806ced6e 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -189,8 +189,6 @@ extern enum object_creation_mode object_creation_mode;\n \n extern int grafts_keep_true_parents;\n \n-extern int repository_format_precious_objects;\n-\n const char *get_log_output_encoding(void);\n const char *get_commit_output_encoding(void);\n \ndiff --git a/repository.c b/repository.c\nindex 9b3d6665fc..62709d1c91 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -284,6 +284,7 @@ int repo_init(struct repository *repo,\n \trepo_set_ref_storage_format(repo, format.ref_storage_format);\n \trepo->repository_format_worktree_config = format.worktree_config;\n \trepo->repository_format_relative_worktrees = format.relative_worktrees;\n+\trepo->repository_format_precious_objects = format.precious_objects;\n \n \t/* take ownership of format.partial_clone */\n \trepo->repository_format_partial_clone = format.partial_clone;\ndiff --git a/repository.h b/repository.h\nindex c4c92b2ab9..ad23a243c6 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -151,6 +151,7 @@ struct repository {\n \t/* Configurations */\n \tint repository_format_worktree_config;\n \tint repository_format_relative_worktrees;\n+\tint repository_format_precious_objects;\n \n \t/* Indicate if a repository has a different 'commondir' from 'gitdir' */\n \tunsigned different_commondir:1;\ndiff --git a/setup.c b/setup.c\nindex f93bd6a24a..3ea01e9331 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -753,7 +753,8 @@ static int check_repository_format_gently(const char *gitdir, struct repository_\n \t\tdie(\"%s\", err.buf);\n \t}\n \n-\trepository_format_precious_objects = candidate->precious_objects;\n+\tthe_repository->repository_format_precious_objects = candidate->precious_objects;\n+\n \tstring_list_clear(&candidate->unknown_extensions, 0);\n \tstring_list_clear(&candidate->v1_only_extensions, 0);\n \n@@ -1864,6 +1865,8 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\tthe_repository->repository_format_partial_clone =\n \t\t\t\trepo_fmt.partial_clone;\n \t\t\trepo_fmt.partial_clone = NULL;\n+\t\t\tthe_repository->repository_format_precious_objects =\n+\t\t\t\trepo_fmt.precious_objects;\n \t\t}\n \t}\n \t/*\n-- \n2.49.0\n\n"},{"id":"520936","messageId":"f70de9d549f2cb744810df7a9ee09e0b3626e62a.1751296633.git.ayu.chandekar@gmail.com","threadId":"63600","inReplyTo":"cover.1751296633.git.ayu.chandekar@gmail.com","subject":"[GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-06-30T16:41:05Z","receivedAt":"2025-06-30T16:41:35Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"Refactor builtin/prune.c to remove the dependency on the global\n'the_repository'. Replace all the occurrences of 'the_repository' with\nrepo and thus remove the definition '#define\nUSE_THE_REPOSITORY_VARIABLE'\n\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>\nSigned-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n---\n builtin/prune.c | 27 ++++++++++++---------------\n 1 file changed, 12 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex dab3c19b6f..499d2432d1 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -64,7 +63,7 @@ static void perform_reachability_traversal(struct rev_info *revs)\n \t\treturn;\n \n \tif (show_progress)\n-\t\tprogress = start_delayed_progress(the_repository,\n+\t\tprogress = start_delayed_progress(revs->repo,\n \t\t\t\t\t\t  _(\"Checking connectivity\"), 0);\n \tmark_reachable_objects(revs, 1, expire, progress);\n \tstop_progress(&progress);\n@@ -78,7 +77,7 @@ static int is_object_reachable(const struct object_id *oid,\n \n \tperform_reachability_traversal(revs);\n \n-\tobj = lookup_object(the_repository, oid);\n+\tobj = lookup_object(revs->repo, oid);\n \treturn obj && (obj->flags & SEEN);\n }\n \n@@ -99,8 +98,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,\n \tif (st.st_mtime > expire)\n \t\treturn 0;\n \tif (show_only || verbose) {\n-\t\tenum object_type type = oid_object_info(the_repository, oid,\n-\t\t\t\t\t\t\tNULL);\n+\t\tenum object_type type = oid_object_info(revs->repo, oid, NULL);\n \t\tprintf(\"%s %s\\n\", oid_to_hex(oid),\n \t\t       (type > 0) ? type_name(type) : \"unknown\");\n \t}\n@@ -154,7 +152,7 @@ static void remove_temporary_files(const char *path)\n int cmd_prune(int argc,\n \t      const char **argv,\n \t      const char *prefix,\n-\t      struct repository *repo UNUSED)\n+\t      struct repository *repo)\n {\n \tstruct rev_info revs;\n \tint exclude_promisor_objects = 0;\n@@ -173,20 +171,19 @@ int cmd_prune(int argc,\n \texpire = TIME_MAX;\n \tsave_commit_buffer = 0;\n \tdisable_replace_refs();\n-\trepo_init_revisions(the_repository, &revs, prefix);\n+\trepo_init_revisions(repo, &revs, prefix);\n \n \targc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n \n-\tif (the_repository->repository_format_precious_objects)\n+\tif (repo->repository_format_precious_objects)\n \t\tdie(_(\"cannot prune in a precious-objects repo\"));\n \n \twhile (argc--) {\n \t\tstruct object_id oid;\n \t\tconst char *name = *argv++;\n \n-\t\tif (!repo_get_oid(the_repository, name, &oid)) {\n-\t\t\tstruct object *object = parse_object_or_die(the_repository, &oid,\n-\t\t\t\t\t\t\t\t    name);\n+\t\tif (!repo_get_oid(repo, name, &oid)) {\n+\t\t\tstruct object *object = parse_object_or_die(repo, &oid, name);\n \t\t\tadd_pending_object(&revs, object, \"\");\n \t\t}\n \t\telse\n@@ -200,16 +197,16 @@ int cmd_prune(int argc,\n \t\trevs.exclude_promisor_objects = 1;\n \t}\n \n-\tfor_each_loose_file_in_objdir(repo_get_object_directory(the_repository),\n+\tfor_each_loose_file_in_objdir(repo_get_object_directory(repo),\n \t\t\t\t      prune_object, prune_cruft, prune_subdir, &revs);\n \n \tprune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);\n-\tremove_temporary_files(repo_get_object_directory(the_repository));\n-\ts = mkpathdup(\"%s/pack\", repo_get_object_directory(the_repository));\n+\tremove_temporary_files(repo_get_object_directory(repo));\n+\ts = mkpathdup(\"%s/pack\", repo_get_object_directory(repo));\n \tremove_temporary_files(s);\n \tfree(s);\n \n-\tif (is_repository_shallow(the_repository)) {\n+\tif (is_repository_shallow(repo)) {\n \t\tperform_reachability_traversal(&revs);\n \t\tprune_shallow(show_only ? PRUNE_SHOW_ONLY : 0);\n \t}\n-- \n2.49.0\n\n"},{"id":"521042","messageId":"aGPcJMfBCJuQLdtu@pks.im","threadId":"63600","inReplyTo":"995389d6229df0c2a76ee4ba57e663a43abb4540.1751296633.git.ayu.chandekar@gmail.com","subject":"Re: [GSOC PATCH v2 1/2] repository: move 'repository_format_precious_objects' to repo scope","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-07-01T13:01:24Z","receivedAt":"2025-07-01T13:01:31Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Jun 30, 2025 at 10:11:04PM +0530, Ayush Chandekar wrote:\n> The 'extensions.preciousObjects' setting when set true, prevents\n> operations that might drop objects from the object storage.\n> This setting is populated in the global variable\n> 'repository_format_precious_objects'.\n> Move this global variable to repo scope by adding it to struct\n> `repository` and also refactor all the occurences accordingly.\n\nTiny nit: the line wrapping of this paragraph is a bit weird -- it\nshould generally wrap at 72 characters and paragraphs are typically\nseparated from one another by an empty newline.\n\n> diff --git a/repository.c b/repository.c\n> index 9b3d6665fc..62709d1c91 100644\n> --- a/repository.c\n> +++ b/repository.c\n> @@ -284,6 +284,7 @@ int repo_init(struct repository *repo,\n>  \trepo_set_ref_storage_format(repo, format.ref_storage_format);\n>  \trepo->repository_format_worktree_config = format.worktree_config;\n>  \trepo->repository_format_relative_worktrees = format.relative_worktrees;\n> +\trepo->repository_format_precious_objects = format.precious_objects;\n>  \n>  \t/* take ownership of format.partial_clone */\n>  \trepo->repository_format_partial_clone = format.partial_clone;\n\nThe list of variables that we copy from `format` grows longer and\nlonger. I wonder whether it would make sense to embed a `struct\nrepository_format` in the repository and then copy over the whole\nstructure?\n\nPatrick\n"},{"id":"521043","messageId":"aGPcKgR0G72JRSlM@pks.im","threadId":"63600","inReplyTo":"f70de9d549f2cb744810df7a9ee09e0b3626e62a.1751296633.git.ayu.chandekar@gmail.com","subject":"Re: [GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-07-01T13:01:30Z","receivedAt":"2025-07-01T13:01:35Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Jun 30, 2025 at 10:11:05PM +0530, Ayush Chandekar wrote:\n> @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n>  \texpire = TIME_MAX;\n>  \tsave_commit_buffer = 0;\n>  \tdisable_replace_refs();\n> -\trepo_init_revisions(the_repository, &revs, prefix);\n> +\trepo_init_revisions(repo, &revs, prefix);\n\nDoes this work correctly when running outside of a repository? In\ngeneral `cmd_prune()` is not executed and would instead die as it is\ndeclared as `RUN_SETUP`, without the `_GENTLY` suffix. But when the user\nasks for help we may still execute the function with a NULL pointer.\n\nPatrick\n"},{"id":"521082","messageId":"xmqqikkbkglx.fsf@gitster.g","threadId":"63600","inReplyTo":"aGPcKgR0G72JRSlM@pks.im","subject":"Re: [GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-07-01T16:42:18Z","receivedAt":"2025-07-01T16:42:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> On Mon, Jun 30, 2025 at 10:11:05PM +0530, Ayush Chandekar wrote:\n>> @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n>>  \texpire = TIME_MAX;\n>>  \tsave_commit_buffer = 0;\n>>  \tdisable_replace_refs();\n>> -\trepo_init_revisions(the_repository, &revs, prefix);\n>> +\trepo_init_revisions(repo, &revs, prefix);\n>\n> Does this work correctly when running outside of a repository? In\n> general `cmd_prune()` is not executed and would instead die as it is\n> declared as `RUN_SETUP`, without the `_GENTLY` suffix. But when the user\n> asks for help we may still execute the function with a NULL pointer.\n\nGood eyes.  \"git prune -h\" would safely exit in parse_options() in\nsuch a case, but this part happens before the parse_options() call.\n\n"},{"id":"521093","messageId":"CAE7as+YtmRxD3P-T4bzccgJnd0Ocj0kdW00g-=3gtdoWhTRVeA@mail.gmail.com","threadId":"63600","inReplyTo":"xmqqikkbkglx.fsf@gitster.g","subject":"Re: [GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-07-01T18:09:48Z","receivedAt":"2025-07-01T18:10:01Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"On Tue, Jul 1, 2025 at 10:12 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Patrick Steinhardt <ps@pks.im> writes:\n>\n> > On Mon, Jun 30, 2025 at 10:11:05PM +0530, Ayush Chandekar wrote:\n> >> @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n> >>      expire = TIME_MAX;\n> >>      save_commit_buffer = 0;\n> >>      disable_replace_refs();\n> >> -    repo_init_revisions(the_repository, &revs, prefix);\n> >> +    repo_init_revisions(repo, &revs, prefix);\n> >\n> > Does this work correctly when running outside of a repository? In\n> > general `cmd_prune()` is not executed and would instead die as it is\n> > declared as `RUN_SETUP`, without the `_GENTLY` suffix. But when the user\n> > asks for help we may still execute the function with a NULL pointer.\n>\n> Good eyes.  \"git prune -h\" would safely exit in parse_options() in\n> such a case, but this part happens before the parse_options() call.\n>\n\nThanks for pointing that out, Patrick. Right now, `parse_options()` is\ncalled just after the `repo_init_revisions()`. I can move the call to\nit before this.\n\nAlthough when I tried running \"git prune -h\", it still gave me the\nexpected output.\n"},{"id":"521094","messageId":"CAE7as+aVrZZtu7goaMC2W9dEc4xsqOT7RRxPZ6Dmvu=cm8h1vw@mail.gmail.com","threadId":"63600","inReplyTo":"aGPcJMfBCJuQLdtu@pks.im","subject":"Re: [GSOC PATCH v2 1/2] repository: move 'repository_format_precious_objects' to repo scope","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-07-01T18:24:02Z","receivedAt":"2025-07-01T18:24:15Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"On Tue, Jul 1, 2025 at 6:31 PM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> On Mon, Jun 30, 2025 at 10:11:04PM +0530, Ayush Chandekar wrote:\n> > The 'extensions.preciousObjects' setting when set true, prevents\n> > operations that might drop objects from the object storage.\n> > This setting is populated in the global variable\n> > 'repository_format_precious_objects'.\n> > Move this global variable to repo scope by adding it to struct\n> > `repository` and also refactor all the occurences accordingly.\n>\n> Tiny nit: the line wrapping of this paragraph is a bit weird -- it\n> should generally wrap at 72 characters and paragraphs are typically\n> separated from one another by an empty newline.\n>\n\nOkay, I will fix it.\n\n> > diff --git a/repository.c b/repository.c\n> > index 9b3d6665fc..62709d1c91 100644\n> > --- a/repository.c\n> > +++ b/repository.c\n> > @@ -284,6 +284,7 @@ int repo_init(struct repository *repo,\n> >       repo_set_ref_storage_format(repo, format.ref_storage_format);\n> >       repo->repository_format_worktree_config = format.worktree_config;\n> >       repo->repository_format_relative_worktrees = format.relative_worktrees;\n> > +     repo->repository_format_precious_objects = format.precious_objects;\n> >\n> >       /* take ownership of format.partial_clone */\n> >       repo->repository_format_partial_clone = format.partial_clone;\n>\n> The list of variables that we copy from `format` grows longer and\n> longer. I wonder whether it would make sense to embed a `struct\n> repository_format` in the repository and then copy over the whole\n> structure?\n>\n> Patrick\n\nYeah, I suggested this in a discussion with my mentors and was\nexpecting comments regarding the same. I can create a new patch for\nthis change if there's consensus on this.\n"},{"id":"521099","messageId":"CAPSxiM8EkctHgD=to=JxwDC8L6=5xgu=vpb5=bfhQ7bL592eWQ@mail.gmail.com","threadId":"63600","inReplyTo":"CAE7as+YtmRxD3P-T4bzccgJnd0Ocj0kdW00g-=3gtdoWhTRVeA@mail.gmail.com","subject":"Re: [GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-07-01T19:44:37Z","receivedAt":"2025-07-01T19:44:50Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Tue, Jul 1, 2025 at 11:40 PM Ayush Chandekar <ayu.chandekar@gmail.com> wrote:\n>\n> On Tue, Jul 1, 2025 at 10:12 PM Junio C Hamano <gitster@pobox.com> wrote:\n> >\n> > Patrick Steinhardt <ps@pks.im> writes:\n> >\n> > > On Mon, Jun 30, 2025 at 10:11:05PM +0530, Ayush Chandekar wrote:\n> > >> @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n> > >>      expire = TIME_MAX;\n> > >>      save_commit_buffer = 0;\n> > >>      disable_replace_refs();\n> > >> -    repo_init_revisions(the_repository, &revs, prefix);\n> > >> +    repo_init_revisions(repo, &revs, prefix);\n> > >\n> > > Does this work correctly when running outside of a repository? In\n> > > general `cmd_prune()` is not executed and would instead die as it is\n> > > declared as `RUN_SETUP`, without the `_GENTLY` suffix. But when the user\n> > > asks for help we may still execute the function with a NULL pointer.\n> >\n> > Good eyes.  \"git prune -h\" would safely exit in parse_options() in\n> > such a case, but this part happens before the parse_options() call.\n> >\nHello Ayush,\n>\n> Thanks for pointing that out, Patrick. Right now, `parse_options()` is\n> called just after the `repo_init_revisions()`. I can move the call to\n> it before this.\n>\n> Although when I tried running \"git prune -h\", it still gave me the\n> expected output.\nDo try this outside a repo, i.e outside a git repository and try to\nrun the all the test if it works.\n>\n"},{"id":"521125","messageId":"CAE7as+ZC-sXs11YN-247fG5ikFUNxcGTgH2a8SQUaeAuUN7=YQ@mail.gmail.com","threadId":"63600","inReplyTo":"CAPSxiM8EkctHgD=to=JxwDC8L6=5xgu=vpb5=bfhQ7bL592eWQ@mail.gmail.com","subject":"Re: [GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-07-01T22:04:07Z","receivedAt":"2025-07-01T22:04:19Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"On Wed, Jul 2, 2025 at 1:14 AM Usman Akinyemi\n<usmanakinyemi202@gmail.com> wrote:\n>\n> On Tue, Jul 1, 2025 at 11:40 PM Ayush Chandekar <ayu.chandekar@gmail.com> wrote:\n> >\n> > On Tue, Jul 1, 2025 at 10:12 PM Junio C Hamano <gitster@pobox.com> wrote:\n> > >\n> > > Patrick Steinhardt <ps@pks.im> writes:\n> > >\n> > > > On Mon, Jun 30, 2025 at 10:11:05PM +0530, Ayush Chandekar wrote:\n> > > >> @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n> > > >>      expire = TIME_MAX;\n> > > >>      save_commit_buffer = 0;\n> > > >>      disable_replace_refs();\n> > > >> -    repo_init_revisions(the_repository, &revs, prefix);\n> > > >> +    repo_init_revisions(repo, &revs, prefix);\n> > > >\n> > > > Does this work correctly when running outside of a repository? In\n> > > > general `cmd_prune()` is not executed and would instead die as it is\n> > > > declared as `RUN_SETUP`, without the `_GENTLY` suffix. But when the user\n> > > > asks for help we may still execute the function with a NULL pointer.\n> > >\n> > > Good eyes.  \"git prune -h\" would safely exit in parse_options() in\n> > > such a case, but this part happens before the parse_options() call.\n> > >\n> Hello Ayush,\n\nHi Usman,\n\n> >\n> > Thanks for pointing that out, Patrick. Right now, `parse_options()` is\n> > called just after the `repo_init_revisions()`. I can move the call to\n> > it before this.\n> >\n> > Although when I tried running \"git prune -h\", it still gave me the\n> > expected output.\n> Do try this outside a repo, i.e outside a git repository and try to\n> run the all the test if it works.\n> >\n\nYes, I tried it. All my tests passed as well, you can check it here:\nhttps://github.com/ayu-ch/git/commits/precious-objects-3\n\nThanks,\nAyush\n"},{"id":"521140","messageId":"aGSYLJaqDziLqtXk@pks.im","threadId":"63600","inReplyTo":"CAE7as+YtmRxD3P-T4bzccgJnd0Ocj0kdW00g-=3gtdoWhTRVeA@mail.gmail.com","subject":"Re: [GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-07-02T02:23:40Z","receivedAt":"2025-07-02T02:23:47Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Jul 01, 2025 at 11:39:48PM +0530, Ayush Chandekar wrote:\n> On Tue, Jul 1, 2025 at 10:12 PM Junio C Hamano <gitster@pobox.com> wrote:\n> >\n> > Patrick Steinhardt <ps@pks.im> writes:\n> >\n> > > On Mon, Jun 30, 2025 at 10:11:05PM +0530, Ayush Chandekar wrote:\n> > >> @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n> > >>      expire = TIME_MAX;\n> > >>      save_commit_buffer = 0;\n> > >>      disable_replace_refs();\n> > >> -    repo_init_revisions(the_repository, &revs, prefix);\n> > >> +    repo_init_revisions(repo, &revs, prefix);\n> > >\n> > > Does this work correctly when running outside of a repository? In\n> > > general `cmd_prune()` is not executed and would instead die as it is\n> > > declared as `RUN_SETUP`, without the `_GENTLY` suffix. But when the user\n> > > asks for help we may still execute the function with a NULL pointer.\n> >\n> > Good eyes.  \"git prune -h\" would safely exit in parse_options() in\n> > such a case, but this part happens before the parse_options() call.\n> >\n> \n> Thanks for pointing that out, Patrick. Right now, `parse_options()` is\n> called just after the `repo_init_revisions()`. I can move the call to\n> it before this.\n> \n> Although when I tried running \"git prune -h\", it still gave me the\n> expected output.\n\nWell, as long as it works and as long as we have a test somewhere that\nensures it keeps working I'm happy.\n\nPatrick\n"},{"id":"521141","messageId":"aGSYM9W_41w8ImIx@pks.im","threadId":"63600","inReplyTo":"CAE7as+aVrZZtu7goaMC2W9dEc4xsqOT7RRxPZ6Dmvu=cm8h1vw@mail.gmail.com","subject":"Re: [GSOC PATCH v2 1/2] repository: move 'repository_format_precious_objects' to repo scope","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-07-02T02:23:47Z","receivedAt":"2025-07-02T02:23:52Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Jul 01, 2025 at 11:54:02PM +0530, Ayush Chandekar wrote:\n> On Tue, Jul 1, 2025 at 6:31 PM Patrick Steinhardt <ps@pks.im> wrote:\n> > On Mon, Jun 30, 2025 at 10:11:04PM +0530, Ayush Chandekar wrote:\n> > > diff --git a/repository.c b/repository.c\n> > > index 9b3d6665fc..62709d1c91 100644\n> > > --- a/repository.c\n> > > +++ b/repository.c\n> > > @@ -284,6 +284,7 @@ int repo_init(struct repository *repo,\n> > >       repo_set_ref_storage_format(repo, format.ref_storage_format);\n> > >       repo->repository_format_worktree_config = format.worktree_config;\n> > >       repo->repository_format_relative_worktrees = format.relative_worktrees;\n> > > +     repo->repository_format_precious_objects = format.precious_objects;\n> > >\n> > >       /* take ownership of format.partial_clone */\n> > >       repo->repository_format_partial_clone = format.partial_clone;\n> >\n> > The list of variables that we copy from `format` grows longer and\n> > longer. I wonder whether it would make sense to embed a `struct\n> > repository_format` in the repository and then copy over the whole\n> > structure?\n> >\n> > Patrick\n> \n> Yeah, I suggested this in a discussion with my mentors and was\n> expecting comments regarding the same. I can create a new patch for\n> this change if there's consensus on this.\n\nYou could also do it as a follow-up change after this series has landed.\nThat would be perfectly fine with me.\n\nPatrick\n"},{"id":"521166","messageId":"CAPSxiM9ahAPEr5fj_A1RpgYjJQmv9kZ2jYfR2Knat5yHZNDkEA@mail.gmail.com","threadId":"63600","inReplyTo":"aGSYLJaqDziLqtXk@pks.im","subject":"Re: [GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Usman Akinyemi","fromEmail":"usmanakinyemi202@gmail.com","sentAt":"2025-07-02T11:18:19Z","receivedAt":"2025-07-02T11:18:31Z","isPatch":true,"sender":{"key":"usmanakinyemi202@gmail.com","avatar":"https://avatars.githubusercontent.com/u/86585626?v=4"},"body":"On Wed, Jul 2, 2025 at 4:17 PM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> On Tue, Jul 01, 2025 at 11:39:48PM +0530, Ayush Chandekar wrote:\n> > On Tue, Jul 1, 2025 at 10:12 PM Junio C Hamano <gitster@pobox.com> wrote:\n> > >\n> > > Patrick Steinhardt <ps@pks.im> writes:\n> > >\n> > > > On Mon, Jun 30, 2025 at 10:11:05PM +0530, Ayush Chandekar wrote:\n> > > >> @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n> > > >>      expire = TIME_MAX;\n> > > >>      save_commit_buffer = 0;\n> > > >>      disable_replace_refs();\n> > > >> -    repo_init_revisions(the_repository, &revs, prefix);\n> > > >> +    repo_init_revisions(repo, &revs, prefix);\n> > > >\n> > > > Does this work correctly when running outside of a repository? In\n> > > > general `cmd_prune()` is not executed and would instead die as it is\n> > > > declared as `RUN_SETUP`, without the `_GENTLY` suffix. But when the user\n> > > > asks for help we may still execute the function with a NULL pointer.\n> > >\n> > > Good eyes.  \"git prune -h\" would safely exit in parse_options() in\n> > > such a case, but this part happens before the parse_options() call.\n> > >\n> >\n> > Thanks for pointing that out, Patrick. Right now, `parse_options()` is\n> > called just after the `repo_init_revisions()`. I can move the call to\n> > it before this.\n> >\n> > Although when I tried running \"git prune -h\", it still gave me the\n> > expected output.\n>\n> Well, as long as it works and as long as we have a test somewhere that\n> ensures it keeps working I'm happy.\nTo add to the testing part, I noticed that there is no test for\nchecking \"git prune -h\".\n\nYou(Ayush) can add that in \"t/t1517-outside-repo.sh\" there is a\nsimilar test for that also in the file.\n\"test_expect_success 'update-server-info does not crash with -h\" You\ncan check it out.\n\nUsman\n>\n> Patrick\n>\n"},{"id":"521185","messageId":"3CBFE196-1666-497D-B92E-5272736E8B94@gmail.com","threadId":"63600","inReplyTo":"CAPSxiM9ahAPEr5fj_A1RpgYjJQmv9kZ2jYfR2Knat5yHZNDkEA@mail.gmail.com","subject":"Re: [GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2025-07-02T16:53:39Z","receivedAt":"2025-07-02T16:53:51Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"\n> Le 2 juil. 2025 à 07:18, Usman Akinyemi <usmanakinyemi202@gmail.com> a écrit :\n> \n> ﻿On Wed, Jul 2, 2025 at 4:17 PM Patrick Steinhardt <ps@pks.im> wrote:\n>> \n>>> On Tue, Jul 01, 2025 at 11:39:48PM +0530, Ayush Chandekar wrote:\n>>> On Tue, Jul 1, 2025 at 10:12 PM Junio C Hamano <gitster@pobox.com> wrote:\n>>>> \n>>>> Patrick Steinhardt <ps@pks.im> writes:\n>>>> \n>>>>> On Mon, Jun 30, 2025 at 10:11:05PM +0530, Ayush Chandekar wrote:\n>>>>>> @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n>>>>>>     expire = TIME_MAX;\n>>>>>>     save_commit_buffer = 0;\n>>>>>>     disable_replace_refs();\n>>>>>> -    repo_init_revisions(the_repository, &revs, prefix);\n>>>>>> +    repo_init_revisions(repo, &revs, prefix);\n>>>>> \n>>>>> Does this work correctly when running outside of a repository? In\n>>>>> general `cmd_prune()` is not executed and would instead die as it is\n>>>>> declared as `RUN_SETUP`, without the `_GENTLY` suffix. But when the user\n>>>>> asks for help we may still execute the function with a NULL pointer.\n>>>> \n>>>> Good eyes.  \"git prune -h\" would safely exit in parse_options() in\n>>>> such a case, but this part happens before the parse_options() call.\n>>>> \n>>> \n>>> Thanks for pointing that out, Patrick. Right now, `parse_options()` is\n>>> called just after the `repo_init_revisions()`. I can move the call to\n>>> it before this.\n>>> \n>>> Although when I tried running \"git prune -h\", it still gave me the\n>>> expected output.\n>> \n>> Well, as long as it works and as long as we have a test somewhere that\n>> ensures it keeps working I'm happy.\n> To add to the testing part, I noticed that there is no test for\n> checking \"git prune -h\".\n> \n> You(Ayush) can add that in \"t/t1517-outside-repo.sh\" there is a\n> similar test for that also in the file.\n> \"test_expect_success 'update-server-info does not crash with -h\" You\n> can check it out.\n\nAha, TIL! I’ve been working on an (unpublished) series to make help-all work outside repos, too, and I am going to add tests. This will be a nice place. \n\n> \n> Usman\n>> \n>> Patrick\n>> \n> \n"},{"id":"521188","messageId":"xmqq7c0qed3z.fsf@gitster.g","threadId":"63600","inReplyTo":"CAPSxiM9ahAPEr5fj_A1RpgYjJQmv9kZ2jYfR2Knat5yHZNDkEA@mail.gmail.com","subject":"Re: [GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-07-02T17:06:40Z","receivedAt":"2025-07-02T17:06:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Usman Akinyemi <usmanakinyemi202@gmail.com> writes:\n\n> To add to the testing part, I noticed that there is no test for\n> checking \"git prune -h\".\n>\n> You(Ayush) can add that in \"t/t1517-outside-repo.sh\" there is a\n> similar test for that also in the file.\n> \"test_expect_success 'update-server-info does not crash with -h\" You\n> can check it out.\n\nThanks for finding and suggesting a good place to add new test.\n"},{"id":"521221","messageId":"CAE7as+ac6i9RZK5ay7UnAAXA8H1h9gmiHxPU6ezrVDRENZ4DAg@mail.gmail.com","threadId":"63600","inReplyTo":"CAPSxiM9ahAPEr5fj_A1RpgYjJQmv9kZ2jYfR2Knat5yHZNDkEA@mail.gmail.com","subject":"Re: [GSOC PATCH v2 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-07-02T23:51:29Z","receivedAt":"2025-07-02T23:51:42Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"On Wed, Jul 2, 2025 at 4:48 PM Usman Akinyemi\n<usmanakinyemi202@gmail.com> wrote:\n>\n> On Wed, Jul 2, 2025 at 4:17 PM Patrick Steinhardt <ps@pks.im> wrote:\n> >\n> > On Tue, Jul 01, 2025 at 11:39:48PM +0530, Ayush Chandekar wrote:\n> > > On Tue, Jul 1, 2025 at 10:12 PM Junio C Hamano <gitster@pobox.com> wrote:\n> > > >\n> > > > Patrick Steinhardt <ps@pks.im> writes:\n> > > >\n> > > > > On Mon, Jun 30, 2025 at 10:11:05PM +0530, Ayush Chandekar wrote:\n> > > > >> @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n> > > > >>      expire = TIME_MAX;\n> > > > >>      save_commit_buffer = 0;\n> > > > >>      disable_replace_refs();\n> > > > >> -    repo_init_revisions(the_repository, &revs, prefix);\n> > > > >> +    repo_init_revisions(repo, &revs, prefix);\n> > > > >\n> > > > > Does this work correctly when running outside of a repository? In\n> > > > > general `cmd_prune()` is not executed and would instead die as it is\n> > > > > declared as `RUN_SETUP`, without the `_GENTLY` suffix. But when the user\n> > > > > asks for help we may still execute the function with a NULL pointer.\n> > > >\n> > > > Good eyes.  \"git prune -h\" would safely exit in parse_options() in\n> > > > such a case, but this part happens before the parse_options() call.\n> > > >\n> > >\n> > > Thanks for pointing that out, Patrick. Right now, `parse_options()` is\n> > > called just after the `repo_init_revisions()`. I can move the call to\n> > > it before this.\n> > >\n> > > Although when I tried running \"git prune -h\", it still gave me the\n> > > expected output.\n> >\n> > Well, as long as it works and as long as we have a test somewhere that\n> > ensures it keeps working I'm happy.\n> To add to the testing part, I noticed that there is no test for\n> checking \"git prune -h\".\n>\n> You(Ayush) can add that in \"t/t1517-outside-repo.sh\" there is a\n> similar test for that also in the file.\n> \"test_expect_success 'update-server-info does not crash with -h\" You\n> can check it out.\n>\n> Usman\n> >\n> > Patrick\n> >\n\nHey Usman,\n\nThanks a lot for suggesting the test file. Will include it in the\nupdated version of this patch series.\n\nAyush:)\n"},{"id":"521322","messageId":"cover.1751630981.git.ayu.chandekar@gmail.com","threadId":"63600","inReplyTo":"cover.1751296633.git.ayu.chandekar@gmail.com","subject":"[GSOC PATCH v3 0/2] builtin/prune: remove dependency on global variables and 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-07-04T14:12:33Z","receivedAt":"2025-07-04T14:14:03Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"The aim of this patch series is to remove the definition '#define USE_THE_REPOSITORY_VARIABLE' \nfrom \"builtin/prune.c\" by removing global variables and the global 'the_repository'.\n\nThis patch series contains two patches:\n\n1 - Move the global variable 'repository_format_precious_objects' into 'struct repository' \nand update all affected code paths accordingly.\n\n2 - Remove the dependency of 'the_repository' in \"builtin/prunce.c\", allowing the removal of \nthe definition. Also, add a test to check if 'git prune -h' can be run when repository is 'NULL'.\n\n\nAyush Chandekar (2):\n  repository: move 'repository_format_precious_objects' to repo scope\n  builtin/prune: stop depending on 'the_repository'\n\n builtin/gc.c            |  2 +-\n builtin/prune.c         | 27 ++++++++++++---------------\n builtin/repack.c        |  2 +-\n environment.c           |  1 -\n environment.h           |  2 --\n repository.c            |  1 +\n repository.h            |  1 +\n setup.c                 |  5 ++++-\n t/t1517-outside-repo.sh |  7 +++++++\n 9 files changed, 27 insertions(+), 21 deletions(-)\n\n-- \n\nSummary of range-diff:\n* Format the commit message of 1/2 correctly.\n* Move the call to `repo_init_revisions()` after `parse_options()` in 2/2. \n* Add a test to check if 'git prune -h' can be run outside repository in 2/2.\n\nRange-diff with v2:\n1:  a58577a147 ! 1:  a828ade541 repository: move 'repository_format_precious_objects' to repo scope\n    @@ Commit message\n         repository: move 'repository_format_precious_objects' to repo scope\n     \n         The 'extensions.preciousObjects' setting when set true, prevents\n    -    operations that might drop objects from the object storage.\n    -    This setting is populated in the global variable\n    +    operations that might drop objects from the object storage. This setting\n    +    is populated in the global variable\n         'repository_format_precious_objects'.\n    -    Move this global variable to repo scope by adding it to struct\n    -    `repository` and also refactor all the occurences accordingly.\n    +\n    +    Move this global variable to repo scope by adding it to 'struct\n    +    repository and also refactor all the occurences accordingly.\n     \n         This change is part of an ongoing effort to eliminate global variables,\n         improve modularity and help libify the codebase.\n2:  c5eaebc2cc ! 2:  22fbbc8cf1 builtin/prune: stop depending on 'the_repository'\n    @@ Commit message\n         Refactor builtin/prune.c to remove the dependency on the global\n         'the_repository'. Replace all the occurrences of 'the_repository' with\n         repo and thus remove the definition '#define\n    -    USE_THE_REPOSITORY_VARIABLE'\n    +    USE_THE_REPOSITORY_VARIABLE'. Also, add a test to make sure that 'git\n    +    prune -h' can be called when the repository is `NULL`.\n     \n         Mentored-by: Christian Couder <christian.couder@gmail.com>\n         Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>\n    @@ builtin/prune.c: int cmd_prune(int argc,\n      \tsave_commit_buffer = 0;\n      \tdisable_replace_refs();\n     -\trepo_init_revisions(the_repository, &revs, prefix);\n    -+\trepo_init_revisions(repo, &revs, prefix);\n      \n      \targc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n      \n     -\tif (the_repository->repository_format_precious_objects)\n    ++\trepo_init_revisions(repo, &revs, prefix);\n     +\tif (repo->repository_format_precious_objects)\n      \t\tdie(_(\"cannot prune in a precious-objects repo\"));\n      \n    @@ builtin/prune.c: int cmd_prune(int argc,\n      \t\tperform_reachability_traversal(&revs);\n      \t\tprune_shallow(show_only ? PRUNE_SHOW_ONLY : 0);\n      \t}\n    +\n    + ## t/t1517-outside-repo.sh ##\n    +@@ t/t1517-outside-repo.sh: test_expect_success 'update-server-info does not crash with -h' '\n    + \ttest_grep \"[Uu]sage: git update-server-info \" usage\n    + '\n    + \n    ++test_expect_success 'prune does not crash with -h' '\n    ++\ttest_expect_code 129 git prune -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git prune \" usage &&\n    ++\ttest_expect_code 129 nongit git prune -h >usage &&\n    ++\ttest_grep \"[Uu]sage: git prune \" usage\n    ++'\n    ++\n    + test_done\n\n2.49.0\n\n"},{"id":"521323","messageId":"a828ade541b9255a655ad6d4cb3b6a64c900627f.1751630981.git.ayu.chandekar@gmail.com","threadId":"63600","inReplyTo":"cover.1751630981.git.ayu.chandekar@gmail.com","subject":"[GSOC PATCH v3 1/2] repository: move 'repository_format_precious_objects' to repo scope","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-07-04T14:12:34Z","receivedAt":"2025-07-04T14:14:08Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"The 'extensions.preciousObjects' setting when set true, prevents\noperations that might drop objects from the object storage. This setting\nis populated in the global variable\n'repository_format_precious_objects'.\n\nMove this global variable to repo scope by adding it to 'struct\nrepository and also refactor all the occurences accordingly.\n\nThis change is part of an ongoing effort to eliminate global variables,\nimprove modularity and help libify the codebase.\n\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>\nSigned-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n---\n builtin/gc.c     | 2 +-\n builtin/prune.c  | 2 +-\n builtin/repack.c | 2 +-\n environment.c    | 1 -\n environment.h    | 2 --\n repository.c     | 1 +\n repository.h     | 1 +\n setup.c          | 5 ++++-\n 8 files changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 845876ff02..ec10b81dcc 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -998,7 +998,7 @@ int cmd_gc(int argc,\n \tif (opts.detach <= 0 && !skip_foreground_tasks)\n \t\tgc_foreground_tasks(&opts, &cfg);\n \n-\tif (!repository_format_precious_objects) {\n+\tif (!the_repository->repository_format_precious_objects) {\n \t\tstruct child_process repack_cmd = CHILD_PROCESS_INIT;\n \n \t\trepack_cmd.git_cmd = 1;\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex e930caa0c0..dab3c19b6f 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -177,7 +177,7 @@ int cmd_prune(int argc,\n \n \targc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n \n-\tif (repository_format_precious_objects)\n+\tif (the_repository->repository_format_precious_objects)\n \t\tdie(_(\"cannot prune in a precious-objects repo\"));\n \n \twhile (argc--) {\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 5ddc6e7f95..d0e4fa6bed 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -1240,7 +1240,7 @@ int cmd_repack(int argc,\n \tpo_args.depth = xstrdup_or_null(opt_depth);\n \tpo_args.threads = xstrdup_or_null(opt_threads);\n \n-\tif (delete_redundant && repository_format_precious_objects)\n+\tif (delete_redundant && the_repository->repository_format_precious_objects)\n \t\tdie(_(\"cannot delete packs in a precious-objects repo\"));\n \n \tdie_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), \"-A\",\ndiff --git a/environment.c b/environment.c\nindex 7bf0390a33..7c2480b22e 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -37,7 +37,6 @@ int ignore_case;\n int assume_unchanged;\n int is_bare_repository_cfg = -1; /* unspecified */\n int warn_on_object_refname_ambiguity = 1;\n-int repository_format_precious_objects;\n char *git_commit_encoding;\n char *git_log_output_encoding;\n char *apply_default_whitespace;\ndiff --git a/environment.h b/environment.h\nindex 9a3d05d414..3d806ced6e 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -189,8 +189,6 @@ extern enum object_creation_mode object_creation_mode;\n \n extern int grafts_keep_true_parents;\n \n-extern int repository_format_precious_objects;\n-\n const char *get_log_output_encoding(void);\n const char *get_commit_output_encoding(void);\n \ndiff --git a/repository.c b/repository.c\nindex 9b3d6665fc..62709d1c91 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -284,6 +284,7 @@ int repo_init(struct repository *repo,\n \trepo_set_ref_storage_format(repo, format.ref_storage_format);\n \trepo->repository_format_worktree_config = format.worktree_config;\n \trepo->repository_format_relative_worktrees = format.relative_worktrees;\n+\trepo->repository_format_precious_objects = format.precious_objects;\n \n \t/* take ownership of format.partial_clone */\n \trepo->repository_format_partial_clone = format.partial_clone;\ndiff --git a/repository.h b/repository.h\nindex c4c92b2ab9..ad23a243c6 100644\n--- a/repository.h\n+++ b/repository.h\n@@ -151,6 +151,7 @@ struct repository {\n \t/* Configurations */\n \tint repository_format_worktree_config;\n \tint repository_format_relative_worktrees;\n+\tint repository_format_precious_objects;\n \n \t/* Indicate if a repository has a different 'commondir' from 'gitdir' */\n \tunsigned different_commondir:1;\ndiff --git a/setup.c b/setup.c\nindex f93bd6a24a..3ea01e9331 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -753,7 +753,8 @@ static int check_repository_format_gently(const char *gitdir, struct repository_\n \t\tdie(\"%s\", err.buf);\n \t}\n \n-\trepository_format_precious_objects = candidate->precious_objects;\n+\tthe_repository->repository_format_precious_objects = candidate->precious_objects;\n+\n \tstring_list_clear(&candidate->unknown_extensions, 0);\n \tstring_list_clear(&candidate->v1_only_extensions, 0);\n \n@@ -1864,6 +1865,8 @@ const char *setup_git_directory_gently(int *nongit_ok)\n \t\t\tthe_repository->repository_format_partial_clone =\n \t\t\t\trepo_fmt.partial_clone;\n \t\t\trepo_fmt.partial_clone = NULL;\n+\t\t\tthe_repository->repository_format_precious_objects =\n+\t\t\t\trepo_fmt.precious_objects;\n \t\t}\n \t}\n \t/*\n-- \n2.49.0\n\n"},{"id":"521324","messageId":"22fbbc8cf1b5cd622197e6d9f009acdbbcc0e802.1751630981.git.ayu.chandekar@gmail.com","threadId":"63600","inReplyTo":"cover.1751630981.git.ayu.chandekar@gmail.com","subject":"[GSOC PATCH v3 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-07-04T14:12:35Z","receivedAt":"2025-07-04T14:14:15Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"Refactor builtin/prune.c to remove the dependency on the global\n'the_repository'. Replace all the occurrences of 'the_repository' with\nrepo and thus remove the definition '#define\nUSE_THE_REPOSITORY_VARIABLE'. Also, add a test to make sure that 'git\nprune -h' can be called when the repository is `NULL`.\n\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>\nSigned-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>\n---\n builtin/prune.c         | 27 ++++++++++++---------------\n t/t1517-outside-repo.sh |  7 +++++++\n 2 files changed, 19 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex dab3c19b6f..320e9c2341 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"builtin.h\"\n@@ -64,7 +63,7 @@ static void perform_reachability_traversal(struct rev_info *revs)\n \t\treturn;\n \n \tif (show_progress)\n-\t\tprogress = start_delayed_progress(the_repository,\n+\t\tprogress = start_delayed_progress(revs->repo,\n \t\t\t\t\t\t  _(\"Checking connectivity\"), 0);\n \tmark_reachable_objects(revs, 1, expire, progress);\n \tstop_progress(&progress);\n@@ -78,7 +77,7 @@ static int is_object_reachable(const struct object_id *oid,\n \n \tperform_reachability_traversal(revs);\n \n-\tobj = lookup_object(the_repository, oid);\n+\tobj = lookup_object(revs->repo, oid);\n \treturn obj && (obj->flags & SEEN);\n }\n \n@@ -99,8 +98,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,\n \tif (st.st_mtime > expire)\n \t\treturn 0;\n \tif (show_only || verbose) {\n-\t\tenum object_type type = oid_object_info(the_repository, oid,\n-\t\t\t\t\t\t\tNULL);\n+\t\tenum object_type type = oid_object_info(revs->repo, oid, NULL);\n \t\tprintf(\"%s %s\\n\", oid_to_hex(oid),\n \t\t       (type > 0) ? type_name(type) : \"unknown\");\n \t}\n@@ -154,7 +152,7 @@ static void remove_temporary_files(const char *path)\n int cmd_prune(int argc,\n \t      const char **argv,\n \t      const char *prefix,\n-\t      struct repository *repo UNUSED)\n+\t      struct repository *repo)\n {\n \tstruct rev_info revs;\n \tint exclude_promisor_objects = 0;\n@@ -173,20 +171,19 @@ int cmd_prune(int argc,\n \texpire = TIME_MAX;\n \tsave_commit_buffer = 0;\n \tdisable_replace_refs();\n-\trepo_init_revisions(the_repository, &revs, prefix);\n \n \targc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n \n-\tif (the_repository->repository_format_precious_objects)\n+\trepo_init_revisions(repo, &revs, prefix);\n+\tif (repo->repository_format_precious_objects)\n \t\tdie(_(\"cannot prune in a precious-objects repo\"));\n \n \twhile (argc--) {\n \t\tstruct object_id oid;\n \t\tconst char *name = *argv++;\n \n-\t\tif (!repo_get_oid(the_repository, name, &oid)) {\n-\t\t\tstruct object *object = parse_object_or_die(the_repository, &oid,\n-\t\t\t\t\t\t\t\t    name);\n+\t\tif (!repo_get_oid(repo, name, &oid)) {\n+\t\t\tstruct object *object = parse_object_or_die(repo, &oid, name);\n \t\t\tadd_pending_object(&revs, object, \"\");\n \t\t}\n \t\telse\n@@ -200,16 +197,16 @@ int cmd_prune(int argc,\n \t\trevs.exclude_promisor_objects = 1;\n \t}\n \n-\tfor_each_loose_file_in_objdir(repo_get_object_directory(the_repository),\n+\tfor_each_loose_file_in_objdir(repo_get_object_directory(repo),\n \t\t\t\t      prune_object, prune_cruft, prune_subdir, &revs);\n \n \tprune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);\n-\tremove_temporary_files(repo_get_object_directory(the_repository));\n-\ts = mkpathdup(\"%s/pack\", repo_get_object_directory(the_repository));\n+\tremove_temporary_files(repo_get_object_directory(repo));\n+\ts = mkpathdup(\"%s/pack\", repo_get_object_directory(repo));\n \tremove_temporary_files(s);\n \tfree(s);\n \n-\tif (is_repository_shallow(the_repository)) {\n+\tif (is_repository_shallow(repo)) {\n \t\tperform_reachability_traversal(&revs);\n \t\tprune_shallow(show_only ? PRUNE_SHOW_ONLY : 0);\n \t}\ndiff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh\nindex 6824581317..8f59b867f2 100755\n--- a/t/t1517-outside-repo.sh\n+++ b/t/t1517-outside-repo.sh\n@@ -114,4 +114,11 @@ test_expect_success 'update-server-info does not crash with -h' '\n \ttest_grep \"[Uu]sage: git update-server-info \" usage\n '\n \n+test_expect_success 'prune does not crash with -h' '\n+\ttest_expect_code 129 git prune -h >usage &&\n+\ttest_grep \"[Uu]sage: git prune \" usage &&\n+\ttest_expect_code 129 nongit git prune -h >usage &&\n+\ttest_grep \"[Uu]sage: git prune \" usage\n+'\n+\n test_done\n-- \n2.49.0\n\n"},{"id":"521412","messageId":"aGtkZgbJhO-GQ1XX@pks.im","threadId":"63600","inReplyTo":"22fbbc8cf1b5cd622197e6d9f009acdbbcc0e802.1751630981.git.ayu.chandekar@gmail.com","subject":"Re: [GSOC PATCH v3 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-07-07T06:08:38Z","receivedAt":"2025-07-07T06:08:45Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Jul 04, 2025 at 07:42:35PM +0530, Ayush Chandekar wrote:\n> diff --git a/builtin/prune.c b/builtin/prune.c\n> index dab3c19b6f..320e9c2341 100644\n> --- a/builtin/prune.c\n> +++ b/builtin/prune.c\n> @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n>  \texpire = TIME_MAX;\n>  \tsave_commit_buffer = 0;\n>  \tdisable_replace_refs();\n> -\trepo_init_revisions(the_repository, &revs, prefix);\n>  \n>  \targc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n>  \n> -\tif (the_repository->repository_format_precious_objects)\n> +\trepo_init_revisions(repo, &revs, prefix);\n> +\tif (repo->repository_format_precious_objects)\n>  \t\tdie(_(\"cannot prune in a precious-objects repo\"));\n>  \n\nOkay, we now only end up using the passed-in potentially-NULL `repo`\nafter we have called `parse_options`. Makes sense.\n\n> diff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh\n> index 6824581317..8f59b867f2 100755\n> --- a/t/t1517-outside-repo.sh\n> +++ b/t/t1517-outside-repo.sh\n> @@ -114,4 +114,11 @@ test_expect_success 'update-server-info does not crash with -h' '\n>  \ttest_grep \"[Uu]sage: git update-server-info \" usage\n>  '\n>  \n> +test_expect_success 'prune does not crash with -h' '\n> +\ttest_expect_code 129 git prune -h >usage &&\n> +\ttest_grep \"[Uu]sage: git prune \" usage &&\n> +\ttest_expect_code 129 nongit git prune -h >usage &&\n> +\ttest_grep \"[Uu]sage: git prune \" usage\n> +'\n> +\n>  test_done\n\nAnd we have another test that verifies that all of this works outside of\na repository.\n\nThis addresses my review comments, so this version looks good to me.\nThanks!\n\nPatrick\n"},{"id":"521545","messageId":"CAE7as+ZVk0jNb7jXZgrUBHpMAMQqB_3D04qmR-rsjeKNg2mdoA@mail.gmail.com","threadId":"63600","inReplyTo":"aGtkZgbJhO-GQ1XX@pks.im","subject":"Re: [GSOC PATCH v3 2/2] builtin/prune: stop depending on 'the_repository'","fromName":"Ayush Chandekar","fromEmail":"ayu.chandekar@gmail.com","sentAt":"2025-07-08T13:52:14Z","receivedAt":"2025-07-08T13:52:26Z","isPatch":true,"sender":{"key":"ayu.chandekar@gmail.com","avatar":"https://avatars.githubusercontent.com/u/137001939?v=4"},"body":"Hi Patrick,\n\nOn Mon, Jul 7, 2025 at 11:38 AM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> On Fri, Jul 04, 2025 at 07:42:35PM +0530, Ayush Chandekar wrote:\n> > diff --git a/builtin/prune.c b/builtin/prune.c\n> > index dab3c19b6f..320e9c2341 100644\n> > --- a/builtin/prune.c\n> > +++ b/builtin/prune.c\n> > @@ -173,20 +171,19 @@ int cmd_prune(int argc,\n> >       expire = TIME_MAX;\n> >       save_commit_buffer = 0;\n> >       disable_replace_refs();\n> > -     repo_init_revisions(the_repository, &revs, prefix);\n> >\n> >       argc = parse_options(argc, argv, prefix, options, prune_usage, 0);\n> >\n> > -     if (the_repository->repository_format_precious_objects)\n> > +     repo_init_revisions(repo, &revs, prefix);\n> > +     if (repo->repository_format_precious_objects)\n> >               die(_(\"cannot prune in a precious-objects repo\"));\n> >\n>\n> Okay, we now only end up using the passed-in potentially-NULL `repo`\n> after we have called `parse_options`. Makes sense.\n>\n> > diff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh\n> > index 6824581317..8f59b867f2 100755\n> > --- a/t/t1517-outside-repo.sh\n> > +++ b/t/t1517-outside-repo.sh\n> > @@ -114,4 +114,11 @@ test_expect_success 'update-server-info does not crash with -h' '\n> >       test_grep \"[Uu]sage: git update-server-info \" usage\n> >  '\n> >\n> > +test_expect_success 'prune does not crash with -h' '\n> > +     test_expect_code 129 git prune -h >usage &&\n> > +     test_grep \"[Uu]sage: git prune \" usage &&\n> > +     test_expect_code 129 nongit git prune -h >usage &&\n> > +     test_grep \"[Uu]sage: git prune \" usage\n> > +'\n> > +\n> >  test_done\n>\n> And we have another test that verifies that all of this works outside of\n> a repository.\n>\n> This addresses my review comments, so this version looks good to me.\n> Thanks!\n>\n> Patrick\n\nThanks a lot for reviewing!\n\nAyush\n"}]}