convert-to-git.bash 6.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
#!/usr/bin/env bash

GIT_CLEANUP=$PWD/git-cleanup.bash
GIT_CONVERT=$PWD/convert-to-git.bash

if ! [[ -f ${GIT_CONVERT} ]]; then
    cat <<EOF
error: This script expects to be called convert-to-git.bash and reside in the
       directory in which it is executed.
EOF
    exit -1
fi

clone() {
    git svn clone --stdlayout \
        https://svn.imp.fu-berlin.de/agnumpde/software/dune-modules/$1
}

handle_gitignore_and_filter() {
    git svn show-ignore > .gitignore
    git add .gitignore
    git commit -m 'Convert svn:ignore properties to .gitignore.'

    git filter-branch -f \
        --msg-filter '
            sed -e "/^\$/{ :l; N; s/^\n\$//; t l; p; d; }" | \
            sed -e "/^git-svn-id:/s/.*@\([^ ]*\) .*$/[[Imported from SVN: r\1]]/"' \
        --commit-filter ". ${GIT_CLEANUP};" \
        HEAD
}

create_release_branch() {
    git checkout -b releases/$1 $2
}

create_git_cleanup() {
    cat > ${GIT_CLEANUP} <<'EOF'
#!/usr/bin/env bash

case $GIT_AUTHOR_NAME in
    akbib*|youett*)
        GIT_AUTHOR_NAME="Jonathan Youett"
        GIT_AUTHOR_EMAIL=youett@mi.fu-berlin.de
        ;;
    ansgar)
        GIT_AUTHOR_NAME="Ansgar Burchardt"
        GIT_AUTHOR_EMAIL=burchardt@igpm.rwth-aachen.de
        ;;
    forster*)
        GIT_AUTHOR_NAME="Ralf Forster"
        GIT_AUTHOR_EMAIL=forster@math.fu-berlin.de
        ;;
    graeser*)
        GIT_AUTHOR_NAME="Carsten Gräser"
        GIT_AUTHOR_EMAIL=graeser@mi.fu-berlin.de
        ;;
    lschmidt*|oel*)
        GIT_AUTHOR_NAME="Leo Schmidt"
        GIT_AUTHOR_EMAIL=lschmidt@math.fu-berlin.de
        ;;
    klapprot*)
        GIT_AUTHOR_NAME="Corinna Klapproth"
        GIT_AUTHOR_EMAIL=klapproth@zib.de
        ;;
    mawolf*)
        GIT_AUTHOR_NAME="Maren-Wanda Wolf"
        GIT_AUTHOR_EMAIL=mawolf@math.fu-berlin.de
        ;;
    maxka)
        GIT_AUTHOR_NAME="Max Kahnt"
        GIT_AUTHOR_EMAIL=max.kahnt@fu-berlin.de
        ;;
    pipping*)
        GIT_AUTHOR_NAME="Elias Pipping"
        GIT_AUTHOR_EMAIL=elias.pipping@fu-berlin.de
        ;;
    podlesjo)
        GIT_AUTHOR_NAME="Joscha Podlesny"
        GIT_AUTHOR_EMAIL=joscha.py@googlemail.com
        ;;
    sander*)
        GIT_AUTHOR_NAME="Oliver Sander"
        GIT_AUTHOR_EMAIL=sander@igpm.rwth-aachen.de
        ;;
    sertel)
        GIT_AUTHOR_NAME="Susanne Ertel"
        GIT_AUTHOR_EMAIL=ertel@zib.de
        ;;
    usack*)
        GIT_AUTHOR_NAME="Uli Sack"
        GIT_AUTHOR_EMAIL=usack@math.fu-berlin.de
        ;;
esac
git commit-tree "$@"
EOF
}

save_script_and_create_tag() {
    cp ${GIT_CONVERT} .
    git add convert-to-git.bash
    git commit -m 'Document subversion->git migration process'
    git tag -a \
        -m "Subversion->Git migration completed. Master rev: $@" \
        'subversion->git'
}

### Check out and clean up repositories

create_git_cleanup

clone dune-fufem
(
    cd dune-fufem
    master_rev=$(git svn find-rev HEAD)
    create_release_branch 2.0-1 2.0.0-1 ; handle_gitignore_and_filter; # Rename
    create_release_branch 2.1-1 2.1-1   ; handle_gitignore_and_filter;
    create_release_branch 2.2-1 2.2-1   ; handle_gitignore_and_filter;
    git checkout master                 ; handle_gitignore_and_filter;
    save_script_and_create_tag ${master_rev}
)

clone dune-solvers
(
    cd dune-solvers
    master_rev=$(git svn find-rev HEAD)
    create_release_branch 2.0-1 2.0.0-1 ; handle_gitignore_and_filter; # Rename
    create_release_branch 2.1-1 2.1-1   ; handle_gitignore_and_filter;
    create_release_branch 2.2-1 2.2-1   ; handle_gitignore_and_filter;
    git checkout master                 ; handle_gitignore_and_filter;
    save_script_and_create_tag ${master_rev}
)

clone dune-tnnmg
(
    cd dune-tnnmg
    master_rev=$(git svn find-rev HEAD)
    create_release_branch 2.0-1 2.0.0-1 ; handle_gitignore_and_filter; # Rename
    create_release_branch 2.1-1 2.1-1   ; handle_gitignore_and_filter;
    create_release_branch 2.2-1 2.2-1   ; handle_gitignore_and_filter;
    git checkout master                 ; handle_gitignore_and_filter;
    save_script_and_create_tag ${master_rev}
)

clone dune-biomech
(
    cd dune-biomech
    master_rev=$(git svn find-rev HEAD)
    create_release_branch 2.0-1 2.0-1   ; handle_gitignore_and_filter;
    create_release_branch 2.1-1 2.1-1   ; handle_gitignore_and_filter;
    create_release_branch 2.2-1 2.2     ; handle_gitignore_and_filter; # Rename
    git checkout master                 ; handle_gitignore_and_filter;
    save_script_and_create_tag ${master_rev}
)

clone dune-contact
(
    cd dune-contact
    master_rev=$(git svn find-rev HEAD)
    create_release_branch 2.0-1 2.0-1   ; handle_gitignore_and_filter;
    create_release_branch 2.1-1 2.1     ; handle_gitignore_and_filter; # Rename
    create_release_branch 2.2-1 2.2     ; handle_gitignore_and_filter; # Rename
    git checkout master                 ; handle_gitignore_and_filter;
    save_script_and_create_tag ${master_rev}
)

clone dune-contact-timeint
(
    cd dune-contact-timeint
    master_rev=$(git svn find-rev HEAD)
    create_release_branch 2.0-1 2.0-1   ; handle_gitignore_and_filter;
    create_release_branch 2.1-1 2.1-1   ; handle_gitignore_and_filter;
    create_release_branch 2.2-1 2.2     ; handle_gitignore_and_filter; # Rename
    git checkout master                 ; handle_gitignore_and_filter;
    save_script_and_create_tag ${master_rev}
)

clone dune-elasticity
(
    cd dune-elasticity
    master_rev=$(git svn find-rev HEAD)
    create_release_branch 2.0-1 2.0-1   ; handle_gitignore_and_filter;
    create_release_branch 2.1-1 2.1-1   ; handle_gitignore_and_filter;
    create_release_branch 2.2-1 2.2     ; handle_gitignore_and_filter; # Rename
    git checkout master                 ; handle_gitignore_and_filter;
    save_script_and_create_tag ${master_rev}
)

clone dune-schur-newton
(
    cd dune-schur-newton
    master_rev=$(git svn find-rev HEAD)
    git checkout master                 ; handle_gitignore_and_filter;
    save_script_and_create_tag ${master_rev}
)

rm -f ${GIT_CLEANUP}

## Debugging section
#
# Use the following scripts to check if the conversion went according to plan
#
# (1) To generate a list of authors
#
#       !/usr/bin/env bash
#
#       for i in dune-*; do
#           (
#               cd $i;
#               git log --format=tformat:'%an <%ae>';
#           );
#       done | perl -e '
#           use 5.018;
#           my %a;
#           while (<>) {
#               chomp; $a{$_}++;
#           };
#           while (each %a) {
#               printf "%d\t%s\n", $a{$_}, $_;
#           }
#       ' | sort -n
#
# (2) To generate a list of converted branches
#
#       !/usr/bin/env bash
#
#       for i in dune-*; do
#           (
#               cd $i;
#               echo $i;
#               git for-each-ref --format='  %(refname)' refs/heads;
#           );
#       done