3 # this script is used to regenerate a number of special build files
4 # based on either information contained in a file called .patch or
6 # The files involved are:
7 # .patchnum # information about the current checkout
8 # lib/Config_git.pl # holds some special configure settings related to git
9 # unpushed.h # header file used by patchlevel.h to store unpushed commits
11 config_file="lib/Config_git.pl"
12 header_file="git_version.h"
15 git_dir=`git rev-parse --git-dir 2>/dev/null`
16 existing_config=`cat $config_file 2>/dev/null`
17 existing_header=`cat $header_file 2>/dev/null`
19 unpushed_commits='/*no-op*/'
20 if [ -s $patch_file ] ; then
21 # this is the minimal expectation for the
22 read branch snapshot_created commit_id describe < .patch
24 extra_info="git_snapshot_date='$snapshot_created'"
25 commit_title='Snapshot of:'
26 elif [ -n "$git_dir" ]; then
27 branch=`git branch | awk 'BEGIN{ORS=""} /^\* [^(]/ { print $2 }'`
28 test -n "$branch" && remote=`git config branch.$branch.remote`
29 test -n "$branch" && merge=`git config branch.$branch.merge | sed s,refs/heads/,,`
30 commit_id=`git rev-parse HEAD`
31 changed=`git diff-index --name-only HEAD`
32 describe=`git describe --tags`
33 commit_created=`git log -1 --pretty='format:%ci'`
34 extra_info="git_commit_date='$commit_created'"
35 if [ -n "$merge" ] && [ -n "$remote" ]; then
36 unpushed_commit_list=`git cherry $remote/$merge | awk 'BEGIN{ORS=","} /\+/ {print $2}' | sed -e 's/,$//'`
37 unpushed_commits=`git cherry $remote/$merge | awk 'BEGIN{ORS="\t\\\\\n"} /\+/ {print ",\"" $2 "\""}'`
39 if [ -n "$unpushed_commits" ]; then
40 commit_title="Local Commit:"
41 ancestor=`git rev-parse $remote/$merge`
42 extra_info="$extra_info
43 git_ancestor='$ancestor'
44 git_remote_branch='$remote/$merge'
45 git_unpushed='$unpushed_commit_list'"
51 Something is wrong with your source tree. You should
52 either have a .git directory and a functional git toolset
53 OR should have a .patch file in the source tree. Please
54 report the particulars of this situation to
55 perl5-porters@perl.org.
60 # Set up defaults for various values
61 if [ -n "$changed" ]; then
63 commit_title="Derived from:"
64 status="#define PERL_GIT_UNCOMMITTED_CHANGES uncommitted-changes"
66 status="/* clean working directory */"
68 test -z "$commit_title" && commit_title='Commit id:'
70 new_header=`cat <<EOFTEXT
71 /***************************************************************************
72 * WARNING: $header_file is automatically generated by make_patchnum.sh
73 * DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead
74 ****************************************************************************/
75 #define PERL_PATCHNUM $describe
77 #define PERL_GIT_UNPUSHED_COMMITS $unpushed_commits
78 /*leave-this-comment*/
81 new_config=`cat <<EOFDATA
82 #######################################################################
83 # WARNING: $config_file is generated by make_patchnum.sh
84 # DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead
85 #######################################################################
86 \\$Config::Git_Data=<<'ENDOFGIT';
87 git_commit_id='$commit_id'
88 git_describe='$describe'
90 git_uncommitted_changes='$changed'
91 git_commit_id_title='$commit_title'
96 # only update the files if necessary, other build product depends on these files
97 if [ "$new_config" != "$existing_config" ] || [ "$existing_header" != "$new_header" ]; then
98 echo "Updating $header_file and $config_file"
99 echo "$new_config" > $config_file
100 echo "$new_header" > $header_file
102 echo "Reusing $header_file and $config_file"