]>
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' |
af3fc030 JM |
33 | git config alias.gcc-style '!f() { |
34 | check=`git rev-parse --show-toplevel`/contrib/check_GNU_style.py; | |
35 | arg=; if [ $# -ge 1 ] && [ "$1" != "-f" ]; then arg="$1"; shift; | |
36 | elif [ $# -eq 3 ]; then arg="$3"; set -- "$1" "$2"; fi | |
37 | git show $arg | $check "$@" -; }; f' | |
757dbb59 | 38 | |
affb7b66 | 39 | # Make diff on MD files use "(define" as a function marker. |
743d4d82 RE |
40 | # Use this in conjunction with a .gitattributes file containing |
41 | # *.md diff=md | |
42 | git config diff.md.xfuncname '^\(define.*$' | |
43 | ||
4ed34c60 JM |
44 | # Tell git send-email where patches go. |
45 | # ??? Maybe also set sendemail.tocmd to guess from MAINTAINERS? | |
46 | git config sendemail.to 'gcc-patches@gcc.gnu.org' | |
47 | ||
545f5fad RE |
48 | set_user=$(git config --get "user.name") |
49 | set_email=$(git config --get "user.email") | |
50 | ||
51 | if [ "x$set_user" = "x" ] | |
52 | then | |
53 | # Try to guess the user's name by looking it up in the password file | |
5c3c0496 JW |
54 | if type getent >/dev/null 2>&1; then |
55 | new_user=$(getent passwd $(whoami) | awk -F: '{ print $5 }') | |
56 | elif [ $(uname -s) = Darwin ]; then | |
57 | new_user=$(id -F 2>/dev/null) | |
58 | fi | |
545f5fad RE |
59 | if [ "x$new_user" = "x" ] |
60 | then | |
61 | new_user="(no default)" | |
62 | fi | |
63 | else | |
64 | new_user=$set_user | |
65 | fi | |
66 | ask "Your name" "${new_user}" new_user | |
67 | if [ "x$new_user" = "x(no default)" ] | |
68 | then | |
69 | echo "Cannot continue, git needs to record your name against commits" | |
70 | exit 1 | |
71 | fi | |
72 | ||
73 | if [ "x$set_email" = "x" ] | |
74 | then | |
75 | new_email="(no_default)" | |
76 | else | |
77 | new_email=$set_email | |
78 | fi | |
79 | ||
80 | ask "Your email address (for git commits)" "${new_email}" new_email | |
81 | if [ "x$new_email" = "x(no default)" ] | |
82 | then | |
83 | echo "Cannot continue, git needs to record your email address against commits" | |
84 | exit 1 | |
85 | fi | |
86 | ||
87 | if [ "x$set_user" != "x$new_user" ] | |
88 | then | |
89 | git config "user.name" "$new_user" | |
90 | fi | |
91 | ||
92 | if [ "x$set_email" != "x$new_email" ] | |
93 | then | |
94 | git config "user.email" "$new_email" | |
95 | fi | |
96 | ||
97 | upstream=$(git config --get "gcc-config.upstream") | |
743d4d82 RE |
98 | if [ "x$upstream" = "x" ] |
99 | then | |
100 | upstream="origin" | |
101 | fi | |
102 | ask "Local name for upstream repository" "origin" upstream | |
24b17818 RE |
103 | |
104 | v=$(git config --get-all "remote.${upstream}.fetch") | |
105 | if [ "x$v" = "x" ] | |
106 | then | |
107 | echo "Remote $upstream does not seem to exist as a remote" | |
108 | exit 1 | |
109 | fi | |
743d4d82 RE |
110 | git config "gcc-config.upstream" "$upstream" |
111 | ||
545f5fad | 112 | remote_id=$(git config --get "gcc-config.user") |
743d4d82 RE |
113 | if [ "x$remote_id" = "x" ] |
114 | then | |
115 | # See if the url specifies the remote user name. | |
545f5fad | 116 | url=$(git config --get "remote.$upstream.url") |
743d4d82 RE |
117 | if [ "x$url" = "x" ] |
118 | then | |
119 | # This is a pure guess, but for many people it might be OK. | |
545f5fad | 120 | remote_id=$(whoami) |
743d4d82 | 121 | else |
d563b0bf | 122 | remote_id=$(echo $url | sed 's|^.*ssh://\(..*\)@gcc.gnu.org.*$|\1|') |
743d4d82 RE |
123 | if [ x$remote_id = x$url ] |
124 | then | |
545f5fad | 125 | remote_id=$(whoami) |
743d4d82 RE |
126 | fi |
127 | fi | |
128 | fi | |
24b17818 | 129 | |
d563b0bf | 130 | ask "Account name on gcc.gnu.org (for your personal branches area)" "$remote_id" remote_id |
743d4d82 RE |
131 | git config "gcc-config.user" "$remote_id" |
132 | ||
545f5fad | 133 | old_pfx=$(git config --get "gcc-config.userpfx") |
743d4d82 RE |
134 | if [ "x$old_pfx" = "x" ] |
135 | then | |
136 | old_pfx="me" | |
137 | fi | |
24b17818 | 138 | echo |
743d4d82 RE |
139 | echo "Local branch prefix for personal branches you want to share" |
140 | echo "(local branches starting <prefix>/ can be pushed directly to your" | |
141 | ask "personal area on the gcc server)" $old_pfx new_pfx | |
142 | git config "gcc-config.userpfx" "$new_pfx" | |
143 | ||
757dbb59 JM |
144 | echo |
145 | ask "Install prepare-commit-msg git hook for 'git commit-mklog' alias" yes dohook | |
146 | if [ "x$dohook" = xyes ]; then | |
d563b0bf JW |
147 | hookdir=`git rev-parse --git-path hooks 2>/dev/null` |
148 | if [ $? -eq 0 ]; then | |
149 | if [ -f "$hookdir/prepare-commit-msg" ]; then | |
150 | echo " Moving existing prepare-commit-msg hook to prepare-commit-msg.bak" | |
151 | mv "$hookdir/prepare-commit-msg" "$hookdir/prepare-commit-msg.bak" | |
152 | fi | |
153 | install -c "`git rev-parse --show-toplevel`/contrib/prepare-commit-msg" "$hookdir" | |
154 | else | |
155 | echo " `git --version` is too old, cannot find hooks dir" | |
757dbb59 | 156 | fi |
757dbb59 JM |
157 | fi |
158 | ||
24b17818 | 159 | # Scan the existing settings to see if there are any we need to rewrite. |
d563b0bf | 160 | vendors=$(git config --get-all "remote.${upstream}.fetch" "refs/vendors/" | sed 's:.*refs/vendors/\([^/][^/]*\)/.*:\1:' | sort | uniq) |
24b17818 RE |
161 | url=$(git config --get "remote.${upstream}.url") |
162 | pushurl=$(git config --get "remote.${upstream}.pushurl") | |
163 | for v in $vendors | |
164 | do | |
612137e1 | 165 | echo "Migrating vendor \"$v\" to new remote \"vendors/$v\"" |
24b17818 RE |
166 | git config --unset-all "remote.${upstream}.fetch" "refs/vendors/$v/" |
167 | git config --unset-all "remote.${upstream}.push" "refs/vendors/$v/" | |
168 | git config "remote.vendors/${v}.url" "${url}" | |
169 | if [ "x$pushurl" != "x" ] | |
170 | then | |
171 | git config "remote.vendors/${v}.pushurl" "${pushurl}" | |
172 | fi | |
173 | git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/heads/*:refs/remotes/vendors/${v}/*" | |
174 | git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/tags/*:refs/tags/vendors/${v}/*" | |
175 | done | |
e6107422 | 176 | |
612137e1 RE |
177 | # Convert the remote 'pfx' to users/pfx to avoid problems with ambiguous refs |
178 | # on user branches | |
179 | old_remote=$(git config --get "remote.${old_pfx}.url") | |
180 | if [ -n "${old_remote}" ] | |
181 | then | |
182 | echo "Migrating remote \"${old_pfx}\" to new remote \"users/${new_pfx}\"" | |
183 | # Create a dummy fetch rule that will cause the subsequent prune to remove the old remote refs. | |
184 | git config --replace-all "remote.${old_pfx}.fetch" "+refs/empty/*:refs/remotes/${old_pfx}/*" | |
185 | # Remove any remotes | |
186 | git remote prune ${old_pfx} | |
187 | git config --remove-section "remote.${old_pfx}" | |
188 | for br in $(git branch --list "${old_pfx}/*") | |
189 | do | |
190 | old_remote=$(git config --get "branch.${br}.remote") | |
191 | if [ "${old_remote}" = "${old_pfx}" ] | |
192 | then | |
193 | git config "branch.${br}.remote" "users/${new_pfx}" | |
194 | fi | |
195 | done | |
196 | fi | |
197 | ||
198 | echo "Setting up tracking for personal namespace $remote_id in remotes/users/${new_pfx}" | |
199 | git config "remote.users/${new_pfx}.url" "${url}" | |
24b17818 | 200 | if [ "x$pushurl" != "x" ] |
e6107422 | 201 | then |
612137e1 | 202 | git config "remote.users/${new_pfx}.pushurl" "${pushurl}" |
e6107422 | 203 | fi |
612137e1 RE |
204 | git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/users/${new_pfx}/*" "refs/users/${remote_id}/heads/" |
205 | git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/users/${new_pfx}/*" "refs/users/${remote_id}/tags/" | |
206 | git config --replace-all "remote.users/${new_pfx}.push" "refs/heads/${new_pfx}/*:refs/users/${remote_id}/heads/*" "refs/users/${remote_id}" | |
24b17818 RE |
207 | |
208 | if [ "$old_pfx" != "$new_pfx" -a "$old_pfx" != "${upstream}" ] | |
209 | then | |
210 | git config --remove-section "remote.${old_pfx}" | |
211 | fi | |
212 | ||
213 | git config --unset-all "remote.${upstream}.fetch" "refs/users/${remote_id}/" | |
214 | git config --unset-all "remote.${upstream}.push" "refs/users/${remote_id}/" | |
612137e1 RE |
215 | |
216 | git fetch "users/${new_pfx}" |