]> git.ipfire.org Git - thirdparty/git.git/commitdiff
config: make `packed_git_(limit|window_size)` non-global variables
authorKarthik Nayak <karthik.188@gmail.com>
Tue, 3 Dec 2024 14:44:02 +0000 (15:44 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Dec 2024 23:21:55 +0000 (08:21 +0900)
The variables `packed_git_window_size` and `packed_git_limit` are global
config variables used in the `packfile.c` file. Since it is only used in
this file, let's change it from being a global config variable to a
local variable for the subsystem.

With this, we rid `packfile.c` from all global variable usage and this
means we can also remove the `USE_THE_REPOSITORY_VARIABLE` guard from
the file.

Helped-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-import.c
config.c
environment.c
packfile.c
packfile.h
repo-settings.c
repo-settings.h

index 3ccc4c572272a9a2b7c1199bd0d99e05fbde97c5..0ece07026044e06c2a2ca2b83874590f11527f16 100644 (file)
@@ -3539,7 +3539,7 @@ static void parse_argv(void)
 int cmd_fast_import(int argc,
                    const char **argv,
                    const char *prefix,
-                   struct repository *repo UNUSED)
+                   struct repository *repo)
 {
        unsigned int i;
 
@@ -3660,7 +3660,7 @@ int cmd_fast_import(int argc,
                fprintf(stderr, "       pools:    %10lu KiB\n", (unsigned long)((tree_entry_allocd + fi_mem_pool.pool_alloc) /1024));
                fprintf(stderr, "     objects:    %10" PRIuMAX " KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
                fprintf(stderr, "---------------------------------------------------------------------\n");
-               pack_report();
+               pack_report(repo);
                fprintf(stderr, "---------------------------------------------------------------------\n");
                fprintf(stderr, "\n");
        }
index 728ef98e427d6a8b7ae6ec71cfca444911fbdae5..2c295f7430848c6751fb8ae2c36acfd0a0c15bc8 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1493,28 +1493,11 @@ static int git_default_core_config(const char *var, const char *value,
                return 0;
        }
 
-       if (!strcmp(var, "core.packedgitwindowsize")) {
-               int pgsz_x2 = getpagesize() * 2;
-               packed_git_window_size = git_config_ulong(var, value, ctx->kvi);
-
-               /* This value must be multiple of (pagesize * 2) */
-               packed_git_window_size /= pgsz_x2;
-               if (packed_git_window_size < 1)
-                       packed_git_window_size = 1;
-               packed_git_window_size *= pgsz_x2;
-               return 0;
-       }
-
        if (!strcmp(var, "core.bigfilethreshold")) {
                big_file_threshold = git_config_ulong(var, value, ctx->kvi);
                return 0;
        }
 
-       if (!strcmp(var, "core.packedgitlimit")) {
-               packed_git_limit = git_config_ulong(var, value, ctx->kvi);
-               return 0;
-       }
-
        if (!strcmp(var, "core.autocrlf")) {
                if (value && !strcasecmp(value, "input")) {
                        auto_crlf = AUTO_CRLF_INPUT;
index 8e5022c282ca032411942d29b0a83e6cc010ea6a..8389a272700eac7e07710b6899eb045c7df4f69a 100644 (file)
@@ -49,8 +49,6 @@ int fsync_object_files = -1;
 int use_fsync = -1;
 enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
 enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;
-size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
-size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
 unsigned long big_file_threshold = 512 * 1024 * 1024;
 char *editor_program;
 char *askpass_program;
index 64248ca664a0309cfc86bbfe727aa20740afea8a..2e0e28c7de88c5456c56d37fb790016ac10578e8 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
 
 #include "git-compat-util.h"
 #include "environment.h"
@@ -46,15 +45,15 @@ static size_t pack_mapped;
 #define SZ_FMT PRIuMAX
 static inline uintmax_t sz_fmt(size_t s) { return s; }
 
-void pack_report(void)
+void pack_report(struct repository *repo)
 {
        fprintf(stderr,
                "pack_report: getpagesize()            = %10" SZ_FMT "\n"
                "pack_report: core.packedGitWindowSize = %10" SZ_FMT "\n"
                "pack_report: core.packedGitLimit      = %10" SZ_FMT "\n",
                sz_fmt(getpagesize()),
-               sz_fmt(packed_git_window_size),
-               sz_fmt(packed_git_limit));
+               sz_fmt(repo->settings.packed_git_window_size),
+               sz_fmt(repo->settings.packed_git_limit));
        fprintf(stderr,
                "pack_report: pack_used_ctr            = %10u\n"
                "pack_report: pack_mmap_calls          = %10u\n"
@@ -650,8 +649,15 @@ unsigned char *use_pack(struct packed_git *p,
                                break;
                }
                if (!win) {
-                       size_t window_align = packed_git_window_size / 2;
+                       size_t window_align;
                        off_t len;
+                       struct repo_settings *settings;
+
+                       /* lazy load the settings in case it hasn't been setup */
+                       prepare_repo_settings(p->repo);
+                       settings = &p->repo->settings;
+
+                       window_align = settings->packed_git_window_size / 2;
 
                        if (p->pack_fd == -1 && open_packed_git(p))
                                die("packfile %s cannot be accessed", p->pack_name);
@@ -659,11 +665,12 @@ unsigned char *use_pack(struct packed_git *p,
                        CALLOC_ARRAY(win, 1);
                        win->offset = (offset / window_align) * window_align;
                        len = p->pack_size - win->offset;
-                       if (len > packed_git_window_size)
-                               len = packed_git_window_size;
+                       if (len > settings->packed_git_window_size)
+                               len = settings->packed_git_window_size;
                        win->len = (size_t)len;
                        pack_mapped += win->len;
-                       while (packed_git_limit < pack_mapped
+
+                       while (settings->packed_git_limit < pack_mapped
                                && unuse_one_window(p))
                                ; /* nothing */
                        win->base = xmmap_gently(NULL, win->len,
index addb95b0c44800dd2e0497afcdc3add15d57eef3..58104fa009d601c40aaf4fa7ab8e462b841fdef1 100644 (file)
@@ -89,7 +89,7 @@ unsigned long repo_approximate_object_count(struct repository *r);
 struct packed_git *find_oid_pack(const struct object_id *oid,
                                 struct packed_git *packs);
 
-void pack_report(void);
+void pack_report(struct repository *repo);
 
 /*
  * mmap the index file for the specified packfile (if it is not
index acc27eb8fe7ce7dd9dbf3ff23c1f485f513c4c53..9d16d5399e3751a59f4cd527671d216f5e805363 100644 (file)
@@ -128,6 +128,19 @@ void prepare_repo_settings(struct repository *r)
 
        if (!repo_config_get_ulong(r, "core.deltabasecachelimit", &ulongval))
                r->settings.delta_base_cache_limit = ulongval;
+
+       if (!repo_config_get_ulong(r, "core.packedgitwindowsize", &ulongval)) {
+               int pgsz_x2 = getpagesize() * 2;
+
+               /* This value must be multiple of (pagesize * 2) */
+               ulongval /= pgsz_x2;
+               if (ulongval < 1)
+                       ulongval = 1;
+               r->settings.packed_git_window_size = ulongval * pgsz_x2;
+       }
+
+       if (!repo_config_get_ulong(r, "core.packedgitlimit", &ulongval))
+               r->settings.packed_git_limit = ulongval;
 }
 
 enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo)
index 10a6f7ed64da636a5d98f135d11efa9f87b51938..93ea0c3274112531bd93804a57da6469486a1ec1 100644 (file)
@@ -59,6 +59,8 @@ struct repo_settings {
        int warn_ambiguous_refs; /* lazily loaded via accessor */
 
        size_t delta_base_cache_limit;
+       size_t packed_git_window_size;
+       size_t packed_git_limit;
 };
 #define REPO_SETTINGS_INIT { \
        .index_version = -1, \
@@ -66,6 +68,8 @@ struct repo_settings {
        .fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \
        .warn_ambiguous_refs = -1, \
        .delta_base_cache_limit = DEFAULT_DELTA_BASE_CACHE_LIMIT, \
+       .packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE, \
+       .packed_git_limit = DEFAULT_PACKED_GIT_LIMIT, \
 }
 
 void prepare_repo_settings(struct repository *r);