Merge branch 'jk/fallthrough'
authorJunio C Hamano <gitster@pobox.com>
Thu, 28 Sep 2017 05:47:53 +0000 (14:47 +0900)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 Sep 2017 05:47:53 +0000 (14:47 +0900)
Many codepaths have been updated to squelch -Wimplicit-fallthrough
warnings from Gcc 7 (which is a good code hygiene).

* jk/fallthrough:
consistently use "fallthrough" comments in switches
curl_trace(): eliminate switch fallthrough
test-line-buffer: simplify command parsing

1  2 
builtin/cat-file.c
config.c
read-cache.c
diff --combined builtin/cat-file.c
index 1ea25331d38f4395f1c5079a1ca39263c69701b2,aee280ea2cdb988ef918a2fb8fbdb3f80c68a251..f5fa4fd75af26a66cd1b2c0d493116704bc16dd5
@@@ -97,7 -97,7 +97,7 @@@ static int cat_one_file(int opt, const 
                return !has_object_file(&oid);
  
        case 'w':
 -              if (!path[0])
 +              if (!path)
                        die("git cat-file --filters %s: <object> must be "
                            "<sha1:path>", obj_name);
  
                break;
  
        case 'c':
 -              if (!path[0])
 +              if (!path)
                        die("git cat-file --textconv %s: <object> must be <sha1:path>",
                            obj_name);
  
                if (textconv_object(path, obj_context.mode, &oid, 1, &buf, &size))
                        break;
+               /* else fallthrough */
  
        case 'p':
                type = sha1_object_info(oid.hash, NULL);
diff --combined config.c
index a77cae56ed26212c6bfbbd831c85c8cf64deb8b9,08490dfe81f369bc863635f34c275a343ba31db5..7ab37bacae927864329782d68c30e73f267176ce
+++ b/config.c
@@@ -2292,11 -2292,10 +2292,11 @@@ static int write_error(const char *file
        return 4;
  }
  
 -static int store_write_section(int fd, const char *key)
 +static ssize_t write_section(int fd, const char *key)
  {
        const char *dot;
 -      int i, success;
 +      int i;
 +      ssize_t ret;
        struct strbuf sb = STRBUF_INIT;
  
        dot = memchr(key, '.', store.baselen);
                strbuf_addf(&sb, "[%.*s]\n", store.baselen, key);
        }
  
 -      success = write_in_full(fd, sb.buf, sb.len) == sb.len;
 +      ret = write_in_full(fd, sb.buf, sb.len);
        strbuf_release(&sb);
  
 -      return success;
 +      return ret;
  }
  
 -static int store_write_pair(int fd, const char *key, const char *value)
 +static ssize_t write_pair(int fd, const char *key, const char *value)
  {
 -      int i, success;
 +      int i;
 +      ssize_t ret;
        int length = strlen(key + store.baselen + 1);
        const char *quote = "";
        struct strbuf sb = STRBUF_INIT;
                case '"':
                case '\\':
                        strbuf_addch(&sb, '\\');
+                       /* fallthrough */
                default:
                        strbuf_addch(&sb, value[i]);
                        break;
                }
        strbuf_addf(&sb, "%s\n", quote);
  
 -      success = write_in_full(fd, sb.buf, sb.len) == sb.len;
 +      ret = write_in_full(fd, sb.buf, sb.len);
        strbuf_release(&sb);
  
 -      return success;
 +      return ret;
  }
  
  static ssize_t find_beginning_of_line(const char *contents, size_t size,
@@@ -2493,8 -2492,8 +2494,8 @@@ int git_config_set_multivar_in_file_gen
                }
  
                store.key = (char *)key;
 -              if (!store_write_section(fd, key) ||
 -                  !store_write_pair(fd, key, value))
 +              if (write_section(fd, key) < 0 ||
 +                  write_pair(fd, key, value) < 0)
                        goto write_err_out;
        } else {
                struct stat st;
                        /* write the first part of the config */
                        if (copy_end > copy_begin) {
                                if (write_in_full(fd, contents + copy_begin,
 -                                                copy_end - copy_begin) <
 -                                  copy_end - copy_begin)
 +                                                copy_end - copy_begin) < 0)
                                        goto write_err_out;
                                if (new_line &&
 -                                  write_str_in_full(fd, "\n") != 1)
 +                                  write_str_in_full(fd, "\n") < 0)
                                        goto write_err_out;
                        }
                        copy_begin = store.offset[i];
                /* write the pair (value == NULL means unset) */
                if (value != NULL) {
                        if (store.state == START) {
 -                              if (!store_write_section(fd, key))
 +                              if (write_section(fd, key) < 0)
                                        goto write_err_out;
                        }
 -                      if (!store_write_pair(fd, key, value))
 +                      if (write_pair(fd, key, value) < 0)
                                goto write_err_out;
                }
  
                /* write the rest of the config */
                if (copy_begin < contents_sz)
                        if (write_in_full(fd, contents + copy_begin,
 -                                        contents_sz - copy_begin) <
 -                          contents_sz - copy_begin)
 +                                        contents_sz - copy_begin) < 0)
                                goto write_err_out;
  
                munmap(contents, contents_sz);
@@@ -2803,7 -2804,7 +2804,7 @@@ int git_config_rename_section_in_file(c
                                        continue;
                                }
                                store.baselen = strlen(new_name);
 -                              if (!store_write_section(out_fd, new_name)) {
 +                              if (write_section(out_fd, new_name) < 0) {
                                        ret = write_error(get_lock_file_path(lock));
                                        goto out;
                                }
                if (remove)
                        continue;
                length = strlen(output);
 -              if (write_in_full(out_fd, output, length) != length) {
 +              if (write_in_full(out_fd, output, length) < 0) {
                        ret = write_error(get_lock_file_path(lock));
                        goto out;
                }
diff --combined read-cache.c
index cdcd11c71efd67130dd8159c9ac4da86e854222a,a051567610aab041017201f1b1bfa2e7e816a059..65f4fe8375d59234d5e58f87a8593fc50e6336a2
@@@ -220,6 -220,7 +220,7 @@@ static int ce_modified_check_fs(const s
        case S_IFDIR:
                if (S_ISGITLINK(ce->ce_mode))
                        return ce_compare_gitlink(ce) ? DATA_CHANGED : 0;
+               /* else fallthrough */
        default:
                return TYPE_CHANGED;
        }
@@@ -1922,7 -1923,7 +1923,7 @@@ static int ce_write_flush(git_SHA_CTX *
        unsigned int buffered = write_buffer_len;
        if (buffered) {
                git_SHA1_Update(context, write_buffer, buffered);
 -              if (write_in_full(fd, write_buffer, buffered) != buffered)
 +              if (write_in_full(fd, write_buffer, buffered) < 0)
                        return -1;
                write_buffer_len = 0;
        }
@@@ -1971,7 -1972,7 +1972,7 @@@ static int ce_flush(git_SHA_CTX *contex
  
        /* Flush first if not enough space for SHA1 signature */
        if (left + 20 > WRITE_BUFFER_SIZE) {
 -              if (write_in_full(fd, write_buffer, left) != left)
 +              if (write_in_full(fd, write_buffer, left) < 0)
                        return -1;
                left = 0;
        }
        git_SHA1_Final(write_buffer + left, context);
        hashcpy(sha1, write_buffer + left);
        left += 20;
 -      return (write_in_full(fd, write_buffer, left) != left) ? -1 : 0;
 +      return (write_in_full(fd, write_buffer, left) < 0) ? -1 : 0;
  }
  
  static void ce_smudge_racily_clean_entry(struct cache_entry *ce)
@@@ -2103,9 -2104,7 +2104,9 @@@ static int ce_write_entry(git_SHA_CTX *
                if (!result)
                        result = ce_write(c, fd, to_remove_vi, prefix_size);
                if (!result)
 -                      result = ce_write(c, fd, ce->name + common, ce_namelen(ce) - common + 1);
 +                      result = ce_write(c, fd, ce->name + common, ce_namelen(ce) - common);
 +              if (!result)
 +                      result = ce_write(c, fd, padding, 1);
  
                strbuf_splice(previous_name, common, to_remove,
                              ce->name + common, ce_namelen(ce) - common);