]>
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 | |
10 | echo -n $question "["$default"]? " | |
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 | |
2588197b | 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" |
6ff7efb7 | 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" |
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' |
00243d9a | 30 | git config alias.gcc-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/mklog.py" $@; } ; f' |
0684c8d3 | 31 | git config alias.gcc-commit-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/git-commit-mklog.py" "$@"; }; f' |
757dbb59 | 32 | |
affb7b66 | 33 | # Make diff on MD files use "(define" as a function marker. |
743d4d82 RE |
34 | # Use this in conjunction with a .gitattributes file containing |
35 | # *.md diff=md | |
36 | git config diff.md.xfuncname '^\(define.*$' | |
37 | ||
4ed34c60 JM |
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' | |
41 | ||
545f5fad RE |
42 | set_user=$(git config --get "user.name") |
43 | set_email=$(git config --get "user.email") | |
44 | ||
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)" | |
52 | fi | |
53 | else | |
54 | new_user=$set_user | |
55 | fi | |
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 | |
61 | fi | |
62 | ||
63 | if [ "x$set_email" = "x" ] | |
64 | then | |
65 | new_email="(no_default)" | |
66 | else | |
67 | new_email=$set_email | |
68 | fi | |
69 | ||
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 | |
75 | fi | |
76 | ||
77 | if [ "x$set_user" != "x$new_user" ] | |
78 | then | |
79 | git config "user.name" "$new_user" | |
80 | fi | |
81 | ||
82 | if [ "x$set_email" != "x$new_email" ] | |
83 | then | |
84 | git config "user.email" "$new_email" | |
85 | fi | |
86 | ||
87 | upstream=$(git config --get "gcc-config.upstream") | |
743d4d82 RE |
88 | if [ "x$upstream" = "x" ] |
89 | then | |
90 | upstream="origin" | |
91 | fi | |
92 | ask "Local name for upstream repository" "origin" upstream | |
24b17818 RE |
93 | |
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 | |
99 | fi | |
743d4d82 RE |
100 | git config "gcc-config.upstream" "$upstream" |
101 | ||
545f5fad | 102 | remote_id=$(git config --get "gcc-config.user") |
743d4d82 RE |
103 | if [ "x$remote_id" = "x" ] |
104 | then | |
105 | # See if the url specifies the remote user name. | |
545f5fad | 106 | url=$(git config --get "remote.$upstream.url") |
743d4d82 RE |
107 | if [ "x$url" = "x" ] |
108 | then | |
109 | # This is a pure guess, but for many people it might be OK. | |
545f5fad | 110 | remote_id=$(whoami) |
743d4d82 | 111 | else |
545f5fad | 112 | remote_id=$(echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|") |
743d4d82 RE |
113 | if [ x$remote_id = x$url ] |
114 | then | |
545f5fad | 115 | remote_id=$(whoami) |
743d4d82 RE |
116 | fi |
117 | fi | |
118 | fi | |
24b17818 | 119 | |
e6107422 | 120 | ask "Account name on gcc.gnu.org (for your personal branches area)" $remote_id remote_id |
743d4d82 RE |
121 | git config "gcc-config.user" "$remote_id" |
122 | ||
545f5fad | 123 | old_pfx=$(git config --get "gcc-config.userpfx") |
743d4d82 RE |
124 | if [ "x$old_pfx" = "x" ] |
125 | then | |
126 | old_pfx="me" | |
127 | fi | |
24b17818 | 128 | echo |
743d4d82 RE |
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" | |
133 | ||
757dbb59 JM |
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" | |
141 | fi | |
142 | install -c "`git rev-parse --show-toplevel`/contrib/prepare-commit-msg" "$hookdir" | |
143 | fi | |
144 | ||
24b17818 RE |
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 | |
150 | do | |
612137e1 | 151 | echo "Migrating vendor \"$v\" to new remote \"vendors/$v\"" |
24b17818 RE |
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}" | |
158 | fi | |
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 | |
e6107422 | 162 | |
612137e1 RE |
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}/*") | |
175 | do | |
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}" | |
180 | fi | |
181 | done | |
182 | fi | |
183 | ||
184 | echo "Setting up tracking for personal namespace $remote_id in remotes/users/${new_pfx}" | |
185 | git config "remote.users/${new_pfx}.url" "${url}" | |
24b17818 | 186 | if [ "x$pushurl" != "x" ] |
e6107422 | 187 | then |
612137e1 | 188 | git config "remote.users/${new_pfx}.pushurl" "${pushurl}" |
e6107422 | 189 | fi |
612137e1 RE |
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}" | |
24b17818 RE |
193 | |
194 | if [ "$old_pfx" != "$new_pfx" -a "$old_pfx" != "${upstream}" ] | |
195 | then | |
196 | git config --remove-section "remote.${old_pfx}" | |
197 | fi | |
198 | ||
199 | git config --unset-all "remote.${upstream}.fetch" "refs/users/${remote_id}/" | |
200 | git config --unset-all "remote.${upstream}.push" "refs/users/${remote_id}/" | |
612137e1 RE |
201 | |
202 | git fetch "users/${new_pfx}" |