fetch-pack: move code to report unmatched refs to a function
[git.git] / Documentation / cmd-list.perl
blob5aa73cfe458d9485510c6a9a67e38e522394b62a
1 #!/usr/bin/perl -w
3 use File::Compare qw(compare);
5 sub format_one {
6 my ($out, $nameattr) = @_;
7 my ($name, $attr) = @$nameattr;
8 my ($state, $description);
9 $state = 0;
10 open I, '<', "$name.txt" or die "No such file $name.txt";
11 while (<I>) {
12 if (/^NAME$/) {
13 $state = 1;
14 next;
16 if ($state == 1 && /^----$/) {
17 $state = 2;
18 next;
20 next if ($state != 2);
21 chomp;
22 $description = $_;
23 last;
25 close I;
26 if (!defined $description) {
27 die "No description found in $name.txt";
29 if (my ($verify_name, $text) = ($description =~ /^($name) - (.*)/)) {
30 print $out "linkgit:$name\[1\]::\n\t";
31 if ($attr =~ / deprecated /) {
32 print $out "(deprecated) ";
34 print $out "$text.\n\n";
36 else {
37 die "Description does not match $name: $description";
41 while (<>) {
42 last if /^### command list/;
45 my %cmds = ();
46 for (sort <>) {
47 next if /^#/;
49 chomp;
50 my ($name, $cat, $attr) = /^(\S+)\s+(.*?)(?:\s+(.*))?$/;
51 $attr = '' unless defined $attr;
52 push @{$cmds{$cat}}, [$name, " $attr "];
55 for my $cat (qw(ancillaryinterrogators
56 ancillarymanipulators
57 mainporcelain
58 plumbinginterrogators
59 plumbingmanipulators
60 synchingrepositories
61 foreignscminterface
62 purehelpers
63 synchelpers)) {
64 my $out = "cmds-$cat.txt";
65 open O, '>', "$out+" or die "Cannot open output file $out+";
66 for (@{$cmds{$cat}}) {
67 format_one(\*O, $_);
69 close O;
71 if (-f "$out" && compare("$out", "$out+") == 0) {
72 unlink "$out+";
74 else {
75 print STDERR "$out\n";
76 rename "$out+", "$out";