summaryrefslogtreecommitdiffstats
path: root/scripts/mk-patch-list.sh
blob: aa6aa6d5f56e4c059be9ba45c0c2a659e14b619e (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
#!/bin/bash

die() {
	[ "$#" -eq 0 ] || echo "$*" >&2
	exit 1
}

err() {
	echo "$*" >&2
}

quit() {
	[ "$#" -eq 0 ] || echo "$*"
	exit 0
}

#### Main

USAGE="Usage: ${0##*/} [-o <output_dir>] [-s <start_num>] [-b <base>] commit_id..."
OUTPUT=
BASE=
NUM=

while [ -n "$1" -a -z "${1##-*}" ]; do
	case "$1" in
		-b)        BASE="$2"      ; shift 2 ;;
		-o)        OUTPUT="$2"    ; shift 2 ;;
		-s)        NUM="$2"       ; shift 2 ;;
		-h|--help) quit "$USAGE" ;;
		*)         die  "$USAGE" ;;
	esac
done

PATCHES=( "$@" )
NUM=${NUM:-1}

for p in ${PATCHES[@]}; do
        if [ -n "$BASE" ]; then
                # find the patch number from the base.
                # E.g. v2.9-dev0-774-gd710dfbac
                NUM=$(git describe --match "$BASE" "$p")
                NUM=${NUM#"$BASE"-}
                NUM=${NUM%-*}
        fi
        git format-patch -k -1 --start-number=$NUM ${OUTPUT:+-o $OUTPUT} "$p"
        ((NUM++))
done