From e5e6667b489badf6f2a3ae1d2bdc021c8060657c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 13 Oct 2022 17:38:55 +0200 Subject: [PATCH 01/34] tests: assert *.txt SYNOPSIS and -h output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a test to assert basic compliance with the CodingGuidelines in the SYNOPSIS and builtin -h output. For now we only assert that the "-h" output doesn't have "\t" characters, as a very basic syntax check. Subsequent commits will expand on the checks here as various issues are fixed, but let's first add the test scaffolding. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t0450-txt-doc-vs-help.sh | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 t/t0450-txt-doc-vs-help.sh diff --git a/t/t0450-txt-doc-vs-help.sh b/t/t0450-txt-doc-vs-help.sh new file mode 100755 index 0000000000..c8820bdd38 --- /dev/null +++ b/t/t0450-txt-doc-vs-help.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +test_description='assert (unbuilt) Documentation/*.txt and -h output' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh + +test_expect_success 'setup: list of builtins' ' + git --list-cmds=builtins >builtins +' + +help_to_synopsis () { + builtin="$1" && + out_dir="out/$builtin" && + out="$out_dir/help.synopsis" && + if test -f "$out" + then + echo "$out" && + return 0 + fi && + mkdir -p "$out_dir" && + test_expect_code 129 git $builtin -h >"$out.raw" 2>&1 && + sed -n \ + -e '1,/^$/ { + /^$/d; + s/^usage: //; + s/^ *or: //; + p; + }' <"$out.raw" >"$out" && + echo "$out" +} + +HT=" " + +while read builtin +do + # -h output assertions + test_expect_success "$builtin -h output has no \t" ' + h2s="$(help_to_synopsis "$builtin")" && + ! grep "$HT" "$h2s" + ' +done Date: Thu, 13 Oct 2022 17:38:56 +0200 Subject: [PATCH 02/34] CodingGuidelines: update and clarify command-line conventions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Edit the section which explains how to create a good SYNOPSIS section for clarity and accuracy, it was mostly introduced in c455bd8950e (CodingGuidelines: Add a section on writing documentation, 2010-11-04): * Change "extra" example to "file", which now naturally follows from previous "..." example (one or more) to "[...]" (zero or more). * Explain how we prefer spacing around "[]()" tokens and "|" alternatives, this is not a new policy, but just codifies what's already the pattern in the most wide use in the documentation. Having a space around " | " for flags, but not for flag values is inconsistent, but this style guide codifies existing patterns. Grepping shows that we don't have any instance matching the second "Don't" example: git grep -E -h -o '=\([^)]+\)' -- builtin Documentation/ Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 4c756be517..b5a85d0cd4 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -650,8 +650,8 @@ Writing Documentation: (One or more of .) Optional parts are enclosed in square brackets: - [] - (Zero or one .) + [...] + (Zero or more of .) --exec-path[=] (Option with an optional argument. Note that the "=" is inside the @@ -665,6 +665,16 @@ Writing Documentation: [-q | --quiet] [--utf8 | --no-utf8] + Use spacing around "|" token(s), but not immediately after opening or + before closing a [] or () pair: + Do: [-q | --quiet] + Don't: [-q|--quiet] + + Don't use spacing around "|" tokens when they're used to seperate the + alternate arguments of an option: + Do: --track[=(direct|inherit)] + Don't: --track[=(direct | inherit)] + Parentheses are used for grouping: [( | )...] (Any number of either or . Parens are needed to make From 968a04e4478dff3aacbdd225e436fc2ec1c6a76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 13 Oct 2022 17:38:57 +0200 Subject: [PATCH 03/34] builtin/bundle.c: indent with tabs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix indentation issues introduced with 73c3253d75e (bundle: framework for options before bundle file, 2019-11-10), and carried forward in some subsequent commits. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/bundle.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/builtin/bundle.c b/builtin/bundle.c index e80efce3a4..5c78894afd 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -12,31 +12,31 @@ */ static const char * const builtin_bundle_usage[] = { - N_("git bundle create [] "), - N_("git bundle verify [] "), - N_("git bundle list-heads [...]"), - N_("git bundle unbundle [...]"), - NULL + N_("git bundle create [] "), + N_("git bundle verify [] "), + N_("git bundle list-heads [...]"), + N_("git bundle unbundle [...]"), + NULL }; static const char * const builtin_bundle_create_usage[] = { - N_("git bundle create [] "), - NULL + N_("git bundle create [] "), + NULL }; static const char * const builtin_bundle_verify_usage[] = { - N_("git bundle verify [] "), - NULL + N_("git bundle verify [] "), + NULL }; static const char * const builtin_bundle_list_heads_usage[] = { - N_("git bundle list-heads [...]"), - NULL + N_("git bundle list-heads [...]"), + NULL }; static const char * const builtin_bundle_unbundle_usage[] = { - N_("git bundle unbundle [...]"), - NULL + N_("git bundle unbundle [...]"), + NULL }; static int parse_options_cmd_bundle(int argc, From f587d16471a8ce438b7d19afe6f3cdbf5a42cb63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 13 Oct 2022 17:38:58 +0200 Subject: [PATCH 04/34] bundle: define subcommand -h in terms of command -h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid repeating the "-h" output for the "git bundle" command, and instead define the usage of each subcommand with macros, so that the "-h" output for the command itself can re-use those definitions. See [1], [2] and [3] for prior art using the same pattern. 1. b25b727494f (builtin/multi-pack-index.c: define common usage with a macro, 2021-03-30) 2. 8757b35d443 (commit-graph: define common usage with a macro, 2021-08-23) 3. 1e91d3faf6c (reflog: move "usage" variables and use macros, 2022-03-17) Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/bundle.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/builtin/bundle.c b/builtin/bundle.c index 5c78894afd..1b08700bf9 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -11,31 +11,40 @@ * bundle supporting "fetch", "pull", and "ls-remote". */ -static const char * const builtin_bundle_usage[] = { - N_("git bundle create [] "), - N_("git bundle verify [] "), - N_("git bundle list-heads [...]"), - N_("git bundle unbundle [...]"), - NULL +#define BUILTIN_BUNDLE_CREATE_USAGE \ + N_("git bundle create [] ") +#define BUILTIN_BUNDLE_VERIFY_USAGE \ + N_("git bundle verify [] ") +#define BUILTIN_BUNDLE_LIST_HEADS_USAGE \ + N_("git bundle list-heads [...]") +#define BUILTIN_BUNDLE_UNBUNDLE_USAGE \ + N_("git bundle unbundle [...]") + +static char const * const builtin_bundle_usage[] = { + BUILTIN_BUNDLE_CREATE_USAGE, + BUILTIN_BUNDLE_VERIFY_USAGE, + BUILTIN_BUNDLE_LIST_HEADS_USAGE, + BUILTIN_BUNDLE_UNBUNDLE_USAGE, + NULL, }; static const char * const builtin_bundle_create_usage[] = { - N_("git bundle create [] "), + BUILTIN_BUNDLE_CREATE_USAGE, NULL }; static const char * const builtin_bundle_verify_usage[] = { - N_("git bundle verify [] "), + BUILTIN_BUNDLE_VERIFY_USAGE, NULL }; static const char * const builtin_bundle_list_heads_usage[] = { - N_("git bundle list-heads [...]"), + BUILTIN_BUNDLE_LIST_HEADS_USAGE, NULL }; static const char * const builtin_bundle_unbundle_usage[] = { - N_("git bundle unbundle [...]"), + BUILTIN_BUNDLE_UNBUNDLE_USAGE, NULL }; From b2ca7e417ea64a1cb49d00aaf48a4e62bfd0e35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 13 Oct 2022 17:38:59 +0200 Subject: [PATCH 05/34] doc SYNOPSIS: don't use ' for subcommands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Almost all of our documentation doesn't use "'" syntax for subcommands, but these did, let's make them consistent with the rest. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/git-reflog.txt | 2 +- Documentation/git-rerere.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/git-reflog.txt b/Documentation/git-reflog.txt index db9d46edfa..0537d4645b 100644 --- a/Documentation/git-reflog.txt +++ b/Documentation/git-reflog.txt @@ -17,7 +17,7 @@ The command takes various subcommands, and different options depending on the subcommand: [verse] -'git reflog' ['show'] [] [] +'git reflog' [show] [] [] 'git reflog expire' [--expire=