Showing posts with label hg to git. Show all posts
Showing posts with label hg to git. Show all posts

Friday, August 30, 2013

Moving Checkstyle sources from sourceforge to github

Sources: http://sourceforge.net/p/checkstyle/code/ci/default/tree/
Destination: https://github.com/checkstyle

Follow installation steps from "How to convert mercurial to git" manual:  http://codeimpossible.com/2011/12/29/Moving-your-mercurial-repository-to-git/

Command to do clone and convert in same time:
git-hg clone http://hg.code.sf.net/p/checkstyle/code checkstyle-git

Review all participants to find duplicates:
git log --raw | grep "^Author: " | sort | uniq -c

2 Author: Bewied <BenWiederhake.......de>
4 Author: BurnOl <BurnOl@KAZ-027469>
1 Author: convert-repo <devnull@localhost>
1 Author: Lars Kühne <lkuehne>
683 Author: lkuehne <devnull@localhost>
43 Author: mstudman <devnull@localhost>
1054 Author: oburn <devnull@localhost>
9 Author: Oleg Sukhodolsky <o_sukhodolsky>
3 Author: Oliver Burn Cygwin <devnull@localhost>
135 Author: Oliver Burn <devnull@localhost>
288 Author: o_sukhodolsky <devnull@localhost>
410 Author: rickgiles <devnull@localhost>
14 Author: tschneeberger <devnull@localhost>


Create bash file that do squash of authors duplicates - change_names.sh:
#!/usr/bin/bash
   
git filter-branch --tag-name-filter cat --commit-filter '
      if [ "$GIT_AUTHOR_NAME" = "BurnOl" ] && [ "$GIT_AUTHOR_EMAIL" = "BurnOl@KAZ-027469" ]; then
              GIT_AUTHOR_NAME="Oliver Burn";
              GIT_AUTHOR_EMAIL="oliver@.......com";
              GIT_COMMITTER_NAME="Oliver Burn";
              GIT_COMMITTER_EMAIL="oliver@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "convert-repo" ] && [ "$GIT_AUTHOR_EMAIL" = "devnull@localhost" ]; then
              GIT_AUTHOR_NAME="Oliver Burn";
              GIT_AUTHOR_EMAIL="oliver@.......com";
              GIT_COMMITTER_NAME="Oliver Burn";
              GIT_COMMITTER_EMAIL="oliver@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "lkuehne" ] && [ "$GIT_AUTHOR_EMAIL" = "devnull@localhost" ]; then
              GIT_AUTHOR_NAME="Lars Kühne";
              GIT_AUTHOR_EMAIL="lakuehne@.......com";
              GIT_COMMITTER_NAME="Lars Kühne";
              GIT_COMMITTER_EMAIL="lakuehne@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "Lars Kühne" ] && [ "$GIT_AUTHOR_EMAIL" = "lkuehne" ]; then
              GIT_AUTHOR_NAME="Lars Kühne";
              GIT_AUTHOR_EMAIL="lakuehne@.......com";
              GIT_COMMITTER_NAME="Lars Kühne";
              GIT_COMMITTER_EMAIL="lakuehne@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "mstudman" ] && [ "$GIT_AUTHOR_EMAIL" = "devnull@localhost" ]; then
              GIT_AUTHOR_NAME="Michael Studman";
              GIT_AUTHOR_EMAIL="mstudman@.......com";
              GIT_COMMITTER_NAME="Michael Studman";
              GIT_COMMITTER_EMAIL="mstudman@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "Oliver Burn" ] && [ "$GIT_AUTHOR_EMAIL" = "devnull@localhost" ]; then
              GIT_AUTHOR_NAME="Oliver Burn";
              GIT_AUTHOR_EMAIL="oliver@.......com";
              GIT_COMMITTER_NAME="Oliver Burn";
              GIT_COMMITTER_EMAIL="oliver@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "Oliver Burn Cygwin" ] && [ "$GIT_AUTHOR_EMAIL" = "devnull@localhost" ]; then
              GIT_AUTHOR_NAME="Oliver Burn";
              GIT_AUTHOR_EMAIL="oliver@.......com";
              GIT_COMMITTER_NAME="Oliver Burn";
              GIT_COMMITTER_EMAIL="oliver@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "oburn" ] && [ "$GIT_AUTHOR_EMAIL" = "devnull@localhost" ]; then
              GIT_AUTHOR_NAME="Oliver Burn";
              GIT_AUTHOR_EMAIL="oliver@.......com";
              GIT_COMMITTER_NAME="Oliver Burn";
              GIT_COMMITTER_EMAIL="oliver@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "Oleg Sukhodolsky" ] && [ "$GIT_AUTHOR_EMAIL" = "o_sukhodolsky" ]; then
              GIT_AUTHOR_NAME="Oleg Sukhodolsky";
              GIT_AUTHOR_EMAIL="os97673@.......com";
              GIT_COMMITTER_NAME="Oleg Sukhodolsky";
              GIT_COMMITTER_EMAIL="os97673@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "o_sukhodolsky" ] && [ "$GIT_AUTHOR_EMAIL" = "o_sukhodolsky" ]; then
              GIT_AUTHOR_NAME="Oleg Sukhodolsky";
              GIT_AUTHOR_EMAIL="os97673@.......com";
              GIT_COMMITTER_NAME="Oleg Sukhodolsky";
              GIT_COMMITTER_EMAIL="os97673@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "o_sukhodolsky" ] && [ "$GIT_AUTHOR_EMAIL" = "devnull@localhost" ]; then
              GIT_AUTHOR_NAME="Oleg Sukhodolsky";
              GIT_AUTHOR_EMAIL="os97673@.......com";
              GIT_COMMITTER_NAME="Oleg Sukhodolsky";
              GIT_COMMITTER_EMAIL="os97673@.......com";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "rickgiles" ] && [ "$GIT_AUTHOR_EMAIL" = "devnull@localhost" ]; then
              GIT_AUTHOR_NAME="Rick Giles";
              GIT_AUTHOR_EMAIL="rickgiles";
              GIT_COMMITTER_NAME="Rick Giles";
              GIT_COMMITTER_EMAIL="rickgiles";
              git commit-tree "$@";
      elif [ "$GIT_AUTHOR_NAME" = "tschneeberger" ] && [ "$GIT_AUTHOR_EMAIL" = "devnull@localhost" ]; then
              GIT_AUTHOR_NAME="Travis Schneeberger";
              GIT_AUTHOR_EMAIL="leo.herbie@.......com";
              GIT_COMMITTER_NAME="Travis Schneeberger";
              GIT_COMMITTER_EMAIL="leo.herbie@.......com";
              git commit-tree "$@";
      else
              git commit-tree "$@";
      fi' HEAD



explanation to script:
" --tag-name-filter cat" - required to not loose tags after history rewrite.
"GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL" - to let github show commits correctly at page of commits history, in other case you have invalid-email-address in details for each commmit.

Do changes to authors and do push to remote:
./change_names.sh
git remote add origin git@github.com:checkstyle/checkstyle.git
git push -u origin master --tags

Sources of wisdom:
In filter-branch shell syntax for IF-ELSE should be used - http://www.dreamsyssoft.com/unix-shell-scripting/ifelse-tutorial.php
usage of bash syntax for IF- ELSE cause errors - http://blog.linuxacademy.com/linux/conditions-in-bash-scripting-if-statements/
http://git-scm.com/book/ch6-4.html (chapter "Changing E-Mail Addresses Globally")
http://ayende.com/blog/4532/extracting-a-list-of-committers-from-git