1#!/bin/sh
2
3usage ()
4{
5    echo "Usage: $0 [--enable-push] <vendor>"
6    echo "The following vendors are already known:"
7    git ls-remote ${upstream} "*/vendors/*" | sed -r "s:.*/vendors/([^/]+)/.*:\1:"|sort|uniq
8    exit 1
9}
10
11# Should we insert a "push" refspec to enable pushing to the vendor branch?
12enable_push=no
13
14upstream=`git config --get "gcc-config.upstream"`
15if [ x"$upstream" = x ]
16then
17    echo "Config gcc-config.upstream not set, run contrib/gcc-git-customization"
18    exit 1
19fi
20
21case $# in
22    1)
23	# vendor names never start with -, so catch this in case user wrote something like --help.
24	case "$1" in
25	    -*)
26		usage
27		;;
28	    *)
29		vendor=$1
30		;;
31	esac
32	;;
33    2)
34	vendor=$2
35	if [ "$1" = "--enable-push" ]
36	then
37	    enable_push=yes
38	else
39	    usage
40	fi
41	;;
42    *)
43	usage
44	;;
45esac
46
47
48echo "setting up git to fetch vendor ${vendor} to remotes/vendors/${vendor}"
49url=$(git config --get "remote.${upstream}.url")
50pushurl=$(git config --get "remote.${upstream}.pushurl")
51git config "remote.vendors/${vendor}.url" "${url}"
52if [ "x$pushurl" != "x" ]
53then
54    git config "remote.vendors/${vendor}.pushurl" "${pushurl}"
55fi
56git config --replace-all "remote.vendors/${vendor}.fetch" "+refs/vendors/${vendor}/heads/*:refs/remotes/vendors/${vendor}/*" "refs/vendors/${vendor}/heads"
57git config --replace-all "remote.vendors/${vendor}.fetch" "+refs/vendors/${vendor}/tags/*:refs/tags/vendors/${vendor}/*" "refs/vendors/${vendor}/tags"
58if [ "$enable_push" = "yes" ]
59then
60    echo "Warning: take care when pushing that you only push the changes you intend."
61    echo "E.g. use \"git push vendors/${vendor} HEAD\" to push the current branch"
62    git config --replace-all "remote.vendors/${vendor}.push" "refs/heads/${vendor}/*:refs/vendors/${vendor}/heads/*"
63else
64    git config --unset-all "remote.vendors/${vendor}.push"
65fi
66git fetch vendors/${vendor}
67