git-commit-vandalism/Documentation/sort_glossary.pl
J. Bruce Fields c816eb1784 glossary: fix overoptimistic automatic linking of defined terms
The script sort_glossary.pl turns each use of "term" into a link to the
definition of "term".  To avoid mangling links like

	gitlink:git-term[1]

it doesn't replace any occurence of "term" preceded by "link:git-".
This fails for gitlink:git-symbolic-ref[1] when substituting for "ref".

So instead just refuse to replace anything preceded by a "-".
That could result in missing some opportunities, but that's a less
annoying error.

Actually I find the automatic substitution a little distracting; some
day maybe we should just run it once and commit the result, so it can
be hand-tuned.

Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
2007-03-10 23:05:01 -05:00

70 lines
1.1 KiB
Perl

#!/usr/bin/perl
%terms=();
while(<>) {
if(/^(\S.*)::$/) {
my $term=$1;
if(defined($terms{$term})) {
die "$1 defined twice\n";
}
$terms{$term}="";
LOOP: while(<>) {
if(/^$/) {
last LOOP;
}
if(/^ \S/) {
$terms{$term}.=$_;
} else {
die "Error 1: $_";
}
}
}
}
sub format_tab_80 ($) {
my $text=$_[0];
my $result="";
$text=~s/\s+/ /g;
$text=~s/^\s+//;
while($text=~/^(.{1,72})(|\s+(\S.*)?)$/) {
$result.=" ".$1."\n";
$text=$3;
}
return $result;
}
sub no_spaces ($) {
my $result=$_[0];
$result=~tr/ /_/;
return $result;
}
print 'GIT Glossary
============
This list is sorted alphabetically:
';
@keys=sort {uc($a) cmp uc($b)} keys %terms;
$pattern='(\b(?<!link:git-)'.join('\b|\b(?<!-)',reverse @keys).'\b)';
foreach $key (@keys) {
$terms{$key}=~s/$pattern/sprintf "<<ref_".no_spaces($1).",$1>>";/eg;
print '[[ref_'.no_spaces($key).']]'.$key."::\n"
.format_tab_80($terms{$key})."\n";
}
print '
Author
------
Written by Johannes Schindelin <Johannes.Schindelin@gmx.de> and
the git-list <git@vger.kernel.org>.
GIT
---
Part of the link:git.html[git] suite
';