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

[PATCH 1/3] parse-options: teach "git cmd -h" to show alias as alias

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 16, 2020, 21:28 UTC
Message-ID
<20200316212857.259093-2-gitster@pobox.com>
In-Reply-To
<20200316212857.259093-1-gitster@pobox.com>

There is a long-standing NEEDSWORK comment that complains about inconsistency between how an aliased option ("git clone --recurse" which is the only one that currently exists) gives a help text in a usage-error message vs "git cmd -h"). Get rid of it and then make sure we say an option is an alias for another, instead of repeating the same short help text for both, which leads to "they seem to do the same---is there any subtle difference?" puzzlement to end-users.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * I couldn't easily see how to trigger usage_with_options() with
   the original options[], which is the potential cause of the
   inconsistency the NEEDSWORK comment mentions.  But if there were,
   this should take care of it.  Our test suite did not have an
   example, though.
 parse-options.c          | 9 +++------
 t/t0040-parse-options.sh | 2 +-
 2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 63d6bab60c..c57618d537 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -648,6 +648,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
 		int short_name;
 		const char *long_name;
 		const char *source;
+		struct strbuf help = STRBUF_INIT;
 		int j;
 
 		if (newopt[i].type != OPTION_ALIAS)
@@ -659,6 +660,7 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
 
 		if (!long_name)
 			BUG("An alias must have long option name");
+		strbuf_addf(&help, _("alias of --%s"), source);
 
 		for (j = 0; j < nr; j++) {
 			const char *name = options[j].long_name;
@@ -669,15 +671,10 @@ static struct option *preprocess_options(struct parse_opt_ctx_t *ctx,
 			if (options[j].type == OPTION_ALIAS)
 				BUG("No please. Nested aliases are not supported.");
 
-			/*
-			 * NEEDSWORK: this is a bit inconsistent because
-			 * usage_with_options() on the original options[] will print
-			 * help string as "alias of %s" but "git cmd -h" will
-			 * print the original help string.
-			 */
 			memcpy(newopt + i, options + j, sizeof(*newopt));
 			newopt[i].short_name = short_name;
 			newopt[i].long_name = long_name;
+			newopt[i].help = strbuf_detach(&help, NULL);
 			break;
 		}
 
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 3483b72db4..f8178ee4e3 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -54,7 +54,7 @@ Alias
     -A, --alias-source <string>
                           get a string
     -Z, --alias-target <string>
-                          get a string
+                          alias of --alias-source
 
 EOF
 
-- 
2.26.0-rc1-11-g30e9940356
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 6 in “I keep typing "git log --no-mailmap" X-<”
  1. 0/3 I keep typing "git log --no-mailmap" X-<Junio C Hamano, Mar 16, 2020
  2. 2/3 clone: reorder --recursive/--recurse-submodulesJunio C Hamano, Mar 16, 2020
  3. 1/3 parse-options: teach "git cmd -h" to show alias as aliasJunio C Hamano, Mar 16, 2020
  4. 3/3 log: give --[no-]use-mailmap a more sensible synonym --[no-]mailmapJunio C Hamano, Mar 16, 2020
  5. Eric SunshineMar 16, 2020
  6. Junio C HamanoMar 16, 2020

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.