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 existing_patchnum=`cat .patchnum 2>/dev/null`
12 existing_config=`cat lib/Config_git.pl 2>/dev/null`
13 existing_unpushed=`cat unpushed.h 2>/dev/null`
15 unpushed_commits='/*no-op*/'
16 if [ -s ".patch" ] ; then
17 # this is the minimal expectation for the
18 read branch snapshot_created commit_id describe < .patch
20 extra_info="git_snapshot_date='$snapshot_created'"
21 commit_title='Snapshot of:'
22 elif [ -d ".git" ]; then
23 branch=`git branch | awk 'BEGIN{ORS=""} /\*/ { print $2 }'`
24 test -n "$branch" && remote=`git config branch.$branch.remote`
25 commit_id=`git rev-parse HEAD`
26 changed=`git diff-index --name-only HEAD`
27 describe=`git describe --tags`
28 commit_created=`git log -1 --pretty='format:%ci'`
29 extra_info="git_commit_date='$commit_created'"
30 if [ -n "$branch" ] && [ -n "$remote" ]; then
31 unpushed_commit_list=`git cherry $remote/$branch | awk 'BEGIN{ORS=","} /\+/ {print $2}' | sed -e 's/,$//'`
32 unpushed_commits=`git cherry $remote/$branch | awk 'BEGIN{ORS="\t\\\\\n"} /\+/ {print ",\"" $2 "\""}'`
34 if [ -n "$unpushed_commits" ]; then
35 commit_title="Local Commit:"
36 ancestor=`git rev-parse $remote/$branch`
37 extra_info="$extra_info
38 git_ancestor='$ancestor'
39 git_unpushed='$unpushed_commit_list'"
45 Something is wrong with your source tree. You should
46 either have a .git directory and a functional git toolset
47 OR should have a .patch file in the source tree. Please
48 report the particulars of this situation to
49 perl5-porters@perl.org.
54 # Set up defaults for various values
55 new_patchnum="describe: $describe"
56 if [ -n "$changed" ]; then
58 commit_title="Derived from:"
59 new_patchnum="$new_patchnum
60 status: uncommitted-changes"
62 test -z "$commit_title" && commit_title='Commit id:'
64 new_unpushed=`cat <<EOFTEXT
65 /*********************************************************************
66 * WARNING: unpushed.h is automatically generated by make_patchnum.sh *
67 * DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead *
68 *********************************************************************/
69 #define PERL_GIT_UNPUSHED_COMMITS $unpushed_commits
70 /*leave-this-comment*/
73 new_config=`cat <<EOFDATA
74 #################################################################
75 # WARNING: lib/Config_git.pl is generated by make_patchnum.sh #
76 # DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead #
77 #################################################################
78 \\$Config::Git_Data=<<'ENDOFGIT';
79 git_commit_id='$commit_id'
80 git_describe='$describe'
82 git_uncommitted_changes='$changed'
83 git_commit_id_title='$commit_title'
88 # only update the files if necessary, other build product depends on these files
89 if [ "$existing_patchnum" != "$new_patchnum" ] || [ "$new_config" != "$existing_config" ] || [ "$existing_unpushed" != "$new_unpushed" ]; then
90 echo "Updating .patchnum and lib/Config_git.pl"
91 echo "$new_patchnum" > .patchnum
92 echo "$new_config" > lib/Config_git.pl
93 echo "$new_unpushed" > unpushed.h
95 echo "Reusing .patchnum and lib/Config_git.pl"