summaryrefslogtreecommitdiff
path: root/format_patch_dep3
blob: 3dd40f2ab573ed033dc7f31e2372f89cfa4541ff (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
#!/bin/sh

# patch_debian: generate sensible DEP3 headers from a Asterisk commits

set -e

dir=''
commit=''

usage() {
	me=`basename $0`
	echo "$me: format a DEP3 patch from Asterisk Git-SVN commits"
	echo ""
	echo "Usage:"
	echo "  git format-patch --stdout COMMIT(s) | $0  # Recommended"
	echo "  git show COMMIT | $0                      # Also works"
	echo "  $0 -c COMMIT [ -d DIRECTORY ]             # Shortcut"
	echo ""
	echo "  COMMIT: git commit to use. Should also work with multiple"
	echo "          patches in a mbox."
	echo ""
	echo "  DIRECTORY: If set, use git repository from that directory"
	echo "             (change into it first)."
}

while getopts 'c:d:h' opt; do
	case "$opt" in
		c) commit="$OPTARG" ;;
		d) dir="$OPTARG" ;;
		h) usage; exit 0;;
		?) usage; exit 1;;
	esac
done
shift $((OPTIND-1))

# By default, we just grab what the user provided in the standard input
get_patch() {
	cat
}

if [ "$commit" != '' ]; then
	#redefine the input function:
	get_patch() {
		if [ "$dir" != '' ]; then
			cd "$dir"
		fi
		git format-patch --stdout "$commit"^.."$commit"
	}
fi


# FIXME: ^' *' makes it work with 'git show', but increases the chance of
# it changing the actual patch.
get_patch \
| sed -r \
	-e 's#^ *git-svn-id: (http://svn.asterisk.org|https://origsvn.digium.com)/[^@]*@([0-9]+) .*#Origin: http://svnview.digium.com/svn/asterisk?view=rev\&rev=\2#' \
	-e 's@^ *\((|closes )issue #([0-9]+)\)$@Bug: https://issues.asterisk.org/view.php?id=\2@i' \
	
#git-svn-id:  git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/1.4@233609
#(issue #16299)
#(closes issue #16299)