diff mbox series

[1/5] commit-graph: define common usage with a macro

Message ID 20210215184118.11306-2-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series commit-graph: parse_options() cleanup | expand

Commit Message

Ævar Arnfjörð Bjarmason Feb. 15, 2021, 6:41 p.m. UTC
Share the usage message between these three variables by using a
macro. Before this new options needed to copy/paste the usage
information, see e.g. 809e0327f5 (builtin/commit-graph.c: introduce
'--max-new-filters=<n>', 2020-09-18).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/commit-graph.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

Comments

Derrick Stolee Feb. 16, 2021, 11:33 a.m. UTC | #1
On 2/15/2021 1:41 PM, Ævar Arnfjörð Bjarmason wrote:
> +static const char * builtin_commit_graph_verify_usage[] = {
> +#define BUILTIN_COMMIT_GRAPH_VERIFY_USAGE \
> +	N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]")
> +	BUILTIN_COMMIT_GRAPH_VERIFY_USAGE,
>  	NULL
>  };
>  
> +static const char * builtin_commit_graph_write_usage[] = {
> +#define BUILTIN_COMMIT_GRAPH_WRITE_USAGE \
> +	N_("git commit-graph write [--object-dir <objdir>] [--append] " \
> +	   "[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] " \
> +	   "[--changed-paths] [--[no-]max-new-filters <n>] [--[no-]progress] " \
> +	   "<split options>")
> +	BUILTIN_COMMIT_GRAPH_WRITE_USAGE,
>  	NULL
>  };

This seemed very unnatural to me, but it all makes sense in the end:

> +static char const * const builtin_commit_graph_usage[] = {
> +	BUILTIN_COMMIT_GRAPH_VERIFY_USAGE,
> +	BUILTIN_COMMIT_GRAPH_WRITE_USAGE,
> +	NULL,
>  };

Clever!

Thanks,
-Stolee
diff mbox series

Patch

diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index cd86315221..c3fa4fde3e 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -9,26 +9,27 @@ 
 #include "progress.h"
 #include "tag.h"
 
-static char const * const builtin_commit_graph_usage[] = {
-	N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
-	N_("git commit-graph write [--object-dir <objdir>] [--append] "
-	   "[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] "
-	   "[--changed-paths] [--[no-]max-new-filters <n>] [--[no-]progress] "
-	   "<split options>"),
+static const char * builtin_commit_graph_verify_usage[] = {
+#define BUILTIN_COMMIT_GRAPH_VERIFY_USAGE \
+	N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]")
+	BUILTIN_COMMIT_GRAPH_VERIFY_USAGE,
 	NULL
 };
 
-static const char * const builtin_commit_graph_verify_usage[] = {
-	N_("git commit-graph verify [--object-dir <objdir>] [--shallow] [--[no-]progress]"),
+static const char * builtin_commit_graph_write_usage[] = {
+#define BUILTIN_COMMIT_GRAPH_WRITE_USAGE \
+	N_("git commit-graph write [--object-dir <objdir>] [--append] " \
+	   "[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] " \
+	   "[--changed-paths] [--[no-]max-new-filters <n>] [--[no-]progress] " \
+	   "<split options>")
+	BUILTIN_COMMIT_GRAPH_WRITE_USAGE,
 	NULL
 };
 
-static const char * const builtin_commit_graph_write_usage[] = {
-	N_("git commit-graph write [--object-dir <objdir>] [--append] "
-	   "[--split[=<strategy>]] [--reachable|--stdin-packs|--stdin-commits] "
-	   "[--changed-paths] [--[no-]max-new-filters <n>] [--[no-]progress] "
-	   "<split options>"),
-	NULL
+static char const * const builtin_commit_graph_usage[] = {
+	BUILTIN_COMMIT_GRAPH_VERIFY_USAGE,
+	BUILTIN_COMMIT_GRAPH_WRITE_USAGE,
+	NULL,
 };
 
 static struct opts_commit_graph {