this seems to work, still not using the perl version, but this works the way it would
[p5sagit/p5-mst-13.2.git] / make_patchnum.sh
CommitLineData
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 11config_file="lib/Config_git.pl"
12header_file="git_version.h"
13patch_file=".patch"
14
15git_dir=`git rev-parse --git-dir 2>/dev/null`
16existing_config=`cat $config_file 2>/dev/null`
17existing_header=`cat $header_file 2>/dev/null`
7ba92e4f 18
46807d8e 19unpushed_commits='/*no-op*/'
dcff826f 20if [ -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 26elif [ -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
43git_ancestor='$ancestor'
dcff826f 44git_remote_branch='$remote/$merge'
46807d8e 45git_unpushed='$unpushed_commit_list'"
46 fi
47
48 fi
166a466f 49else
50 cat <<SNDOGS
51Something is wrong with your source tree. You should
52either have a .git directory and a functional git toolset
53OR should have a .patch file in the source tree. Please
54report the particulars of this situation to
55perl5-porters@perl.org.
56SNDOGS
57 exit 2
58fi
59
60# Set up defaults for various values
166a466f 61if [ -n "$changed" ]; then
62 changed="true"
63 commit_title="Derived from:"
dcff826f 64 status="#define PERL_GIT_UNCOMMITTED_CHANGES uncommitted-changes"
65else
66 status="/* clean working directory */"
46807d8e 67fi
166a466f 68test -z "$commit_title" && commit_title='Commit id:'
953f6acf 69
dcff826f 70new_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*/
79EOFTEXT
8ffec826 80`
81new_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 87git_commit_id='$commit_id'
88git_describe='$describe'
89git_branch='$branch'
90git_uncommitted_changes='$changed'
91git_commit_id_title='$commit_title'
92$extra_info
93ENDOFGIT
94EOFDATA
8ffec826 95`
46807d8e 96# only update the files if necessary, other build product depends on these files
dcff826f 97if [ "$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 102else
dcff826f 103 echo "Reusing $header_file and $config_file"
8565263a 104fi
46807d8e 105