Merge branch 'rs/config-write-section-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 27 Nov 2017 02:06:38 +0000 (11:06 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Nov 2017 02:06:38 +0000 (11:06 +0900)
There was a recent semantic mismerge in the codepath to write out a
section of a configuration section, which has been corrected.

* rs/config-write-section-fix:
config: flip return value of write_section()

1  2 
config.c
diff --combined config.c
index 731b9b1de2fa222be838c73b410b9619e234feec,201ad36d34376ceee44b530197863924fb7051b4..676786a028f2c726a55694cb5af1b1781ddd6e4e
+++ b/config.c
@@@ -16,6 -16,7 +16,6 @@@
  #include "string-list.h"
  #include "utf8.h"
  #include "dir.h"
 -#include "color.h"
  
  struct config_source {
        struct config_source *prev;
@@@ -1350,6 -1351,9 +1350,6 @@@ int git_default_config(const char *var
        if (starts_with(var, "advice."))
                return git_default_advice_config(var, value);
  
 -      if (git_color_config(var, value, dummy) < 0)
 -              return -1;
 -
        if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
                pager_use_color = git_config_bool(var,value);
                return 0;
@@@ -2156,20 -2160,6 +2156,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 -2319,7 +2329,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;
@@@ -2765,7 -2755,7 +2765,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;
        }
  
                         * multiple [branch "$name"] sections.
                         */
                        if (copystr.len > 0) {
 -                              if (write_in_full(out_fd, copystr.buf, copystr.len) != copystr.len) {
 -                                      ret = write_error(get_lock_file_path(lock));
 +                              if (write_in_full(out_fd, copystr.buf, copystr.len) < 0) {
 +                                      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;
                }
        }
         * logic in the loop above.
         */
        if (copystr.len > 0) {
 -              if (write_in_full(out_fd, copystr.buf, copystr.len) != copystr.len) {
 -                      ret = write_error(get_lock_file_path(lock));
 +              if (write_in_full(out_fd, copystr.buf, copystr.len) < 0) {
 +                      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;