@@ -21,7 +21,7 @@ my $indent_opts =
2121
2222my $devnull = File::Spec-> devnull;
2323
24- my ($typedefs_file , $typedef_str , $code_base ,
24+ my ($typedefs_file , $typedef_str ,
2525 @excludes , $indent , $build ,
2626 $show_diff , $silent_diff , $help ,
2727 @commits ,);
@@ -33,10 +33,8 @@ my %options = (
3333 " commit=s" => \@commits ,
3434 " typedefs=s" => \$typedefs_file ,
3535 " list-of-typedefs=s" => \$typedef_str ,
36- " code-base=s" => \$code_base ,
3736 " excludes=s" => \@excludes ,
3837 " indent=s" => \$indent ,
39- " build" => \$build ,
4038 " show-diff" => \$show_diff ,
4139 " silent-diff" => \$silent_diff ,);
4240GetOptions(%options ) || usage(" bad command line argument" );
@@ -46,22 +44,16 @@ usage() if $help;
4644usage(" Cannot have both --silent-diff and --show-diff" )
4745 if $silent_diff && $show_diff ;
4846
49- usage(" Cannot use --commit with --code-base or command line file list" )
50- if (@commits && ( $code_base || @ARGV ) );
47+ usage(" Cannot use --commit with command line file list" )
48+ if (@commits && @ARGV );
5149
52- run_build($code_base ) if ($build );
53-
54- # command line option wins, then environment (which is how --build sets it) ,
55- # then locations. based on current dir, then default location
50+ # command line option wins, then environment, then locations based on current
51+ # dir, then default location
5652$typedefs_file ||= $ENV {PGTYPEDEFS };
5753
58- # build mode sets PGINDENT
54+ # get indent location for environment or default
5955$indent ||= $ENV {PGINDENT } || $ENV {INDENT } || " pg_bsd_indent" ;
6056
61- # if no non-option arguments or commits are given, default to looking in the
62- # current directory
63- $code_base ||= ' .' unless (@ARGV || @commits );
64-
6557my $sourcedir = locate_sourcedir();
6658
6759# if it's the base of a postgres tree, we will exclude the files
@@ -121,8 +113,7 @@ sub check_indent
121113sub locate_sourcedir
122114{
123115 # try fairly hard to locate the sourcedir
124- my $where = $code_base || ' .' ;
125- my $sub = " $where /src/tools/pgindent" ;
116+ my $sub = " ./src/tools/pgindent" ;
126117 return $sub if -d $sub ;
127118 # try to find it from an ancestor directory
128119 $sub = " ../src/tools/pgindent" ;
@@ -320,72 +311,6 @@ sub show_diff
320311 return $diff ;
321312}
322313
323- sub run_build
324- {
325- eval " use LWP::Simple;" ; # # no critic (ProhibitStringyEval);
326-
327- my $code_base = shift || ' .' ;
328- my $save_dir = getcwd();
329-
330- # look for the code root
331- foreach (1 .. 5)
332- {
333- last if -d " $code_base /src/tools/pgindent" ;
334- $code_base = " $code_base /.." ;
335- }
336-
337- die " cannot locate src/tools/pgindent directory in \" $code_base \"\n "
338- unless -d " $code_base /src/tools/pgindent" ;
339-
340- chdir " $code_base /src/tools/pgindent" ;
341-
342- my $typedefs_list_url =
343- " https://buildfarm.postgresql.org/cgi-bin/typedefs.pl" ;
344-
345- my $rv = getstore($typedefs_list_url , " tmp_typedefs.list" );
346-
347- die " cannot fetch typedefs list from $typedefs_list_url \n "
348- unless is_success($rv );
349-
350- $ENV {PGTYPEDEFS } = abs_path(' tmp_typedefs.list' );
351-
352- my $indentrepo = " https://git.postgresql.org/git/pg_bsd_indent.git" ;
353- system (" git clone $indentrepo >$devnull 2>&1" );
354- die " could not fetch pg_bsd_indent sources from $indentrepo \n "
355- unless $? == 0;
356-
357- chdir " pg_bsd_indent" || die ;
358- system (" make all check >$devnull " );
359- die " could not build pg_bsd_indent from source\n "
360- unless $? == 0;
361-
362- $ENV {PGINDENT } = abs_path(' pg_bsd_indent' );
363-
364- chdir $save_dir ;
365- return ;
366- }
367-
368- sub build_clean
369- {
370- my $code_base = shift || ' .' ;
371-
372- # look for the code root
373- foreach (1 .. 5)
374- {
375- last if -d " $code_base /src/tools/pgindent" ;
376- $code_base = " $code_base /.." ;
377- }
378-
379- die " cannot locate src/tools/pgindent directory in \" $code_base \"\n "
380- unless -d " $code_base /src/tools/pgindent" ;
381-
382- chdir " $code_base " ;
383-
384- system (" rm -rf src/tools/pgindent/pg_bsd_indent" );
385- system (" rm -f src/tools/pgindent/tmp_typedefs.list" );
386- return ;
387- }
388-
389314sub usage
390315{
391316 my $message = shift ;
@@ -397,10 +322,8 @@ Options:
397322 --commit=gitref use files modified by the named commit
398323 --typedefs=FILE file containing a list of typedefs
399324 --list-of-typedefs=STR string containing typedefs, space separated
400- --code-base=DIR path to the base of PostgreSQL source code
401325 --excludes=PATH file containing list of filename patterns to ignore
402326 --indent=PATH path to pg_bsd_indent program
403- --build build the pg_bsd_indent program
404327 --show-diff show the changes that would be made
405328 --silent-diff exit with status 2 if any changes would be made
406329The --excludes and --commit options can be given more than once.
@@ -423,8 +346,6 @@ $filtered_typedefs_fh = load_typedefs();
423346
424347check_indent();
425348
426- build_clean($code_base ) if $build ;
427-
428349my $wanted = sub
429350{
430351 my ($dev , $ino , $mode , $nlink , $uid , $gid );
@@ -434,12 +355,12 @@ my $wanted = sub
434355 && push (@files , $File::Find::name );
435356};
436357
437- # get the list of files under code base, if it's set
438- File::Find::find({wanted => $wanted }, $code_base ) if $code_base ;
439-
440358# any non-option arguments are files or directories to be processed
441359File::Find::find({wanted => $wanted }, @ARGV ) if @ARGV ;
442360
361+ # commit file locations are relative to the source root
362+ chdir " $sourcedir /../../.." if @commits && $sourcedir ;
363+
443364# process named commits by comparing each with their immediate ancestor
444365foreach my $commit (@commits )
445366{
@@ -450,6 +371,8 @@ foreach my $commit (@commits)
450371 push (@files ,@affected );
451372}
452373
374+ warn " No files to process" unless @files ;
375+
453376# remove excluded files from the file list
454377process_exclude();
455378
0 commit comments