git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Derrick Stolee" <stolee@gmail.com>,
	"Taylor Blau" <me@ttaylorr.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 0/5] commit-graph: usage fixes
Date: Sun, 18 Jul 2021 09:58:04 +0200	[thread overview]
Message-ID: <cover-0.5-00000000000-20210718T074936Z-avarab@gmail.com> (raw)

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


             reply	other threads:[~2021-07-18  7:58 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-18  7:58 Ævar Arnfjörð Bjarmason [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover-0.5-00000000000-20210718T074936Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.com \
    --cc=stolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).