]>
Commit | Line | Data |
---|---|---|
743d4d82 RE |
1 | #!/bin/sh |
2 | ||
3 | # Script to add some local git customizations suitable for working | |
4 | # with the GCC git repository | |
5 | ||
6 | ask () { | |
7 | question=$1 | |
8 | default=$2 | |
9 | var=$3 | |
d563b0bf | 10 | printf "%s [%s]? " "$question" "$default" |
743d4d82 RE |
11 | read answer |
12 | if [ "x$answer" = "x" ] | |
13 | then | |
7aa4e0db | 14 | eval $var=\$default |
743d4d82 | 15 | else |
7aa4e0db | 16 | eval $var=\$answer |
743d4d82 RE |
17 | fi |
18 | } | |
19 | ||
20 | # Add a git command to find the git commit equivalent to legacy SVN revision NNN | |
fa4aab7f | 21 | git config alias.svn-rev '!f() { rev=$1; shift; git log --all --grep="^From-SVN: r\\?$rev\\b" "${@}"; } ; f' |
743d4d82 | 22 | |
e19db6a2 JJ |
23 | # Add git commands to convert git commit to monotonically increasing revision number |
24 | # and vice versa | |
9cbfbe24 ML |
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' | |
e19db6a2 | 27 | |
c3b44e34 | 28 | git config alias.gcc-verify '!f() { "`git rev-parse --show-toplevel`/contrib/gcc-changelog/git_check_commit.py" $@; } ; f' |
e247d592 | 29 | git config alias.gcc-backport '!f() { "`git rev-parse --show-toplevel`/contrib/git-backport.py" $@; } ; f' |
03b0bf78 | 30 | git config alias.gcc-fix-changelog '!f() { "`git rev-parse --show-toplevel`/contrib/git-fix-changelog.py" $@; } ; f' |
00243d9a | 31 | git config alias.gcc-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/mklog.py" $@; } ; f' |
0684c8d3 | 32 | git config alias.gcc-commit-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/git-commit-mklog.py" "$@"; }; f' |
757dbb59 | 33 | |
affb7b66 | 34 | # Make diff on MD files use "(define" as a function marker. |
743d4d82 RE |
35 | # Use this in conjunction with a .gitattributes file containing |
36 | # *.md diff=md | |
37 | git config diff.md.xfuncname '^\(define.*$' | |
38 | ||
4ed34c60 JM |
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' | |
42 | ||
545f5fad RE |
43 | set_user=$(git config --get "user.name") |
44 | set_email=$(git config --get "user.email") | |
45 | ||
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 | new_user=$(getent passwd $(whoami) | awk -F: '{ print $5 }') | |
50 | if [ "x$new_user" = "x" ] | |
51 | then | |
52 | new_user="(no default)" | |
53 | fi | |
54 | else | |
55 | new_user=$set_user | |
56 | fi | |
57 | ask "Your name" "${new_user}" new_user | |
58 | if [ "x$new_user" = "x(no default)" ] | |
59 | then | |
60 | echo "Cannot continue, git needs to record your name against commits" | |
61 | exit 1 | |
62 | fi | |
63 | ||
64 | if [ "x$set_email" = "x" ] | |
65 | then | |
66 | new_email="(no_default)" | |
67 | else | |
68 | new_email=$set_email | |
69 | fi | |
70 | ||
71 | ask "Your email address (for git commits)" "${new_email}" new_email | |
72 | if [ "x$new_email" = "x(no default)" ] | |
73 | then | |
74 | echo "Cannot continue, git needs to record your email address against commits" | |
75 | exit 1 | |
76 | fi | |
77 | ||
78 | if [ "x$set_user" != "x$new_user" ] | |
79 | then | |
80 | git config "user.name" "$new_user" | |
81 | fi | |
82 | ||
83 | if [ "x$set_email" != "x$new_email" ] | |
84 | then | |
85 | git config "user.email" "$new_email" | |
86 | fi | |
87 | ||
88 | upstream=$(git config --get "gcc-config.upstream") | |
743d4d82 RE |
89 | if [ "x$upstream" = "x" ] |
90 | then | |
91 | upstream="origin" | |
92 | fi | |
93 | ask "Local name for upstream repository" "origin" upstream | |
24b17818 RE |
94 | |
95 | v=$(git config --get-all "remote.${upstream}.fetch") | |
96 | if [ "x$v" = "x" ] | |
97 | then | |
98 | echo "Remote $upstream does not seem to exist as a remote" | |
99 | exit 1 | |
100 | fi | |
743d4d82 RE |
101 | git config "gcc-config.upstream" "$upstream" |
102 | ||
545f5fad | 103 | remote_id=$(git config --get "gcc-config.user") |
743d4d82 RE |
104 | if [ "x$remote_id" = "x" ] |
105 | then | |
106 | # See if the url specifies the remote user name. | |
545f5fad | 107 | url=$(git config --get "remote.$upstream.url") |
743d4d82 RE |
108 | if [ "x$url" = "x" ] |
109 | then | |
110 | # This is a pure guess, but for many people it might be OK. | |
545f5fad | 111 | remote_id=$(whoami) |
743d4d82 | 112 | else |
d563b0bf | 113 | remote_id=$(echo $url | sed 's|^.*ssh://\(..*\)@gcc.gnu.org.*$|\1|') |
743d4d82 RE |
114 | if [ x$remote_id = x$url ] |
115 | then | |
545f5fad | 116 | remote_id=$(whoami) |
743d4d82 RE |
117 | fi |
118 | fi | |
119 | fi | |
24b17818 | 120 | |
d563b0bf | 121 | ask "Account name on gcc.gnu.org (for your personal branches area)" "$remote_id" remote_id |
743d4d82 RE |
122 | git config "gcc-config.user" "$remote_id" |
123 | ||
545f5fad | 124 | old_pfx=$(git config --get "gcc-config.userpfx") |
743d4d82 RE |
125 | if [ "x$old_pfx" = "x" ] |
126 | then | |
127 | old_pfx="me" | |
128 | fi | |
24b17818 | 129 | echo |
743d4d82 RE |
130 | echo "Local branch prefix for personal branches you want to share" |
131 | echo "(local branches starting <prefix>/ can be pushed directly to your" | |
132 | ask "personal area on the gcc server)" $old_pfx new_pfx | |
133 | git config "gcc-config.userpfx" "$new_pfx" | |
134 | ||
757dbb59 JM |
135 | echo |
136 | ask "Install prepare-commit-msg git hook for 'git commit-mklog' alias" yes dohook | |
137 | if [ "x$dohook" = xyes ]; then | |
d563b0bf JW |
138 | hookdir=`git rev-parse --git-path hooks 2>/dev/null` |
139 | if [ $? -eq 0 ]; then | |
140 | if [ -f "$hookdir/prepare-commit-msg" ]; then | |
141 | echo " Moving existing prepare-commit-msg hook to prepare-commit-msg.bak" | |
142 | mv "$hookdir/prepare-commit-msg" "$hookdir/prepare-commit-msg.bak" | |
143 | fi | |
144 | install -c "`git rev-parse --show-toplevel`/contrib/prepare-commit-msg" "$hookdir" | |
145 | else | |
146 | echo " `git --version` is too old, cannot find hooks dir" | |
757dbb59 | 147 | fi |
757dbb59 JM |
148 | fi |
149 | ||
24b17818 | 150 | # Scan the existing settings to see if there are any we need to rewrite. |
d563b0bf | 151 | vendors=$(git config --get-all "remote.${upstream}.fetch" "refs/vendors/" | sed 's:.*refs/vendors/\([^/][^/]*\)/.*:\1:' | sort | uniq) |
24b17818 RE |
152 | url=$(git config --get "remote.${upstream}.url") |
153 | pushurl=$(git config --get "remote.${upstream}.pushurl") | |
154 | for v in $vendors | |
155 | do | |
612137e1 | 156 | echo "Migrating vendor \"$v\" to new remote \"vendors/$v\"" |
24b17818 RE |
157 | git config --unset-all "remote.${upstream}.fetch" "refs/vendors/$v/" |
158 | git config --unset-all "remote.${upstream}.push" "refs/vendors/$v/" | |
159 | git config "remote.vendors/${v}.url" "${url}" | |
160 | if [ "x$pushurl" != "x" ] | |
161 | then | |
162 | git config "remote.vendors/${v}.pushurl" "${pushurl}" | |
163 | fi | |
164 | git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/heads/*:refs/remotes/vendors/${v}/*" | |
165 | git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/tags/*:refs/tags/vendors/${v}/*" | |
166 | done | |
e6107422 | 167 | |
612137e1 RE |
168 | # Convert the remote 'pfx' to users/pfx to avoid problems with ambiguous refs |
169 | # on user branches | |
170 | old_remote=$(git config --get "remote.${old_pfx}.url") | |
171 | if [ -n "${old_remote}" ] | |
172 | then | |
173 | echo "Migrating remote \"${old_pfx}\" to new remote \"users/${new_pfx}\"" | |
174 | # Create a dummy fetch rule that will cause the subsequent prune to remove the old remote refs. | |
175 | git config --replace-all "remote.${old_pfx}.fetch" "+refs/empty/*:refs/remotes/${old_pfx}/*" | |
176 | # Remove any remotes | |
177 | git remote prune ${old_pfx} | |
178 | git config --remove-section "remote.${old_pfx}" | |
179 | for br in $(git branch --list "${old_pfx}/*") | |
180 | do | |
181 | old_remote=$(git config --get "branch.${br}.remote") | |
182 | if [ "${old_remote}" = "${old_pfx}" ] | |
183 | then | |
184 | git config "branch.${br}.remote" "users/${new_pfx}" | |
185 | fi | |
186 | done | |
187 | fi | |
188 | ||
189 | echo "Setting up tracking for personal namespace $remote_id in remotes/users/${new_pfx}" | |
190 | git config "remote.users/${new_pfx}.url" "${url}" | |
24b17818 | 191 | if [ "x$pushurl" != "x" ] |
e6107422 | 192 | then |
612137e1 | 193 | git config "remote.users/${new_pfx}.pushurl" "${pushurl}" |
e6107422 | 194 | fi |
612137e1 RE |
195 | git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/users/${new_pfx}/*" "refs/users/${remote_id}/heads/" |
196 | git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/users/${new_pfx}/*" "refs/users/${remote_id}/tags/" | |
197 | git config --replace-all "remote.users/${new_pfx}.push" "refs/heads/${new_pfx}/*:refs/users/${remote_id}/heads/*" "refs/users/${remote_id}" | |
24b17818 RE |
198 | |
199 | if [ "$old_pfx" != "$new_pfx" -a "$old_pfx" != "${upstream}" ] | |
200 | then | |
201 | git config --remove-section "remote.${old_pfx}" | |
202 | fi | |
203 | ||
204 | git config --unset-all "remote.${upstream}.fetch" "refs/users/${remote_id}/" | |
205 | git config --unset-all "remote.${upstream}.push" "refs/users/${remote_id}/" | |
612137e1 RE |
206 | |
207 | git fetch "users/${new_pfx}" |