git-blame: migrate to incremental parse-option [2/2]
Now use handle_revision_args instead of parse_revisions, and simplify the handling of old-style arguments a lot thanks to the filtering. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5817da0143
commit
3f8d520489
124
builtin-blame.c
124
builtin-blame.c
@ -2262,8 +2262,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
|
|||||||
struct scoreboard sb;
|
struct scoreboard sb;
|
||||||
struct origin *o;
|
struct origin *o;
|
||||||
struct blame_entry *ent;
|
struct blame_entry *ent;
|
||||||
int i, seen_dashdash, unk;
|
long dashdash_pos, bottom, top, lno;
|
||||||
long bottom, top, lno;
|
|
||||||
const char *final_commit_name = NULL;
|
const char *final_commit_name = NULL;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
|
|
||||||
@ -2301,6 +2300,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
|
|||||||
git_config(git_blame_config, NULL);
|
git_config(git_blame_config, NULL);
|
||||||
init_revisions(&revs, NULL);
|
init_revisions(&revs, NULL);
|
||||||
save_commit_buffer = 0;
|
save_commit_buffer = 0;
|
||||||
|
dashdash_pos = 0;
|
||||||
|
|
||||||
parse_options_start(&ctx, argc, argv, PARSE_OPT_KEEP_DASHDASH |
|
parse_options_start(&ctx, argc, argv, PARSE_OPT_KEEP_DASHDASH |
|
||||||
PARSE_OPT_KEEP_ARGV0);
|
PARSE_OPT_KEEP_ARGV0);
|
||||||
@ -2311,6 +2311,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
|
|||||||
case PARSE_OPT_HELP:
|
case PARSE_OPT_HELP:
|
||||||
exit(129);
|
exit(129);
|
||||||
case PARSE_OPT_DONE:
|
case PARSE_OPT_DONE:
|
||||||
|
if (ctx.argv[0])
|
||||||
|
dashdash_pos = ctx.cpidx;
|
||||||
goto parse_done;
|
goto parse_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2330,20 +2332,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
|
|||||||
parse_done:
|
parse_done:
|
||||||
argc = parse_options_end(&ctx);
|
argc = parse_options_end(&ctx);
|
||||||
|
|
||||||
seen_dashdash = 0;
|
|
||||||
for (unk = i = 1; i < argc; i++) {
|
|
||||||
const char *arg = argv[i];
|
|
||||||
if (*arg != '-')
|
|
||||||
break;
|
|
||||||
else if (!strcmp("--", arg)) {
|
|
||||||
seen_dashdash = 1;
|
|
||||||
i++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
argv[unk++] = arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!blame_move_score)
|
if (!blame_move_score)
|
||||||
blame_move_score = BLAME_DEFAULT_MOVE_SCORE;
|
blame_move_score = BLAME_DEFAULT_MOVE_SCORE;
|
||||||
if (!blame_copy_score)
|
if (!blame_copy_score)
|
||||||
@ -2356,92 +2344,50 @@ parse_done:
|
|||||||
*
|
*
|
||||||
* The remaining are:
|
* The remaining are:
|
||||||
*
|
*
|
||||||
* (1) if seen_dashdash, its either
|
* (1) if dashdash_pos != 0, its either
|
||||||
* "-options -- <path>" or
|
* "blame [revisions] -- <path>" or
|
||||||
* "-options -- <path> <rev>".
|
* "blame -- <path> <rev>"
|
||||||
* but the latter is allowed only if there is no
|
|
||||||
* options that we passed to revision machinery.
|
|
||||||
*
|
*
|
||||||
* (2) otherwise, we may have "--" somewhere later and
|
* (2) otherwise, its one of the two:
|
||||||
* might be looking at the first one of multiple 'rev'
|
* "blame [revisions] <path>"
|
||||||
* parameters (e.g. " master ^next ^maint -- path").
|
* "blame <path> <rev>"
|
||||||
* See if there is a dashdash first, and give the
|
|
||||||
* arguments before that to revision machinery.
|
|
||||||
* After that there must be one 'path'.
|
|
||||||
*
|
*
|
||||||
* (3) otherwise, its one of the three:
|
* Note that we must strip out <path> from the arguments: we do not
|
||||||
* "-options <path> <rev>"
|
* want the path pruning but we may want "bottom" processing.
|
||||||
* "-options <rev> <path>"
|
|
||||||
* "-options <path>"
|
|
||||||
* but again the first one is allowed only if
|
|
||||||
* there is no options that we passed to revision
|
|
||||||
* machinery.
|
|
||||||
*/
|
*/
|
||||||
|
if (dashdash_pos) {
|
||||||
if (seen_dashdash) {
|
switch (argc - dashdash_pos - 1) {
|
||||||
/* (1) */
|
case 2: /* (1b) */
|
||||||
if (argc <= i)
|
if (argc != 4)
|
||||||
usage_with_options(blame_opt_usage, options);
|
usage_with_options(blame_opt_usage, options);
|
||||||
path = add_prefix(prefix, argv[i]);
|
/* reorder for the new way: <rev> -- <path> */
|
||||||
if (i + 1 == argc - 1) {
|
argv[1] = argv[3];
|
||||||
if (unk != 1)
|
argv[3] = argv[2];
|
||||||
usage_with_options(blame_opt_usage, options);
|
argv[2] = "--";
|
||||||
argv[unk++] = argv[i + 1];
|
/* FALLTHROUGH */
|
||||||
}
|
case 1: /* (1a) */
|
||||||
else if (i + 1 != argc)
|
path = add_prefix(prefix, argv[--argc]);
|
||||||
/* garbage at end */
|
argv[argc] = NULL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
usage_with_options(blame_opt_usage, options);
|
usage_with_options(blame_opt_usage, options);
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
int j;
|
if (argc < 2)
|
||||||
for (j = i; !seen_dashdash && j < argc; j++)
|
|
||||||
if (!strcmp(argv[j], "--"))
|
|
||||||
seen_dashdash = j;
|
|
||||||
if (seen_dashdash) {
|
|
||||||
/* (2) */
|
|
||||||
if (seen_dashdash + 1 != argc - 1)
|
|
||||||
usage_with_options(blame_opt_usage, options);
|
usage_with_options(blame_opt_usage, options);
|
||||||
path = add_prefix(prefix, argv[seen_dashdash + 1]);
|
path = add_prefix(prefix, argv[argc - 1]);
|
||||||
for (j = i; j < seen_dashdash; j++)
|
if (argc == 3 && !has_path_in_work_tree(path)) { /* (2b) */
|
||||||
argv[unk++] = argv[j];
|
path = add_prefix(prefix, argv[1]);
|
||||||
|
argv[1] = argv[2];
|
||||||
}
|
}
|
||||||
else {
|
argv[argc - 1] = "--";
|
||||||
/* (3) */
|
|
||||||
if (argc <= i)
|
|
||||||
usage_with_options(blame_opt_usage, options);
|
|
||||||
path = add_prefix(prefix, argv[i]);
|
|
||||||
if (i + 1 == argc - 1) {
|
|
||||||
final_commit_name = argv[i + 1];
|
|
||||||
|
|
||||||
/* if (unk == 1) we could be getting
|
|
||||||
* old-style
|
|
||||||
*/
|
|
||||||
if (unk == 1 && !has_path_in_work_tree(path)) {
|
|
||||||
path = add_prefix(prefix, argv[i + 1]);
|
|
||||||
final_commit_name = argv[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (i != argc - 1)
|
|
||||||
usage_with_options(blame_opt_usage, options);
|
|
||||||
|
|
||||||
setup_work_tree();
|
setup_work_tree();
|
||||||
if (!has_path_in_work_tree(path))
|
if (!has_path_in_work_tree(path))
|
||||||
die("cannot stat path %s: %s",
|
die("cannot stat path %s: %s", path, strerror(errno));
|
||||||
path, strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (final_commit_name)
|
setup_revisions(argc, argv, &revs, NULL);
|
||||||
argv[unk++] = final_commit_name;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now we got rev and path. We do not want the path pruning
|
|
||||||
* but we may want "bottom" processing.
|
|
||||||
*/
|
|
||||||
argv[unk++] = "--"; /* terminate the rev name */
|
|
||||||
argv[unk] = NULL;
|
|
||||||
|
|
||||||
setup_revisions(unk, argv, &revs, NULL);
|
|
||||||
memset(&sb, 0, sizeof(sb));
|
memset(&sb, 0, sizeof(sb));
|
||||||
|
|
||||||
sb.revs = &revs;
|
sb.revs = &revs;
|
||||||
|
Loading…
Reference in New Issue
Block a user