public inbox for [email protected]  
help / color / mirror / Atom feed
From: Andrew Dunstan <[email protected]>
To: Peter Eisentraut <[email protected]>
To: Tom Lane <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: Re: pgindent vs. pgperltidy command-line arguments
Date: Tue, 20 Jun 2023 11:38:10 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>


On 2023-06-14 We 03:37, Peter Eisentraut wrote:
> On 25.05.23 15:20, Tom Lane wrote:
>> Peter Eisentraut <[email protected]> writes:
>>> Until PG15, calling pgindent without arguments would process the whole
>>> tree.  Now you get
>>> No files to process at ./src/tools/pgindent/pgindent line 372.
>>> Is that intentional?
>>
>> It was intentional, cf b16259b3c and the linked discussion.
>>
>>> Also, pgperltidy accepts no arguments and always processes the whole
>>> tree.  It would be nice if there were a way to process individual files
>>> or directories, like pgindent can.
>>
>> +1, although I wonder if we shouldn't follow pgindent's new lead
>> and require some argument(s).
>
> That makes sense to me.  Here is a small update with this behavior 
> change and associated documentation update.


I'm intending to add some of the new pgindent features to pgperltidy. 
Preparatory to that here's a rewrite of pgperltidy in perl - no new 
features yet but it does remove the hardcoded path, and requires you to 
pass in one or more files / directories as arguments.


cheers


andrew

--
Andrew Dunstan
EDB:https://www.enterprisedb.com

#!/usr/bin/perl

# Copyright (c) 2023, PostgreSQL Global Development Group

# src/tools/pgindent/pgperltidy

use strict;
use warnings;

use File::Find;

my $perltidy = $ENV{PERLTIDY} || 'perltidy';

my @files;

die "No directories or files specified" unless @ARGV;

sub is_perl_exec
{
	my $name = shift;
	my $out = `file $name 2>/dev/null`;
	return $out =~ /:.*perl[0-9]*\b/i;
}

my $wanted = sub {

	my $name = $File::Find::name;
	my ($dev, $ino, $mode, $nlink, $uid, $gid);

	# check it's a plain file and either it has a perl extension (.p[lm])
	# or it's executable and `file` thinks it's a perl script.

	(($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_))
	  && -f _
	  && (/\.p[lm]$/ || ((($mode & 0100) == 0100) && is_perl_exec($_)))
	  && push(@files, $name);
};

File::Find::find({ wanted => $wanted }, @ARGV);

my $list = join(" ", @files);

system "$perltidy --profile=src/tools/pgindent/perltidyrc $list";


Attachments:

  [text/plain] pgperltidy (921B, ../[email protected]/3-pgperltidy)
  download | inline:
#!/usr/bin/perl

# Copyright (c) 2023, PostgreSQL Global Development Group

# src/tools/pgindent/pgperltidy

use strict;
use warnings;

use File::Find;

my $perltidy = $ENV{PERLTIDY} || 'perltidy';

my @files;

die "No directories or files specified" unless @ARGV;

sub is_perl_exec
{
	my $name = shift;
	my $out = `file $name 2>/dev/null`;
	return $out =~ /:.*perl[0-9]*\b/i;
}

my $wanted = sub {

	my $name = $File::Find::name;
	my ($dev, $ino, $mode, $nlink, $uid, $gid);

	# check it's a plain file and either it has a perl extension (.p[lm])
	# or it's executable and `file` thinks it's a perl script.

	(($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_))
	  && -f _
	  && (/\.p[lm]$/ || ((($mode & 0100) == 0100) && is_perl_exec($_)))
	  && push(@files, $name);
};

File::Find::find({ wanted => $wanted }, @ARGV);

my $list = join(" ", @files);

system "$perltidy --profile=src/tools/pgindent/perltidyrc $list";

view thread (8+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: pgindent vs. pgperltidy command-line arguments
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox