Skip to content
Browse files

Unify the parsing of blame options and other view options

This refactor lays the groundwork for further cross-view options.
  • Loading branch information...
1 parent 9c3a0a2 commit 9267d2ab5bcfc3cd505ee631b903108433f0a9ff @tsibley tsibley committed
Showing with 23 additions and 18 deletions.
  1. +1 −1 tig.1.txt
  2. +21 −16 tig.c
  3. +1 −1 tigmanual.7.txt
View
2 tig.1.txt
@@ -10,7 +10,7 @@ SYNOPSIS
[verse]
tig [options] [revisions] [--] [paths]
tig show [options] [revisions] [--] [paths]
-tig blame [options] [rev] path
+tig blame [options] [rev] [--] path
tig status
tig < [git command output]
View
37 tig.c
@@ -7416,10 +7416,15 @@ filter_rev_parse(const char ***args, const char *arg1, const char *arg2, const c
}
static void
-filter_options(const char *argv[])
+filter_options(const char *argv[], bool blame)
{
filter_rev_parse(&opt_file_argv, "--no-revs", "--no-flags", argv);
- filter_rev_parse(&opt_diff_argv, "--no-revs", "--flags", argv);
+
+ if (blame)
+ filter_rev_parse(&opt_blame_argv, "--no-revs", "--flags", argv);
+ else
+ filter_rev_parse(&opt_diff_argv, "--no-revs", "--flags", argv);
+
filter_rev_parse(&opt_rev_argv, "--symbolic", "--revs-only", argv);
}
@@ -7445,19 +7450,7 @@ parse_options(int argc, const char *argv[])
return REQ_VIEW_STATUS;
} else if (!strcmp(subcommand, "blame")) {
- filter_rev_parse(&opt_file_argv, "--no-revs", "--no-flags", argv + 2);
- filter_rev_parse(&opt_blame_argv, "--no-revs", "--flags", argv + 2);
- filter_rev_parse(&opt_rev_argv, "--symbolic", "--revs-only", argv + 2);
-
- if (!opt_file_argv || opt_file_argv[1] || (opt_rev_argv && opt_rev_argv[1]))
- die("invalid number of options to blame\n\n%s", usage);
-
- if (opt_rev_argv) {
- string_ncopy(opt_ref, opt_rev_argv[0], strlen(opt_rev_argv[0]));
- }
-
- string_ncopy(opt_file, opt_file_argv[0], strlen(opt_file_argv[0]));
- return REQ_VIEW_BLAME;
+ request = REQ_VIEW_BLAME;
} else if (!strcmp(subcommand, "show")) {
request = REQ_VIEW_DIFF;
@@ -7491,7 +7484,19 @@ parse_options(int argc, const char *argv[])
}
if (filter_argv)
- filter_options(filter_argv);
+ filter_options(filter_argv, request == REQ_VIEW_BLAME);
+
+ /* Finish validating and setting up blame options */
+ if (request == REQ_VIEW_BLAME) {
+ if (!opt_file_argv || opt_file_argv[1] || (opt_rev_argv && opt_rev_argv[1]))
+ die("invalid number of options to blame\n\n%s", usage);
+
+ if (opt_rev_argv) {
+ string_ncopy(opt_ref, opt_rev_argv[0], strlen(opt_rev_argv[0]));
+ }
+
+ string_ncopy(opt_file, opt_file_argv[0], strlen(opt_file_argv[0]));
+ }
return request;
}
View
2 tigmanual.7.txt
@@ -10,7 +10,7 @@ SYNOPSIS
[verse]
tig [options] [revisions] [--] [paths]
tig show [options] [revisions] [--] [paths]
-tig blame [rev] path
+tig blame [options] [rev] [--] path
tig status
tig < [git command output]

0 comments on commit 9267d2a

Please sign in to comment.
Something went wrong with that request. Please try again.