public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/2] repo: factor repo usage strings into shared macros
       [not found] <20260323152937.257406-1- mahlet.takassa@gmail.com>
@ 2026-03-25 11:51 ` Mahi Kassa
  2026-03-25 11:51   ` [PATCH v4 2/2] repo: show subcommand-specific help text Mahi Kassa
  2026-03-25 17:35   ` [PATCH v4 1/2] repo: factor repo usage strings into shared macros Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Mahi Kassa @ 2026-03-25 11:51 UTC (permalink / raw)
  To: git; +Cc: gitster, lucasseikioshiro, jltobler, stolee, Mahi Kassa

Factor the "git repo info" and "git repo structure" usage
strings into shared macros so they can be reused in multiple
usage arrays.

This is a preparatory refactoring for subsequent changes to
subcommand-specific help output.

Signed-off-by: Mahi Kassa <mahlet.takassa@gmail.com>

---
v4:
- split the preparatory macro refactoring into its own patch
 builtin/repo.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/builtin/repo.c b/builtin/repo.c
index 55f9b9095c..b5146499d0 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -20,11 +20,17 @@
 #include "tree-walk.h"
 #include "utf8.h"
 
+#define REPO_INFO_USAGE \
+	"git repo info [--format=(lines|nul) | -z] [--all | <key>...]", \
+	"git repo info --keys [--format=(lines|nul) | -z]"
+
+#define REPO_STRUCTURE_USAGE \
+	"git repo structure [--format=(table|lines|nul) | -z]"
+
 static const char *const repo_usage[] = {
-	"git repo info [--format=(lines|nul) | -z] [--all | <key>...]",
-	"git repo info --keys [--format=(lines|nul) | -z]",
-	"git repo structure [--format=(table|lines|nul) | -z]",
-	NULL
+	REPO_INFO_USAGE,
+	REPO_STRUCTURE_USAGE,
+	NULL,
 };
 
 typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/2] repo: show subcommand-specific help text
  2026-03-25 11:51 ` [PATCH v4 1/2] repo: factor repo usage strings into shared macros Mahi Kassa
@ 2026-03-25 11:51   ` Mahi Kassa
  2026-03-25 17:40     ` Junio C Hamano
  2026-03-25 17:35   ` [PATCH v4 1/2] repo: factor repo usage strings into shared macros Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Mahi Kassa @ 2026-03-25 11:51 UTC (permalink / raw)
  To: git; +Cc: gitster, lucasseikioshiro, jltobler, stolee, Mahi Kassa

Use subcommand-specific usage arrays for "git repo info" and
"git repo structure" so that each command shows only its own
synopsis in help output.

Add tests to cover the subcommand help behavior.

Signed-off-by: Mahi Kassa <mahlet.takassa@gmail.com>

---
v4:
- split the subcommand-specific help change into a second patch
- keep the behavior change and tests together
 builtin/repo.c            | 14 ++++++++++++--
 t/t1900-repo-info.sh      |  6 ++++++
 t/t1901-repo-structure.sh |  6 ++++++
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/builtin/repo.c b/builtin/repo.c
index b5146499d0..71a5c1c29c 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -33,6 +33,16 @@ static const char *const repo_usage[] = {
 	NULL,
 };
 
+static const char *const repo_info_usage[] = {
+	REPO_INFO_USAGE,
+	NULL,
+};
+
+static const char *const repo_structure_usage[] = {
+	REPO_STRUCTURE_USAGE,
+	NULL,
+};
+
 typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
 
 enum output_format {
@@ -220,7 +230,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
 		OPT_END()
 	};
 
-	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, repo_info_usage, 0);
 
 	if (show_keys && (all_keys || argc))
 		die(_("--keys cannot be used with a <key> or --all"));
@@ -885,7 +895,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
 		OPT_END()
 	};
 
-	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
+	argc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);
 	if (argc)
 		usage(_("too many arguments"));
 
diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
index a9eb07abe8..39bb77dda0 100755
--- a/t/t1900-repo-info.sh
+++ b/t/t1900-repo-info.sh
@@ -149,4 +149,10 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
 	test_cmp expect actual
 '
 
+test_expect_success 'git repo info -h shows only repo info usage' '
+	test_must_fail git repo info -h >actual &&
+	test_grep "git repo info" actual &&
+	test_grep ! "git repo structure" actual
+'
+
 test_done
diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh
index 98921ce1cb..10050abd70 100755
--- a/t/t1901-repo-structure.sh
+++ b/t/t1901-repo-structure.sh
@@ -224,4 +224,10 @@ test_expect_success 'progress meter option' '
 	)
 '
 
+test_expect_success 'git repo structure -h shows only repo structure usage' '
+	test_must_fail git repo structure -h >actual &&
+	test_grep "git repo structure" actual &&
+	test_grep ! "git repo info" actual
+'
+
 test_done
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 1/2] repo: factor repo usage strings into shared macros
  2026-03-25 11:51 ` [PATCH v4 1/2] repo: factor repo usage strings into shared macros Mahi Kassa
  2026-03-25 11:51   ` [PATCH v4 2/2] repo: show subcommand-specific help text Mahi Kassa
@ 2026-03-25 17:35   ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2026-03-25 17:35 UTC (permalink / raw)
  To: Mahi Kassa; +Cc: git, lucasseikioshiro, jltobler, stolee

Mahi Kassa <mahlet.takassa@gmail.com> writes:

> Factor the "git repo info" and "git repo structure" usage
> strings into shared macros so they can be reused in multiple
> usage arrays.
>
> This is a preparatory refactoring for subsequent changes to
> subcommand-specific help output.
>
> Signed-off-by: Mahi Kassa <mahlet.takassa@gmail.com>
>
> ---
> v4:
> - split the preparatory macro refactoring into its own patch
>  builtin/repo.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)

Looking good.  The distribution of commas are sensible, too.

> diff --git a/builtin/repo.c b/builtin/repo.c
> index 55f9b9095c..b5146499d0 100644
> --- a/builtin/repo.c
> +++ b/builtin/repo.c
> @@ -20,11 +20,17 @@
>  #include "tree-walk.h"
>  #include "utf8.h"
>  
> +#define REPO_INFO_USAGE \
> +	"git repo info [--format=(lines|nul) | -z] [--all | <key>...]", \
> +	"git repo info --keys [--format=(lines|nul) | -z]"
> +
> +#define REPO_STRUCTURE_USAGE \
> +	"git repo structure [--format=(table|lines|nul) | -z]"
> +
>  static const char *const repo_usage[] = {
> -	"git repo info [--format=(lines|nul) | -z] [--all | <key>...]",
> -	"git repo info --keys [--format=(lines|nul) | -z]",
> -	"git repo structure [--format=(table|lines|nul) | -z]",
> -	NULL
> +	REPO_INFO_USAGE,
> +	REPO_STRUCTURE_USAGE,
> +	NULL,
>  };
>  
>  typedef int get_value_fn(struct repository *repo, struct strbuf *buf);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 2/2] repo: show subcommand-specific help text
  2026-03-25 11:51   ` [PATCH v4 2/2] repo: show subcommand-specific help text Mahi Kassa
@ 2026-03-25 17:40     ` Junio C Hamano
  2026-03-26 14:07       ` Patrick Steinhardt
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2026-03-25 17:40 UTC (permalink / raw)
  To: Mahi Kassa; +Cc: git, lucasseikioshiro, jltobler, stolee

Mahi Kassa <mahlet.takassa@gmail.com> writes:

> Use subcommand-specific usage arrays for "git repo info" and
> "git repo structure" so that each command shows only its own
> synopsis in help output.
>
> Add tests to cover the subcommand help behavior.
>
> Signed-off-by: Mahi Kassa <mahlet.takassa@gmail.com>
>
> ---
> v4:
> - split the subcommand-specific help change into a second patch
> - keep the behavior change and tests together
>  builtin/repo.c            | 14 ++++++++++++--
>  t/t1900-repo-info.sh      |  6 ++++++
>  t/t1901-repo-structure.sh |  6 ++++++
>  3 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/repo.c b/builtin/repo.c
> index b5146499d0..71a5c1c29c 100644
> --- a/builtin/repo.c
> +++ b/builtin/repo.c
> @@ -33,6 +33,16 @@ static const char *const repo_usage[] = {
>  	NULL,
>  };
>  
> +static const char *const repo_info_usage[] = {
> +	REPO_INFO_USAGE,
> +	NULL,
> +};
> +
> +static const char *const repo_structure_usage[] = {
> +	REPO_STRUCTURE_USAGE,
> +	NULL,
> +};
> +
>  typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
>  
>  enum output_format {
> @@ -220,7 +230,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
>  		OPT_END()
>  	};
>  
> -	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
> +	argc = parse_options(argc, argv, prefix, options, repo_info_usage, 0);
>  
>  	if (show_keys && (all_keys || argc))
>  		die(_("--keys cannot be used with a <key> or --all"));
> @@ -885,7 +895,7 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
>  		OPT_END()
>  	};
>  
> -	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
> +	argc = parse_options(argc, argv, prefix, options, repo_structure_usage, 0);
>  	if (argc)
>  		usage(_("too many arguments"));

OK.  It makes sense.  Is repo_usage() still used?

    ... goes and looks ...

Yes, "git repo -h" uses it to tell us that info/structure are the
available subcommands.

> diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
> index a9eb07abe8..39bb77dda0 100755
> --- a/t/t1900-repo-info.sh
> +++ b/t/t1900-repo-info.sh
> @@ -149,4 +149,10 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'git repo info -h shows only repo info usage' '
> +	test_must_fail git repo info -h >actual &&

There was a topic about the exit code and the output destination of
"-h", which is the mode of any command that gives exactly what the
end-user asked, which should go to the standard error, and does so
successfully, which hints that we may want to exit with 0.  So this
may later have to change to expect success, but let's leave it as is
for now.  Existing tests on "-h" will also have to be updatd if/when
such a change happens.

> +	test_grep "git repo info" actual &&
> +	test_grep ! "git repo structure" actual
> +'
>  test_done
> diff --git a/t/t1901-repo-structure.sh b/t/t1901-repo-structure.sh
> index 98921ce1cb..10050abd70 100755
> --- a/t/t1901-repo-structure.sh
> +++ b/t/t1901-repo-structure.sh
> @@ -224,4 +224,10 @@ test_expect_success 'progress meter option' '
>  	)
>  '
>  
> +test_expect_success 'git repo structure -h shows only repo structure usage' '
> +	test_must_fail git repo structure -h >actual &&
> +	test_grep "git repo structure" actual &&
> +	test_grep ! "git repo info" actual
> +'
> +
>  test_done

Looking good.

Will queue.  Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 2/2] repo: show subcommand-specific help text
  2026-03-25 17:40     ` Junio C Hamano
@ 2026-03-26 14:07       ` Patrick Steinhardt
  0 siblings, 0 replies; 5+ messages in thread
From: Patrick Steinhardt @ 2026-03-26 14:07 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Mahi Kassa, git, lucasseikioshiro, jltobler, stolee

On Wed, Mar 25, 2026 at 10:40:22AM -0700, Junio C Hamano wrote:
> Looking good.
> 
> Will queue.  Thanks.

Yup, I'm happy with this version, too. Thanks!

Patrick

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-26 14:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260323152937.257406-1- mahlet.takassa@gmail.com>
2026-03-25 11:51 ` [PATCH v4 1/2] repo: factor repo usage strings into shared macros Mahi Kassa
2026-03-25 11:51   ` [PATCH v4 2/2] repo: show subcommand-specific help text Mahi Kassa
2026-03-25 17:40     ` Junio C Hamano
2026-03-26 14:07       ` Patrick Steinhardt
2026-03-25 17:35   ` [PATCH v4 1/2] repo: factor repo usage strings into shared macros Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox