aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-03-08 11:48:49 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2019-03-08 11:48:49 -0500
commit27aaf6eff49a6348408476652911fe4acceffc71 (patch)
tree7f4e066b48f614eca029eaa82622471cd618532b /src
parente1e0e8d58c5c70da92e36cb9d59c2f7ecf839e00 (diff)
downloadpostgresql-27aaf6eff49a6348408476652911fe4acceffc71.tar.gz
postgresql-27aaf6eff49a6348408476652911fe4acceffc71.zip
Minor improvements for reformat_dat_file.pl.
Use Getopt::Long in preference to hand-rolled option parsing code. Also, remove "-I .../backend/catalog" switch from the Makefile invocations. That's been unnecessary for some time, and leaving it there gives the false impression it's needed in manual invocations. John Naylor (extracted from a larger but more controversial patch) Discussion: https://postgr.es/m/CACPNZCsHdcQN2jQ1=ptbi1Co2Nj3aHgRCUMk62=ThgWNabPY+Q@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r--src/include/catalog/Makefile7
-rwxr-xr-xsrc/include/catalog/reformat_dat_file.pl43
2 files changed, 16 insertions, 34 deletions
diff --git a/src/include/catalog/Makefile b/src/include/catalog/Makefile
index ae797d24658..33fbcf7677f 100644
--- a/src/include/catalog/Makefile
+++ b/src/include/catalog/Makefile
@@ -13,19 +13,16 @@ subdir = src/include/catalog
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
-# location of Catalog.pm
-catalogdir = $(top_srcdir)/src/backend/catalog
-
# 'make reformat-dat-files' is a convenience target for rewriting the
# catalog data files in our standard format. This includes collapsing
# out any entries that are redundant with a BKI_DEFAULT annotation.
reformat-dat-files:
- $(PERL) -I $(catalogdir) $(srcdir)/reformat_dat_file.pl -o $(srcdir) $(srcdir)/pg_*.dat
+ $(PERL) $(srcdir)/reformat_dat_file.pl --output $(srcdir) $(srcdir)/pg_*.dat
# 'make expand-dat-files' is a convenience target for expanding out all
# default values in the catalog data files. This should be run before
# altering or removing any BKI_DEFAULT annotation.
expand-dat-files:
- $(PERL) -I $(catalogdir) $(srcdir)/reformat_dat_file.pl -o $(srcdir) $(srcdir)/pg_*.dat --full-tuples
+ $(PERL) $(srcdir)/reformat_dat_file.pl --output $(srcdir) $(srcdir)/pg_*.dat --full-tuples
.PHONY: reformat-dat-files expand-dat-files
diff --git a/src/include/catalog/reformat_dat_file.pl b/src/include/catalog/reformat_dat_file.pl
index 4835c2e41bd..fd4dbad67ef 100755
--- a/src/include/catalog/reformat_dat_file.pl
+++ b/src/include/catalog/reformat_dat_file.pl
@@ -20,9 +20,11 @@
use strict;
use warnings;
+use FindBin;
+use Getopt::Long;
+
# If you copy this script to somewhere other than src/include/catalog,
# you'll need to modify this "use lib" or provide a suitable -I switch.
-use FindBin;
use lib "$FindBin::RealBin/../../backend/catalog/";
use Catalog;
@@ -34,35 +36,16 @@ use Catalog;
my @METADATA =
('oid', 'oid_symbol', 'array_type_oid', 'descr', 'autogenerated');
-my @input_files;
+# Process command line switches.
my $output_path = '';
my $full_tuples = 0;
-# Process command line switches.
-while (@ARGV)
-{
- my $arg = shift @ARGV;
- if ($arg !~ /^-/)
- {
- push @input_files, $arg;
- }
- elsif ($arg =~ /^-o/)
- {
- $output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
- }
- elsif ($arg eq '--full-tuples')
- {
- $full_tuples = 1;
- }
- else
- {
- usage();
- }
-}
+GetOptions(
+ 'output=s' => \$output_path,
+ 'full-tuples' => \$full_tuples) || usage();
# Sanity check arguments.
-die "No input files.\n"
- if !@input_files;
+die "No input files.\n" unless @ARGV;
# Make sure output_path ends in a slash.
if ($output_path ne '' && substr($output_path, -1) ne '/')
@@ -76,7 +59,7 @@ if ($output_path ne '' && substr($output_path, -1) ne '/')
my %catalogs;
my %catalog_data;
my @catnames;
-foreach my $datfile (@input_files)
+foreach my $datfile (@ARGV)
{
$datfile =~ /(.+)\.dat$/
or die "Input files need to be data (.dat) files.\n";
@@ -130,7 +113,7 @@ foreach my $catname (@catnames)
if !(grep { $_ eq $attname } @METADATA);
}
- # Overwrite .dat files in place, since they are under version control.
+ # Write output files to specified directory.
my $datfile = "$output_path$catname.dat";
open my $dat, '>', $datfile
or die "can't open $datfile: $!";
@@ -318,10 +301,12 @@ sub usage
Usage: reformat_dat_file.pl [options] datafile...
Options:
- -o PATH write output files to PATH instead of current directory
+ --output PATH output directory (default '.')
--full-tuples write out full tuples, including default values
-Expects a list of .dat files as arguments.
+Non-option arguments are the names of input .dat files.
+Updated files are written to the output directory,
+possibly overwriting the input files.
EOM
}