This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
prepare for refactoring to perl
[perl5.git] / make_patchnum.pl
CommitLineData
8ed12dca
YO
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
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)
14
15unpushed_commits='/*no-op*/'
16if [ -s ".patch" ] ; then
17 # this is the minimal expectation for the
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
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')
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
38git_ancestor='$ancestor'
39git_unpushed='$unpushed_commit_list'"
40 fi
41
42 fi
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
60status: uncommitted-changes"
61fi
62test -z "$commit_title" && commit_title='Commit id:'
63
64new_unpushed=$(cat <<EOFTEXT
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
72)
73new_config=$(cat <<EOFDATA
74#################################################################
75# WARNING: lib/Config_git.pl is generated by make_patchnum.sh #
76# DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead #
77#################################################################
78\$Config::Git_Data=<<'ENDOFGIT';
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
87)
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
94else
95 echo "Reusing .patchnum and lib/Config_git.pl"
96fi
97