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

[PATCH v2 0/5] commit-graph: usage fixes

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jul 18, 2021, 07:58 UTC
Message-ID
<cover-0.5-00000000000-20210718T074936Z-avarab@gmail.com>

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
Next: Ævar Arnfjörð Bjarmason
Message 1 of 40 in “commit-graph: usage fixes”
  1. 0/5 commit-graph: usage fixesÆvar Arnfjörð Bjarmason, Jul 18, 2021
  2. 2/5 commit-graph: remove redundant handling of -hÆvar Arnfjörð Bjarmason, Jul 18, 2021
  3. Andrei RybakJul 18, 2021
  4. Taylor BlauJul 19, 2021
  5. 1/5 commit-graph: define common usage with a macroÆvar Arnfjörð Bjarmason, Jul 18, 2021
  6. Taylor BlauJul 19, 2021
  7. 3/5 commit-graph: use parse_options_concat()Ævar Arnfjörð Bjarmason, Jul 18, 2021
  8. Taylor BlauJul 19, 2021
  9. Ævar Arnfjörð BjarmasonJul 20, 2021
  10. 4/5 commit-graph: early exit to "usage" on !argcÆvar Arnfjörð Bjarmason, Jul 18, 2021
  11. Taylor BlauJul 19, 2021
  12. 5/5 commit-graph: show usage on "commit-graph [write|verify] garbage"Ævar Arnfjörð Bjarmason, Jul 18, 2021
  13. Taylor BlauJul 19, 2021
  14. 0/6 commit-graph: usage fixesÆvar Arnfjörð Bjarmason, Jul 20, 2021
  15. 1/6 commit-graph: define common usage with a macroÆvar Arnfjörð Bjarmason, Jul 20, 2021
  16. 2/6 commit-graph: remove redundant handling of -hÆvar Arnfjörð Bjarmason, Jul 20, 2021
  17. 3/6 commit-graph: use parse_options_concat()Ævar Arnfjörð Bjarmason, Jul 20, 2021
  18. 4/6 multi-pack-index: refactor "goto usage" patternÆvar Arnfjörð Bjarmason, Jul 20, 2021
  19. Taylor BlauJul 20, 2021
  20. 6/6 commit-graph: show usage on "commit-graph [write|verify] garbage"Ævar Arnfjörð Bjarmason, Jul 20, 2021
  21. SZEDER GáborJul 20, 2021
  22. SZEDER GáborJul 20, 2021
  23. Taylor BlauJul 20, 2021
  24. Ævar Arnfjörð BjarmasonJul 20, 2021
  25. Taylor BlauJul 20, 2021
  26. Ævar Arnfjörð BjarmasonJul 21, 2021
  27. Jeff KingJul 21, 2021
  28. Junio C HamanoJul 21, 2021
  29. 5/6 commit-graph: early exit to "usage" on !argcÆvar Arnfjörð Bjarmason, Jul 20, 2021
  30. Taylor BlauJul 20, 2021
  31. 0/7 commit-graph: usage fixesÆvar Arnfjörð Bjarmason, Aug 23, 2021
  32. 1/7 commit-graph: define common usage with a macroÆvar Arnfjörð Bjarmason, Aug 23, 2021
  33. 2/7 commit-graph: remove redundant handling of -hÆvar Arnfjörð Bjarmason, Aug 23, 2021
  34. 3/7 commit-graph: use parse_options_concat()Ævar Arnfjörð Bjarmason, Aug 23, 2021
  35. 4/7 multi-pack-index: refactor "goto usage" patternÆvar Arnfjörð Bjarmason, Aug 23, 2021
  36. 5/7 commit-graph: early exit to "usage" on !argcÆvar Arnfjörð Bjarmason, Aug 23, 2021
  37. 6/7 commit-graph: show usage on "commit-graph [write|verify] garbage"Ævar Arnfjörð Bjarmason, Aug 23, 2021
  38. 7/7 commit-graph: show "unexpected subcommand" errorÆvar Arnfjörð Bjarmason, Aug 23, 2021
  39. Taylor BlauAug 30, 2021
  40. Junio C HamanoAug 30, 2021

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.