Merge branch 'hm/config-parse-expiry-date'
authorJunio C Hamano <gitster@pobox.com>
Wed, 6 Dec 2017 17:23:37 +0000 (09:23 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Dec 2017 17:23:37 +0000 (09:23 -0800)
"git config --expiry-date gc.reflogexpire" can read "2.weeks" from
the configuration and report it as a timestamp, just like "--int"
would read "1k" and report 1024, to help consumption by scripts.

* hm/config-parse-expiry-date:
config: add --expiry-date

1  2 
config.c
config.h
diff --combined config.c
index 676786a028f2c726a55694cb5af1b1781ddd6e4e,64f8aa42beb09920b8e67d7aaf7169cd3708c0ff..e617c2018d22b6d389548a3573d2deb2ec608b99
+++ b/config.c
@@@ -990,6 -990,16 +990,16 @@@ int git_config_pathname(const char **de
        return 0;
  }
  
+ int git_config_expiry_date(timestamp_t *timestamp, const char *var, const char *value)
+ {
+       if (!value)
+               return config_error_nonbool(var);
+       if (parse_expiry_date(value, timestamp))
+               return error(_("'%s' for '%s' is not a valid timestamp"),
+                            value, var);
+       return 0;
+ }
  static int git_default_core_config(const char *var, const char *value)
  {
        /* This needs a better name */
@@@ -2156,20 -2166,6 +2166,20 @@@ int git_config_get_max_percent_split_ch
        return -1; /* default value */
  }
  
 +int git_config_get_fsmonitor(void)
 +{
 +      if (git_config_get_pathname("core.fsmonitor", &core_fsmonitor))
 +              core_fsmonitor = getenv("GIT_FSMONITOR_TEST");
 +
 +      if (core_fsmonitor && !*core_fsmonitor)
 +              core_fsmonitor = NULL;
 +
 +      if (core_fsmonitor)
 +              return 1;
 +
 +      return 0;
 +}
 +
  NORETURN
  void git_die_config_linenr(const char *key, const char *filename, int linenr)
  {
@@@ -2329,7 -2325,7 +2339,7 @@@ static ssize_t write_section(int fd, co
        struct strbuf sb = store_create_section(key);
        ssize_t ret;
  
 -      ret = write_in_full(fd, sb.buf, sb.len) == sb.len;
 +      ret = write_in_full(fd, sb.buf, sb.len);
        strbuf_release(&sb);
  
        return ret;
@@@ -2824,7 -2820,7 +2834,7 @@@ static int git_config_copy_or_rename_se
                         * multiple [branch "$name"] sections.
                         */
                        if (copystr.len > 0) {
 -                              if (write_in_full(out_fd, copystr.buf, copystr.len) != copystr.len) {
 +                              if (write_in_full(out_fd, copystr.buf, copystr.len) < 0) {
                                        ret = write_error(get_lock_file_path(&lock));
                                        goto out;
                                }
         * logic in the loop above.
         */
        if (copystr.len > 0) {
 -              if (write_in_full(out_fd, copystr.buf, copystr.len) != copystr.len) {
 +              if (write_in_full(out_fd, copystr.buf, copystr.len) < 0) {
                        ret = write_error(get_lock_file_path(&lock));
                        goto out;
                }
diff --combined config.h
index 524d411823e1949dd180ada236a6f4edee8ef7eb,fc66c593328ff1bb2d6481486011b62afbf8fb9a..ef70a9cac1e6dc67df24d157a4e5de38edd8c984
+++ b/config.h
@@@ -58,6 -58,7 +58,7 @@@ extern int git_config_bool_or_int(cons
  extern int git_config_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_expiry_date(timestamp_t *, const char *, const char *);
  extern int git_config_set_in_file_gently(const char *, const char *, const char *);
  extern void git_config_set_in_file(const char *, const char *, const char *);
  extern int git_config_set_gently(const char *, const char *);
@@@ -212,7 -213,6 +213,7 @@@ extern int git_config_get_pathname(cons
  extern int git_config_get_untracked_cache(void);
  extern int git_config_get_split_index(void);
  extern int git_config_get_max_percent_split_change(void);
 +extern int git_config_get_fsmonitor(void);
  
  /* This dies if the configured or default date is in the future */
  extern int git_config_get_expiry(const char *key, const char **output);