145
|
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 # Make diff on MD files use "(define" as a function marker.
|
|
29 # Use this in conjunction with a .gitattributes file containing
|
|
30 # *.md diff=md
|
|
31 git config diff.md.xfuncname '^\(define.*$'
|
|
32
|
|
33 set_user=$(git config --get "user.name")
|
|
34 set_email=$(git config --get "user.email")
|
|
35
|
|
36 if [ "x$set_user" = "x" ]
|
|
37 then
|
|
38 # Try to guess the user's name by looking it up in the password file
|
|
39 new_user=$(getent passwd $(whoami) | awk -F: '{ print $5 }')
|
|
40 if [ "x$new_user" = "x" ]
|
|
41 then
|
|
42 new_user="(no default)"
|
|
43 fi
|
|
44 else
|
|
45 new_user=$set_user
|
|
46 fi
|
|
47 ask "Your name" "${new_user}" new_user
|
|
48 if [ "x$new_user" = "x(no default)" ]
|
|
49 then
|
|
50 echo "Cannot continue, git needs to record your name against commits"
|
|
51 exit 1
|
|
52 fi
|
|
53
|
|
54 if [ "x$set_email" = "x" ]
|
|
55 then
|
|
56 new_email="(no_default)"
|
|
57 else
|
|
58 new_email=$set_email
|
|
59 fi
|
|
60
|
|
61 ask "Your email address (for git commits)" "${new_email}" new_email
|
|
62 if [ "x$new_email" = "x(no default)" ]
|
|
63 then
|
|
64 echo "Cannot continue, git needs to record your email address against commits"
|
|
65 exit 1
|
|
66 fi
|
|
67
|
|
68 if [ "x$set_user" != "x$new_user" ]
|
|
69 then
|
|
70 git config "user.name" "$new_user"
|
|
71 fi
|
|
72
|
|
73 if [ "x$set_email" != "x$new_email" ]
|
|
74 then
|
|
75 git config "user.email" "$new_email"
|
|
76 fi
|
|
77
|
|
78 upstream=$(git config --get "gcc-config.upstream")
|
|
79 if [ "x$upstream" = "x" ]
|
|
80 then
|
|
81 upstream="origin"
|
|
82 fi
|
|
83 ask "Local name for upstream repository" "origin" upstream
|
|
84
|
|
85 v=$(git config --get-all "remote.${upstream}.fetch")
|
|
86 if [ "x$v" = "x" ]
|
|
87 then
|
|
88 echo "Remote $upstream does not seem to exist as a remote"
|
|
89 exit 1
|
|
90 fi
|
|
91 git config "gcc-config.upstream" "$upstream"
|
|
92
|
|
93 remote_id=$(git config --get "gcc-config.user")
|
|
94 if [ "x$remote_id" = "x" ]
|
|
95 then
|
|
96 # See if the url specifies the remote user name.
|
|
97 url=$(git config --get "remote.$upstream.url")
|
|
98 if [ "x$url" = "x" ]
|
|
99 then
|
|
100 # This is a pure guess, but for many people it might be OK.
|
|
101 remote_id=$(whoami)
|
|
102 else
|
|
103 remote_id=$(echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|")
|
|
104 if [ x$remote_id = x$url ]
|
|
105 then
|
|
106 remote_id=$(whoami)
|
|
107 fi
|
|
108 fi
|
|
109 fi
|
|
110
|
|
111 ask "Account name on gcc.gnu.org (for your personal branches area)" $remote_id remote_id
|
|
112 git config "gcc-config.user" "$remote_id"
|
|
113
|
|
114 old_pfx=$(git config --get "gcc-config.userpfx")
|
|
115 if [ "x$old_pfx" = "x" ]
|
|
116 then
|
|
117 old_pfx="me"
|
|
118 fi
|
|
119 echo
|
|
120 echo "Local branch prefix for personal branches you want to share"
|
|
121 echo "(local branches starting <prefix>/ can be pushed directly to your"
|
|
122 ask "personal area on the gcc server)" $old_pfx new_pfx
|
|
123 git config "gcc-config.userpfx" "$new_pfx"
|
|
124
|
|
125 # Scan the existing settings to see if there are any we need to rewrite.
|
|
126 vendors=$(git config --get-all "remote.${upstream}.fetch" "refs/vendors/" | sed -r "s:.*refs/vendors/([^/]+)/.*:\1:" | sort | uniq)
|
|
127 url=$(git config --get "remote.${upstream}.url")
|
|
128 pushurl=$(git config --get "remote.${upstream}.pushurl")
|
|
129 for v in $vendors
|
|
130 do
|
|
131 echo "Migrating vendor \"$v\" to new remote \"vendors/$v\""
|
|
132 git config --unset-all "remote.${upstream}.fetch" "refs/vendors/$v/"
|
|
133 git config --unset-all "remote.${upstream}.push" "refs/vendors/$v/"
|
|
134 git config "remote.vendors/${v}.url" "${url}"
|
|
135 if [ "x$pushurl" != "x" ]
|
|
136 then
|
|
137 git config "remote.vendors/${v}.pushurl" "${pushurl}"
|
|
138 fi
|
|
139 git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/heads/*:refs/remotes/vendors/${v}/*"
|
|
140 git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/tags/*:refs/tags/vendors/${v}/*"
|
|
141 done
|
|
142
|
|
143 # Convert the remote 'pfx' to users/pfx to avoid problems with ambiguous refs
|
|
144 # on user branches
|
|
145 old_remote=$(git config --get "remote.${old_pfx}.url")
|
|
146 if [ -n "${old_remote}" ]
|
|
147 then
|
|
148 echo "Migrating remote \"${old_pfx}\" to new remote \"users/${new_pfx}\""
|
|
149 # Create a dummy fetch rule that will cause the subsequent prune to remove the old remote refs.
|
|
150 git config --replace-all "remote.${old_pfx}.fetch" "+refs/empty/*:refs/remotes/${old_pfx}/*"
|
|
151 # Remove any remotes
|
|
152 git remote prune ${old_pfx}
|
|
153 git config --remove-section "remote.${old_pfx}"
|
|
154 for br in $(git branch --list "${old_pfx}/*")
|
|
155 do
|
|
156 old_remote=$(git config --get "branch.${br}.remote")
|
|
157 if [ "${old_remote}" = "${old_pfx}" ]
|
|
158 then
|
|
159 git config "branch.${br}.remote" "users/${new_pfx}"
|
|
160 fi
|
|
161 done
|
|
162 fi
|
|
163
|
|
164 echo "Setting up tracking for personal namespace $remote_id in remotes/users/${new_pfx}"
|
|
165 git config "remote.users/${new_pfx}.url" "${url}"
|
|
166 if [ "x$pushurl" != "x" ]
|
|
167 then
|
|
168 git config "remote.users/${new_pfx}.pushurl" "${pushurl}"
|
|
169 fi
|
|
170 git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/users/${new_pfx}/*" "refs/users/${remote_id}/heads/"
|
|
171 git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/users/${new_pfx}/*" "refs/users/${remote_id}/tags/"
|
|
172 git config --replace-all "remote.users/${new_pfx}.push" "refs/heads/${new_pfx}/*:refs/users/${remote_id}/heads/*" "refs/users/${remote_id}"
|
|
173
|
|
174 if [ "$old_pfx" != "$new_pfx" -a "$old_pfx" != "${upstream}" ]
|
|
175 then
|
|
176 git config --remove-section "remote.${old_pfx}"
|
|
177 fi
|
|
178
|
|
179 git config --unset-all "remote.${upstream}.fetch" "refs/users/${remote_id}/"
|
|
180 git config --unset-all "remote.${upstream}.push" "refs/users/${remote_id}/"
|
|
181
|
|
182 git fetch "users/${new_pfx}"
|