This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
modified make_patchnum.sh script
[perl5.git] / make_patchnum.sh
CommitLineData
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
11existing_patchnum=`cat .patchnum 2>/dev/null`
12existing_config=`cat lib/Config_git.pl 2>/dev/null`
13existing_unpushed=`cat unpushed.h 2>/dev/null`
7ba92e4f 14
46807d8e
YO
15unpushed_commits='/*no-op*/'
16if [ -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:'
22elif [ -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
38git_ancestor='$ancestor'
39git_unpushed='$unpushed_commit_list'"
40 fi
41
42 fi
166a466f
YO
43else
44 cat <<SNDOGS
45Something is wrong with your source tree. You should
46either have a .git directory and a functional git toolset
47OR should have a .patch file in the source tree. Please
48report the particulars of this situation to
49perl5-porters@perl.org.
50SNDOGS
51 exit 2
52fi
53
54# Set up defaults for various values
55new_patchnum="describe: $describe"
56if [ -n "$changed" ]; then
57 changed="true"
58 commit_title="Derived from:"
59 new_patchnum="$new_patchnum
46807d8e 60status: uncommitted-changes"
46807d8e 61fi
166a466f 62test -z "$commit_title" && commit_title='Commit id:'
953f6acf 63
8ffec826 64new_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*/
71EOFTEXT
8ffec826
NC
72`
73new_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
79git_commit_id='$commit_id'
80git_describe='$describe'
81git_branch='$branch'
82git_uncommitted_changes='$changed'
83git_commit_id_title='$commit_title'
84$extra_info
85ENDOFGIT
86EOFDATA
8ffec826 87`
46807d8e
YO
88# only update the files if necessary, other build product depends on these files
89if [ "$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 94else
46807d8e 95 echo "Reusing .patchnum and lib/Config_git.pl"
8565263a 96fi
46807d8e 97