diff --git a/include/tig/io.h b/include/tig/io.h index b2ca0b4d0..5b1505e6c 100644 --- a/include/tig/io.h +++ b/include/tig/io.h @@ -103,7 +103,7 @@ enum status_code io_load(struct io *io, const char *separators, io_read_fn read_property, void *data); enum status_code io_load_span(struct io *io, const char *separators, size_t *lineno, io_read_fn read_property, void *data); -enum status_code io_run_load(const char **argv, const char *separators, +enum status_code io_run_load(struct io *io, const char **argv, const char *separators, io_read_fn read_property, void *data); char *io_memchr(struct buffer *buf, char *data, int c); diff --git a/src/io.c b/src/io.c index f60e98d4e..6d74b0c5b 100644 --- a/src/io.c +++ b/src/io.c @@ -702,14 +702,12 @@ io_load(struct io *io, const char *separators, } enum status_code -io_run_load(const char **argv, const char *separators, +io_run_load(struct io *io, const char **argv, const char *separators, io_read_fn read_property, void *data) { - struct io io; - - if (!io_run(&io, IO_RD, NULL, NULL, argv)) + if (!io_run(io, IO_RD, NULL, NULL, argv)) return error("Failed to open IO"); - return io_load(&io, separators, read_property, data); + return io_load(io, separators, read_property, data); } bool diff --git a/src/options.c b/src/options.c index cb1177a8d..a2d5312b6 100644 --- a/src/options.c +++ b/src/options.c @@ -1475,9 +1475,10 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen enum status_code load_git_config(void) { + struct io io; const char *config_list_argv[] = { "git", "config", "--list", NULL }; - return io_run_load(config_list_argv, "=", read_repo_config_option, NULL); + return io_run_load(&io, config_list_argv, "=", read_repo_config_option, NULL); } /* vim: set ts=8 sw=8 noexpandtab: */ diff --git a/src/refdb.c b/src/refdb.c index 9aee13514..ae9444bfb 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -311,6 +311,7 @@ cleanup_refs(void *data, void *ref_) static enum status_code reload_refs(bool force) { + struct io io; const char *ls_remote_argv[SIZEOF_ARG] = { "git", "show-ref", "--head", "--dereference", NULL }; @@ -342,7 +343,7 @@ reload_refs(bool force) string_map_clear(&refs_by_id); string_map_foreach(&refs_by_name, invalidate_refs, NULL); - code = io_run_load(ls_remote_argv, " \t", read_ref, &opt); + code = io_run_load(&io, ls_remote_argv, " \t", read_ref, &opt); if (code != SUCCESS) return code; diff --git a/src/repo.c b/src/repo.c index 665b0248c..69c978153 100644 --- a/src/repo.c +++ b/src/repo.c @@ -80,9 +80,10 @@ read_repo_info(char *name, size_t namelen, char *value, size_t valuelen, void *d static enum status_code reload_repo_info(const char **rev_parse_argv) { + struct io io; struct repo_info_state state = { rev_parse_argv + 2 }; - return io_run_load(rev_parse_argv, "\n", read_repo_info, &state); + return io_run_load(&io, rev_parse_argv, "\n", read_repo_info, &state); } enum status_code diff --git a/src/tig.c b/src/tig.c index 25b9c20c4..44ad49de4 100644 --- a/src/tig.c +++ b/src/tig.c @@ -402,29 +402,32 @@ read_filter_args(char *name, size_t namelen, char *value, size_t valuelen, void return argv_append(filter_args, name) ? SUCCESS : ERROR_OUT_OF_MEMORY; } -static void +static bool filter_rev_parse(const char ***args, const char *arg1, const char *arg2, const char *argv[]) { const char *rev_parse_argv[SIZEOF_ARG] = { "git", "rev-parse", arg1, arg2 }; const char **all_argv = NULL; + struct io io; if (!argv_append_array(&all_argv, rev_parse_argv) || !argv_append_array(&all_argv, argv) || - io_run_load(all_argv, "\n", read_filter_args, args) != SUCCESS) + io_run_load(&io, all_argv, "\n", read_filter_args, args) != SUCCESS) die("Failed to split arguments"); argv_free(all_argv); free(all_argv); + + return !io.status; } static void -filter_options(const char *argv[], bool rev_parse) +filter_options(const char *argv[], enum request request) { const char **flags = NULL; int next, flags_pos; update_options_from_argv(argv); - if (!rev_parse) { + if (request == REQ_VIEW_GREP || request == REQ_VIEW_REFS) { opt_cmdline_args = argv; return; } @@ -446,7 +449,9 @@ filter_options(const char *argv[], bool rev_parse) argv[flags_pos] = NULL; - filter_rev_parse(&opt_file_args, "--no-revs", "--no-flags", argv); + if (!filter_rev_parse(&opt_file_args, "--no-revs", "--no-flags", argv) && + request != REQ_VIEW_BLAME) + die("No revisions match the given arguments."); filter_rev_parse(&flags, "--flags", "--no-revs", argv); if (flags) { @@ -473,7 +478,6 @@ parse_options(int argc, const char *argv[], bool pager_mode) enum request request; const char *subcommand; bool seen_dashdash = false; - bool rev_parse = true; const char **filter_argv = NULL; int i; @@ -503,7 +507,6 @@ parse_options(int argc, const char *argv[], bool pager_mode) } else if (!strcmp(subcommand, "grep")) { request = REQ_VIEW_GREP; - rev_parse = false; } else if (!strcmp(subcommand, "show")) { request = REQ_VIEW_DIFF; @@ -519,7 +522,6 @@ parse_options(int argc, const char *argv[], bool pager_mode) } else if (!strcmp(subcommand, "refs")) { request = REQ_VIEW_REFS; - rev_parse = false; } else { subcommand = NULL; @@ -568,7 +570,7 @@ parse_options(int argc, const char *argv[], bool pager_mode) } if (filter_argv) - filter_options(filter_argv, rev_parse); + filter_options(filter_argv, request); return request; }