Merge branch 'ps/revision-stdin-with-options'
The set-up code for the get_revision() API now allows feeding options like --all and --not in the --stdin mode. * ps/revision-stdin-with-options: revision: handle pseudo-opts in `--stdin` mode revision: small readability improvement for reading from stdin revision: reorder `read_revisions_from_stdin()`
This commit is contained in:
82
revision.c
82
revision.c
@ -2198,39 +2198,6 @@ static void read_pathspec_from_stdin(struct strbuf *sb,
|
||||
strvec_push(prune, sb->buf);
|
||||
}
|
||||
|
||||
static void read_revisions_from_stdin(struct rev_info *revs,
|
||||
struct strvec *prune)
|
||||
{
|
||||
struct strbuf sb;
|
||||
int seen_dashdash = 0;
|
||||
int save_warning;
|
||||
|
||||
save_warning = warn_on_object_refname_ambiguity;
|
||||
warn_on_object_refname_ambiguity = 0;
|
||||
|
||||
strbuf_init(&sb, 1000);
|
||||
while (strbuf_getline(&sb, stdin) != EOF) {
|
||||
int len = sb.len;
|
||||
if (!len)
|
||||
break;
|
||||
if (sb.buf[0] == '-') {
|
||||
if (len == 2 && sb.buf[1] == '-') {
|
||||
seen_dashdash = 1;
|
||||
break;
|
||||
}
|
||||
die("options not supported in --stdin mode");
|
||||
}
|
||||
if (handle_revision_arg(sb.buf, revs, 0,
|
||||
REVARG_CANNOT_BE_FILENAME))
|
||||
die("bad revision '%s'", sb.buf);
|
||||
}
|
||||
if (seen_dashdash)
|
||||
read_pathspec_from_stdin(&sb, prune);
|
||||
|
||||
strbuf_release(&sb);
|
||||
warn_on_object_refname_ambiguity = save_warning;
|
||||
}
|
||||
|
||||
static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token what)
|
||||
{
|
||||
append_grep_pattern(&revs->grep_filter, ptn, "command line", 0, what);
|
||||
@ -2819,6 +2786,53 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void read_revisions_from_stdin(struct rev_info *revs,
|
||||
struct strvec *prune,
|
||||
int *flags)
|
||||
{
|
||||
struct strbuf sb;
|
||||
int seen_dashdash = 0;
|
||||
int seen_end_of_options = 0;
|
||||
int save_warning;
|
||||
|
||||
save_warning = warn_on_object_refname_ambiguity;
|
||||
warn_on_object_refname_ambiguity = 0;
|
||||
|
||||
strbuf_init(&sb, 1000);
|
||||
while (strbuf_getline(&sb, stdin) != EOF) {
|
||||
if (!sb.len)
|
||||
break;
|
||||
|
||||
if (!strcmp(sb.buf, "--")) {
|
||||
seen_dashdash = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!seen_end_of_options && sb.buf[0] == '-') {
|
||||
const char *argv[] = { sb.buf, NULL };
|
||||
|
||||
if (!strcmp(sb.buf, "--end-of-options")) {
|
||||
seen_end_of_options = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (handle_revision_pseudo_opt(revs, argv, flags) > 0)
|
||||
continue;
|
||||
|
||||
die(_("invalid option '%s' in --stdin mode"), sb.buf);
|
||||
}
|
||||
|
||||
if (handle_revision_arg(sb.buf, revs, 0,
|
||||
REVARG_CANNOT_BE_FILENAME))
|
||||
die("bad revision '%s'", sb.buf);
|
||||
}
|
||||
if (seen_dashdash)
|
||||
read_pathspec_from_stdin(&sb, prune);
|
||||
|
||||
strbuf_release(&sb);
|
||||
warn_on_object_refname_ambiguity = save_warning;
|
||||
}
|
||||
|
||||
static void NORETURN diagnose_missing_default(const char *def)
|
||||
{
|
||||
int flags;
|
||||
@ -2891,7 +2905,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
|
||||
}
|
||||
if (revs->read_from_stdin++)
|
||||
die("--stdin given twice?");
|
||||
read_revisions_from_stdin(revs, &prune_data);
|
||||
read_revisions_from_stdin(revs, &prune_data, &flags);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user