pgindent-dirty-cached.patch
text/x-patch
Filename: pgindent-dirty-cached.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/tools/pgindent/pgindent | 23 | 3 |
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index 07970f758c..c9f42302c9 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -24,13 +24,15 @@ my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, $code_base,
@excludes, $indent, $build,
$show_diff, $silent_diff, $help,
- @commits,);
+ @commits, $dirty, $cached);
$help = 0;
my %options = (
"help" => \$help,
"commit=s" => \@commits,
+ "dirty" => \$dirty,
+ "cached" => \$cached,
"typedefs=s" => \$typedefs_file,
"list-of-typedefs=s" => \$typedef_str,
"code-base=s" => \$code_base,
@@ -46,8 +48,11 @@ usage() if $help;
usage("Cannot have both --silent-diff and --show-diff")
if $silent_diff && $show_diff;
-usage("Cannot use --commit with --code-base or command line file list")
- if (@commits && ($code_base || @ARGV));
+usage("Cannot use --commit, --dirty or --cached with --code-base or command line file list")
+ if (($dirty || $cached || @commits) && ($code_base || @ARGV));
+
+usage( "Cannot use --dirty or --cached with --commit")
+ if (($dirty || $cached) && @commits);
run_build($code_base) if ($build);
@@ -395,6 +400,8 @@ pgindent [OPTION]... [FILE]...
Options:
--help show this message and quit
--commit=gitref use files modified by the named commit
+ --dirty use modified files under current directory
+ --cached use staged files under current directory
--typedefs=FILE file containing a list of typedefs
--list-of-typedefs=STR string containing typedefs, space separated
--code-base=DIR path to the base of PostgreSQL source code
@@ -450,6 +457,19 @@ foreach my $commit (@commits)
push(@files,@affected);
}
+# look for dirty / cached files under the CWD
+if ($dirty || $cached)
+{
+ my $gitcmd = "git diff --diff-filter=ACMR --name-only";
+ $gitcmd .= " --cached" if ($cached && !$dirty);
+ $gitcmd .= " HEAD" if ($dirty && $cached);
+ $gitcmd .= " -- .";
+ my @affected=`$gitcmd`;
+ die "git error" if $?;
+ chomp(@affected);
+ push(@files,@affected);
+}
+
# remove excluded files from the file list
process_exclude();