@@ -23,12 +23,14 @@ my $devnull = File::Spec->devnull;
23
23
24
24
my ($typedefs_file , $typedef_str , $code_base ,
25
25
@excludes , $indent , $build ,
26
- $show_diff , $silent_diff , $help );
26
+ $show_diff , $silent_diff , $help ,
27
+ @commits ,);
27
28
28
29
$help = 0;
29
30
30
31
my %options = (
31
32
" help" => \$help ,
33
+ " commit=s" => \@commits ,
32
34
" typedefs=s" => \$typedefs_file ,
33
35
" list-of-typedefs=s" => \$typedef_str ,
34
36
" code-base=s" => \$code_base ,
@@ -44,6 +46,9 @@ usage() if $help;
44
46
usage(" Cannot have both --silent-diff and --show-diff" )
45
47
if $silent_diff && $show_diff ;
46
48
49
+ usage(" Cannot use --commit with --code-base or command line file list" )
50
+ if (@commits && ($code_base || @ARGV ));
51
+
47
52
run_build($code_base ) if ($build );
48
53
49
54
# command line option wins, then environment (which is how --build sets it) ,
@@ -53,8 +58,9 @@ $typedefs_file ||= $ENV{PGTYPEDEFS};
53
58
# build mode sets PGINDENT
54
59
$indent ||= $ENV {PGINDENT } || $ENV {INDENT } || " pg_bsd_indent" ;
55
60
56
- # no non-option arguments given. so do everything in the current directory
57
- $code_base ||= ' .' unless @ARGV ;
61
+ # if no non-option arguments or commits are given, default to looking in the
62
+ # current directory
63
+ $code_base ||= ' .' unless (@ARGV || @commits );
58
64
59
65
my $sourcedir = locate_sourcedir();
60
66
@@ -388,6 +394,7 @@ Usage:
388
394
pgindent [OPTION]... [FILE]...
389
395
Options:
390
396
--help show this message and quit
397
+ --commit=gitref use files modified by the named commit
391
398
--typedefs=FILE file containing a list of typedefs
392
399
--list-of-typedefs=STR string containing typedefs, space separated
393
400
--code-base=DIR path to the base of PostgreSQL source code
@@ -396,7 +403,7 @@ Options:
396
403
--build build the pg_bsd_indent program
397
404
--show-diff show the changes that would be made
398
405
--silent-diff exit with status 2 if any changes would be made
399
- The --excludes option can be given more than once.
406
+ The --excludes and --commit options can be given more than once.
400
407
EOF
401
408
if ($help )
402
409
{
@@ -412,27 +419,38 @@ EOF
412
419
413
420
# main
414
421
415
- # get the list of files under code base, if it's set
416
- File::Find::find(
417
- {
418
- wanted => sub {
419
- my ($dev , $ino , $mode , $nlink , $uid , $gid );
420
- (($dev , $ino , $mode , $nlink , $uid , $gid ) = lstat ($_ ))
421
- && -f _
422
- && / ^.*\. [ch]\z /s
423
- && push (@files , $File::Find::name );
424
- }
425
- },
426
- $code_base ) if $code_base ;
427
-
428
422
$filtered_typedefs_fh = load_typedefs();
429
423
430
424
check_indent();
431
425
432
- # any non-option arguments are files to be processed
433
- push (@files , @ARGV );
426
+ build_clean($code_base ) if $build ;
427
+
428
+ my $wanted = sub
429
+ {
430
+ my ($dev , $ino , $mode , $nlink , $uid , $gid );
431
+ (($dev , $ino , $mode , $nlink , $uid , $gid ) = lstat ($_ ))
432
+ && -f _
433
+ && / ^.*\. [ch]\z /s
434
+ && push (@files , $File::Find::name );
435
+ };
436
+
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
+ # any non-option arguments are files or directories to be processed
441
+ File::Find::find({wanted => $wanted }, @ARGV ) if @ARGV ;
442
+
443
+ # process named commits by comparing each with their immediate ancestor
444
+ foreach my $commit (@commits )
445
+ {
446
+ my $prev =" $commit ~" ;
447
+ my @affected =` git diff-tree --no-commit-id --name-only -r $commit $prev ` ;
448
+ die " git error" if $? ;
449
+ chomp (@affected );
450
+ push (@files ,@affected );
451
+ }
434
452
435
- # the exclude list applies to command line arguments as well as found files
453
+ # remove excluded files from the file list
436
454
process_exclude();
437
455
438
456
foreach my $source_filename (@files )
@@ -481,6 +499,4 @@ foreach my $source_filename (@files)
481
499
}
482
500
}
483
501
484
- build_clean($code_base ) if $build ;
485
-
486
502
exit 0;
0 commit comments