hppa: Fix typo in PA 2.0 trampoline template
[official-gcc.git] / contrib / gcc-git-customization.sh
blob2e173e859d7c2b5b6c0a4a187e41111a5bdd6340
1 #!/bin/sh
3 # Script to add some local git customizations suitable for working
4 # with the GCC git repository
6 ask () {
7 question=$1
8 default=$2
9 var=$3
10 printf "%s [%s]? " "$question" "$default"
11 read answer
12 if [ "x$answer" = "x" ]
13 then
14 eval $var=\$default
15 else
16 eval $var=\$answer
20 # Add a git command to find the git commit equivalent to legacy SVN revision NNN
21 git config alias.svn-rev '!f() { rev=$1; shift; git log --all --grep="^From-SVN: r\\?$rev\\b" "${@}"; } ; f'
23 # Add git commands to convert git commit to monotonically increasing revision number
24 # and vice versa
25 git config alias.gcc-descr '!f() { "`git rev-parse --show-toplevel`/contrib/git-descr.sh" $@; } ; f'
26 git config alias.gcc-undescr '!f() { "`git rev-parse --show-toplevel`/contrib/git-undescr.sh" $@; } ; f'
28 git config alias.gcc-verify '!f() { "`git rev-parse --show-toplevel`/contrib/gcc-changelog/git_check_commit.py" $@; } ; f'
29 git config alias.gcc-backport '!f() { "`git rev-parse --show-toplevel`/contrib/git-backport.py" $@; } ; f'
30 git config alias.gcc-fix-changelog '!f() { "`git rev-parse --show-toplevel`/contrib/git-fix-changelog.py" $@; } ; f'
31 git config alias.gcc-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/mklog.py" $@; } ; f'
32 git config alias.gcc-commit-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/git-commit-mklog.py" "$@"; }; f'
34 # Make diff on MD files use "(define" as a function marker.
35 # Use this in conjunction with a .gitattributes file containing
36 # *.md diff=md
37 git config diff.md.xfuncname '^\(define.*$'
39 # Tell git send-email where patches go.
40 # ??? Maybe also set sendemail.tocmd to guess from MAINTAINERS?
41 git config sendemail.to 'gcc-patches@gcc.gnu.org'
43 set_user=$(git config --get "user.name")
44 set_email=$(git config --get "user.email")
46 if [ "x$set_user" = "x" ]
47 then
48 # Try to guess the user's name by looking it up in the password file
49 if type getent >/dev/null 2>&1; then
50 new_user=$(getent passwd $(whoami) | awk -F: '{ print $5 }')
51 elif [ $(uname -s) = Darwin ]; then
52 new_user=$(id -F 2>/dev/null)
54 if [ "x$new_user" = "x" ]
55 then
56 new_user="(no default)"
58 else
59 new_user=$set_user
61 ask "Your name" "${new_user}" new_user
62 if [ "x$new_user" = "x(no default)" ]
63 then
64 echo "Cannot continue, git needs to record your name against commits"
65 exit 1
68 if [ "x$set_email" = "x" ]
69 then
70 new_email="(no_default)"
71 else
72 new_email=$set_email
75 ask "Your email address (for git commits)" "${new_email}" new_email
76 if [ "x$new_email" = "x(no default)" ]
77 then
78 echo "Cannot continue, git needs to record your email address against commits"
79 exit 1
82 if [ "x$set_user" != "x$new_user" ]
83 then
84 git config "user.name" "$new_user"
87 if [ "x$set_email" != "x$new_email" ]
88 then
89 git config "user.email" "$new_email"
92 upstream=$(git config --get "gcc-config.upstream")
93 if [ "x$upstream" = "x" ]
94 then
95 upstream="origin"
97 ask "Local name for upstream repository" "origin" upstream
99 v=$(git config --get-all "remote.${upstream}.fetch")
100 if [ "x$v" = "x" ]
101 then
102 echo "Remote $upstream does not seem to exist as a remote"
103 exit 1
105 git config "gcc-config.upstream" "$upstream"
107 remote_id=$(git config --get "gcc-config.user")
108 if [ "x$remote_id" = "x" ]
109 then
110 # See if the url specifies the remote user name.
111 url=$(git config --get "remote.$upstream.url")
112 if [ "x$url" = "x" ]
113 then
114 # This is a pure guess, but for many people it might be OK.
115 remote_id=$(whoami)
116 else
117 remote_id=$(echo $url | sed 's|^.*ssh://\(..*\)@gcc.gnu.org.*$|\1|')
118 if [ x$remote_id = x$url ]
119 then
120 remote_id=$(whoami)
125 ask "Account name on gcc.gnu.org (for your personal branches area)" "$remote_id" remote_id
126 git config "gcc-config.user" "$remote_id"
128 old_pfx=$(git config --get "gcc-config.userpfx")
129 if [ "x$old_pfx" = "x" ]
130 then
131 old_pfx="me"
133 echo
134 echo "Local branch prefix for personal branches you want to share"
135 echo "(local branches starting <prefix>/ can be pushed directly to your"
136 ask "personal area on the gcc server)" $old_pfx new_pfx
137 git config "gcc-config.userpfx" "$new_pfx"
139 echo
140 ask "Install prepare-commit-msg git hook for 'git commit-mklog' alias" yes dohook
141 if [ "x$dohook" = xyes ]; then
142 hookdir=`git rev-parse --git-path hooks 2>/dev/null`
143 if [ $? -eq 0 ]; then
144 if [ -f "$hookdir/prepare-commit-msg" ]; then
145 echo " Moving existing prepare-commit-msg hook to prepare-commit-msg.bak"
146 mv "$hookdir/prepare-commit-msg" "$hookdir/prepare-commit-msg.bak"
148 install -c "`git rev-parse --show-toplevel`/contrib/prepare-commit-msg" "$hookdir"
149 else
150 echo " `git --version` is too old, cannot find hooks dir"
154 # Scan the existing settings to see if there are any we need to rewrite.
155 vendors=$(git config --get-all "remote.${upstream}.fetch" "refs/vendors/" | sed 's:.*refs/vendors/\([^/][^/]*\)/.*:\1:' | sort | uniq)
156 url=$(git config --get "remote.${upstream}.url")
157 pushurl=$(git config --get "remote.${upstream}.pushurl")
158 for v in $vendors
160 echo "Migrating vendor \"$v\" to new remote \"vendors/$v\""
161 git config --unset-all "remote.${upstream}.fetch" "refs/vendors/$v/"
162 git config --unset-all "remote.${upstream}.push" "refs/vendors/$v/"
163 git config "remote.vendors/${v}.url" "${url}"
164 if [ "x$pushurl" != "x" ]
165 then
166 git config "remote.vendors/${v}.pushurl" "${pushurl}"
168 git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/heads/*:refs/remotes/vendors/${v}/*"
169 git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/tags/*:refs/tags/vendors/${v}/*"
170 done
172 # Convert the remote 'pfx' to users/pfx to avoid problems with ambiguous refs
173 # on user branches
174 old_remote=$(git config --get "remote.${old_pfx}.url")
175 if [ -n "${old_remote}" ]
176 then
177 echo "Migrating remote \"${old_pfx}\" to new remote \"users/${new_pfx}\""
178 # Create a dummy fetch rule that will cause the subsequent prune to remove the old remote refs.
179 git config --replace-all "remote.${old_pfx}.fetch" "+refs/empty/*:refs/remotes/${old_pfx}/*"
180 # Remove any remotes
181 git remote prune ${old_pfx}
182 git config --remove-section "remote.${old_pfx}"
183 for br in $(git branch --list "${old_pfx}/*")
185 old_remote=$(git config --get "branch.${br}.remote")
186 if [ "${old_remote}" = "${old_pfx}" ]
187 then
188 git config "branch.${br}.remote" "users/${new_pfx}"
190 done
193 echo "Setting up tracking for personal namespace $remote_id in remotes/users/${new_pfx}"
194 git config "remote.users/${new_pfx}.url" "${url}"
195 if [ "x$pushurl" != "x" ]
196 then
197 git config "remote.users/${new_pfx}.pushurl" "${pushurl}"
199 git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/users/${new_pfx}/*" "refs/users/${remote_id}/heads/"
200 git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/users/${new_pfx}/*" "refs/users/${remote_id}/tags/"
201 git config --replace-all "remote.users/${new_pfx}.push" "refs/heads/${new_pfx}/*:refs/users/${remote_id}/heads/*" "refs/users/${remote_id}"
203 if [ "$old_pfx" != "$new_pfx" -a "$old_pfx" != "${upstream}" ]
204 then
205 git config --remove-section "remote.${old_pfx}"
208 git config --unset-all "remote.${upstream}.fetch" "refs/users/${remote_id}/"
209 git config --unset-all "remote.${upstream}.push" "refs/users/${remote_id}/"
211 git fetch "users/${new_pfx}"