Commit | Line | Data |
---|---|---|
8565263a YO |
1 | #!/bin/sh |
2 | ||
46807d8e YO |
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 | |
8ffec826 NC |
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` | |
7ba92e4f | 14 | |
46807d8e YO |
15 | unpushed_commits='/*no-op*/' |
16 | if [ -s ".patch" ] ; then | |
166a466f | 17 | # this is the minimal expectation for the |
46807d8e YO |
18 | read branch snapshot_created commit_id describe < .patch |
19 | changed="" | |
20 | extra_info="git_snapshot_date='$snapshot_created'" | |
21 | commit_title='Snapshot of:' | |
22 | elif [ -d ".git" ]; then | |
8ffec826 NC |
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'` | |
46807d8e YO |
29 | extra_info="git_commit_date='$commit_created'" |
30 | if [ -n "$branch" ] && [ -n "$remote" ]; then | |
a2837a9e | 31 | unpushed_commit_list=`git cherry $remote/$branch | awk 'BEGIN{ORS=","} /\+/ {print $2}' | sed -e 's/,$//'` |
050a6864 | 32 | unpushed_commits=`git cherry $remote/$branch | awk 'BEGIN{ORS="\t\\\\\n"} /\+/ {print ",\"" $2 "\""}'` |
8565263a | 33 | |
46807d8e YO |
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 | |
166a466f YO |
43 | else |
44 | cat <<SNDOGS | |
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. | |
50 | SNDOGS | |
51 | exit 2 | |
52 | fi | |
53 | ||
54 | # Set up defaults for various values | |
55 | new_patchnum="describe: $describe" | |
56 | if [ -n "$changed" ]; then | |
57 | changed="true" | |
58 | commit_title="Derived from:" | |
59 | new_patchnum="$new_patchnum | |
46807d8e | 60 | status: uncommitted-changes" |
46807d8e | 61 | fi |
166a466f | 62 | test -z "$commit_title" && commit_title='Commit id:' |
953f6acf | 63 | |
8ffec826 | 64 | new_unpushed=`cat <<EOFTEXT |
46807d8e YO |
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*/ | |
71 | EOFTEXT | |
8ffec826 NC |
72 | ` |
73 | new_config=`cat <<EOFDATA | |
46807d8e YO |
74 | ################################################################# |
75 | # WARNING: lib/Config_git.pl is generated by make_patchnum.sh # | |
76 | # DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead # | |
77 | ################################################################# | |
28b1daef | 78 | \\$Config::Git_Data=<<'ENDOFGIT'; |
46807d8e YO |
79 | git_commit_id='$commit_id' |
80 | git_describe='$describe' | |
81 | git_branch='$branch' | |
82 | git_uncommitted_changes='$changed' | |
83 | git_commit_id_title='$commit_title' | |
84 | $extra_info | |
85 | ENDOFGIT | |
86 | EOFDATA | |
8ffec826 | 87 | ` |
46807d8e YO |
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 | |
8565263a | 94 | else |
46807d8e | 95 | echo "Reusing .patchnum and lib/Config_git.pl" |
8565263a | 96 | fi |
46807d8e | 97 |