1#!/bin/bash
2#
3# NAME:
4#         make-patches.sh - extract a set of linuxized patches from the
5#                           ACPICA git repository
6#
7# SYNOPSIS:
8#         make-patches.sh [-n hash] [-r release] [-u] <old_commit> [new_commit]
9#
10# DESCRIPTION:
11#         Creates the linuxized patch set from old_commit to new_commit in
12#         ACPICA git repository.
13#         Parameters:
14#          old_commit The old commit ID.
15#          new_commit The new commit ID.  If this parameter is not specified,
16#                     the new commit ID is default to HEAD.
17#         Options:
18#          -n hash    Specify number of digits from commit hash to form a name.
19#          -r release Specify a release ID, it will turn out to be the name of
20#                     the patch files.  If this option is not specified, the
21#                     default name of the patch files will be the current month
22#                     in YYYYmm date format.
23#          -u         Generate upstream commit IDs in the linuxized patches.
24#
25
26RELEASE=`date +%Y%m`
27HASH=8
28
29usage()
30{
31	echo "Usage: `basename $0` [-n hash] [-r release] [-u] <old_commit> [new_commit]"
32	echo "Where:"
33	echo "  -n: Specify number of digits from commit hash to form a name"
34	echo "      (default to 8)."
35	echo "  -r: Set release ID, default is $RELEASE in YYYYmm- date format"
36	echo "  -u: Generate upstream commit IDs"
37	echo "  old_commit: The old commit id\n";
38	echo "  new_commit: Optional, the new commit id, default to HEAD";
39	exit 0
40}
41
42SCRIPT=`(cd \`dirname $0\`; pwd)`
43. $SCRIPT/libacpica.sh
44
45ACPICA_DIR=$CURDIR/patches.acpica.$RELEASE
46LINUX_DIR=$CURDIR/patches.linux.$RELEASE
47NEW_RELEASE="HEAD"
48OLD_RELEASE="HEAD"
49ACPICA_CNT=0
50LINUX_CNT=0
51MAINTAINER="Bob Moore <robert.moore@intel.com>"
52GIT_EXTRACT="$SCRIPT/gen-patch.sh"
53RELEASE="${RELEASE}-"
54
55while getopts "dn:r:u" opt
56do
57	case $opt in
58	d) DRYRUN="yes";;
59	n) HASH=$OPTARG;;
60	r) RELEASE=$OPTARG;;
61	u) GIT_EXTRACT="${GIT_EXTRACT} -u -m '${MAINTAINER}'";;
62	?) echo "Invalid argument $opt"
63	   usage;;
64	esac
65done
66shift $(($OPTIND - 1))
67
68if [ -z $1 ]; then
69	echo "old_commit is not specified"
70	usage
71fi
72OLD_RELEASE=$1
73if [ ! -z $2 ]; then
74	NEW_RELEASE=$2
75fi
76
77COMMITS=`git rev-list --reverse $OLD_RELEASE..$NEW_RELEASE`
78
79for c in $COMMITS; do
80	ACPICA_CNT=`expr $ACPICA_CNT + 1`
81done
82
83generate_patch()
84{
85	local cid aid lid
86	local COMMIT SUBJECT
87
88	cid=$1
89	aid=$2
90	lid=$3
91
92	COMMIT=`git log -1 $cid --format=%H`
93	COMMIT_NAME=`git log -1 $cid --format=%H | cut -c 1-${HASH}`
94	SUBJECT=`git log -1 $cid --format=%s`
95
96	echo "[make-patches.sh] Generating patch ($aid:$lid:$COMMIT_NAME: $SUBJECT)..."
97	(
98		cd $SCRIPT
99
100		if [ "x$DRYRUN" = "xyes" ]; then
101			echo $GIT_EXTRACT -i $lid -n $HASH $COMMIT
102		else
103			eval $GIT_EXTRACT -i $lid -n $HASH $COMMIT
104			echo "[make-patches.sh]  Copying ACPICA patch ($RELEASE$aid.patch)..."
105			mv acpica-$COMMIT_NAME.patch $ACPICA_DIR/$RELEASE$aid.patch
106			echo $RELEASE$aid.patch >> $ACPICA_DIR/series
107		fi
108
109
110		if [ -f linux-$COMMIT_NAME.patch ]; then
111			if [ "x$DRYRUN" != "xyes" ]; then
112				echo "[make-patches.sh] Copying Linux patch ($RELEASE$lid.patch)..."
113				mv linux-$COMMIT_NAME.patch $LINUX_DIR/$RELEASE$lid.patch
114				echo $RELEASE$lid.patch >> $LINUX_DIR/series
115			fi
116		fi
117	)
118}
119
120rm -rf $ACPICA_DIR
121rm -rf $LINUX_DIR
122mkdir -p $ACPICA_DIR
123mkdir -p $LINUX_DIR
124
125ACPICA_IDX=1
126LINUX_IDX=1
127make_acpisrc $SRCDIR force > /dev/null
128
129for c in $COMMITS; do
130	generate_patch $c $ACPICA_IDX $LINUX_IDX
131
132	LINUX_TO=$LINUX_DIR/$RELEASE$LINUX_IDX.patch
133	if [ -f $LINUX_TO ]; then
134		echo "[make-patches.sh] Generated $LINUX_TO."
135		LINUX_IDX=`expr $LINUX_IDX + 1`
136	fi
137
138	ACPICA_IDX=`expr $ACPICA_IDX + 1`
139done
140
141LINUX_CNT=`expr $LINUX_IDX - 1`
142
143echo "[make-patches.sh] Generated $ACPICA_CNT raw patches and $LINUX_CNT linuxized patches."
144