]>
git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/gcc-git-customization.sh
3 # Script to add some local git customizations suitable for working
4 # with the GCC git repository
10 echo -n $question "["$default"]? "
12 if [ "x$answer" = "x" ]
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'
23 # Add git commands to convert git commit to monotonically increasing revision number
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"
28 # Make diff on MD files use "(define" as a function marker.
29 # Use this in conjunction with a .gitattributes file containing
31 git config
diff.md.xfuncname
'^\(define.*$'
33 set_user
=$
(git config
--get "user.name")
34 set_email
=$
(git config
--get "user.email")
36 if [ "x$set_user" = "x" ]
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" ]
42 new_user
="(no default)"
47 ask
"Your name" "${new_user}" new_user
48 if [ "x$new_user" = "x(no default)" ]
50 echo "Cannot continue, git needs to record your name against commits"
54 if [ "x$set_email" = "x" ]
56 new_email
="(no_default)"
61 ask
"Your email address (for git commits)" "${new_email}" new_email
62 if [ "x$new_email" = "x(no default)" ]
64 echo "Cannot continue, git needs to record your email address against commits"
68 if [ "x$set_user" != "x$new_user" ]
70 git config
"user.name" "$new_user"
73 if [ "x$set_email" != "x$new_email" ]
75 git config
"user.email" "$new_email"
78 upstream
=$
(git config
--get "gcc-config.upstream")
79 if [ "x$upstream" = "x" ]
83 ask
"Local name for upstream repository" "origin" upstream
84 git config
"gcc-config.upstream" "$upstream"
86 remote_id
=$
(git config
--get "gcc-config.user")
87 if [ "x$remote_id" = "x" ]
89 # See if the url specifies the remote user name.
90 url
=$
(git config
--get "remote.$upstream.url")
93 # This is a pure guess, but for many people it might be OK.
96 remote_id
=$
(echo $url |
sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|")
97 if [ x
$remote_id = x
$url ]
103 ask
"Account name on gcc.gnu.org (for your personal branches area)" $remote_id remote_id
104 git config
"gcc-config.user" "$remote_id"
106 old_pfx
=$
(git config
--get "gcc-config.userpfx")
107 if [ "x$old_pfx" = "x" ]
111 echo "Local branch prefix for personal branches you want to share"
112 echo "(local branches starting <prefix>/ can be pushed directly to your"
113 ask
"personal area on the gcc server)" $old_pfx new_pfx
114 git config
"gcc-config.userpfx" "$new_pfx"
116 echo "Setting up tracking for personal namespace $remote_id in remotes/$upstream/${new_pfx}"
117 git config
--replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/${upstream}/${new_pfx}/*" ":refs/remotes/${upstream}/${old_pfx}/"
118 git config
--replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/${new_pfx}/*" ":refs/tags/${old_pfx}/"
120 push_rule
=$
(git config
--get "remote.${upstream}.push")
121 if [ "x$push_rule" != "x" ]
123 echo "***********************************************"
125 echo "***********************************************"
127 echo "Old versions of this script used to add custom push"
128 echo "rules to simplify pushing to personal branches."
129 echo "Your configuration contains such rules, but we no-longer"
130 echo "recommend doing this."
132 echo "To delete these rules run:"
133 echo " git config --unset-all \"remote.${upstream}.push\""