]> git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/gcc-git-customization.sh
contrib: Add in the default push rule which was overridden
[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 r=\$(git describe --all --abbrev=40 --match 'basepoints/gcc-[0-9]*' \${2:-master} | 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}); test -n \$r && echo \${r}; else git describe --all --match 'basepoints/gcc-[0-9]*' \${1:-master} | sed -n 's,^tags/basepoints/gcc-\\([0-9]\\+\\)-\\([0-9]\\+\\)-g[0-9a-f]*\$,r\\1-\\2,p;s,^tags/basepoints/gcc-\\([0-9]\\+\\)\$,r\\1-0,p'; 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]*\$,\\1,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 uses "(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 upstream=`git config --get "gcc-config.upstream"`
34 if [ "x$upstream" = "x" ]
35 then
36 upstream="origin"
37 fi
38 ask "Local name for upstream repository" "origin" upstream
39 git config "gcc-config.upstream" "$upstream"
40
41 remote_id=`git config --get "gcc-config.user"`
42 if [ "x$remote_id" = "x" ]
43 then
44 # See if the url specifies the remote user name.
45 url=`git config --get "remote.$upstream.url"`
46 if [ "x$url" = "x" ]
47 then
48 # This is a pure guess, but for many people it might be OK.
49 remote_id=`whoami`
50 else
51 remote_id=`echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|"`
52 if [ x$remote_id = x$url ]
53 then
54 remote_id=`whoami`
55 fi
56 fi
57 fi
58 ask "Account name on gcc.gnu.org" $remote_id remote_id
59 git config "gcc-config.user" "$remote_id"
60
61 old_pfx=`git config --get "gcc-config.userpfx"`
62 if [ "x$old_pfx" = "x" ]
63 then
64 old_pfx="me"
65 fi
66 echo "Local branch prefix for personal branches you want to share"
67 echo "(local branches starting <prefix>/ can be pushed directly to your"
68 ask "personal area on the gcc server)" $old_pfx new_pfx
69 git config "gcc-config.userpfx" "$new_pfx"
70
71 # This entry needs to come last, so unset it now, then reset it after the updates.
72 git config --unset "remote.${upstream}.push" "refs/heads/\\*:refs/heads/\\*"
73 echo "Setting up tracking for personal namespace $remote_id in remotes/$upstream/${new_pfx}"
74 git config --replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/${upstream}/${new_pfx}/*" ":refs/remotes/${upstream}/${old_pfx}/"
75 git config --replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/${new_pfx}/*" ":refs/tags/${old_pfx}/"
76 git config --replace-all "remote.${upstream}.push" "refs/heads/${new_pfx}/*:refs/users/${remote_id}/heads/*" "^\+?refs/heads/${old_pfx}/"
77 # Re-add the line deleted above.
78 git config --add "remote.${upstream}.push" "refs/heads/*:refs/heads/*"