All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: Thomas Rast <trast@student.ethz.ch>
Cc: git@vger.kernel.org, "Jonathan Nieder" <jrnieder@gmail.com>,
	"Jeff King" <peff@peff.net>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH 2/24] Documentation: Add variable-substitution script
Date: Mon, 26 Jul 2010 14:17:57 -0700 (PDT)	[thread overview]
Message-ID: <m3wrsikkol.fsf@localhost.localdomain> (raw)
In-Reply-To: <049043aa444288fd9409a3706fe3190fd679cb7d.1280169048.git.trast@student.ethz.ch>

Thomas Rast <trast@student.ethz.ch> writes:

> 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);                       # [1]
> +substitute_variables($vars, $input, $output);            # [2]
> +exit 0;
> +
> +sub read_varlist {
> +    my ($file) = @_;
> +
> +    open my $fh, "<", $varlist or die "cannot open $varlist: $!";

NITPICK

You are passing global variable $varlist to this function as parameter
$file, see place marked [1].  Why don't you use there $file instead of
$varlist?  Alternatively, why don't you name parameter as $varlist?

> +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: $!";

Same here: $input or $in, $output or $out?

> +
> +    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;
> +}

Also, could you consitently start error messages (in die "sth") with
capital letter (upper-case), or with lower-case letter?

-- 
Jakub Narebski
Poland
ShadeHawk on #git

  parent reply	other threads:[~2010-07-26 21:18 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 ` [PATCH 2/24] Documentation: Add variable-substitution script Thomas Rast
2010-07-26 19:51   ` Jonathan Nieder
2010-07-26 20:27     ` Ævar Arnfjörð Bjarmason
2010-07-26 21:17   ` Jakub Narebski [this message]
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3wrsikkol.fsf@localhost.localdomain \
    --to=jnareb@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=trast@student.ethz.ch \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.