summaryrefslogtreecommitdiff
path: root/functions
blob: 61ccfe930304129c4e1c92020f4fb59ca1ab25df (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
# 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
	if [ "$1" = "--linaro" ]; then
		SERVER="git://review.android.git.linaro.org/"
		shift
	elif [ "$1" = "--server" ]; then
		shift
		SERVER="$1"
		shift
	else
		SERVER="https://android.googlesource.com/"
	fi

	if echo "$1" |grep -q '^device/'; then
		REPO="$1"
	else
		REPO="platform/$1"
	fi
	DIR=`echo $2 |cut -d/ -f1 |rev |cut -b1-2 |rev`

	cd "$AOSP"/"$1"
	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() {
	cd "$AOSP"/"$1"
	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))
}