From: Thomas Rast <trast@student.ethz.ch>
To: <git@vger.kernel.org>
Cc: "Jonathan Nieder" <jrnieder@gmail.com>,
"Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 2/24] Documentation: Add variable-substitution script
Date: Mon, 26 Jul 2010 20:48:54 +0200 [thread overview]
Message-ID: <049043aa444288fd9409a3706fe3190fd679cb7d.1280169048.git.trast@student.ethz.ch> (raw)
In-Reply-To: <cover.1280169048.git.trast@student.ethz.ch>
The new subst-config.perl is run by the Makefile as
./subst-config.perl <vars> <in> <out>
It first reads <vars> for variable-documenting blocks. A line
consisting of '<name>::' starts the block for <name>, except inside a
'--' delimited block (which is used to generate sub-lists). A block
extends until the first blank line, which is what asciidoc also looks
for.
Then it copies from <in> to <out>, substituting lines of the form
@@CONFIG(<name>)@@
with the documentation block for <name>.
Ævar kindly implemented the following, squashed into this patch:
- Print a usage message when argument prerequisites aren't met
- Use Getopt::Long instead of manually looking at @ARGV
- use warnings, not -w
- Split the parsing & substituting functionality into subroutines
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
Documentation/Makefile | 14 +++++---
Documentation/config-vars.txt | 1 +
Documentation/subst-config.perl | 74 +++++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+), 5 deletions(-)
create mode 100755 Documentation/subst-config.perl
diff --git a/Documentation/Makefile b/Documentation/Makefile
index a4c4063..c20d580 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -239,12 +239,16 @@ cmd-list.made: cmd-list.perl ../command-list.txt $(MAN1_TXT)
clean:
$(RM) *.xml *.xml+ *.html *.html+ *.1 *.5 *.7
$(RM) *.texi *.texi+ *.texi++ git.info gitman.info
+ $(RM) *.txt.cv
$(RM) howto-index.txt howto/*.html doc.dep
$(RM) technical/api-*.html technical/api-index.txt
$(RM) $(cmds_txt) *.made
$(RM) manpage-base-url.xsl
-$(MAN_HTML): %.html : %.txt
+%.txt.cv : %.txt subst-config.perl config-vars.txt
+ $(QUIET_GEN) ./subst-config.perl --varlist=config-vars.txt --input=$< --output=$@
+
+$(patsubst %.txt,%.txt.cv,$(MAN_HTML)): %.html : %.txt.cv
$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
$(ASCIIDOC) -b xhtml11 -d manpage -f asciidoc.conf \
$(ASCIIDOC_EXTRA) -agit_version=$(GIT_VERSION) -o $@+ $< && \
@@ -257,13 +261,13 @@ manpage-base-url.xsl: manpage-base-url.xsl.in
$(QUIET_XMLTO)$(RM) $@ && \
xmlto -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $<
-%.xml : %.txt
+%.xml : %.txt.cv
$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
$(ASCIIDOC) -b docbook -d manpage -f asciidoc.conf \
$(ASCIIDOC_EXTRA) -agit_version=$(GIT_VERSION) -o $@+ $< && \
mv $@+ $@
-user-manual.xml: user-manual.txt user-manual.conf
+user-manual.xml: user-manual.txt.cv user-manual.conf
$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
$(ASCIIDOC) $(ASCIIDOC_EXTRA) -b docbook -d book -o $@+ $< && \
mv $@+ $@
@@ -320,8 +324,8 @@ howto-index.txt: howto-index.sh $(wildcard howto/*.txt)
'$(SHELL_PATH_SQ)' ./howto-index.sh $(wildcard howto/*.txt) >$@+ && \
mv $@+ $@
-$(patsubst %,%.html,$(ARTICLES)) : %.html : %.txt
- $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_EXTRA) -b xhtml11 $*.txt
+$(patsubst %,%.html,$(ARTICLES)) : %.html : %.txt.cv
+ $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_EXTRA) -b xhtml11 $*.txt.cv
WEBDOC_DEST = /pub/software/scm/git/docs
diff --git a/Documentation/config-vars.txt b/Documentation/config-vars.txt
index b82fada..3fcefe9 100644
--- a/Documentation/config-vars.txt
+++ b/Documentation/config-vars.txt
@@ -689,6 +689,7 @@ diff.mnemonicprefix::
standard "a/" and "b/" depending on what is being compared. When
this configuration is in effect, reverse diff output also swaps
the order of the prefixes:
+
diff.noprefix::
If set, 'git diff' does not show any source or destination prefix.
`git diff`;;
diff --git a/Documentation/subst-config.perl b/Documentation/subst-config.perl
new file mode 100755
index 0000000..a981670
--- /dev/null
+++ b/Documentation/subst-config.perl
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+use 5.006002;
+use strict;
+use warnings;
+use Getopt::Long;
+
+Getopt::Long::Configure qw/ pass_through /;
+
+my $rc = GetOptions(
+ "varlist=s" => \my $varlist,
+ "input=s" => \my $input,
+ "output=s" => \my $output,
+);
+
+if (!$rc or (!-r $varlist or !-r $input)) {
+ print "$0 --varlist=<varlist> --input=<in> --output=<out>\n";
+ exit 1;
+}
+
+my $vars = read_varlist($varlist);
+substitute_variables($vars, $input, $output);
+exit 0;
+
+sub read_varlist {
+ my ($file) = @_;
+
+ open my $fh, "<", $varlist or die "cannot open $varlist: $!";
+ my %vars;
+
+ my ($v, $last_v);
+ my $in_block = 0;
+ while (<$fh>) {
+ if (/^(\S+)::/) {
+ $v = lc $1;
+ $in_block = 0;
+ push @{$vars{$v}}, $_;
+ } elsif (/^$/ && !$in_block) {
+ if (defined $last_v && !$#{$vars{$last_v}}) {
+ $vars{$last_v} = $vars{$v};
+ }
+ $last_v = $v;
+ } elsif (defined $v) {
+ push @{$vars{$v}}, $_;
+ $in_block = !$in_block if /^--$/;
+ }
+ }
+
+ close $fh or die "eh? close failed: $!";
+
+ return \%vars
+}
+
+sub substitute_variables {
+ my ($varlist, $in, $out) = @_;
+
+ open my $infh, "<", $input or die "Can't open $in for reading: $!";
+ open my $outfh, ">", $output or die "Can't open $out for reading: $!";
+
+ while (<$infh>) {
+ if (/^\@\@CONFIG\((\S+)\)\@\@$/) {
+ my $v = lc $1;
+ die "Key $v not documented" unless exists $varlist->{$v};
+ print $outfh @{$varlist->{$v}};
+ print $outfh "\n";
+ } else {
+ print $outfh $_;
+ }
+ }
+
+ close $infh or die "closing input failed: $!";
+ close $outfh or die "closing output failed: $!";
+
+ return;
+}
--
1.7.2.349.gd5452
next prev parent reply other threads:[~2010-07-26 18:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-26 18:48 [RFC PATCH 0/24] Documentation: refactor config variable descriptions Thomas Rast
2010-07-26 18:48 ` Thomas Rast [this message]
2010-07-26 19:51 ` [PATCH 2/24] Documentation: Add variable-substitution script Jonathan Nieder
2010-07-26 20:27 ` Ævar Arnfjörð Bjarmason
2010-07-26 21:17 ` Jakub Narebski
2010-07-26 21:49 ` Ævar Arnfjörð Bjarmason
2010-07-26 18:48 ` [PATCH 3-24/24] Documentation: include configuration options in manpages Thomas Rast
2010-07-26 19:55 ` Jonathan Nieder
2010-07-26 19:05 ` [RFC PATCH 0/24] Documentation: refactor config variable descriptions Ævar Arnfjörð Bjarmason
[not found] ` <75c9db91f5ab43ebb60cace0d20389462a2ab02c.1280169048.git.trast@student.ethz.ch>
2010-07-26 19:38 ` [PATCH 1/24] Documentation: Move variables from config.txt to separate file Jonathan Nieder
2010-07-26 20:18 ` Ævar Arnfjörð Bjarmason
2010-07-27 6:48 ` Sverre Rabbelier
2010-07-28 17:23 ` Junio C Hamano
2010-07-26 22:25 ` [RFC PATCH 0/24] Documentation: refactor config variable descriptions Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=049043aa444288fd9409a3706fe3190fd679cb7d.1280169048.git.trast@student.ethz.ch \
--to=trast@student.ethz.ch \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).