Browse Source

Merge branch 'jk/unused'

Code cleanup.

* jk/unused:
  dir.c: drop unused "untracked" from treat_path_fast()
  sequencer: handle ignore_footer when parsing trailers
  test-advise: check argument count with argc instead of argv
  sparse-checkout: fill in some options boilerplate
  sequencer: drop repository argument from run_git_commit()
  push: drop unused repo argument to do_push()
  assert PARSE_OPT_NONEG in parse-options callbacks
  env--helper: write to opt->value in parseopt helper
  drop unused argc parameters
  convert: drop unused crlf_action from check_global_conv_flags_eol()
maint
Junio C Hamano 4 years ago
parent
commit
19dd352d03
  1. 4
      builtin/add.c
  2. 2
      builtin/am.c
  3. 2
      builtin/commit-graph.c
  4. 12
      builtin/commit.c
  5. 13
      builtin/env--helper.c
  6. 4
      builtin/push.c
  7. 37
      builtin/sparse-checkout.c
  8. 2
      commit.h
  9. 4
      convert.c
  10. 3
      dir.c
  11. 2
      parse-options-cb.c
  12. 6
      revision.c
  13. 20
      sequencer.c
  14. 4
      t/helper/test-advise.c
  15. 6
      t/helper/test-submodule-nested-repo-config.c

4
builtin/add.c

@ -239,7 +239,7 @@ int run_add_interactive(const char *revision, const char *patch_mode, @@ -239,7 +239,7 @@ int run_add_interactive(const char *revision, const char *patch_mode,
return status;
}

int interactive_add(int argc, const char **argv, const char *prefix, int patch)
int interactive_add(const char **argv, const char *prefix, int patch)
{
struct pathspec pathspec;

@ -451,7 +451,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) @@ -451,7 +451,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
if (add_interactive) {
if (pathspec_from_file)
die(_("--pathspec-from-file is incompatible with --interactive/--patch"));
exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));
exit(interactive_add(argv + 1, prefix, patch_interactive));
}
if (legacy_stash_p) {
struct pathspec pathspec;

2
builtin/am.c

@ -2180,6 +2180,8 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar @@ -2180,6 +2180,8 @@ static int parse_opt_show_current_patch(const struct option *opt, const char *ar
};
int new_value = SHOW_PATCH_RAW;

BUG_ON_OPT_NEG(unset);

if (arg) {
for (new_value = 0; new_value < ARRAY_SIZE(valid_modes); new_value++) {
if (!strcmp(arg, valid_modes[new_value]))

2
builtin/commit-graph.c

@ -128,6 +128,8 @@ static int write_option_parse_split(const struct option *opt, const char *arg, @@ -128,6 +128,8 @@ static int write_option_parse_split(const struct option *opt, const char *arg,
{
enum commit_graph_split_flags *flags = opt->value;

BUG_ON_OPT_NEG(unset);

opts.split = 1;
if (!arg)
return 0;

12
builtin/commit.c

@ -326,7 +326,7 @@ static void refresh_cache_or_die(int refresh_flags) @@ -326,7 +326,7 @@ static void refresh_cache_or_die(int refresh_flags)
die_resolve_conflict("commit");
}

static const char *prepare_index(int argc, const char **argv, const char *prefix,
static const char *prepare_index(const char **argv, const char *prefix,
const struct commit *current_head, int is_status)
{
struct string_list partial = STRING_LIST_INIT_DUP;
@ -378,7 +378,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix @@ -378,7 +378,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);

if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
if (interactive_add(argv, prefix, patch_interactive) != 0)
die(_("interactive add failed"));

the_repository->index_file = old_repo_index_file;
@ -1241,13 +1241,13 @@ static int parse_and_validate_options(int argc, const char *argv[], @@ -1241,13 +1241,13 @@ static int parse_and_validate_options(int argc, const char *argv[],
return argc;
}

static int dry_run_commit(int argc, const char **argv, const char *prefix,
static int dry_run_commit(const char **argv, const char *prefix,
const struct commit *current_head, struct wt_status *s)
{
int committable;
const char *index_file;

index_file = prepare_index(argc, argv, prefix, current_head, 1);
index_file = prepare_index(argv, prefix, current_head, 1);
committable = run_status(stdout, index_file, prefix, 0, s);
rollback_index_files();

@ -1584,8 +1584,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) @@ -1584,8 +1584,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;

if (dry_run)
return dry_run_commit(argc, argv, prefix, current_head, &s);
index_file = prepare_index(argc, argv, prefix, current_head, 0);
return dry_run_commit(argv, prefix, current_head, &s);
index_file = prepare_index(argv, prefix, current_head, 0);

/* Set up everything for writing the commit object. This includes
running hooks, writing the trees, and interacting with the user. */

13
builtin/env--helper.c

@ -7,18 +7,22 @@ static char const * const env__helper_usage[] = { @@ -7,18 +7,22 @@ static char const * const env__helper_usage[] = {
NULL
};

static enum {
enum cmdmode {
ENV_HELPER_TYPE_BOOL = 1,
ENV_HELPER_TYPE_ULONG
} cmdmode = 0;
};

static int option_parse_type(const struct option *opt, const char *arg,
int unset)
{
enum cmdmode *cmdmode = opt->value;

BUG_ON_OPT_NEG(unset);

if (!strcmp(arg, "bool"))
cmdmode = ENV_HELPER_TYPE_BOOL;
*cmdmode = ENV_HELPER_TYPE_BOOL;
else if (!strcmp(arg, "ulong"))
cmdmode = ENV_HELPER_TYPE_ULONG;
*cmdmode = ENV_HELPER_TYPE_ULONG;
else
die(_("unrecognized --type argument, %s"), arg);

@ -33,6 +37,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix) @@ -33,6 +37,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)
int ret;
int ret_int, default_int;
unsigned long ret_ulong, default_ulong;
enum cmdmode cmdmode = 0;
struct option opts[] = {
OPT_CALLBACK_F(0, "type", &cmdmode, N_("type"),
N_("value is given this type"), PARSE_OPT_NONEG,

4
builtin/push.c

@ -379,7 +379,7 @@ static int push_with_options(struct transport *transport, struct refspec *rs, @@ -379,7 +379,7 @@ static int push_with_options(struct transport *transport, struct refspec *rs,
return 1;
}

static int do_push(const char *repo, int flags,
static int do_push(int flags,
const struct string_list *push_options,
struct remote *remote)
{
@ -629,7 +629,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) @@ -629,7 +629,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
if (strchr(item->string, '\n'))
die(_("push options must not have new line characters"));

rc = do_push(repo, flags, push_options, remote);
rc = do_push(flags, push_options, remote);
string_list_clear(&push_options_cmdline, 0);
string_list_clear(&push_options_config, 0);
if (rc == -1)

37
builtin/sparse-checkout.c

@ -46,12 +46,24 @@ static void write_patterns_to_file(FILE *fp, struct pattern_list *pl) @@ -46,12 +46,24 @@ static void write_patterns_to_file(FILE *fp, struct pattern_list *pl)
}
}

static char const * const builtin_sparse_checkout_list_usage[] = {
N_("git sparse-checkout list"),
NULL
};

static int sparse_checkout_list(int argc, const char **argv)
{
static struct option builtin_sparse_checkout_list_options[] = {
OPT_END(),
};
struct pattern_list pl;
char *sparse_filename;
int res;

argc = parse_options(argc, argv, NULL,
builtin_sparse_checkout_list_options,
builtin_sparse_checkout_list_usage, 0);

memset(&pl, 0, sizeof(pl));

pl.use_cone_patterns = core_sparse_checkout_cone;
@ -560,17 +572,42 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix, @@ -560,17 +572,42 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
return modify_pattern_list(argc, argv, m);
}

static char const * const builtin_sparse_checkout_reapply_usage[] = {
N_("git sparse-checkout reapply"),
NULL
};

static int sparse_checkout_reapply(int argc, const char **argv)
{
static struct option builtin_sparse_checkout_reapply_options[] = {
OPT_END(),
};

argc = parse_options(argc, argv, NULL,
builtin_sparse_checkout_reapply_options,
builtin_sparse_checkout_reapply_usage, 0);

repo_read_index(the_repository);
return update_working_directory(NULL);
}

static char const * const builtin_sparse_checkout_disable_usage[] = {
N_("git sparse-checkout disable"),
NULL
};

static int sparse_checkout_disable(int argc, const char **argv)
{
static struct option builtin_sparse_checkout_disable_options[] = {
OPT_END(),
};
struct pattern_list pl;
struct strbuf match_all = STRBUF_INIT;

argc = parse_options(argc, argv, NULL,
builtin_sparse_checkout_disable_options,
builtin_sparse_checkout_disable_usage, 0);

repo_read_index(the_repository);

memset(&pl, 0, sizeof(pl));

2
commit.h

@ -248,7 +248,7 @@ struct oid_array; @@ -248,7 +248,7 @@ struct oid_array;
struct ref;
int for_each_commit_graft(each_commit_graft_fn, void *);

int interactive_add(int argc, const char **argv, const char *prefix, int patch);
int interactive_add(const char **argv, const char *prefix, int patch);
int run_add_interactive(const char *revision, const char *patch_mode,
const struct pathspec *pathspec);


4
convert.c

@ -195,7 +195,7 @@ static enum eol output_eol(enum crlf_action crlf_action) @@ -195,7 +195,7 @@ static enum eol output_eol(enum crlf_action crlf_action)
return core_eol;
}

static void check_global_conv_flags_eol(const char *path, enum crlf_action crlf_action,
static void check_global_conv_flags_eol(const char *path,
struct text_stat *old_stats, struct text_stat *new_stats,
int conv_flags)
{
@ -547,7 +547,7 @@ static int crlf_to_git(const struct index_state *istate, @@ -547,7 +547,7 @@ static int crlf_to_git(const struct index_state *istate,
new_stats.crlf += new_stats.lonelf;
new_stats.lonelf = 0;
}
check_global_conv_flags_eol(path, crlf_action, &stats, &new_stats, conv_flags);
check_global_conv_flags_eol(path, &stats, &new_stats, conv_flags);
}
if (!convert_crlf_into_lf)
return 0;

3
dir.c

@ -2105,7 +2105,6 @@ static int resolve_dtype(int dtype, struct index_state *istate, @@ -2105,7 +2105,6 @@ static int resolve_dtype(int dtype, struct index_state *istate,
}

static enum path_treatment treat_path_fast(struct dir_struct *dir,
struct untracked_cache_dir *untracked,
struct cached_dir *cdir,
struct index_state *istate,
struct strbuf *path,
@ -2153,7 +2152,7 @@ static enum path_treatment treat_path(struct dir_struct *dir, @@ -2153,7 +2152,7 @@ static enum path_treatment treat_path(struct dir_struct *dir,
int has_path_in_index, dtype, excluded;

if (!cdir->d_name)
return treat_path_fast(dir, untracked, cdir, istate, path,
return treat_path_fast(dir, cdir, istate, path,
baselen, pathspec);
if (is_dot_or_dotdot(cdir->d_name) || !fspathcmp(cdir->d_name, ".git"))
return path_none;

2
parse-options-cb.c

@ -105,6 +105,8 @@ int parse_opt_commit(const struct option *opt, const char *arg, int unset) @@ -105,6 +105,8 @@ int parse_opt_commit(const struct option *opt, const char *arg, int unset)
struct commit *commit;
struct commit **target = opt->value;

BUG_ON_OPT_NEG(unset);

if (!arg)
return -1;
if (get_oid(arg, &oid))

6
revision.c

@ -2580,8 +2580,8 @@ static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void @@ -2580,8 +2580,8 @@ static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void
}

static int handle_revision_pseudo_opt(const char *submodule,
struct rev_info *revs,
int argc, const char **argv, int *flags)
struct rev_info *revs,
const char **argv, int *flags)
{
const char *arg = argv[0];
const char *optarg;
@ -2752,7 +2752,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s @@ -2752,7 +2752,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
int opts;

opts = handle_revision_pseudo_opt(submodule,
revs, argc - i, argv + i,
revs, argv + i,
&flags);
if (opts > 0) {
i += opts - 1;

20
sequencer.c

@ -249,11 +249,20 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob, @@ -249,11 +249,20 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
struct trailer_info info;
size_t i;
int found_sob = 0, found_sob_last = 0;
char saved_char;

opts.no_divider = 1;

if (ignore_footer) {
saved_char = sb->buf[sb->len - ignore_footer];
sb->buf[sb->len - ignore_footer] = '\0';
}

trailer_info_get(&info, sb->buf, &opts);

if (ignore_footer)
sb->buf[sb->len - ignore_footer] = saved_char;

if (info.trailer_start == info.trailer_end)
return 0;

@ -934,8 +943,7 @@ static int run_command_silent_on_success(struct child_process *cmd) @@ -934,8 +943,7 @@ static int run_command_silent_on_success(struct child_process *cmd)
* interactive rebase: in that case, we will want to retain the
* author metadata.
*/
static int run_git_commit(struct repository *r,
const char *defmsg,
static int run_git_commit(const char *defmsg,
struct replay_opts *opts,
unsigned int flags)
{
@ -1545,7 +1553,7 @@ static int do_commit(struct repository *r, @@ -1545,7 +1553,7 @@ static int do_commit(struct repository *r,
if (is_rebase_i(opts) && oid)
if (write_rebase_head(oid))
return -1;
return run_git_commit(r, msg_file, opts, flags);
return run_git_commit(msg_file, opts, flags);
}

return res;
@ -2060,7 +2068,7 @@ static int do_pick_commit(struct repository *r, @@ -2060,7 +2068,7 @@ static int do_pick_commit(struct repository *r,
*check_todo = !!(flags & EDIT_MSG);
if (!res && reword) {
fast_forward_edit:
res = run_git_commit(r, NULL, opts, EDIT_MSG |
res = run_git_commit(NULL, opts, EDIT_MSG |
VERIFY_MSG | AMEND_MSG |
(flags & ALLOW_EMPTY));
*check_todo = 1;
@ -3749,7 +3757,7 @@ static int do_merge(struct repository *r, @@ -3749,7 +3757,7 @@ static int do_merge(struct repository *r,
* command needs to be rescheduled).
*/
fast_forward_edit:
ret = !!run_git_commit(r, git_path_merge_msg(r), opts,
ret = !!run_git_commit(git_path_merge_msg(r), opts,
run_commit_flags);

leave_merge:
@ -4438,7 +4446,7 @@ static int commit_staged_changes(struct repository *r, @@ -4438,7 +4446,7 @@ static int commit_staged_changes(struct repository *r,
return 0;
}

if (run_git_commit(r, final_fixup ? NULL : rebase_path_message(),
if (run_git_commit(final_fixup ? NULL : rebase_path_message(),
opts, flags))
return error(_("could not commit staged changes."));
unlink(rebase_path_amend());

4
t/helper/test-advise.c

@ -5,8 +5,8 @@ @@ -5,8 +5,8 @@

int cmd__advise_if_enabled(int argc, const char **argv)
{
if (!argv[1])
die("usage: %s <advice>", argv[0]);
if (argc != 2)
die("usage: %s <advice>", argv[0]);

setup_git_directory();
git_config(git_default_config, NULL);

6
t/helper/test-submodule-nested-repo-config.c

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
#include "test-tool.h"
#include "submodule-config.h"

static void die_usage(int argc, const char **argv, const char *msg)
static void die_usage(const char **argv, const char *msg)
{
fprintf(stderr, "%s\n", msg);
fprintf(stderr, "Usage: %s <submodulepath> <config name>\n", argv[0]);
@ -14,13 +14,13 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv) @@ -14,13 +14,13 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv)
const struct submodule *sub;

if (argc < 3)
die_usage(argc, argv, "Wrong number of arguments.");
die_usage(argv, "Wrong number of arguments.");

setup_git_directory();

sub = submodule_from_path(the_repository, &null_oid, argv[1]);
if (repo_submodule_init(&subrepo, the_repository, sub)) {
die_usage(argc, argv, "Submodule not found.");
die_usage(argv, "Submodule not found.");
}

/* Read the config of _child_ submodules. */

Loading…
Cancel
Save