summaryrefslogtreecommitdiff
path: root/functions
blob: 04707920b394f7e98c79245fb60240ad1e2068ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# vim:syn=sh

init() {
	# AOSP's gerrit doesn't like anonymous checkouts
	git config --global user.email &>/dev/null || git config --global user.email buildbot@linaro.org
	git config --global user.name &>/dev/null || git config --global user.name "Linaro Build Bot"
}

apply() {
	local REPO
	local DIR
	local SERVER
	local LOCAL_DIR
	if [ "$1" = "--linaro" ]; then
		SERVER="git://android-review.linaro.org/"
		shift
	elif [ "$1" = "--server" ]; then
		shift
		SERVER="$1"
		shift
	else
		SERVER="https://android.googlesource.com/"
	fi

	# Make specifying local path possible
	if [ "$1" = "--local" ]; then
		shift
		LOCAL_DIR="$1"
		shift
	else
		LOCAL_DIR="$1"
	fi

	# device and kernel have different path on repo to projects under platform
	if echo "$1" |grep -q -e '^device/' -e '^kernel/'; then
		REPO="$1"
	else
		REPO="platform/$1"
	fi
	DIR=`echo $2 |cut -d/ -f1 |rev |cut -b1-2 |rev`

	cd "$AOSP"/"${LOCAL_DIR}"
	echo "=== Applying $2 ==="
	if ! git fetch "$SERVER$REPO" refs/changes/$DIR/"$2"; then
		echo "Failed to fetch $2, typo in script?"
		exit 1
	fi
	if ! git cherry-pick FETCH_HEAD; then
		echo "$2 failed to apply, please fix"
		exit 1
	fi
	PATCHES=$((PATCHES+1))
}

cherrypick() {
	local URL=""
	local BRANCH=""
	if [ "$1" = "--url" ]; then
		shift
		URL="$1"
		shift
	fi
	if [ "$1" = "--branch" ]; then
		shift
		BRANCH="$1"
		shift
	fi
	cd "$AOSP"/"$1"
	if [ -n "${URL}" ]; then
		local remote_name=$(mktemp -u cherrypick-server-XXXX)
		if ! git remote add ${remote_name} ${URL}; then
			echo "Failed to add remote ${remote_name} for ${URL}"
			exit 1
		fi
		if ! git fetch ${remote_name} ${BRANCH}; then
		echo "Failed to fetch from ${remote_name} for branch ${BRANCH}"
		exit 1
		fi
	fi
	echo "=== Cherry-picking $2 ==="
	if ! git cherry-pick "$2"; then
		echo "$2 failed to apply, please fix"
		exit 1
	fi
	PATCHES=$((PATCHES+1))
}

revert() {
	local PATCH
	PATCH=false
	if [ "$1" == "--patch" -o "$1" == "-p" ]; then
		PATCH=true
		shift
	fi
	cd "$AOSP"/"$1"
	echo "=== Reverting $2 ==="
	if $PATCH; then
		if ! git show $2 |patch -p1 -R; then
			echo "$2 failed to revert by patching, please fix"
			exit 1
		fi
		git commit -am "Revert $2"
	else
		if ! git revert --no-edit "$2"; then
			echo "$2 failed to revert, please fix"
			exit 1
		fi
	fi
	PATCHES=$((PATCHES+1))
}