Merge branch 'jk/flockfile-stdio'
authorJunio C Hamano <gitster@pobox.com>
Wed, 25 Apr 2018 04:28:52 +0000 (13:28 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Apr 2018 04:28:52 +0000 (13:28 +0900)
Code clean-up.

* jk/flockfile-stdio:
config: move flockfile() closer to unlocked functions

1  2 
config.c
diff --combined config.c
index c698988f5e11cd416bef9a77c998d94b9ef87930,25686d9ff5064cff0fa9625d0f13aa9297f7ce1a..563853c4be2620d86f90734034427206ed92e613
+++ b/config.c
@@@ -990,16 -990,6 +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 */
        }
  
        if (!strcmp(var, "core.safecrlf")) {
 +              int eol_rndtrp_die;
                if (value && !strcasecmp(value, "warn")) {
 -                      safe_crlf = SAFE_CRLF_WARN;
 +                      global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
                        return 0;
                }
 -              safe_crlf = git_config_bool(var, value);
 +              eol_rndtrp_die = git_config_bool(var, value);
 +              global_conv_flags_eol = eol_rndtrp_die ?
 +                      CONV_EOL_RNDTRP_DIE : CONV_EOL_RNDTRP_WARN;
                return 0;
        }
  
                return 0;
        }
  
 +      if (!strcmp(var, "core.partialclonefilter")) {
 +              return git_config_string(&core_partial_clone_filter_default,
 +                                       var, value);
 +      }
 +
        /* Add other config variables here and to Documentation/config.txt. */
        return 0;
  }
@@@ -1426,6 -1408,7 +1426,7 @@@ static int do_config_from_file(config_f
                void *data)
  {
        struct config_source top;
+       int ret;
  
        top.u.file = f;
        top.origin_type = origin_type;
        top.do_ungetc = config_file_ungetc;
        top.do_ftell = config_file_ftell;
  
-       return do_config_from(&top, fn, data);
+       flockfile(f);
+       ret = do_config_from(&top, fn, data);
+       funlockfile(f);
+       return ret;
  }
  
  static int git_config_from_stdin(config_fn_t fn, void *data)
@@@ -1451,9 -1437,7 +1455,7 @@@ int git_config_from_file(config_fn_t fn
  
        f = fopen_or_warn(filename, "r");
        if (f) {
-               flockfile(f);
                ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename, filename, f, data);
-               funlockfile(f);
                fclose(f);
        }
        return ret;
@@@ -1488,7 -1472,7 +1490,7 @@@ int git_config_from_blob_oid(config_fn_
        unsigned long size;
        int ret;
  
 -      buf = read_sha1_file(oid->hash, &type, &size);
 +      buf = read_object_file(oid, &type, &size);
        if (!buf)
                return error("unable to load config blob object '%s'", name);
        if (type != OBJ_BLOB) {
@@@ -2174,20 -2158,6 +2176,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)
  {
@@@ -2783,7 -2753,7 +2785,7 @@@ static int git_config_copy_or_rename_se
  {
        int ret = 0, remove = 0;
        char *filename_buf = NULL;
 -      struct lock_file *lock;
 +      struct lock_file lock = LOCK_INIT;
        int out_fd;
        char buf[1024];
        FILE *config_file = NULL;
        if (!config_filename)
                config_filename = filename_buf = git_pathdup("config");
  
 -      lock = xcalloc(1, sizeof(struct lock_file));
 -      out_fd = hold_lock_file_for_update(lock, config_filename, 0);
 +      out_fd = hold_lock_file_for_update(&lock, config_filename, 0);
        if (out_fd < 0) {
                ret = error("could not lock config file %s", config_filename);
                goto out;
                goto out;
        }
  
 -      if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) {
 +      if (chmod(get_lock_file_path(&lock), st.st_mode & 07777) < 0) {
                ret = error_errno("chmod on %s failed",
 -                                get_lock_file_path(lock));
 +                                get_lock_file_path(&lock));
                goto out;
        }
  
                         */
                        if (copystr.len > 0) {
                                if (write_in_full(out_fd, copystr.buf, copystr.len) < 0) {
 -                                      ret = write_error(get_lock_file_path(lock));
 +                                      ret = write_error(get_lock_file_path(&lock));
                                        goto out;
                                }
                                strbuf_reset(&copystr);
                                store.baselen = strlen(new_name);
                                if (!copy) {
                                        if (write_section(out_fd, new_name) < 0) {
 -                                              ret = write_error(get_lock_file_path(lock));
 +                                              ret = write_error(get_lock_file_path(&lock));
                                                goto out;
                                        }
                                        /*
                }
  
                if (write_in_full(out_fd, output, length) < 0) {
 -                      ret = write_error(get_lock_file_path(lock));
 +                      ret = write_error(get_lock_file_path(&lock));
                        goto out;
                }
        }
         */
        if (copystr.len > 0) {
                if (write_in_full(out_fd, copystr.buf, copystr.len) < 0) {
 -                      ret = write_error(get_lock_file_path(lock));
 +                      ret = write_error(get_lock_file_path(&lock));
                        goto out;
                }
                strbuf_reset(&copystr);
        fclose(config_file);
        config_file = NULL;
  commit_and_out:
 -      if (commit_lock_file(lock) < 0)
 +      if (commit_lock_file(&lock) < 0)
                ret = error_errno("could not write config file %s",
                                  config_filename);
  out:
        if (config_file)
                fclose(config_file);
 -      rollback_lock_file(lock);
 +      rollback_lock_file(&lock);
  out_no_rollback:
        free(filename_buf);
        return ret;