From bb65e4fb63653178b9d4645d06f5d0289e38225b Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Tue, 23 Jul 2013 09:17:51 +0100 Subject: As discussed on QA list implement a branch name policy. We do not allow any branch names, but to allow for an easy import we have adopted this strategy: 1. Branches matching ([1-3]) are renamed to distro/mga\1 2. Branches matching (20[0-9\.]+) are renamed to distro/mdv\1 3. Branches matching (mes[0-9].*) are renamed to distro/\1 4. All other branches are renamed to topic/\1 (excl. master) --- scripts/mageia-reset-and-import.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/scripts/mageia-reset-and-import.sh b/scripts/mageia-reset-and-import.sh index 2c0dc80..4cd9e53 100755 --- a/scripts/mageia-reset-and-import.sh +++ b/scripts/mageia-reset-and-import.sh @@ -385,6 +385,44 @@ for tag in $tags; do git update-ref -d "$ref" done +# Implement a branch name policy +# 1. Branches matching ([1-3]) are renamed to distro/mga\1 +# 2. Branches matching (20[0-9\.]+) are renamed to distro/mdv\1 +# 3. Branches matching (mes[0-9].*) are renamed to distro/\1 +# 4. All other branches are renamed to topic/\1 (excl. master) + +branches=$(git for-each-ref --format='%(refname)' refs/heads | cut -d / -f 3-) +for branch in $branches; do + ref="refs/heads/$branch" + refsha1=$(git rev-parse "$ref") + reftreesha1=$(git rev-parse "$ref":) + + # Find the oldest ancestor for which the tree is the same + parentref="$ref" + while [ $(git rev-parse --quiet --verify "$parentref"^:) = "$reftreesha1" ]; do + parentref="$parentref"^ + done + parent=$(git rev-parse "$parentref") + + # If this ancestor is in master then we can just squash it + # otherwise the branch has diverged from master and it's actually a proper + # branch + merge=$(git merge-base master $parent) + if [ "$merge" = "$parent" ]; then + git update-ref "$ref" $parent $refsha1 + fi + + if (echo $branch | grep -qE '^[0-3]$'); then + git branch -m $branch distro/mga$branch + elif (echo $branch | grep -qE '^20[0-9\.]+$'); then + git branch -m $branch distro/mdv$branch + elif (echo $branch | grep -qE '^mes[0-9].*$'); then + git branch -m $branch distro/$branch + elif [ $branch != "master" ]; then + git branch -m $branch topic/$branch + fi +done + git gc --aggressive popd -- cgit v1.2.1