Merge branch 'ma/remove-config-maybe-bool' into next
authorJunio C Hamano <gitster@pobox.com>
Thu, 14 Sep 2017 08:40:37 +0000 (17:40 +0900)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Sep 2017 08:40:37 +0000 (17:40 +0900)
Finishing touches to a recent topic.

* ma/remove-config-maybe-bool:
config: remove git_config_maybe_bool

1  2 
config.c
config.h
diff --combined config.c
index 7931182a547b2e1a627c6dc95061e357abe2febd,f49cd2a014bc34c059bf49d2a2378b743283d4af..cd5a69e6308c0cad6028deb04fb17e8d2dc4086c
+++ b/config.c
@@@ -956,11 -956,6 +956,6 @@@ int git_parse_maybe_bool(const char *va
        return -1;
  }
  
- int git_config_maybe_bool(const char *name, const char *value)
- {
-       return git_parse_maybe_bool(value);
- }
  int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
  {
        int v = git_parse_maybe_bool_text(value);
@@@ -2094,28 -2089,6 +2089,28 @@@ int git_config_get_expiry(const char *k
        return ret;
  }
  
 +int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamp_t now)
 +{
 +      char *expiry_string;
 +      intmax_t days;
 +      timestamp_t when;
 +
 +      if (git_config_get_string(key, &expiry_string))
 +              return 1; /* no such thing */
 +
 +      if (git_parse_signed(expiry_string, &days, maximum_signed_value_of_type(int))) {
 +              const int scale = 86400;
 +              *expiry = now - days * scale;
 +              return 0;
 +      }
 +
 +      if (!parse_expiry_date(expiry_string, &when)) {
 +              *expiry = when;
 +              return 0;
 +      }
 +      return -1; /* thing exists but cannot be parsed */
 +}
 +
  int git_config_get_untracked_cache(void)
  {
        int val = -1;
@@@ -2450,7 -2423,7 +2445,7 @@@ int git_config_set_multivar_in_file_gen
  {
        int fd = -1, in_fd = -1;
        int ret;
 -      struct lock_file *lock = NULL;
 +      struct lock_file lock = LOCK_INIT;
        char *filename_buf = NULL;
        char *contents = NULL;
        size_t contents_sz;
         * The lock serves a purpose in addition to locking: the new
         * contents of .git/config will be written into it.
         */
 -      lock = xcalloc(1, sizeof(struct lock_file));
 -      fd = hold_lock_file_for_update(lock, config_filename, 0);
 +      fd = hold_lock_file_for_update(&lock, config_filename, 0);
        if (fd < 0) {
                error_errno("could not lock config file %s", config_filename);
                free(store.key);
                close(in_fd);
                in_fd = -1;
  
 -              if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
 -                      error_errno("chmod on %s failed", get_lock_file_path(lock));
 +              if (chmod(get_lock_file_path(&lock), st.st_mode & 07777) < 0) {
 +                      error_errno("chmod on %s failed", get_lock_file_path(&lock));
                        ret = CONFIG_NO_WRITE;
                        goto out_free;
                }
                contents = NULL;
        }
  
 -      if (commit_lock_file(lock) < 0) {
 +      if (commit_lock_file(&lock) < 0) {
                error_errno("could not write config file %s", config_filename);
                ret = CONFIG_NO_WRITE;
 -              lock = NULL;
                goto out_free;
        }
  
 -      /*
 -       * lock is committed, so don't try to roll it back below.
 -       * NOTE: Since lockfile.c keeps a linked list of all created
 -       * lock_file structures, it isn't safe to free(lock).  It's
 -       * better to just leave it hanging around.
 -       */
 -      lock = NULL;
        ret = 0;
  
        /* Invalidate the config cache */
        git_config_clear();
  
  out_free:
 -      if (lock)
 -              rollback_lock_file(lock);
 +      rollback_lock_file(&lock);
        free(filename_buf);
        if (contents)
                munmap(contents, contents_sz);
        return ret;
  
  write_err_out:
 -      ret = write_error(get_lock_file_path(lock));
 +      ret = write_error(get_lock_file_path(&lock));
        goto out_free;
  
  }
diff --combined config.h
index 97471b887320b48f1b4c2d5a2023f6ffd1acf94e,bc008b9e15f6daa354459383192a8a6f54c83017..456b3d134d3ed187b80b5941c20690763f3eab35
+++ b/config.h
@@@ -56,7 -56,6 +56,6 @@@ extern unsigned long git_config_ulong(c
  extern ssize_t git_config_ssize_t(const char *, const char *);
  extern int git_config_bool_or_int(const char *, const char *, int *);
  extern int git_config_bool(const char *, const char *);
- extern int git_config_maybe_bool(const char *, const char *);
  extern int git_config_string(const char **, const char *, const char *);
  extern int git_config_pathname(const char **, const char *, const char *);
  extern int git_config_set_in_file_gently(const char *, const char *, const char *);
@@@ -215,9 -214,6 +214,9 @@@ extern int git_config_get_max_percent_s
  /* This dies if the configured or default date is in the future */
  extern int git_config_get_expiry(const char *key, const char **output);
  
 +/* parse either "this many days" integer, or "5.days.ago" approxidate */
 +extern int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now);
 +
  struct key_value_info {
        const char *filename;
        int linenr;