Daily bump.
[official-gcc.git] / contrib / gcc-git-customization.sh
blobaca61b781ff202bdfc77586bc46ec034dba3b7b7
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 echo -n $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() { if test \${1:-no} = --full; then c=\${2:-master}; r=\$(git describe --all --abbrev=40 --match 'basepoints/gcc-[0-9]*' \$c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-,r,p'); expr match \${r:-no} '^r[0-9]\\+\$' >/dev/null && r=\${r}-0-g\$(git rev-parse \${2:-master}); else c=\${1:-master}; r=\$(git describe --all --match 'basepoints/gcc-[0-9]*' \$c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-\\([0-9]\\+\\)-\\([0-9]\\+\\)-g[0-9a-f]*\$,r\\2-\\3,p;s,^\\(tags/\\)\\?basepoints/gcc-\\([0-9]\\+\\)\$,r\\2-0,p'); fi; if test -n \$r; then o=\$(git config --get gcc-config.upstream); rr=\$(echo \$r | sed -n 's,^r\\([0-9]\\+\\)-[0-9]\\+\\(-g[0-9a-f]\\+\\)\\?\$,\\1,p'); if git rev-parse --verify --quiet \${o:-origin}/releases/gcc-\$rr >/dev/null; then m=releases/gcc-\$rr; else m=master; fi; git merge-base --is-ancestor \$c \${o:-origin}/\$m && \echo \${r}; fi; }; f"
26 git config alias.gcc-undescr \!"f() { o=\$(git config --get gcc-config.upstream); r=\$(echo \$1 | sed -n 's,^r\\([0-9]\\+\\)-[0-9]\\+\$,\\1,p'); n=\$(echo \$1 | sed -n 's,^r[0-9]\\+-\\([0-9]\\+\\)\$,\\1,p'); test -z \$r && echo Invalid id \$1 && exit 1; h=\$(git rev-parse --verify --quiet \${o:-origin}/releases/gcc-\$r); test -z \$h && h=\$(git rev-parse --verify --quiet \${o:-origin}/master); p=\$(git describe --all --match 'basepoints/gcc-'\$r \$h | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+-\\([0-9]\\+\\)-g[0-9a-f]*\$,\\2,p;s,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+\$,0,p'); git rev-parse --verify \$h~\$(expr \$p - \$n); }; 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-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/mklog.py" $@; } ; f'
31 git config alias.gcc-commit-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/git-commit-mklog.py" "$@"; }; f'
33 # Make diff on MD files use "(define" as a function marker.
34 # Use this in conjunction with a .gitattributes file containing
35 # *.md diff=md
36 git config diff.md.xfuncname '^\(define.*$'
38 # Tell git send-email where patches go.
39 # ??? Maybe also set sendemail.tocmd to guess from MAINTAINERS?
40 git config sendemail.to 'gcc-patches@gcc.gnu.org'
42 set_user=$(git config --get "user.name")
43 set_email=$(git config --get "user.email")
45 if [ "x$set_user" = "x" ]
46 then
47 # Try to guess the user's name by looking it up in the password file
48 new_user=$(getent passwd $(whoami) | awk -F: '{ print $5 }')
49 if [ "x$new_user" = "x" ]
50 then
51 new_user="(no default)"
53 else
54 new_user=$set_user
56 ask "Your name" "${new_user}" new_user
57 if [ "x$new_user" = "x(no default)" ]
58 then
59 echo "Cannot continue, git needs to record your name against commits"
60 exit 1
63 if [ "x$set_email" = "x" ]
64 then
65 new_email="(no_default)"
66 else
67 new_email=$set_email
70 ask "Your email address (for git commits)" "${new_email}" new_email
71 if [ "x$new_email" = "x(no default)" ]
72 then
73 echo "Cannot continue, git needs to record your email address against commits"
74 exit 1
77 if [ "x$set_user" != "x$new_user" ]
78 then
79 git config "user.name" "$new_user"
82 if [ "x$set_email" != "x$new_email" ]
83 then
84 git config "user.email" "$new_email"
87 upstream=$(git config --get "gcc-config.upstream")
88 if [ "x$upstream" = "x" ]
89 then
90 upstream="origin"
92 ask "Local name for upstream repository" "origin" upstream
94 v=$(git config --get-all "remote.${upstream}.fetch")
95 if [ "x$v" = "x" ]
96 then
97 echo "Remote $upstream does not seem to exist as a remote"
98 exit 1
100 git config "gcc-config.upstream" "$upstream"
102 remote_id=$(git config --get "gcc-config.user")
103 if [ "x$remote_id" = "x" ]
104 then
105 # See if the url specifies the remote user name.
106 url=$(git config --get "remote.$upstream.url")
107 if [ "x$url" = "x" ]
108 then
109 # This is a pure guess, but for many people it might be OK.
110 remote_id=$(whoami)
111 else
112 remote_id=$(echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|")
113 if [ x$remote_id = x$url ]
114 then
115 remote_id=$(whoami)
120 ask "Account name on gcc.gnu.org (for your personal branches area)" $remote_id remote_id
121 git config "gcc-config.user" "$remote_id"
123 old_pfx=$(git config --get "gcc-config.userpfx")
124 if [ "x$old_pfx" = "x" ]
125 then
126 old_pfx="me"
128 echo
129 echo "Local branch prefix for personal branches you want to share"
130 echo "(local branches starting <prefix>/ can be pushed directly to your"
131 ask "personal area on the gcc server)" $old_pfx new_pfx
132 git config "gcc-config.userpfx" "$new_pfx"
134 echo
135 ask "Install prepare-commit-msg git hook for 'git commit-mklog' alias" yes dohook
136 if [ "x$dohook" = xyes ]; then
137 hookdir=`git rev-parse --git-path hooks`
138 if [ -f "$hookdir/prepare-commit-msg" ]; then
139 echo " Moving existing prepare-commit-msg hook to prepare-commit-msg.bak"
140 mv "$hookdir/prepare-commit-msg" "$hookdir/prepare-commit-msg.bak"
142 install -c "`git rev-parse --show-toplevel`/contrib/prepare-commit-msg" "$hookdir"
145 # Scan the existing settings to see if there are any we need to rewrite.
146 vendors=$(git config --get-all "remote.${upstream}.fetch" "refs/vendors/" | sed -r "s:.*refs/vendors/([^/]+)/.*:\1:" | sort | uniq)
147 url=$(git config --get "remote.${upstream}.url")
148 pushurl=$(git config --get "remote.${upstream}.pushurl")
149 for v in $vendors
151 echo "Migrating vendor \"$v\" to new remote \"vendors/$v\""
152 git config --unset-all "remote.${upstream}.fetch" "refs/vendors/$v/"
153 git config --unset-all "remote.${upstream}.push" "refs/vendors/$v/"
154 git config "remote.vendors/${v}.url" "${url}"
155 if [ "x$pushurl" != "x" ]
156 then
157 git config "remote.vendors/${v}.pushurl" "${pushurl}"
159 git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/heads/*:refs/remotes/vendors/${v}/*"
160 git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/tags/*:refs/tags/vendors/${v}/*"
161 done
163 # Convert the remote 'pfx' to users/pfx to avoid problems with ambiguous refs
164 # on user branches
165 old_remote=$(git config --get "remote.${old_pfx}.url")
166 if [ -n "${old_remote}" ]
167 then
168 echo "Migrating remote \"${old_pfx}\" to new remote \"users/${new_pfx}\""
169 # Create a dummy fetch rule that will cause the subsequent prune to remove the old remote refs.
170 git config --replace-all "remote.${old_pfx}.fetch" "+refs/empty/*:refs/remotes/${old_pfx}/*"
171 # Remove any remotes
172 git remote prune ${old_pfx}
173 git config --remove-section "remote.${old_pfx}"
174 for br in $(git branch --list "${old_pfx}/*")
176 old_remote=$(git config --get "branch.${br}.remote")
177 if [ "${old_remote}" = "${old_pfx}" ]
178 then
179 git config "branch.${br}.remote" "users/${new_pfx}"
181 done
184 echo "Setting up tracking for personal namespace $remote_id in remotes/users/${new_pfx}"
185 git config "remote.users/${new_pfx}.url" "${url}"
186 if [ "x$pushurl" != "x" ]
187 then
188 git config "remote.users/${new_pfx}.pushurl" "${pushurl}"
190 git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/users/${new_pfx}/*" "refs/users/${remote_id}/heads/"
191 git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/users/${new_pfx}/*" "refs/users/${remote_id}/tags/"
192 git config --replace-all "remote.users/${new_pfx}.push" "refs/heads/${new_pfx}/*:refs/users/${remote_id}/heads/*" "refs/users/${remote_id}"
194 if [ "$old_pfx" != "$new_pfx" -a "$old_pfx" != "${upstream}" ]
195 then
196 git config --remove-section "remote.${old_pfx}"
199 git config --unset-all "remote.${upstream}.fetch" "refs/users/${remote_id}/"
200 git config --unset-all "remote.${upstream}.push" "refs/users/${remote_id}/"
202 git fetch "users/${new_pfx}"