@@ -21,7 +21,7 @@ my $indent_opts =
21
21
22
22
my $devnull = File::Spec-> devnull;
23
23
24
- my ($typedefs_file , $typedef_str , $code_base ,
24
+ my ($typedefs_file , $typedef_str ,
25
25
@excludes , $indent , $build ,
26
26
$show_diff , $silent_diff , $help ,
27
27
@commits ,);
@@ -33,10 +33,8 @@ my %options = (
33
33
" commit=s" => \@commits ,
34
34
" typedefs=s" => \$typedefs_file ,
35
35
" list-of-typedefs=s" => \$typedef_str ,
36
- " code-base=s" => \$code_base ,
37
36
" excludes=s" => \@excludes ,
38
37
" indent=s" => \$indent ,
39
- " build" => \$build ,
40
38
" show-diff" => \$show_diff ,
41
39
" silent-diff" => \$silent_diff ,);
42
40
GetOptions(%options ) || usage(" bad command line argument" );
@@ -46,22 +44,16 @@ usage() if $help;
46
44
usage(" Cannot have both --silent-diff and --show-diff" )
47
45
if $silent_diff && $show_diff ;
48
46
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 );
51
49
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
56
52
$typedefs_file ||= $ENV {PGTYPEDEFS };
57
53
58
- # build mode sets PGINDENT
54
+ # get indent location for environment or default
59
55
$indent ||= $ENV {PGINDENT } || $ENV {INDENT } || " pg_bsd_indent" ;
60
56
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
-
65
57
my $sourcedir = locate_sourcedir();
66
58
67
59
# if it's the base of a postgres tree, we will exclude the files
@@ -121,8 +113,7 @@ sub check_indent
121
113
sub locate_sourcedir
122
114
{
123
115
# 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" ;
126
117
return $sub if -d $sub ;
127
118
# try to find it from an ancestor directory
128
119
$sub = " ../src/tools/pgindent" ;
@@ -320,72 +311,6 @@ sub show_diff
320
311
return $diff ;
321
312
}
322
313
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
-
389
314
sub usage
390
315
{
391
316
my $message = shift ;
@@ -397,10 +322,8 @@ Options:
397
322
--commit=gitref use files modified by the named commit
398
323
--typedefs=FILE file containing a list of typedefs
399
324
--list-of-typedefs=STR string containing typedefs, space separated
400
- --code-base=DIR path to the base of PostgreSQL source code
401
325
--excludes=PATH file containing list of filename patterns to ignore
402
326
--indent=PATH path to pg_bsd_indent program
403
- --build build the pg_bsd_indent program
404
327
--show-diff show the changes that would be made
405
328
--silent-diff exit with status 2 if any changes would be made
406
329
The --excludes and --commit options can be given more than once.
@@ -423,8 +346,6 @@ $filtered_typedefs_fh = load_typedefs();
423
346
424
347
check_indent();
425
348
426
- build_clean($code_base ) if $build ;
427
-
428
349
my $wanted = sub
429
350
{
430
351
my ($dev , $ino , $mode , $nlink , $uid , $gid );
@@ -434,12 +355,12 @@ my $wanted = sub
434
355
&& push (@files , $File::Find::name );
435
356
};
436
357
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
-
440
358
# any non-option arguments are files or directories to be processed
441
359
File::Find::find({wanted => $wanted }, @ARGV ) if @ARGV ;
442
360
361
+ # commit file locations are relative to the source root
362
+ chdir " $sourcedir /../../.." if @commits && $sourcedir ;
363
+
443
364
# process named commits by comparing each with their immediate ancestor
444
365
foreach my $commit (@commits )
445
366
{
@@ -450,6 +371,8 @@ foreach my $commit (@commits)
450
371
push (@files ,@affected );
451
372
}
452
373
374
+ warn " No files to process" unless @files ;
375
+
453
376
# remove excluded files from the file list
454
377
process_exclude();
455
378
0 commit comments