]> git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/gcc-git-customization.sh
Add new git-backport.py script.
[thirdparty/gcc.git] / contrib / gcc-git-customization.sh
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
14 eval $var=\$default
15 else
16 eval $var=\$answer
17 fi
18 }
19
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'
22
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"
27
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() { GCC_FORCE_MKLOG=1 git commit "$@"; }; f'
32
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.*$'
37
38 set_user=$(git config --get "user.name")
39 set_email=$(git config --get "user.email")
40
41 if [ "x$set_user" = "x" ]
42 then
43 # Try to guess the user's name by looking it up in the password file
44 new_user=$(getent passwd $(whoami) | awk -F: '{ print $5 }')
45 if [ "x$new_user" = "x" ]
46 then
47 new_user="(no default)"
48 fi
49 else
50 new_user=$set_user
51 fi
52 ask "Your name" "${new_user}" new_user
53 if [ "x$new_user" = "x(no default)" ]
54 then
55 echo "Cannot continue, git needs to record your name against commits"
56 exit 1
57 fi
58
59 if [ "x$set_email" = "x" ]
60 then
61 new_email="(no_default)"
62 else
63 new_email=$set_email
64 fi
65
66 ask "Your email address (for git commits)" "${new_email}" new_email
67 if [ "x$new_email" = "x(no default)" ]
68 then
69 echo "Cannot continue, git needs to record your email address against commits"
70 exit 1
71 fi
72
73 if [ "x$set_user" != "x$new_user" ]
74 then
75 git config "user.name" "$new_user"
76 fi
77
78 if [ "x$set_email" != "x$new_email" ]
79 then
80 git config "user.email" "$new_email"
81 fi
82
83 upstream=$(git config --get "gcc-config.upstream")
84 if [ "x$upstream" = "x" ]
85 then
86 upstream="origin"
87 fi
88 ask "Local name for upstream repository" "origin" upstream
89
90 v=$(git config --get-all "remote.${upstream}.fetch")
91 if [ "x$v" = "x" ]
92 then
93 echo "Remote $upstream does not seem to exist as a remote"
94 exit 1
95 fi
96 git config "gcc-config.upstream" "$upstream"
97
98 remote_id=$(git config --get "gcc-config.user")
99 if [ "x$remote_id" = "x" ]
100 then
101 # See if the url specifies the remote user name.
102 url=$(git config --get "remote.$upstream.url")
103 if [ "x$url" = "x" ]
104 then
105 # This is a pure guess, but for many people it might be OK.
106 remote_id=$(whoami)
107 else
108 remote_id=$(echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|")
109 if [ x$remote_id = x$url ]
110 then
111 remote_id=$(whoami)
112 fi
113 fi
114 fi
115
116 ask "Account name on gcc.gnu.org (for your personal branches area)" $remote_id remote_id
117 git config "gcc-config.user" "$remote_id"
118
119 old_pfx=$(git config --get "gcc-config.userpfx")
120 if [ "x$old_pfx" = "x" ]
121 then
122 old_pfx="me"
123 fi
124 echo
125 echo "Local branch prefix for personal branches you want to share"
126 echo "(local branches starting <prefix>/ can be pushed directly to your"
127 ask "personal area on the gcc server)" $old_pfx new_pfx
128 git config "gcc-config.userpfx" "$new_pfx"
129
130 echo
131 ask "Install prepare-commit-msg git hook for 'git commit-mklog' alias" yes dohook
132 if [ "x$dohook" = xyes ]; then
133 hookdir=`git rev-parse --git-path hooks`
134 if [ -f "$hookdir/prepare-commit-msg" ]; then
135 echo " Moving existing prepare-commit-msg hook to prepare-commit-msg.bak"
136 mv "$hookdir/prepare-commit-msg" "$hookdir/prepare-commit-msg.bak"
137 fi
138 install -c "`git rev-parse --show-toplevel`/contrib/prepare-commit-msg" "$hookdir"
139 fi
140
141 # Scan the existing settings to see if there are any we need to rewrite.
142 vendors=$(git config --get-all "remote.${upstream}.fetch" "refs/vendors/" | sed -r "s:.*refs/vendors/([^/]+)/.*:\1:" | sort | uniq)
143 url=$(git config --get "remote.${upstream}.url")
144 pushurl=$(git config --get "remote.${upstream}.pushurl")
145 for v in $vendors
146 do
147 echo "Migrating vendor \"$v\" to new remote \"vendors/$v\""
148 git config --unset-all "remote.${upstream}.fetch" "refs/vendors/$v/"
149 git config --unset-all "remote.${upstream}.push" "refs/vendors/$v/"
150 git config "remote.vendors/${v}.url" "${url}"
151 if [ "x$pushurl" != "x" ]
152 then
153 git config "remote.vendors/${v}.pushurl" "${pushurl}"
154 fi
155 git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/heads/*:refs/remotes/vendors/${v}/*"
156 git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/tags/*:refs/tags/vendors/${v}/*"
157 done
158
159 # Convert the remote 'pfx' to users/pfx to avoid problems with ambiguous refs
160 # on user branches
161 old_remote=$(git config --get "remote.${old_pfx}.url")
162 if [ -n "${old_remote}" ]
163 then
164 echo "Migrating remote \"${old_pfx}\" to new remote \"users/${new_pfx}\""
165 # Create a dummy fetch rule that will cause the subsequent prune to remove the old remote refs.
166 git config --replace-all "remote.${old_pfx}.fetch" "+refs/empty/*:refs/remotes/${old_pfx}/*"
167 # Remove any remotes
168 git remote prune ${old_pfx}
169 git config --remove-section "remote.${old_pfx}"
170 for br in $(git branch --list "${old_pfx}/*")
171 do
172 old_remote=$(git config --get "branch.${br}.remote")
173 if [ "${old_remote}" = "${old_pfx}" ]
174 then
175 git config "branch.${br}.remote" "users/${new_pfx}"
176 fi
177 done
178 fi
179
180 echo "Setting up tracking for personal namespace $remote_id in remotes/users/${new_pfx}"
181 git config "remote.users/${new_pfx}.url" "${url}"
182 if [ "x$pushurl" != "x" ]
183 then
184 git config "remote.users/${new_pfx}.pushurl" "${pushurl}"
185 fi
186 git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/users/${new_pfx}/*" "refs/users/${remote_id}/heads/"
187 git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/users/${new_pfx}/*" "refs/users/${remote_id}/tags/"
188 git config --replace-all "remote.users/${new_pfx}.push" "refs/heads/${new_pfx}/*:refs/users/${remote_id}/heads/*" "refs/users/${remote_id}"
189
190 if [ "$old_pfx" != "$new_pfx" -a "$old_pfx" != "${upstream}" ]
191 then
192 git config --remove-section "remote.${old_pfx}"
193 fi
194
195 git config --unset-all "remote.${upstream}.fetch" "refs/users/${remote_id}/"
196 git config --unset-all "remote.${upstream}.push" "refs/users/${remote_id}/"
197
198 git fetch "users/${new_pfx}"