git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git fast-export: add --no-data option

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 27, 2009, 18:49 UTC
Message-ID
<alpine.DEB.1.00.0907272042450.6883@intel-tinevez-2-302>
In-Reply-To
<7f9d599f0907270548k15c51a01j1fedba20c66b66f6@mail.gmail.com>
Hi,
On Mon, 27 Jul 2009, Geoffrey Irving wrote:
Show 41 quoted lines
> On Sat, Jul 25, 2009 at 1:44 PM, Johannes
> Schindelin<Johannes.Schindelin@gmx.de> wrote:
>
> > On Sat, 25 Jul 2009, Junio C Hamano wrote:
> >
> >> Geoffrey Irving <irving@naml.us> writes:
> >>
> >> > @@ -504,6 +508,8 @@ int cmd_fast_export(int argc, const char **argv,
> >> > const char *prefix)
> >> >                          "Import marks from this file"),
> >> >             OPT_BOOLEAN(0, "fake-missing-tagger", &fake_missing_tagger,
> >> >                          "Fake a tagger when tags lack one"),
> >> > +           OPT_BOOLEAN(0, "no-data", &no_data,
> >> > +                        "Skip output of blob data"),
> >>
> >> Shouldn't this be --[no-]data option that defaults to true? 
> >>  Otherwise you would accept --no-no-data that looks silly.
> >
> > Maybe
> >
> >                OPT_NEGBIT(0, "data", &no_data,
> >                             "Skip output of blob data", 1),
> >
> > Hmm?
> 
> Not quite.  That produces
> 
> usage: git fast-export [rev-list-opts]
> 
>     --progress <n>        show progress after <n> objects
>     --signed-tags <mode>  select handling of signed tags
>     --export-marks <FILE>
>                           Dump marks to this file
>     --import-marks <FILE>
>                           Import marks from this file
>     --fake-missing-tagger
>                           Fake a tagger when tags lack one
>     --data                Skip output of blob data
> 
> I don't see similar uses of OPT_NEGBIT, so maybe the necessary option
> case hasn't been written yet (or I'm missing something obvious)?
There is an ugly solution:
		{ OPTION_NEGBIT, 0, "no-data", &no_data, NULL, NULL,
			PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 0 },
		{ OPTION_BIT, 0, "no-data", NULL, NULL,
			"Skip output of blob data",
			PARSE_OPT_NOARG, NULL, 1 },
and there is a more elegant solution:
[PATCH] parse-opt: optionally show "--no-" option string

It is usually better to have positive options, to avoid confusing double negations. However, sometimes it is desirable to show the negative option in the help.

Introduce the flag PARSE_OPT_NEGHELP to do that.
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 parse-options.c |    6 ++++--
 parse-options.h |    1 +
 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 68accef..a64a4d6 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -511,7 +511,7 @@ static int usage_with_options_internal(const char * const *usagestr,
 			continue;
 
 		pos = fprintf(stderr, "    ");
-		if (opts->short_name) {
+		if (opts->short_name && !(opts->flags & PARSE_OPT_NEGHELP)) {
 			if (opts->flags & PARSE_OPT_NODASH)
 				pos += fprintf(stderr, "%c", opts->short_name);
 			else
@@ -520,7 +520,9 @@ static int usage_with_options_internal(const char * const *usagestr,
 		if (opts->long_name && opts->short_name)
 			pos += fprintf(stderr, ", ");
 		if (opts->long_name)
-			pos += fprintf(stderr, "--%s", opts->long_name);
+			pos += fprintf(stderr, "--%s%s",
+				(opts->flags & PARSE_OPT_NEGHELP) ?  "no-" : "",
+				opts->long_name);
 		if (opts->type == OPTION_NUMBER)
 			pos += fprintf(stderr, "-NUM");
 
diff --git a/parse-options.h b/parse-options.h
index 4b62361..8f0035a 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -36,6 +36,7 @@ enum parse_opt_option_flags {
 	PARSE_OPT_LASTARG_DEFAULT = 16,
 	PARSE_OPT_NODASH = 32,
 	PARSE_OPT_LITERAL_ARGHELP = 64,
+	PARSE_OPT_NEGHELP = 128,
 };
 
 struct option;
Previous: Geoffrey IrvingNext: Geoffrey Irving
Message 6 of 9 in “git fast-export: add --no-data option”
  1. git fast-export: add --no-data optionGeoffrey Irving, Jul 25, 2009
  2. Johannes SchindelinJul 25, 2009
  3. Junio C HamanoJul 25, 2009
  4. Johannes SchindelinJul 25, 2009
  5. Geoffrey IrvingJul 27, 2009
  6. Johannes SchindelinJul 27, 2009
  7. git fast-export: add --no-data optionGeoffrey Irving, Jul 28, 2009
  8. Stephen BoydJul 28, 2009
  9. Johannes SchindelinJul 28, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.