Browse Source

Merge branch 'jk/fallthrough'

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
maint
Junio C Hamano 7 years ago
parent
commit
59373a4e03
  1. 3
      apply.c
  2. 1
      builtin/cat-file.c
  3. 1
      builtin/checkout.c
  4. 2
      builtin/remote-ext.c
  5. 1
      builtin/submodule--helper.c
  6. 1
      config.c
  7. 3
      convert.c
  8. 1
      fsck.c
  9. 1
      http-push.c
  10. 7
      http.c
  11. 1
      mailinfo.c
  12. 1
      quote.c
  13. 1
      read-cache.c
  14. 2
      send-pack.c
  15. 32
      t/helper/test-line-buffer.c

3
apply.c

@ -2920,6 +2920,7 @@ static int apply_one_fragment(struct apply_state *state, @@ -2920,6 +2920,7 @@ static int apply_one_fragment(struct apply_state *state,
if (plen && (ws_rule & WS_BLANK_AT_EOF) &&
ws_blank_line(patch + 1, plen, ws_rule))
is_blank_context = 1;
/* fallthrough */
case '-':
memcpy(old, patch + 1, plen);
add_line_info(&preimage, old, plen,
@ -2927,7 +2928,7 @@ static int apply_one_fragment(struct apply_state *state, @@ -2927,7 +2928,7 @@ static int apply_one_fragment(struct apply_state *state,
old += plen;
if (first == '-')
break;
/* Fall-through for ' ' */
/* fallthrough */
case '+':
/* --no-add does not add new lines */
if (first == '+' && state->no_add)

1
builtin/cat-file.c

@ -113,6 +113,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, @@ -113,6 +113,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *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);

1
builtin/checkout.c

@ -436,6 +436,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o, @@ -436,6 +436,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
* update paths in the work tree, and we cannot revert
* them.
*/
/* fallthrough */
case 0:
return 0;
default:

2
builtin/remote-ext.c

@ -57,7 +57,7 @@ static char *strip_escapes(const char *str, const char *service, @@ -57,7 +57,7 @@ static char *strip_escapes(const char *str, const char *service,
special = str[rpos];
if (rpos == 1)
break;
/* Fall-through to error. */
/* fallthrough */
default:
die("Bad remote-ext placeholder '%%%c'.",
str[rpos]);

1
builtin/submodule--helper.c

@ -1189,6 +1189,7 @@ static int push_check(int argc, const char **argv, const char *prefix) @@ -1189,6 +1189,7 @@ static int push_check(int argc, const char **argv, const char *prefix)
break;
die("HEAD does not match the named branch in the superproject");
}
/* fallthrough */
default:
die("src refspec '%s' must name a ref",
rs->src);

1
config.c

@ -2355,6 +2355,7 @@ static ssize_t write_pair(int fd, const char *key, const char *value) @@ -2355,6 +2355,7 @@ static ssize_t write_pair(int fd, const char *key, const char *value)
case '"':
case '\\':
strbuf_addch(&sb, '\\');
/* fallthrough */
default:
strbuf_addch(&sb, value[i]);
break;

3
convert.c

@ -1545,8 +1545,9 @@ static int ident_filter_fn(struct stream_filter *filter, @@ -1545,8 +1545,9 @@ static int ident_filter_fn(struct stream_filter *filter,
switch (ident->state) {
default:
strbuf_add(&ident->left, head, ident->state);
/* fallthrough */
case IDENT_SKIPPING:
/* fallthru */
/* fallthrough */
case IDENT_DRAINING:
ident_drain(ident, &output, osize_p);
}

1
fsck.c

@ -588,6 +588,7 @@ static int fsck_tree(struct tree *item, struct fsck_options *options) @@ -588,6 +588,7 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)
case S_IFREG | 0664:
if (!options->strict)
break;
/* fallthrough */
default:
has_bad_modes = 1;
}

1
http-push.c

@ -1523,6 +1523,7 @@ static int remote_exists(const char *path) @@ -1523,6 +1523,7 @@ static int remote_exists(const char *path)
break;
case HTTP_ERROR:
error("unable to access '%s': %s", url, curl_errorstr);
/* fallthrough */
default:
ret = -1;
}

7
http.c

@ -638,9 +638,7 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, @@ -638,9 +638,7 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size,
switch (type) {
case CURLINFO_TEXT:
trace_printf_key(&trace_curl, "== Info: %s", data);
default: /* we ignore unknown types by default */
return 0;

break;
case CURLINFO_HEADER_OUT:
text = "=> Send header";
curl_dump_header(text, (unsigned char *)data, size, DO_FILTER);
@ -665,6 +663,9 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, @@ -665,6 +663,9 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size,
text = "<= Recv SSL data";
curl_dump_data(text, (unsigned char *)data, size);
break;

default: /* we ignore unknown types by default */
return 0;
}
return 0;
}

1
mailinfo.c

@ -822,6 +822,7 @@ static void handle_filter(struct mailinfo *mi, struct strbuf *line) @@ -822,6 +822,7 @@ static void handle_filter(struct mailinfo *mi, struct strbuf *line)
if (!handle_commit_msg(mi, line))
break;
mi->filter_stage++;
/* fallthrough */
case 1:
handle_patch(mi, line);
break;

1
quote.c

@ -431,6 +431,7 @@ void tcl_quote_buf(struct strbuf *sb, const char *src) @@ -431,6 +431,7 @@ void tcl_quote_buf(struct strbuf *sb, const char *src)
case '{': case '}':
case '$': case '\\': case '"':
strbuf_addch(sb, '\\');
/* fallthrough */
default:
strbuf_addch(sb, c);
break;

1
read-cache.c

@ -220,6 +220,7 @@ static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st) @@ -220,6 +220,7 @@ static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st)
case S_IFDIR:
if (S_ISGITLINK(ce->ce_mode))
return ce_compare_gitlink(ce) ? DATA_CHANGED : 0;
/* else fallthrough */
default:
return TYPE_CHANGED;
}

2
send-pack.c

@ -497,7 +497,7 @@ int send_pack(struct send_pack_args *args, @@ -497,7 +497,7 @@ int send_pack(struct send_pack_args *args,
strbuf_release(&cap_buf);
return atomic_push_failure(args, remote_refs, ref);
}
/* Fallthrough for non atomic case. */
/* else fallthrough */
default:
continue;
}

32
t/helper/test-line-buffer.c

@ -17,27 +17,17 @@ static uint32_t strtouint32(const char *s) @@ -17,27 +17,17 @@ static uint32_t strtouint32(const char *s)

static void handle_command(const char *command, const char *arg, struct line_buffer *buf)
{
switch (*command) {
case 'b':
if (starts_with(command, "binary ")) {
struct strbuf sb = STRBUF_INIT;
strbuf_addch(&sb, '>');
buffer_read_binary(buf, &sb, strtouint32(arg));
fwrite(sb.buf, 1, sb.len, stdout);
strbuf_release(&sb);
return;
}
case 'c':
if (starts_with(command, "copy ")) {
buffer_copy_bytes(buf, strtouint32(arg));
return;
}
case 's':
if (starts_with(command, "skip ")) {
buffer_skip_bytes(buf, strtouint32(arg));
return;
}
default:
if (starts_with(command, "binary ")) {
struct strbuf sb = STRBUF_INIT;
strbuf_addch(&sb, '>');
buffer_read_binary(buf, &sb, strtouint32(arg));
fwrite(sb.buf, 1, sb.len, stdout);
strbuf_release(&sb);
} else if (starts_with(command, "copy ")) {
buffer_copy_bytes(buf, strtouint32(arg));
} else if (starts_with(command, "skip ")) {
buffer_skip_bytes(buf, strtouint32(arg));
} else {
die("unrecognized command: %s", command);
}
}

Loading…
Cancel
Save