]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ps/maintenance-detach-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 26 Aug 2024 18:32:20 +0000 (11:32 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Aug 2024 18:32:20 +0000 (11:32 -0700)
Maintenance tasks other than "gc" now properly go background when
"git maintenance" runs them.

* ps/maintenance-detach-fix:
  run-command: fix detaching when running auto maintenance
  builtin/maintenance: add a `--detach` flag
  builtin/gc: add a `--detach` flag
  builtin/gc: stop processing log file on signal
  builtin/gc: fix leaking config values
  builtin/gc: refactor to read config into structure
  config: fix constness of out parameter for `git_config_get_expiry()`

1  2 
builtin/gc.c
config.c
config.h
read-cache.c

diff --cc builtin/gc.c
index 45f14fb09bffed43a36de4437f12ffb642b65b0c,bafee330a2408aa712d92f59944928491d9a73fc..bd0a1b92ba19164435695844a14381d7036f4a1c
@@@ -158,24 -179,43 +179,43 @@@ static void gc_config(struct gc_config 
  
        if (gc_config_is_timestamp_never("gc.reflogexpire") &&
            gc_config_is_timestamp_never("gc.reflogexpireunreachable"))
-               prune_reflogs = 0;
+               cfg->prune_reflogs = 0;
+       git_config_get_int("gc.aggressivewindow", &cfg->aggressive_window);
+       git_config_get_int("gc.aggressivedepth", &cfg->aggressive_depth);
+       git_config_get_int("gc.auto", &cfg->gc_auto_threshold);
+       git_config_get_int("gc.autopacklimit", &cfg->gc_auto_pack_limit);
+       git_config_get_bool("gc.autodetach", &cfg->detach_auto);
+       git_config_get_bool("gc.cruftpacks", &cfg->cruft_packs);
+       git_config_get_ulong("gc.maxcruftsize", &cfg->max_cruft_size);
 -      if (!git_config_get_expiry("gc.pruneexpire", &owned)) {
++      if (!repo_config_get_expiry(the_repository, "gc.pruneexpire", &owned)) {
+               free(cfg->prune_expire);
+               cfg->prune_expire = owned;
+       }
  
-       git_config_get_int("gc.aggressivewindow", &aggressive_window);
-       git_config_get_int("gc.aggressivedepth", &aggressive_depth);
-       git_config_get_int("gc.auto", &gc_auto_threshold);
-       git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
-       git_config_get_bool("gc.autodetach", &detach_auto);
-       git_config_get_bool("gc.cruftpacks", &cruft_packs);
-       git_config_get_ulong("gc.maxcruftsize", &max_cruft_size);
-       repo_config_get_expiry(the_repository, "gc.pruneexpire", &prune_expire);
-       repo_config_get_expiry(the_repository, "gc.worktreepruneexpire", &prune_worktrees_expire);
-       repo_config_get_expiry(the_repository, "gc.logexpiry", &gc_log_expire);
 -      if (!git_config_get_expiry("gc.worktreepruneexpire", &owned)) {
++      if (!repo_config_get_expiry(the_repository, "gc.worktreepruneexpire", &owned)) {
+               free(cfg->prune_worktrees_expire);
+               cfg->prune_worktrees_expire = owned;
+       }
 -      if (!git_config_get_expiry("gc.logexpiry", &owned)) {
++      if (!repo_config_get_expiry(the_repository, "gc.logexpiry", &owned)) {
+               free(cfg->gc_log_expire);
+               cfg->gc_log_expire = owned;
+       }
  
-       git_config_get_ulong("gc.bigpackthreshold", &big_pack_threshold);
-       git_config_get_ulong("pack.deltacachesize", &max_delta_cache_size);
+       git_config_get_ulong("gc.bigpackthreshold", &cfg->big_pack_threshold);
+       git_config_get_ulong("pack.deltacachesize", &cfg->max_delta_cache_size);
  
-       git_config_get_string("gc.repackfilter", &repack_filter);
-       git_config_get_string("gc.repackfilterto", &repack_filter_to);
+       if (!git_config_get_string("gc.repackfilter", &owned)) {
+               free(cfg->repack_filter);
+               cfg->repack_filter = owned;
+       }
+       if (!git_config_get_string("gc.repackfilterto", &owned)) {
+               free(cfg->repack_filter_to);
+               cfg->repack_filter_to = owned;
+       }
  
        git_config(git_default_config, NULL);
  }
diff --cc config.c
index 985089752445af45fadd1062d349797e42879474,dfa4df1417992c7716048e5218c10f4a08edfadf..56b5862e59d51411935c399c23cf126005b6b103
+++ b/config.c
@@@ -2694,9 -2694,81 +2694,10 @@@ void git_protected_config(config_fn_t f
        configset_iter(&protected_config, fn, data);
  }
  
- int repo_config_get_expiry(struct repository *r, const char *key, const char **output)
 -/* Functions used historically to read configuration from 'the_repository' */
 -void git_config(config_fn_t fn, void *data)
++int repo_config_get_expiry(struct repository *r, const char *key, char **output)
  {
-       int ret = repo_config_get_string(r, key, (char **)output);
 -      repo_config(the_repository, fn, data);
 -}
++      int ret = repo_config_get_string(r, key, output);
 -void git_config_clear(void)
 -{
 -      repo_config_clear(the_repository);
 -}
 -
 -int git_config_get(const char *key)
 -{
 -      return repo_config_get(the_repository, key);
 -}
 -
 -int git_config_get_value(const char *key, const char **value)
 -{
 -      return repo_config_get_value(the_repository, key, value);
 -}
 -
 -int git_config_get_value_multi(const char *key, const struct string_list **dest)
 -{
 -      return repo_config_get_value_multi(the_repository, key, dest);
 -}
 -
 -int git_config_get_string_multi(const char *key,
 -                              const struct string_list **dest)
 -{
 -      return repo_config_get_string_multi(the_repository, key, dest);
 -}
 -
 -int git_config_get_string(const char *key, char **dest)
 -{
 -      return repo_config_get_string(the_repository, key, dest);
 -}
 -
 -int git_config_get_string_tmp(const char *key, const char **dest)
 -{
 -      return repo_config_get_string_tmp(the_repository, key, dest);
 -}
 -
 -int git_config_get_int(const char *key, int *dest)
 -{
 -      return repo_config_get_int(the_repository, key, dest);
 -}
 -
 -int git_config_get_ulong(const char *key, unsigned long *dest)
 -{
 -      return repo_config_get_ulong(the_repository, key, dest);
 -}
 -
 -int git_config_get_bool(const char *key, int *dest)
 -{
 -      return repo_config_get_bool(the_repository, key, dest);
 -}
 -
 -int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest)
 -{
 -      return repo_config_get_bool_or_int(the_repository, key, is_bool, dest);
 -}
 -
 -int git_config_get_maybe_bool(const char *key, int *dest)
 -{
 -      return repo_config_get_maybe_bool(the_repository, key, dest);
 -}
 -
 -int git_config_get_pathname(const char *key, char **dest)
 -{
 -      return repo_config_get_pathname(the_repository, key, dest);
 -}
 -
 -int git_config_get_expiry(const char *key, char **output)
 -{
 -      int ret = git_config_get_string(key, output);
        if (ret)
                return ret;
        if (strcmp(*output, "now")) {
diff --cc config.h
index 4d319a41937508bd6d63ecfd20bd5b40ba4b8854,4801391c32ca5e953c5d44edc22ed7d1967dff0c..d0497157c52f576bbd7bcceda7739a28a576c6c3
+++ b/config.h
@@@ -651,32 -676,35 +651,32 @@@ int repo_config_get_ulong(struct reposi
   * configuration variable `key` is not found, returns 1 without touching
   * `dest`.
   */
 -int git_config_get_bool(const char *key, int *dest);
 +int repo_config_get_bool(struct repository *r, const char *key, int *dest);
  
  /**
 - * Similar to `git_config_get_bool`, except that integers are copied as-is,
 + * Similar to `repo_config_get_bool`, except that integers are copied as-is,
   * and `is_bool` flag is unset.
   */
 -int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
 +int repo_config_get_bool_or_int(struct repository *r, const char *key,
 +                              int *is_bool, int *dest);
  
  /**
 - * Similar to `git_config_get_bool`, except that it returns -1 on error
 + * Similar to `repo_config_get_bool`, except that it returns -1 on error
   * rather than dying.
   */
 -int git_config_get_maybe_bool(const char *key, int *dest);
 -
 -/**
 - * Similar to `git_config_get_string`, but expands `~` or `~user` into
 - * the user's home directory when found at the beginning of the path.
 - */
 -int git_config_get_pathname(const char *key, char **dest);
 +int repo_config_get_maybe_bool(struct repository *r,
 +                            const char *key, int *dest);
  
 -int git_config_get_index_threads(int *dest);
 -int git_config_get_split_index(void);
 -int git_config_get_max_percent_split_change(void);
 +int repo_config_get_index_threads(struct repository *r, int *dest);
 +int repo_config_get_split_index(struct repository *r);
 +int repo_config_get_max_percent_split_change(struct repository *r);
  
  /* This dies if the configured or default date is in the future */
- int repo_config_get_expiry(struct repository *r, const char *key, const char **output);
 -int git_config_get_expiry(const char *key, char **output);
++int repo_config_get_expiry(struct repository *r, const char *key, char **output);
  
  /* parse either "this many days" integer, or "5.days.ago" approxidate */
 -int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);
 +int repo_config_get_expiry_in_days(struct repository *r, const char *key,
 +                                 timestamp_t *, timestamp_t now);
  
  /**
   * First prints the error message specified by the caller in `err` and then
diff --cc read-cache.c
index 54643981627eef2b23f1138a01de495ba8d58db8,7f393ee687dd8ad72b4e5c2caf94e12bf3f92022..4e67dc182e7467708f3d6195b642523b0f9a5d01
@@@ -3203,10 -3182,18 +3201,18 @@@ static unsigned long get_shared_index_e
        static int shared_index_expire_date_prepared;
  
        if (!shared_index_expire_date_prepared) {
 -              git_config_get_expiry("splitindex.sharedindexexpire",
 -                                    &value);
+               const char *shared_index_expire = "2.weeks.ago";
+               char *value = NULL;
-                                      &shared_index_expire);
 +              repo_config_get_expiry(the_repository, "splitindex.sharedindexexpire",
++                                     &value);
+               if (value)
+                       shared_index_expire = value;
                shared_index_expire_date = approxidate(shared_index_expire);
                shared_index_expire_date_prepared = 1;
+               free(value);
        }
  
        return shared_index_expire_date;