This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix Attribute::Handlers pod to match new $VERSION
[perl5.git] / make_patchnum.pl
index 28148de..fc28d58 100644 (file)
@@ -17,9 +17,9 @@ make_patchnum.pl - make patchnum
 
 This program creates the files holding the information
 about locally applied patches to the source code. The created
 
 This program creates the files holding the information
 about locally applied patches to the source code. The created
-files are  C<git_version.h> and C<lib/Config_git.pl>.
+files are  F<git_version.h> and F<lib/Config_git.pl>.
 
 
-=head2 C<lib/Config_git.pl>
+=head2 F<lib/Config_git.pl>
 
 Contains status information from git in a form meant to be processed
 by the tied hash logic of Config.pm. It is actually optional,
 
 Contains status information from git in a form meant to be processed
 by the tied hash logic of Config.pm. It is actually optional,
@@ -93,14 +93,14 @@ sub backtick {
     my $command = shift;
     if (wantarray) {
         my @result= `$subcd $command`;
     my $command = shift;
     if (wantarray) {
         my @result= `$subcd $command`;
-        warn "$subcd $command: \$?=$?\n" if $?;
+        #warn "$subcd $command: \$?=$?\n" if $?;
         print "#> $subcd $command ->\n @result\n" if !$? and $opt_v;
         chomp @result;
         return @result;
     } else {
         my $result= `$subcd $command`;
         $result="" if ! defined $result;
         print "#> $subcd $command ->\n @result\n" if !$? and $opt_v;
         chomp @result;
         return @result;
     } else {
         my $result= `$subcd $command`;
         $result="" if ! defined $result;
-        warn "$subcd $command: \$?=$?\n" if $?;
+        #warn "$subcd $command: \$?=$?\n" if $?;
         print "#> $subcd $command ->\n $result\n" if !$? and $opt_v;
         chomp $result;
         return $result;
         print "#> $subcd $command ->\n $result\n" if !$? and $opt_v;
         chomp $result;
         return $result;
@@ -122,9 +122,9 @@ sub write_files {
     return 0;
 }
 
     return 0;
 }
 
-my $unpushed_commits = '/*no-op*/';
+my $unpushed_commits = '    ';
 my ($read, $branch, $snapshot_created, $commit_id, $describe)= ("") x 5;
 my ($read, $branch, $snapshot_created, $commit_id, $describe)= ("") x 5;
-my ($changed, $extra_info, $commit_title, $new_patchnum, $status)= ("") x 5;
+my ($changed, $extra_info, $commit_title)= ("") x 3;
 
 if (my $patch_file= read_file(".patch")) {
     ($branch, $snapshot_created, $commit_id, $describe) = split /\s+/, $patch_file;
 
 if (my $patch_file= read_file(".patch")) {
     ($branch, $snapshot_created, $commit_id, $describe) = split /\s+/, $patch_file;
@@ -134,6 +134,7 @@ if (my $patch_file= read_file(".patch")) {
 elsif (-d "$srcdir/.git") {
     # git branch | awk 'BEGIN{ORS=""} /\*/ { print $2 }'
     ($branch) = map { /\* ([^(]\S*)/ ? $1 : () } backtick("git branch");
 elsif (-d "$srcdir/.git") {
     # git branch | awk 'BEGIN{ORS=""} /\*/ { print $2 }'
     ($branch) = map { /\* ([^(]\S*)/ ? $1 : () } backtick("git branch");
+    $branch //= "";
     my ($remote,$merge);
     if (length $branch) {
         $merge= backtick("git config branch.$branch.merge");
     my ($remote,$merge);
     if (length $branch) {
         $merge= backtick("git config branch.$branch.merge");
@@ -145,8 +146,14 @@ elsif (-d "$srcdir/.git") {
     $commit_id = backtick("git rev-parse HEAD");
     $describe = backtick("git describe");
     my $commit_created = backtick(qq{git log -1 --pretty="format:%ci"});
     $commit_id = backtick("git rev-parse HEAD");
     $describe = backtick("git describe");
     my $commit_created = backtick(qq{git log -1 --pretty="format:%ci"});
-    $new_patchnum = "describe: $describe";
     $extra_info = "git_commit_date='$commit_created'";
     $extra_info = "git_commit_date='$commit_created'";
+    backtick("git diff --no-ext-diff --quiet --exit-code");
+    $changed = $?;
+    unless ($changed) {
+        backtick("git diff-index --cached --quiet HEAD --");
+        $changed = $?;
+    }
+
     if (length $branch && length $remote) {
         # git cherry $remote/$branch | awk 'BEGIN{ORS=","} /\+/ {print $2}' | sed -e 's/,$//'
         my $unpushed_commit_list =
     if (length $branch && length $remote) {
         # git cherry $remote/$branch | awk 'BEGIN{ORS=","} /\+/ {print $2}' | sed -e 's/,$//'
         my $unpushed_commit_list =
@@ -165,26 +172,22 @@ git_remote_branch='$remote/$merge'
 git_unpushed='$unpushed_commit_list'";
         }
     }
 git_unpushed='$unpushed_commit_list'";
         }
     }
-    if ($changed) { # not touched since init'd. never true.
-        $changed = 'true';
+    if ($changed) {
         $commit_title =  "Derived from:";
         $commit_title =  "Derived from:";
-        $status='"uncommitted-changes"'
-    } else {
-        $status='/*clean-working-directory-maybe*/'
     }
     $commit_title ||= "Commit id:";
 }
 
     }
     $commit_title ||= "Commit id:";
 }
 
-# we extract the filename out of the warning header, so dont mess with that
+# we extract the filename out of the warning header, so don't mess with that
 write_files(<<"EOF_HEADER", <<"EOF_CONFIG");
 /**************************************************************************
 * WARNING: 'git_version.h' is automatically generated by make_patchnum.pl
 *          DO NOT EDIT DIRECTLY - edit make_patchnum.pl instead
 ***************************************************************************/
 write_files(<<"EOF_HEADER", <<"EOF_CONFIG");
 /**************************************************************************
 * WARNING: 'git_version.h' is automatically generated by make_patchnum.pl
 *          DO NOT EDIT DIRECTLY - edit make_patchnum.pl instead
 ***************************************************************************/
-#define PERL_GIT_UNCOMMITTED_CHANGES $status
-#define PERL_PATCHNUM "$describe"
+@{[$describe ? "#define PERL_PATCHNUM \"$describe\"" : ()]}
 #define PERL_GIT_UNPUSHED_COMMITS\t\t\\
 $unpushed_commits/*leave-this-comment*/
 #define PERL_GIT_UNPUSHED_COMMITS\t\t\\
 $unpushed_commits/*leave-this-comment*/
+@{[$changed ? "#define PERL_GIT_UNCOMMITTED_CHANGES" : ()]}
 EOF_HEADER
 ######################################################################
 # WARNING: 'lib/Config_git.pl' is generated by make_patchnum.pl
 EOF_HEADER
 ######################################################################
 # WARNING: 'lib/Config_git.pl' is generated by make_patchnum.pl