much better git related version numbering in our (*nix for now) build process
[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
46807d8e 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 15unpushed_commits='/*no-op*/'
16if [ -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:'
21elif [ -d ".git" ]; then
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')
28 new_patchnum="describe: $describe"
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 "\""}')
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
38git_ancestor='$ancestor'
39git_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
47status: uncommitted-changes"
953f6acf 48 fi
46807d8e 49 test -z "$commit_title" && commit_title='Commit id:'
50fi
953f6acf 51
46807d8e 52new_unpushed=$(cat <<EOFTEXT
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*/
59EOFTEXT
60)
61new_config=$(cat <<EOFDATA
62#################################################################
63# WARNING: lib/Config_git.pl is generated by make_patchnum.sh #
64# DO NOT EDIT DIRECTLY - edit make_patchnum.sh instead #
65#################################################################
66\$Config::Git_Data=<<'ENDOFGIT';
67git_commit_id='$commit_id'
68git_describe='$describe'
69git_branch='$branch'
70git_uncommitted_changes='$changed'
71git_commit_id_title='$commit_title'
72$extra_info
73ENDOFGIT
74EOFDATA
75)
76# only update the files if necessary, other build product depends on these files
77if [ "$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 82else
46807d8e 83 echo "Reusing .patchnum and lib/Config_git.pl"
8565263a 84fi
46807d8e 85