Merge branch 'bc/rev-parse-parseopt-fix'
Recent versions of "git rev-parse --parseopt" did not parse the option specification that does not have the optional flags (*=?!) correctly, which has been corrected. * bc/rev-parse-parseopt-fix: parse-options: only insert newline in help text if needed parse-options: write blank line to correct output stream t0040,t1502: Demonstrate parse_options bugs git-rebase: don't ignore unexpected command line arguments rev-parse parseopt: interpret any whitespace as start of help text rev-parse parseopt: do not search help text for flag chars t1502: demonstrate rev-parse --parseopt option mis-parsing
This commit is contained in:
@ -387,6 +387,14 @@ static const char *skipspaces(const char *s)
|
||||
return s;
|
||||
}
|
||||
|
||||
static char *findspace(const char *s)
|
||||
{
|
||||
for (; *s; s++)
|
||||
if (isspace(*s))
|
||||
return (char*)s;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int cmd_parseopt(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
static int keep_dashdash = 0, stop_at_non_option = 0;
|
||||
@ -434,7 +442,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
|
||||
/* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
|
||||
while (strbuf_getline(&sb, stdin) != EOF) {
|
||||
const char *s;
|
||||
const char *help;
|
||||
char *help;
|
||||
struct option *o;
|
||||
|
||||
if (!sb.len)
|
||||
@ -444,15 +452,17 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
|
||||
memset(opts + onb, 0, sizeof(opts[onb]));
|
||||
|
||||
o = &opts[onb++];
|
||||
help = strchr(sb.buf, ' ');
|
||||
if (!help || *sb.buf == ' ') {
|
||||
help = findspace(sb.buf);
|
||||
if (!help || sb.buf == help) {
|
||||
o->type = OPTION_GROUP;
|
||||
o->help = xstrdup(skipspaces(sb.buf));
|
||||
continue;
|
||||
}
|
||||
|
||||
*help = '\0';
|
||||
|
||||
o->type = OPTION_CALLBACK;
|
||||
o->help = xstrdup(skipspaces(help));
|
||||
o->help = xstrdup(skipspaces(help+1));
|
||||
o->value = &parsed;
|
||||
o->flags = PARSE_OPT_NOARG;
|
||||
o->callback = &parseopt_dump;
|
||||
|
Reference in New Issue
Block a user