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 | |
8ffec826 |
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 |
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 |
8ffec826 |
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'` |
46807d8e |
28 | new_patchnum="describe: $describe" |
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 |
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" |
953f6acf |
48 | fi |
46807d8e |
49 | test -z "$commit_title" && commit_title='Commit id:' |
50 | fi |
953f6acf |
51 | |
8ffec826 |
52 | new_unpushed=`cat <<EOFTEXT |
46807d8e |
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 |
8ffec826 |
60 | ` |
61 | new_config=`cat <<EOFDATA |
46807d8e |
62 | ################################################################# |
63 | # WARNING: lib/Config_git.pl is generated by make_patchnum.sh # |
64 | # DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead # |
65 | ################################################################# |
28b1daef |
66 | \\$Config::Git_Data=<<'ENDOFGIT'; |
46807d8e |
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 |
8ffec826 |
75 | ` |
46807d8e |
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 |
8565263a |
82 | else |
46807d8e |
83 | echo "Reusing .patchnum and lib/Config_git.pl" |
8565263a |
84 | fi |
46807d8e |
85 | |