Re: [PATCH 5/5] show-ref: stop using PARSE_OPT_NO_INTERNAL_HELP

2015-12-04 Thread Junio C Hamano
René Scharfe  writes:

> The flag PARSE_OPT_NO_INTERNAL_HELP is set to allow overriding the
> option -h, except when it's the only one given.
> This is the default behavior now,...

OK, so in the old world order, "-h" used to trigger the internal
help even before consulting parse_short_opt() to see if there is a
handler supplied by the caller, and NO_INTERNAL_HELP was invented as
a kludge to to disable this behaviour.  The existing two users
(dealt with 4/5 and 5/5) both used this mechanism to let their own
handler kick in, but they had to make "-h" without anything else on
the command line behave just like the internal one, while handling
"-h" with something else on the command line do a custom thing.

In the new world order, internal "-h" handler is called only after
seeing that parse_short_opt() decides there is no handler for "-h"
as a fallback.

Side note.  Not really.  Among the three uses of
intenal_help in parse_options_step(), the first one ("lone
-h asks for help") is used before we ask parse_short_opt().

I wonder if we can/want to further tweak this in a follow-up
series.  If that is done, I think NO_INTERNAL_HELP can go away, as
its only effect would be to make us say "unknown option" when "-h"
alone was given from the command line for an options[] array that
does not have a handler for "-h".


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/5] show-ref: stop using PARSE_OPT_NO_INTERNAL_HELP

2015-11-17 Thread René Scharfe
The flag PARSE_OPT_NO_INTERNAL_HELP is set to allow overriding the
option -h, except when it's the only one given.  This is the default
behavior now, so remove the flag and the hand-rolled --help-all
handling.  The internal --help-all handler now actually shows hidden
options, i.e. -h in this case.

Signed-off-by: Rene Scharfe 
---
 builtin/show-ref.c | 12 +---
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 264c392..6d4e669 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -161,11 +161,6 @@ static int exclude_existing_callback(const struct option 
*opt, const char *arg,
return 0;
 }
 
-static int help_callback(const struct option *opt, const char *arg, int unset)
-{
-   return -1;
-}
-
 static const struct option show_ref_options[] = {
OPT_BOOL(0, "tags", &tags_only, N_("only show tags (can be combined 
with heads)")),
OPT_BOOL(0, "heads", &heads_only, N_("only show heads (can be combined 
with tags)")),
@@ -186,18 +181,13 @@ static const struct option show_ref_options[] = {
{ OPTION_CALLBACK, 0, "exclude-existing", &exclude_existing_arg,
  N_("pattern"), N_("show refs from stdin that aren't in local 
repository"),
  PARSE_OPT_OPTARG | PARSE_OPT_NONEG, exclude_existing_callback },
-   { OPTION_CALLBACK, 0, "help-all", NULL, NULL, N_("show usage"),
- PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback },
OPT_END()
 };
 
 int cmd_show_ref(int argc, const char **argv, const char *prefix)
 {
-   if (argc == 2 && !strcmp(argv[1], "-h"))
-   usage_with_options(show_ref_usage, show_ref_options);
-
argc = parse_options(argc, argv, prefix, show_ref_options,
-show_ref_usage, PARSE_OPT_NO_INTERNAL_HELP);
+show_ref_usage, 0);
 
if (exclude_arg)
return exclude_existing(exclude_existing_arg);
-- 
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html