Add a new test for overloading.pm
[p5sagit/p5-mst-13.2.git] / make_patchnum.sh
1 #!/bin/sh
2
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
5 # directly from git.
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
10
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`
14
15 unpushed_commits='/*no-op*/'
16 if [ -s ".patch" ] ; then
17         read branch snapshot_created commit_id describe < .patch
18         changed=""
19         extra_info="git_snapshot_date='$snapshot_created'"
20         commit_title='Snapshot of:'
21 elif [ -d ".git" ]; then
22         branch=`git branch | awk 'BEGIN{ORS=""} /\*/ { print $2 }'`
23         test -n "$branch" && remote=`git config branch.$branch.remote`
24         commit_id=`git rev-parse HEAD`
25         changed=`git diff-index --name-only HEAD`
26         describe=`git describe --tags`
27         commit_created=`git log -1 --pretty='format:%ci'`
28         new_patchnum="describe: $describe"
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 "\""}'`
33
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'"
40                 fi
41                         
42         fi
43         if [ -n "$changed" ]; then
44                 changed="true"
45                 commit_title="Derived from:"
46                 new_patchnum="$new_patchnum
47 status: uncommitted-changes"
48         fi
49         test -z "$commit_title" && commit_title='Commit id:'
50 fi
51
52 new_unpushed=`cat <<EOFTEXT
53 /*********************************************************************
54 * WARNING: unpushed.h is automatically generated by make_patchnum.sh *
55 *          DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead      *
56 *********************************************************************/
57 #define PERL_GIT_UNPUSHED_COMMITS       $unpushed_commits
58 /*leave-this-comment*/
59 EOFTEXT
60 `
61 new_config=`cat <<EOFDATA
62 #################################################################
63 # WARNING: lib/Config_git.pl is generated by make_patchnum.sh   #
64 #          DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead #
65 #################################################################
66 \\$Config::Git_Data=<<'ENDOFGIT';
67 git_commit_id='$commit_id'
68 git_describe='$describe'
69 git_branch='$branch'
70 git_uncommitted_changes='$changed'
71 git_commit_id_title='$commit_title'
72 $extra_info
73 ENDOFGIT
74 EOFDATA
75 `
76 # only update the files if necessary, other build product depends on these files
77 if [ "$existing_patchnum" != "$new_patchnum" ] || [ "$new_config" != "$existing_config" ] || [ "$existing_unpushed" != "$new_unpushed" ]; then
78         echo "Updating .patchnum and lib/Config_git.pl"
79         echo "$new_patchnum" > .patchnum
80         echo "$new_config" > lib/Config_git.pl
81         echo "$new_unpushed" > unpushed.h
82 else
83         echo "Reusing .patchnum and lib/Config_git.pl"
84 fi
85