All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] commit-graph: usage fixes
@ 2021-07-18  7:58 Ævar Arnfjörð Bjarmason
  2021-07-18  7:58 ` [PATCH v2 1/5] commit-graph: define common usage with a macro Ævar Arnfjörð Bjarmason
                   ` (5 more replies)
  0 siblings, 6 replies; 40+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-07-18  7:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Derrick Stolee, Taylor Blau,
	Ævar Arnfjörð Bjarmason

This set of trivial fixes to commit-graph usage was submitted
originally back in February as
https://lore.kernel.org/git/20210215184118.11306-1-avarab@gmail.com/

I omitted the In-Reply-To in the header because this was deep in an
unrelated thread.

In the meantime Taylor's similar changes to the midx code landed (the
original v1 was a "hey, here's how you can do this with
parse_options()" on my part to him).

I did some changes based on feedback on the v1, but didn't pick up all
the suggestions, it was mostly subjective, so let's see what people
think this time around.

Ævar Arnfjörð Bjarmason (5):
  commit-graph: define common usage with a macro
  commit-graph: remove redundant handling of -h
  commit-graph: use parse_options_concat()
  commit-graph: early exit to "usage" on !argc
  commit-graph: show usage on "commit-graph [write|verify] garbage"

 builtin/commit-graph.c  | 95 +++++++++++++++++++++++------------------
 t/t5318-commit-graph.sh |  7 +++
 2 files changed, 60 insertions(+), 42 deletions(-)

Range-diff against v1:
1:  742648756a5 ! 1:  0b0bb04ecf5 commit-graph: define common usage with a macro
    @@ Commit message
         information, see e.g. 809e0327f5 (builtin/commit-graph.c: introduce
         '--max-new-filters=<n>', 2020-09-18).
     
    +    See b25b727494f (builtin/multi-pack-index.c: define common usage with
    +    a macro, 2021-03-30) for another use of this pattern (but on-list this
    +    one came first).
    +
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## builtin/commit-graph.c ##
2:  497b6cbc9a5 = 2:  6f386fc32c8 commit-graph: remove redundant handling of -h
3:  fd1deaa3c99 ! 3:  2e7d9b0b8e4 commit-graph: use parse_options_concat()
    @@ builtin/commit-graph.c: static struct opts_commit_graph {
      					 const char *obj_dir)
      {
     @@ builtin/commit-graph.c: static int graph_verify(int argc, const char **argv)
    - 	int fd;
    - 	struct stat st;
      	int flags = 0;
    --
    -+	struct option *options = NULL;
    + 
      	static struct option builtin_commit_graph_verify_options[] = {
     -		OPT_STRING(0, "object-dir", &opts.obj_dir,
     -			   N_("dir"),
    @@ builtin/commit-graph.c: static int graph_verify(int argc, const char **argv)
     -		OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")),
      		OPT_END(),
      	};
    -+	options = parse_options_dup(builtin_commit_graph_verify_options);
    ++	struct option *options = parse_options_dup(builtin_commit_graph_verify_options);
     +	options = add_common_options(options);
      
      	trace2_cmd_mode("verify");
    @@ builtin/commit-graph.c: static int graph_verify(int argc, const char **argv)
      
      	if (!opts.obj_dir)
     @@ builtin/commit-graph.c: static int graph_write(int argc, const char **argv)
    - 	int result = 0;
    - 	enum commit_graph_write_flags flags = 0;
      	struct progress *progress = NULL;
    --
    -+	struct option *options = NULL;
    + 
      	static struct option builtin_commit_graph_write_options[] = {
     -		OPT_STRING(0, "object-dir", &opts.obj_dir,
     -			N_("dir"),
    @@ builtin/commit-graph.c: static int graph_write(int argc, const char **argv)
      			0, write_option_max_new_filters),
      		OPT_END(),
      	};
    -+	options = parse_options_dup(builtin_commit_graph_write_options);
    ++	struct option *options = parse_options_dup(builtin_commit_graph_write_options);
     +	options = add_common_options(options);
      
      	opts.progress = isatty(2);
4:  3d4a1fb6680 ! 4:  d776424e8c8 commit-graph: refactor dispatch loop for style
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## Commit message ##
    -    commit-graph: refactor dispatch loop for style
    +    commit-graph: early exit to "usage" on !argc
     
    -    I think it's more readable to have one if/elsif/else chain here than
    -    the code this replaces.
    +    Rather than guarding all of the !argc with an additional "if" arm
    +    let's do an early goto to "usage". This also makes it clear that
    +    "save_commit_buffer" is not needed in this case.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## builtin/commit-graph.c ##
     @@ builtin/commit-graph.c: int cmd_commit_graph(int argc, const char **argv, const char *prefix)
    + 			     builtin_commit_graph_options,
    + 			     builtin_commit_graph_usage,
    + 			     PARSE_OPT_STOP_AT_NON_OPTION);
    ++	if (!argc)
    ++		goto usage;
      
      	save_commit_buffer = 0;
      
    @@ builtin/commit-graph.c: int cmd_commit_graph(int argc, const char **argv, const
     -		if (!strcmp(argv[0], "write"))
     -			return graph_write(argc, argv);
     -	}
    --
    --	usage_with_options(builtin_commit_graph_usage,
    --			   builtin_commit_graph_options);
    -+	if (argc && !strcmp(argv[0], "verify"))
    ++	if (!strcmp(argv[0], "verify"))
     +		return graph_verify(argc, argv);
     +	else if (argc && !strcmp(argv[0], "write"))
     +		return graph_write(argc, argv);
    -+	else
    -+		usage_with_options(builtin_commit_graph_usage,
    -+				   builtin_commit_graph_options);
    + 
    ++usage:
    + 	usage_with_options(builtin_commit_graph_usage,
    + 			   builtin_commit_graph_options);
      }
5:  e8481a0932a = 5:  57ffd5812d6 commit-graph: show usage on "commit-graph [write|verify] garbage"
-- 
2.32.0.873.g94a0c75983d


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

end of thread, other threads:[~2021-08-30 23:58 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-18  7:58 [PATCH v2 0/5] commit-graph: usage fixes Ævar Arnfjörð Bjarmason
2021-07-18  7:58 ` [PATCH v2 1/5] commit-graph: define common usage with a macro Ævar Arnfjörð Bjarmason
2021-07-19 16:29   ` Taylor Blau
2021-07-18  7:58 ` [PATCH v2 2/5] commit-graph: remove redundant handling of -h Ævar Arnfjörð Bjarmason
2021-07-18 12:55   ` Andrei Rybak
2021-07-19 16:34     ` Taylor Blau
2021-07-18  7:58 ` [PATCH v2 3/5] commit-graph: use parse_options_concat() Ævar Arnfjörð Bjarmason
2021-07-19 16:50   ` Taylor Blau
2021-07-20 11:31     ` Ævar Arnfjörð Bjarmason
2021-07-18  7:58 ` [PATCH v2 4/5] commit-graph: early exit to "usage" on !argc Ævar Arnfjörð Bjarmason
2021-07-19 16:55   ` Taylor Blau
2021-07-18  7:58 ` [PATCH v2 5/5] commit-graph: show usage on "commit-graph [write|verify] garbage" Ævar Arnfjörð Bjarmason
2021-07-19 16:53   ` Taylor Blau
2021-07-20 11:39 ` [PATCH v3 0/6] commit-graph: usage fixes Ævar Arnfjörð Bjarmason
2021-07-20 11:39   ` [PATCH v3 1/6] commit-graph: define common usage with a macro Ævar Arnfjörð Bjarmason
2021-07-20 11:39   ` [PATCH v3 2/6] commit-graph: remove redundant handling of -h Ævar Arnfjörð Bjarmason
2021-07-20 11:39   ` [PATCH v3 3/6] commit-graph: use parse_options_concat() Ævar Arnfjörð Bjarmason
2021-07-20 11:39   ` [PATCH v3 4/6] multi-pack-index: refactor "goto usage" pattern Ævar Arnfjörð Bjarmason
2021-07-20 18:14     ` Taylor Blau
2021-07-20 11:39   ` [PATCH v3 5/6] commit-graph: early exit to "usage" on !argc Ævar Arnfjörð Bjarmason
2021-07-20 18:17     ` Taylor Blau
2021-07-20 11:39   ` [PATCH v3 6/6] commit-graph: show usage on "commit-graph [write|verify] garbage" Ævar Arnfjörð Bjarmason
2021-07-20 17:47     ` SZEDER Gábor
2021-07-20 17:55       ` SZEDER Gábor
2021-07-20 18:24         ` Taylor Blau
2021-07-20 21:17           ` Ævar Arnfjörð Bjarmason
2021-07-20 21:47             ` Taylor Blau
2021-07-21  7:26               ` Ævar Arnfjörð Bjarmason
2021-07-21  8:08                 ` Jeff King
2021-07-21 16:54                   ` Junio C Hamano
2021-08-23 12:30   ` [PATCH v4 0/7] commit-graph: usage fixes Ævar Arnfjörð Bjarmason
2021-08-23 12:30     ` [PATCH v4 1/7] commit-graph: define common usage with a macro Ævar Arnfjörð Bjarmason
2021-08-23 12:30     ` [PATCH v4 2/7] commit-graph: remove redundant handling of -h Ævar Arnfjörð Bjarmason
2021-08-23 12:30     ` [PATCH v4 3/7] commit-graph: use parse_options_concat() Ævar Arnfjörð Bjarmason
2021-08-23 12:30     ` [PATCH v4 4/7] multi-pack-index: refactor "goto usage" pattern Ævar Arnfjörð Bjarmason
2021-08-23 12:30     ` [PATCH v4 5/7] commit-graph: early exit to "usage" on !argc Ævar Arnfjörð Bjarmason
2021-08-23 12:30     ` [PATCH v4 6/7] commit-graph: show usage on "commit-graph [write|verify] garbage" Ævar Arnfjörð Bjarmason
2021-08-23 12:30     ` [PATCH v4 7/7] commit-graph: show "unexpected subcommand" error Ævar Arnfjörð Bjarmason
2021-08-30 23:54     ` [PATCH v4 0/7] commit-graph: usage fixes Taylor Blau
2021-08-30 23:58       ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.