@@ -69,7 +69,12 @@ struct argv_env {
extern struct argv_env argv_env;
-bool argv_format(struct argv_env *argv_env, const char ***dst_argv, const char *src_argv[], bool first, bool file_filter);
+enum argv_flag {
+ argv_flag_first = 1 << 0,
+ argv_flag_file_filter = 1 << 1,
+};
+
+bool argv_format(struct argv_env *argv_env, const char ***dst_argv, const char *src_argv[], int flags);
char *argv_format_arg(struct argv_env *argv_env, const char *src_arg);
struct rev_flags {
@@ -277,7 +277,7 @@ struct format_context {
size_t vars_size;
char buf[SIZEOF_MED_STR];
size_t bufpos;
- bool file_filter;
+ int argv_flags;
};
#define ARGV_ENV_INIT(type, name, ifempty, initval) initval,
@@ -318,7 +318,7 @@ format_expand_arg(struct format_context *format, const char *name, const char *e
if (string_enum_compare(name, vars[i].name, vars[i].namelen))
continue;
- if (vars[i].value_ref == &argv_env.file && !format->file_filter)
+ if (vars[i].value_ref == &argv_env.file && !(format->argv_flags & argv_flag_file_filter))
return true;
return vars[i].formatter(format, &vars[i]);
@@ -420,7 +420,7 @@ repo_rev_formatter(struct format_context *format, struct format_var *var)
}
bool
-argv_format(struct argv_env *argv_env, const char ***dst_argv, const char *src_argv[], bool first, bool file_filter)
+argv_format(struct argv_env *argv_env, const char ***dst_argv, const char *src_argv[], int flags)
{
struct format_var vars[] = {
#define FORMAT_VAR(type, name, ifempty, initval) \
@@ -430,7 +430,7 @@ argv_format(struct argv_env *argv_env, const char ***dst_argv, const char *src_a
{ "%(repo:" #name ")", STRING_SIZE("%(repo:" #name ")"), type ## _formatter, &repo.name, "" },
REPO_INFO(FORMAT_REPO_VAR)
};
- struct format_context format = { vars, ARRAY_SIZE(vars), "", 0, file_filter };
+ struct format_context format = { vars, ARRAY_SIZE(vars), "", 0, flags };
int argc;
argv_free(*dst_argv);
@@ -439,7 +439,7 @@ argv_format(struct argv_env *argv_env, const char ***dst_argv, const char *src_a
const char *arg = src_argv[argc];
if (!strcmp(arg, "%(fileargs)")) {
- if (file_filter && !argv_append_array(dst_argv, opt_file_args))
+ if ((flags & argv_flag_file_filter) && !argv_append_array(dst_argv, opt_file_args))
break;
} else if (!strcmp(arg, DIFF_ARGS)) {
@@ -463,7 +463,7 @@ argv_format(struct argv_env *argv_env, const char ***dst_argv, const char *src_a
break;
} else if (!strcmp(arg, "%(revargs)") ||
- (first && !strcmp(arg, "%(commit)"))) {
+ ((flags & argv_flag_first) && !strcmp(arg, "%(commit)"))) {
if (!argv_append_array(dst_argv, opt_rev_args))
break;
@@ -606,7 +606,7 @@ argv_format_arg(struct argv_env *argv_env, const char *src_arg)
const char **dst_argv = NULL;
char *dst_arg = NULL;
- if (argv_format(argv_env, &dst_argv, src_argv, false, true))
+ if (argv_format(argv_env, &dst_argv, src_argv, argv_flag_file_filter))
dst_arg = (char *) dst_argv[0];
free(dst_argv);
@@ -939,7 +939,7 @@ run_prompt_command(struct view *view, const char *argv[])
/* Trim the leading '!'. */
argv[0] = cmd + 1;
- copied = argv_format(view->env, &next->argv, argv, false, true);
+ copied = argv_format(view->env, &next->argv, argv, argv_flag_file_filter);
argv[0] = cmd;
if (!copied) {
@@ -967,7 +967,7 @@ run_prompt_command(struct view *view, const char *argv[])
if (argv[1]
&& strlen(argv[1]) > 0
- && (!argv_format(view->env, &fmt_argv, &argv[1], false, true)
+ && (!argv_format(view->env, &fmt_argv, &argv[1], argv_flag_file_filter)
|| !argv_to_string(fmt_argv, text, sizeof(text), " ")
)) {
report("Failed to format echo string");
@@ -1102,7 +1102,7 @@ exec_run_request(struct view *view, struct run_request *req)
if (!argv_to_string(req->argv, cmd, sizeof(cmd), " ")
|| !argv_from_string_no_quotes(req_argv, &req_argc, cmd)
- || !argv_format(view->env, &argv, req_argv, false, true)
+ || !argv_format(view->env, &argv, req_argv, argv_flag_file_filter)
|| !argv) {
report("Failed to format arguments");
return REQ_NONE;
@@ -48,7 +48,7 @@ reflog_request(struct view *view, enum request request, struct line *line)
};
enum open_flags flags = view_is_displayed(view) ? OPEN_SPLIT : OPEN_DEFAULT;
- if (!argv_format(main_view.env, &main_view.argv, main_argv, false, false))
+ if (!argv_format(main_view.env, &main_view.argv, main_argv, 0))
report("Failed to format argument");
else
open_main_view(view, flags | OPEN_PREPARED);
@@ -81,7 +81,7 @@ refs_request(struct view *view, enum request request, struct line *line)
};
enum open_flags flags = view_is_displayed(view) ? OPEN_SPLIT : OPEN_DEFAULT;
- if (!argv_format(main_view.env, &main_view.argv, all_references_argv, false, false))
+ if (!argv_format(main_view.env, &main_view.argv, all_references_argv, 0))
report("Failed to format argument");
else
open_main_view(view, flags | OPEN_PREPARED);
@@ -87,7 +87,7 @@ stash_request(struct view *view, enum request request, struct line *line)
"--no-color", "%(stash)", NULL
};
- if (!argv_format(diff_view.env, &diff_view.argv, diff_argv, false, false))
+ if (!argv_format(diff_view.env, &diff_view.argv, diff_argv, 0))
report("Failed to format argument");
else
open_diff_view(view, flags | OPEN_PREPARED);
@@ -91,7 +91,7 @@ status_run(struct view *view, const char *argv[], char status, enum line_type ty
struct buffer buf;
struct io io;
const char **status_argv = NULL;
- bool ok = argv_format(view->env, &status_argv, argv, false, false) &&
+ bool ok = argv_format(view->env, &status_argv, argv, 0) &&
io_run(&io, IO_RD, repo.exec_dir, NULL, status_argv);
argv_free(status_argv);
@@ -575,10 +575,14 @@ begin_update(struct view *view, const char *dir, const char **argv, enum open_fl
view->unrefreshable = open_in_pager_mode(flags);
if (!refresh && argv) {
- bool file_filter = !view_has_flags(view, VIEW_FILE_FILTER) || opt_file_filter;
+ int flags = 0;
+ if (!view->prev)
+ flags |= argv_flag_first;
+ if (!view_has_flags(view, VIEW_FILE_FILTER) || opt_file_filter)
+ flags |= argv_flag_file_filter;
view->dir = dir;
- if (!argv_format(view->env, &view->argv, argv, !view->prev, file_filter))
+ if (!argv_format(view->env, &view->argv, argv, flags))
return error("Failed to format %s arguments", view->name);
}