Git fork

repository: move 'repository_format_precious_objects' to repo scope

The 'extensions.preciousObjects' setting when set true, prevents
operations that might drop objects from the object storage. This setting
is populated in the global variable
'repository_format_precious_objects'.

Move this global variable to repo scope by adding it to 'struct
repository and also refactor all the occurences accordingly.

This change is part of an ongoing effort to eliminate global variables,
improve modularity and help libify the codebase.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Ayush Chandekar and committed by
Junio C Hamano
44e300a9 cf6f63ea

+9 -7
+1 -1
builtin/gc.c
··· 998 if (opts.detach <= 0 && !skip_foreground_tasks) 999 gc_foreground_tasks(&opts, &cfg); 1000 1001 - if (!repository_format_precious_objects) { 1002 struct child_process repack_cmd = CHILD_PROCESS_INIT; 1003 1004 repack_cmd.git_cmd = 1;
··· 998 if (opts.detach <= 0 && !skip_foreground_tasks) 999 gc_foreground_tasks(&opts, &cfg); 1000 1001 + if (!the_repository->repository_format_precious_objects) { 1002 struct child_process repack_cmd = CHILD_PROCESS_INIT; 1003 1004 repack_cmd.git_cmd = 1;
+1 -1
builtin/prune.c
··· 177 178 argc = parse_options(argc, argv, prefix, options, prune_usage, 0); 179 180 - if (repository_format_precious_objects) 181 die(_("cannot prune in a precious-objects repo")); 182 183 while (argc--) {
··· 177 178 argc = parse_options(argc, argv, prefix, options, prune_usage, 0); 179 180 + if (the_repository->repository_format_precious_objects) 181 die(_("cannot prune in a precious-objects repo")); 182 183 while (argc--) {
+1 -1
builtin/repack.c
··· 1240 po_args.depth = xstrdup_or_null(opt_depth); 1241 po_args.threads = xstrdup_or_null(opt_threads); 1242 1243 - if (delete_redundant && repository_format_precious_objects) 1244 die(_("cannot delete packs in a precious-objects repo")); 1245 1246 die_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), "-A",
··· 1240 po_args.depth = xstrdup_or_null(opt_depth); 1241 po_args.threads = xstrdup_or_null(opt_threads); 1242 1243 + if (delete_redundant && the_repository->repository_format_precious_objects) 1244 die(_("cannot delete packs in a precious-objects repo")); 1245 1246 die_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), "-A",
-1
environment.c
··· 37 int assume_unchanged; 38 int is_bare_repository_cfg = -1; /* unspecified */ 39 int warn_on_object_refname_ambiguity = 1; 40 - int repository_format_precious_objects; 41 char *git_commit_encoding; 42 char *git_log_output_encoding; 43 char *apply_default_whitespace;
··· 37 int assume_unchanged; 38 int is_bare_repository_cfg = -1; /* unspecified */ 39 int warn_on_object_refname_ambiguity = 1; 40 char *git_commit_encoding; 41 char *git_log_output_encoding; 42 char *apply_default_whitespace;
-2
environment.h
··· 189 190 extern int grafts_keep_true_parents; 191 192 - extern int repository_format_precious_objects; 193 - 194 const char *get_log_output_encoding(void); 195 const char *get_commit_output_encoding(void); 196
··· 189 190 extern int grafts_keep_true_parents; 191 192 const char *get_log_output_encoding(void); 193 const char *get_commit_output_encoding(void); 194
+1
repository.c
··· 284 repo_set_ref_storage_format(repo, format.ref_storage_format); 285 repo->repository_format_worktree_config = format.worktree_config; 286 repo->repository_format_relative_worktrees = format.relative_worktrees; 287 288 /* take ownership of format.partial_clone */ 289 repo->repository_format_partial_clone = format.partial_clone;
··· 284 repo_set_ref_storage_format(repo, format.ref_storage_format); 285 repo->repository_format_worktree_config = format.worktree_config; 286 repo->repository_format_relative_worktrees = format.relative_worktrees; 287 + repo->repository_format_precious_objects = format.precious_objects; 288 289 /* take ownership of format.partial_clone */ 290 repo->repository_format_partial_clone = format.partial_clone;
+1
repository.h
··· 151 /* Configurations */ 152 int repository_format_worktree_config; 153 int repository_format_relative_worktrees; 154 155 /* Indicate if a repository has a different 'commondir' from 'gitdir' */ 156 unsigned different_commondir:1;
··· 151 /* Configurations */ 152 int repository_format_worktree_config; 153 int repository_format_relative_worktrees; 154 + int repository_format_precious_objects; 155 156 /* Indicate if a repository has a different 'commondir' from 'gitdir' */ 157 unsigned different_commondir:1;
+4 -1
setup.c
··· 753 die("%s", err.buf); 754 } 755 756 - repository_format_precious_objects = candidate->precious_objects; 757 string_list_clear(&candidate->unknown_extensions, 0); 758 string_list_clear(&candidate->v1_only_extensions, 0); 759 ··· 1864 the_repository->repository_format_partial_clone = 1865 repo_fmt.partial_clone; 1866 repo_fmt.partial_clone = NULL; 1867 } 1868 } 1869 /*
··· 753 die("%s", err.buf); 754 } 755 756 + the_repository->repository_format_precious_objects = candidate->precious_objects; 757 + 758 string_list_clear(&candidate->unknown_extensions, 0); 759 string_list_clear(&candidate->v1_only_extensions, 0); 760 ··· 1865 the_repository->repository_format_partial_clone = 1866 repo_fmt.partial_clone; 1867 repo_fmt.partial_clone = NULL; 1868 + the_repository->repository_format_precious_objects = 1869 + repo_fmt.precious_objects; 1870 } 1871 } 1872 /*