Loading

Paste #plaovddlh

  1. planetmaker@openttd$ cat update-others.sh
  2. #!/bin/sh
  3.  
  4. # Update both git and mercurial, by checking where the commit was, and updating those repos
  5.  
  6. REV=$1
  7.  
  8. cd /var/repos/scripts
  9. changed=`./detect-branch-changed.sh $REV`
  10. for i in $changed; do
  11.     ./safe-svn-to-others.sh "$i"
  12. done
  13.  
  14. planetmaker@openttd$ cat safe-svn-to-others.sh
  15. #!/bin/sh
  16.  
  17. flock --exclusive --nonblock svn-to-others.lock -c "./svn-to-others.sh \"$1\"" || touch svn-to-others.rerun
  18.  
  19. planetmaker@openttd$ cat svn-to-others.sh
  20. #!/bin/sh
  21.  
  22. if [ `whoami` = "root" ]; then
  23.     echo "Please only execute this script under 'www-data' user"
  24.     exit 1
  25. fi
  26.  
  27. rm -f svn-to-others.rerun
  28. umask 007
  29.  
  30. SVN_REPOS=file:///path/to/svn-repo
  31. # converted svn repositories
  32. CONVERT_DIR=/path/to/scripts/convert_storage
  33. HG_REPOS=/path/to/hg-repos
  34. GIT_REPOS=/path/to/git-repos
  35. HG=/usr/bin/hg
  36. GIT=/usr/bin/git
  37.  
  38. process_only=$1
  39.  
  40. cd $CONVERT_DIR
  41.  
  42. function convert {
  43.     name=$1
  44.     dir=$2
  45.     repos_name=$3
  46.  
  47.     if [ -n "$process_only" ] && [ "$dir$name" != "$process_only" ]; then
  48.         return
  49.     fi
  50.  
  51.     cd $CONVERT_DIR
  52.     mkdir -p hg
  53.     cd hg
  54.  
  55.     if [ -n "$dir" ]; then
  56.         mkdir -p $dir
  57.         cd $dir
  58.     fi
  59.     # Load HG from SVN, and GIT from HG
  60.     $HG --encoding UTF8 convert --datesort --config convert.svn.branches= --config convert.svn.tags= --config convert.svn.trunk= $SVN_REPOS/$dir$name $repos_name.hg
  61.     cd $repos_name.hg
  62.  
  63.     # Set description
  64.     echo "[web]
  65. description=OpenTTD SVN - $dir$repos_name
  66. contact=OpenTTD
  67. allow_archive = bz2 gz zip
  68. allowpull = true
  69. style = gitweb
  70. " > .hg/hgrc
  71.  
  72.     # Set the 'last change' date of 'hgweb' correct
  73.     date=`hg tip | grep date: | cut -b 14- | sed 's/ +0000//'`
  74.     touch -d "$date" .hg/store/00changelog.i
  75.  
  76.     cd $CONVERT_DIR
  77.     mkdir -p git
  78.     cd git
  79.  
  80.     if [ -n "$dir" ]; then
  81.         mkdir -p $dir
  82.         cd $dir
  83.     fi
  84.  
  85.     if [ ! -d "$repos_name.git" ]; then
  86.         mkdir $repos_name.git
  87.         cd $repos_name.git
  88.         $GIT svn init --no-metadata $SVN_REPOS/$dir$name
  89.         $GIT config core.sharedRepository group
  90.         $GIT config gitweb.owner "OpenTTD"
  91.         $GIT svn fetch --no-follow-parent
  92.         $GIT update-ref refs/heads/master git-svn
  93.         $GIT checkout -f master
  94.     else
  95.         cd $repos_name.git
  96.         $GIT svn fetch
  97.         $GIT reset -q --hard git-svn
  98.     fi
  99.  
  100.     echo "OpenTTD SVN - $dir$repos_name" > .git/description
  101.     cd ..
  102.  
  103.  
  104.     # Link to our repos dirs
  105.     if [ ! -d "$HG_REPOS/$dir$repos_name.hg" ]; then
  106.         mkdir -p $HG_REPOS/$dir$repos_name.hg
  107.         ln -s $CONVERT_DIR/hg/$dir$repos_name.hg/.hg $HG_REPOS/$dir$repos_name.hg/.hg
  108.     fi
  109.     if [ ! -L "$GIT_REPOS/$dir$repos_name.git" ]; then
  110.         mkdir -p $GIT_REPOS/$repos_dir
  111.         ln -s $CONVERT_DIR/git/$dir$repos_name.git/.git $GIT_REPOS/$dir$repos_name.git
  112.     fi
  113.  
  114.     if [ "$dir$name" = "trunk" ]; then
  115.         if [ ! -d "$CONVERT_DIR/github" ]; then
  116.             cd $CONVERT_DIR/
  117.             $GIT clone $GIT_REPOS/trunk.git github
  118.             cd github
  119.             $GIT remote add github git@github.com:OpenTTD/OpenTTD.git
  120.         fi
  121.  
  122.         cd $CONVERT_DIR/github
  123.         $GIT pull origin
  124.         $GIT push github master
  125.     fi
  126. }
  127.  
  128. convert "trunk" "" "trunk"
  129.  
  130. for svndir in branches extra; do
  131.     for i in `svn ls $SVN_REPOS/$svndir/ | cut -d/ -f1`; do
  132.         convert "$i" "$svndir/" "$i"
  133.     done
  134. done
  135.  
  136. if [ -f "svn-to-others.rerun" ]; then
  137.     sh $0
  138. fi

Comments