diff options
author | Richard Earnshaw <rearnsha@arm.com> | 2020-01-24 14:38:16 +0000 |
---|---|---|
committer | Richard Earnshaw <rearnsha@arm.com> | 2020-01-24 14:38:16 +0000 |
commit | 612137e17109d890948fe30cb997b590b5944df4 (patch) | |
tree | 0c6e57ab460360b57cd4ca9881f835a02723dfcd /contrib | |
parent | ba386bea11173bfa2f7c76b6368a49a43f366eea (diff) | |
download | gcc-612137e17109d890948fe30cb997b590b5944df4.zip gcc-612137e17109d890948fe30cb997b590b5944df4.tar.gz gcc-612137e17109d890948fe30cb997b590b5944df4.tar.bz2 |
contrib: Change 'remote' for personal branches and add branch creation script
Whilst trying to convert the add vendor branch script to work with
personal branches I encountered a minor issue where git would report
ambiguous refs when checking out the new branch.
It turns out that this is because git considers <me>/<topic> to be
ambiguous if both
refs/heads/<me>/<topic>
and
refs/remotes/<me>/<topic>
exist in the list of known branches.
Having thought about this a bit, I think the best solution is to adopt
something more like the vendors space and call the remote users/<me>
(this also works better if you want to set up remotes to track other
users branches as well).
So this patch has two parts.
1) It updates gcc-git-customization.sh to set up the new 'remote' and
converts any existing remote and branches tracking that to the new
format
2) It adds a new script to set up a personal branch on the gcc git repository.
* gcc-git-customization.sh: Use users/<pfx> for the personal remote
rather than just <pfx>. Convert any existing personal branches to the
new remote.
* git-add-user-branch.sh: New file.
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/ChangeLog | 7 | ||||
-rwxr-xr-x | contrib/gcc-git-customization.sh | 37 | ||||
-rwxr-xr-x | contrib/git-add-user-branch.sh | 46 |
3 files changed, 83 insertions, 7 deletions
diff --git a/contrib/ChangeLog b/contrib/ChangeLog index c5e4604..488a32c 100644 --- a/contrib/ChangeLog +++ b/contrib/ChangeLog @@ -1,3 +1,10 @@ +2020-01-24 Richard Earnshaw <rearnsha@arm.com> + + * gcc-git-customization.sh: Use users/<pfx> for the personal remote + rather than just <pfx>. Convert existing personal branches to the + new remote. + * git-add-user-branch.sh: New file. + 2020-01-22 Richard Earnshaw <rearnsha@arm.com> * git-add-vendor-branch.sh: New file. diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh index c16db74..f3e4831 100755 --- a/contrib/gcc-git-customization.sh +++ b/contrib/gcc-git-customization.sh @@ -128,7 +128,7 @@ url=$(git config --get "remote.${upstream}.url") pushurl=$(git config --get "remote.${upstream}.pushurl") for v in $vendors do - echo "Migrating vendor $v to new remote vendors/$v" + echo "Migrating vendor \"$v\" to new remote \"vendors/$v\"" git config --unset-all "remote.${upstream}.fetch" "refs/vendors/$v/" git config --unset-all "remote.${upstream}.push" "refs/vendors/$v/" git config "remote.vendors/${v}.url" "${url}" @@ -140,15 +140,36 @@ do git config --add "remote.vendors/${v}.fetch" "+refs/vendors/$v/tags/*:refs/tags/vendors/${v}/*" done -echo "Setting up tracking for personal namespace $remote_id in remotes/${new_pfx}" -git config "remote.${new_pfx}.url" "${url}" +# Convert the remote 'pfx' to users/pfx to avoid problems with ambiguous refs +# on user branches +old_remote=$(git config --get "remote.${old_pfx}.url") +if [ -n "${old_remote}" ] +then + echo "Migrating remote \"${old_pfx}\" to new remote \"users/${new_pfx}\"" + # Create a dummy fetch rule that will cause the subsequent prune to remove the old remote refs. + git config --replace-all "remote.${old_pfx}.fetch" "+refs/empty/*:refs/remotes/${old_pfx}/*" + # Remove any remotes + git remote prune ${old_pfx} + git config --remove-section "remote.${old_pfx}" + for br in $(git branch --list "${old_pfx}/*") + do + old_remote=$(git config --get "branch.${br}.remote") + if [ "${old_remote}" = "${old_pfx}" ] + then + git config "branch.${br}.remote" "users/${new_pfx}" + fi + done +fi + +echo "Setting up tracking for personal namespace $remote_id in remotes/users/${new_pfx}" +git config "remote.users/${new_pfx}.url" "${url}" if [ "x$pushurl" != "x" ] then - git config "remote.${new_pfx}.pushurl" "${pushurl}" + git config "remote.users/${new_pfx}.pushurl" "${pushurl}" fi -git config --replace-all "remote.${new_pfx}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/${new_pfx}/*" ":refs/remotes/${old_pfx}/" -git config --replace-all "remote.${new_pfx}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/${new_pfx}/*" ":refs/tags/${old_pfx}/" -git config --replace-all "remote.${new_pfx}.push" "refs/heads/${new_pfx}/*:refs/users/${remote_id}/heads/*" ":refs/users/${remote_id}" +git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/users/${new_pfx}/*" "refs/users/${remote_id}/heads/" +git config --replace-all "remote.users/${new_pfx}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/users/${new_pfx}/*" "refs/users/${remote_id}/tags/" +git config --replace-all "remote.users/${new_pfx}.push" "refs/heads/${new_pfx}/*:refs/users/${remote_id}/heads/*" "refs/users/${remote_id}" if [ "$old_pfx" != "$new_pfx" -a "$old_pfx" != "${upstream}" ] then @@ -157,3 +178,5 @@ fi git config --unset-all "remote.${upstream}.fetch" "refs/users/${remote_id}/" git config --unset-all "remote.${upstream}.push" "refs/users/${remote_id}/" + +git fetch "users/${new_pfx}" diff --git a/contrib/git-add-user-branch.sh b/contrib/git-add-user-branch.sh new file mode 100755 index 0000000..e014f75 --- /dev/null +++ b/contrib/git-add-user-branch.sh @@ -0,0 +1,46 @@ +#! /bin/sh -e + +# Create a new upstream user branch. + +# Usage: +# contrib/git-add-user-branch.sh [<personal-prefix>/]<branch-name> <base> + +usage () +{ + echo "Usage:" + echo " $0 [<personal-prefix>/]<branch-name> <start-point>" + echo + echo "personal space must already have been set up using" + echo "contrib/gcc-git-customization.sh" + exit 1 +} + +if [ $# != 2 ] +then + usage +fi + +userpfx=$(git config --get "gcc-config.userpfx") +user=$(git config --get "gcc-config.user") + +if [ -z "$userpfx" -o -z "$user" ] +then + usage +fi + +branch=$(echo "$1" | sed -r "s:(${userpfx}/)?(.*)$:\2:") +start=$2 + +# Sanity check the new branch argument. If there is no '/', then the +# vendor will be the same as the entire first argument. +if [ -z "$branch" ] +then + usage +fi + +git push users/${userpfx} ${start}:refs/users/${user}/heads/${branch} +git fetch -q users/${userpfx} +git branch ${userpfx}/${branch} remotes/users/${userpfx}/${branch} +echo "You are now ready to check out ${userpfx}/${branch}" +echo "To push the branch upstream use:" +echo " git push users/${userpfx} ${userpfx}/${branch}" |