Commit | Line | Data |
8565263a |
1 | #!/bin/sh |
2 | |
46807d8e |
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 |
953f6acf |
10 | |
dcff826f |
11 | config_file="lib/Config_git.pl" |
12 | header_file="git_version.h" |
13 | patch_file=".patch" |
14 | |
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` |
7ba92e4f |
18 | |
46807d8e |
19 | unpushed_commits='/*no-op*/' |
dcff826f |
20 | if [ -s $patch_file ] ; then |
166a466f |
21 | # this is the minimal expectation for the |
46807d8e |
22 | read branch snapshot_created commit_id describe < .patch |
23 | changed="" |
24 | extra_info="git_snapshot_date='$snapshot_created'" |
25 | commit_title='Snapshot of:' |
dcff826f |
26 | elif [ -n "$git_dir" ]; then |
27 | branch=`git branch | awk 'BEGIN{ORS=""} /^\* [^(]/ { print $2 }'` |
8ffec826 |
28 | test -n "$branch" && remote=`git config branch.$branch.remote` |
dcff826f |
29 | test -n "$branch" && merge=`git config branch.$branch.merge | sed s,refs/heads/,,` |
8ffec826 |
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'` |
46807d8e |
34 | extra_info="git_commit_date='$commit_created'" |
dcff826f |
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 "\""}'` |
8565263a |
38 | |
46807d8e |
39 | if [ -n "$unpushed_commits" ]; then |
40 | commit_title="Local Commit:" |
dcff826f |
41 | ancestor=`git rev-parse $remote/$merge` |
46807d8e |
42 | extra_info="$extra_info |
43 | git_ancestor='$ancestor' |
dcff826f |
44 | git_remote_branch='$remote/$merge' |
46807d8e |
45 | git_unpushed='$unpushed_commit_list'" |
46 | fi |
47 | |
48 | fi |
166a466f |
49 | else |
50 | cat <<SNDOGS |
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. |
56 | SNDOGS |
57 | exit 2 |
58 | fi |
59 | |
60 | # Set up defaults for various values |
166a466f |
61 | if [ -n "$changed" ]; then |
62 | changed="true" |
63 | commit_title="Derived from:" |
dcff826f |
64 | status="#define PERL_GIT_UNCOMMITTED_CHANGES uncommitted-changes" |
65 | else |
66 | status="/* clean working directory */" |
46807d8e |
67 | fi |
166a466f |
68 | test -z "$commit_title" && commit_title='Commit id:' |
953f6acf |
69 | |
dcff826f |
70 | new_header=`cat <<EOFTEXT |
71 | /*************************************************************************** |
12d7e04d |
72 | * WARNING: $header_file is automatically generated by make_patchnum.sh |
73 | * DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead |
dcff826f |
74 | ****************************************************************************/ |
75 | #define PERL_PATCHNUM $describe |
76 | $status |
12d7e04d |
77 | #define PERL_GIT_UNPUSHED_COMMITS $unpushed_commits |
46807d8e |
78 | /*leave-this-comment*/ |
79 | EOFTEXT |
8ffec826 |
80 | ` |
81 | new_config=`cat <<EOFDATA |
dcff826f |
82 | ####################################################################### |
12d7e04d |
83 | # WARNING: $config_file is generated by make_patchnum.sh |
84 | # DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead |
dcff826f |
85 | ####################################################################### |
28b1daef |
86 | \\$Config::Git_Data=<<'ENDOFGIT'; |
46807d8e |
87 | git_commit_id='$commit_id' |
88 | git_describe='$describe' |
89 | git_branch='$branch' |
90 | git_uncommitted_changes='$changed' |
91 | git_commit_id_title='$commit_title' |
92 | $extra_info |
93 | ENDOFGIT |
94 | EOFDATA |
8ffec826 |
95 | ` |
46807d8e |
96 | # only update the files if necessary, other build product depends on these files |
dcff826f |
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 |
12d7e04d |
101 | exit 1 |
8565263a |
102 | else |
dcff826f |
103 | echo "Reusing $header_file and $config_file" |
8565263a |
104 | fi |
46807d8e |
105 | |