2 # These two should go upon release to make the script Perl 5.005 compatible
8 make_patchnum.pl - make patchnum
18 while (!-e "$root/perl.c" and length($root)<100) {
25 die "Can't find toplevel" if !-e "$root/perl.c";
26 sub path_to { "$root/$_[0]" } # use $_[0] if this'd be placed in toplevel.
30 my $file = path_to(@_);
31 return "" unless -e $file;
32 open my $fh, '<', $file
33 or die "Failed to open for read '$file':$!";
34 return do { local $/; <$fh> };
38 my ($file, $content) = @_;
39 $file= path_to($file);
40 open my $fh, '>', $file
41 or die "Failed to open for write '$file':$!";
48 my $result = `$command`;
53 my $existing_patchnum = read_file('.patchnum');
54 my $existing_config = read_file('lib/Config_git.pl');
55 my $existing_unpushed = read_file('unpushed.h');
57 my $unpushed_commits = '/*no-op*/';
58 my ($read, $branch, $snapshot_created, $commit_id, $describe);
59 my ($changed, $extra_info, $commit_title, $new_patchnum);
60 if (my $patch_file= read_file('.patch')) {
61 ($branch, $snapshot_created, $commit_id, $describe) = split /\s+/, $patchfile;
62 $extra_info = "git_snapshot_date='$snapshot_created'";
63 $commit_title = "Snapshot of:";
65 elsif (-d path_to('.git')) {
66 # git branch | awk 'BEGIN{ORS=""} /\*/ { print $2 }'
67 $branch = join "", map { (split /\s/, $_)[1] }
68 grep {/\*/} split /\n/, backtick('git branch');
71 $remote = backtick("git config branch.$branch.remote");
73 $commit_id = backtick("git rev-parse HEAD");
74 $describe = backtick("git describe");
75 my $commit_created = backtick(qq{git log -1 --pretty="format:%ci"});
76 $new_patchnum = "describe: $describe";
77 $extra_info = "git_commit_date='$commit_created'";
78 if (length $branch && length $remote) {
79 # git cherry $remote/$branch | awk 'BEGIN{ORS=","} /\+/ {print $2}' | sed -e 's/,$//'
80 my $unpushed_commit_list =
81 join ",", map { (split /\s/, $_)[1] }
82 grep {/\+/} split /\n/, backtick("git cherry $remote/$branch");
83 # git cherry $remote/$branch | awk 'BEGIN{ORS="\t\\\\\n"} /\+/ {print ",\"" $2 "\""}'
85 join "", map { ',"'.(split /\s/, $_)[1].'"'."\t\\\n" }
86 grep {/\+/} split /\n/, backtick("git cherry $remote/$branch");
87 if (length $unpushed_commits) {
88 $commit_title = "Local Commit:";
89 my $ancestor = backtick("git rev-parse $remote/$branch");
90 $extra_info = "$extra_info
91 git_ancestor='$ancestor'
92 git_unpushed='$unpushed_commit_list'";
95 if (length $changed) {
97 $commit_title = "Derived from:";
98 $new_patchnum = "$new_patchnum
99 status: uncommitted-changes";
101 if (not length $commit_title) {
102 $commit_title = "Commit id:";
106 my $new_unpushed =<<"EOFTEXT";
107 /*********************************************************************
108 * WARNING: unpushed.h is automatically generated by make_patchnum.pl *
109 * DO NOT EDIT DIRECTLY - edit make_patchnum.pl instead *
110 *********************************************************************/
111 #define PERL_GIT_UNPUSHED_COMMITS $unpushed_commits
112 /*leave-this-comment*/
115 my $new_config =<<"EOFDATA";
116 #################################################################
117 # WARNING: lib/Config_git.pl is generated by make_patchnum.pl #
118 # DO NOT EDIT DIRECTLY - edit make_patchnum.pl instead #
119 #################################################################
120 \$Config::Git_Data=<<'ENDOFGIT';
121 git_commit_id='$commit_id'
122 git_describe='$describe'
124 git_uncommitted_changes='$changed'
125 git_commit_id_title='$commit_title'
130 # only update the files if necessary, other build product depends on these files
131 if (( $existing_patchnum ne $new_patchnum ) || ( $existing_config ne $new_config ) || ( $existing_unpushed ne $new_unpushed )) {
132 print "Updating .patchnum and lib/Config_git.pl\n";
133 write_file('.patchnum', $new_patchnum);
134 write_file('lib/Config_git.pl', $new_config);
135 write_file('unpushed.h', $new_unpushed);
138 print "Reusing .patchnum and lib/Config_git.pl\n"
141 # ex: set ts=4 sts=4 et ft=perl: