Skip to content

List all guides in git(1) #691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Documentation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MAN1_TXT += git.txt
MAN1_TXT += gitk.txt
MAN1_TXT += gitweb.txt

# man5 / man7 guides (note: new guides should also be added to command-list.txt)
MAN5_TXT += gitattributes.txt
MAN5_TXT += githooks.txt
MAN5_TXT += gitignore.txt
Expand Down Expand Up @@ -294,14 +295,15 @@ cmds_txt = cmds-ancillaryinterrogators.txt \
cmds-plumbingmanipulators.txt \
cmds-synchingrepositories.txt \
cmds-synchelpers.txt \
cmds-guide.txt \
cmds-purehelpers.txt \
cmds-foreignscminterface.txt

$(cmds_txt): cmd-list.made

cmd-list.made: cmd-list.perl ../command-list.txt $(MAN1_TXT)
$(QUIET_GEN)$(RM) $@ && \
$(PERL_PATH) ./cmd-list.perl ../command-list.txt $(QUIET_STDERR) && \
$(PERL_PATH) ./cmd-list.perl ../command-list.txt $(cmds_txt) $(QUIET_STDERR) && \
date >$@

mergetools_txt = mergetools-diff.txt mergetools-merge.txt
Expand Down
27 changes: 14 additions & 13 deletions Documentation/cmd-list.perl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ sub format_one {
my ($out, $nameattr) = @_;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Philippe Blain <levraiphilippeblain@gmail.com>
>
> Not all guides are mentioned in the 'git(1)' documentation,
> which makes the missing ones somewhat hard to find.
>
> Add a list of the guides to git(1).
>
> Tweak `Documentation/cmd-list.perl` so that it also generates
> a file `cmds-guide.txt` which gets included in git.txt.

Who cleans this?  Do we need a change to Makefile?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Junio C Hamano wrote (reply to this):

Junio C Hamano <gitster@pobox.com> writes:

> "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> From: Philippe Blain <levraiphilippeblain@gmail.com>
>>
>> Not all guides are mentioned in the 'git(1)' documentation,
>> which makes the missing ones somewhat hard to find.
>>
>> Add a list of the guides to git(1).
>>
>> Tweak `Documentation/cmd-list.perl` so that it also generates
>> a file `cmds-guide.txt` which gets included in git.txt.
>
> Who cleans this?  Do we need a change to Makefile?

A band-aid patch would look like this, BUT.

    diff --git a/Documentation/Makefile b/Documentation/Makefile
    index 39f6fc8de7..616449da88 100644
    --- a/Documentation/Makefile
    +++ b/Documentation/Makefile
    @@ -295,6 +295,7 @@ cmds_txt = cmds-ancillaryinterrogators.txt \
            cmds-plumbingmanipulators.txt \
            cmds-synchingrepositories.txt \
            cmds-synchelpers.txt \
    +       cmds-guide.txt \
            cmds-purehelpers.txt \
            cmds-foreignscminterface.txt

I think with a bit more work, we can be at a lot better place.  How
about something along the following line (untested)?

 Documentation/Makefile      |  3 ++-
 Documentation/cmd-list.perl | 21 ++++++++-------------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/Documentation/Makefile b/Documentation/Makefile
index 39f6fc8de7..80d1908a44 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -295,6 +295,7 @@ cmds_txt = cmds-ancillaryinterrogators.txt \
 	cmds-plumbingmanipulators.txt \
 	cmds-synchingrepositories.txt \
 	cmds-synchelpers.txt \
+	cmds-guide.txt \
 	cmds-purehelpers.txt \
 	cmds-foreignscminterface.txt
 
@@ -302,7 +303,7 @@ $(cmds_txt): cmd-list.made
 
 cmd-list.made: cmd-list.perl ../command-list.txt $(MAN1_TXT)
 	$(QUIET_GEN)$(RM) $@ && \
-	$(PERL_PATH) ./cmd-list.perl ../command-list.txt $(QUIET_STDERR) && \
+	$(PERL_PATH) ./cmd-list.perl ../command-list.txt $(cmds_txt) $(QUIET_STDERR) && \
 	date >$@
 
 mergetools_txt = mergetools-diff.txt mergetools-merge.txt
diff --git a/Documentation/cmd-list.perl b/Documentation/cmd-list.perl
index 99f01a0910..af5da45d28 100755
--- a/Documentation/cmd-list.perl
+++ b/Documentation/cmd-list.perl
@@ -43,12 +43,15 @@ sub format_one {
 	}
 }
 
-while (<>) {
+my ($input, @categories) = @ARGV;
+
+open IN, "<$input";
+while (<IN>) {
 	last if /^### command list/;
 }
 
 my %cmds = ();
-for (sort <>) {
+for (sort <IN>) {
 	next if /^#/;
 
 	chomp;
@@ -56,18 +59,10 @@ sub format_one {
 	$attr = '' unless defined $attr;
 	push @{$cmds{$cat}}, [$name, " $attr "];
 }
+close IN;
 
-for my $cat (qw(ancillaryinterrogators
-		ancillarymanipulators
-		mainporcelain
-		plumbinginterrogators
-		plumbingmanipulators
-		synchingrepositories
-		foreignscminterface
-		purehelpers
-		synchelpers
-		guide)) {
-	my $out = "cmds-$cat.txt";
+for my $out (@categories) {
+	my ($cat) = $out =~ /^cmds-(.*)\.txt$/;
 	open O, '>', "$out+" or die "Cannot open output file $out+";
 	for (@{$cmds{$cat}}) {
 		format_one(\*O, $_);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Philippe Blain wrote (reply to this):

Hi Junio, 

> Le 2 août 2020 à 18:05, Junio C Hamano <gitster@pobox.com> a écrit :
> 
> Junio C Hamano <gitster@pobox.com> writes:
> 
>> "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
>> 
>>> From: Philippe Blain <levraiphilippeblain@gmail.com>
>>> 
>>> Not all guides are mentioned in the 'git(1)' documentation,
>>> which makes the missing ones somewhat hard to find.
>>> 
>>> Add a list of the guides to git(1).
>>> 
>>> Tweak `Documentation/cmd-list.perl` so that it also generates
>>> a file `cmds-guide.txt` which gets included in git.txt.
>> 
>> Who cleans this?  Do we need a change to Makefile?

Oups! I checked /.gitignore, but forgot to thoroughly check the Makefile.

> 
> A band-aid patch would look like this, BUT.
> 
>    diff --git a/Documentation/Makefile b/Documentation/Makefile
>    index 39f6fc8de7..616449da88 100644
>    --- a/Documentation/Makefile
>    +++ b/Documentation/Makefile
>    @@ -295,6 +295,7 @@ cmds_txt = cmds-ancillaryinterrogators.txt \
>            cmds-plumbingmanipulators.txt \
>            cmds-synchingrepositories.txt \
>            cmds-synchelpers.txt \
>    +       cmds-guide.txt \
>            cmds-purehelpers.txt \
>            cmds-foreignscminterface.txt
> 
> I think with a bit more work, we can be at a lot better place.  How
> about something along the following line (untested)?
> 
> Documentation/Makefile      |  3 ++-
> Documentation/cmd-list.perl | 21 ++++++++-------------
> 2 files changed, 10 insertions(+), 14 deletions(-)
> 
> diff --git a/Documentation/Makefile b/Documentation/Makefile
> index 39f6fc8de7..80d1908a44 100644
> --- a/Documentation/Makefile
> +++ b/Documentation/Makefile
> @@ -295,6 +295,7 @@ cmds_txt = cmds-ancillaryinterrogators.txt \
> 	cmds-plumbingmanipulators.txt \
> 	cmds-synchingrepositories.txt \
> 	cmds-synchelpers.txt \
> +	cmds-guide.txt \
> 	cmds-purehelpers.txt \
> 	cmds-foreignscminterface.txt
> 
> @@ -302,7 +303,7 @@ $(cmds_txt): cmd-list.made
> 
> cmd-list.made: cmd-list.perl ../command-list.txt $(MAN1_TXT)
> 	$(QUIET_GEN)$(RM) $@ && \
> -	$(PERL_PATH) ./cmd-list.perl ../command-list.txt $(QUIET_STDERR) && \
> +	$(PERL_PATH) ./cmd-list.perl ../command-list.txt $(cmds_txt) $(QUIET_STDERR) && \
> 	date >$@
> 
> mergetools_txt = mergetools-diff.txt mergetools-merge.txt
> diff --git a/Documentation/cmd-list.perl b/Documentation/cmd-list.perl
> index 99f01a0910..af5da45d28 100755
> --- a/Documentation/cmd-list.perl
> +++ b/Documentation/cmd-list.perl
> @@ -43,12 +43,15 @@ sub format_one {
> 	}
> }
> 
> -while (<>) {
> +my ($input, @categories) = @ARGV;
> +
> +open IN, "<$input";
> +while (<IN>) {
> 	last if /^### command list/;
> }
> 
> my %cmds = ();
> -for (sort <>) {
> +for (sort <IN>) {
> 	next if /^#/;
> 
> 	chomp;
> @@ -56,18 +59,10 @@ sub format_one {
> 	$attr = '' unless defined $attr;
> 	push @{$cmds{$cat}}, [$name, " $attr "];
> }
> +close IN;
> 
> -for my $cat (qw(ancillaryinterrogators
> -		ancillarymanipulators
> -		mainporcelain
> -		plumbinginterrogators
> -		plumbingmanipulators
> -		synchingrepositories
> -		foreignscminterface
> -		purehelpers
> -		synchelpers
> -		guide)) {
> -	my $out = "cmds-$cat.txt";
> +for my $out (@categories) {
> +	my ($cat) = $out =~ /^cmds-(.*)\.txt$/;
> 	open O, '>', "$out+" or die "Cannot open output file $out+";
> 	for (@{$cmds{$cat}}) {
> 		format_one(\*O, $_);

Thanks for the suggestion. I tested it and it works correctly. 
I've incorporated it to v2.


Philippe.

my ($name, $attr) = @$nameattr;
my ($state, $description);
my $mansection;
$state = 0;
open I, '<', "$name.txt" or die "No such file $name.txt";
while (<I>) {
if (/^git[a-z0-9-]*\(([0-9])\)$/) {
$mansection = $1;
next;
}
if (/^NAME$/) {
$state = 1;
next;
Expand All @@ -27,7 +32,7 @@ sub format_one {
die "No description found in $name.txt";
}
if (my ($verify_name, $text) = ($description =~ /^($name) - (.*)/)) {
print $out "linkgit:$name\[1\]::\n\t";
print $out "linkgit:$name\[$mansection\]::\n\t";
if ($attr =~ / deprecated /) {
print $out "(deprecated) ";
}
Expand All @@ -38,30 +43,26 @@ sub format_one {
}
}

while (<>) {
my ($input, @categories) = @ARGV;

open IN, "<$input";
while (<IN>) {
last if /^### command list/;
}

my %cmds = ();
for (sort <>) {
for (sort <IN>) {
next if /^#/;

chomp;
my ($name, $cat, $attr) = /^(\S+)\s+(.*?)(?:\s+(.*))?$/;
$attr = '' unless defined $attr;
push @{$cmds{$cat}}, [$name, " $attr "];
}
close IN;

for my $cat (qw(ancillaryinterrogators
ancillarymanipulators
mainporcelain
plumbinginterrogators
plumbingmanipulators
synchingrepositories
foreignscminterface
purehelpers
synchelpers)) {
my $out = "cmds-$cat.txt";
for my $out (@categories) {
my ($cat) = $out =~ /^cmds-(.*)\.txt$/;
open O, '>', "$out+" or die "Cannot open output file $out+";
for (@{$cmds{$cat}}) {
format_one(\*O, $_);
Expand Down
6 changes: 3 additions & 3 deletions Documentation/git-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ on the standard output.
If the option `--all` or `-a` is given, all available commands are
printed on the standard output.

If the option `--guides` or `-g` is given, a list of the useful
Git guides is also printed on the standard output.
If the option `--guides` or `-g` is given, a list of the
Git concept guides is also printed on the standard output.

If a command, or a guide, is given, a manual page for that command or
guide is brought up. The 'man' program is used by default for this
Expand Down Expand Up @@ -58,7 +58,7 @@ OPTIONS

-g::
--guides::
Prints a list of useful guides on the standard output. This
Prints a list of the Git concept guides on the standard output. This
option overrides any given command or guide name.

-i::
Expand Down
7 changes: 7 additions & 0 deletions Documentation/git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ users typically do not use them directly.

include::cmds-purehelpers.txt[]

Guides
------

The following documentation pages are guides about Git concepts.

include::cmds-guide.txt[]


Configuration Mechanism
-----------------------
Expand Down
2 changes: 1 addition & 1 deletion Documentation/gitcredentials.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ gitcredentials(7)

NAME
----
gitcredentials - providing usernames and passwords to Git
gitcredentials - Providing usernames and passwords to Git

SYNOPSIS
--------
Expand Down
2 changes: 1 addition & 1 deletion builtin/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
}

if (show_guides)
list_common_guides_help();
list_guides_help();

if (show_all || show_guides) {
printf("%s\n", _(git_more_info_string));
Expand Down
2 changes: 2 additions & 0 deletions command-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ git-write-tree plumbingmanipulators
gitattributes guide
gitcli guide
gitcore-tutorial guide
gitcredentials guide
gitcvs-migration guide
gitdiffcore guide
giteveryday guide
Expand All @@ -204,6 +205,7 @@ githooks guide
gitignore guide
gitmodules guide
gitnamespaces guide
gitremote-helpers guide
gitrepository-layout guide
gitrevisions guide
gitsubmodules guide
Expand Down
4 changes: 2 additions & 2 deletions help.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ void list_cmds_by_config(struct string_list *list)
}
}

void list_common_guides_help(void)
void list_guides_help(void)
{
struct category_description catdesc[] = {
{ CAT_guide, N_("The common Git guides are:") },
{ CAT_guide, N_("The Git concept guides are:") },
{ 0, NULL }
};
print_cmd_by_category(catdesc, NULL);
Expand Down
2 changes: 1 addition & 1 deletion help.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static inline void mput_char(char c, unsigned int num)

void list_common_cmds_help(void);
void list_all_cmds_help(void);
void list_common_guides_help(void);
void list_guides_help(void);

void list_all_main_cmds(struct string_list *list);
void list_all_other_cmds(struct string_list *list);
Expand Down