path: root/builtin
diff options
authorBrandon Casey <>2017-09-17 22:28:15 (GMT)
committerJunio C Hamano <>2017-09-19 03:13:07 (GMT)
commit28a8d0f77a27646dcbd87f0718b79501113cb82c (patch)
treec7edd6b28bff8ddcadeb2eda0af8be74000f44c2 /builtin
parentf221861e490d2c57b960cf86c5bc37279a3ebc2b (diff)
rev-parse parseopt: do not search help text for flag chars
When searching for flag characters in the option spec, we should ensure the search stays within the bounds of the option spec and does not enter the help text portion of the spec. So when we find the boundary white space marking the start of the help text, let's mark it with a nul character. Then when we search for flag characters starting from the beginning of the string we'll stop at the nul and won't enter the help text. Now, the following option spec: exclame this does something! will produce this 'set' expression when --exclame is specified: set -- --exclame -- instead of this one: set -- --exclame this does something -- Mark t1502.4 and t1502.5 as fixed. Signed-off-by: Brandon Casey <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin')
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index c78b7b3..1cd55a2 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -434,7 +434,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)
@@ -451,8 +451,10 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
+ *help = '\0';
- o->help = xstrdup(skipspaces(help));
+ o->help = xstrdup(skipspaces(help+1));
o->value = &parsed;
o->flags = PARSE_OPT_NOARG;
o->callback = &parseopt_dump;