# # Migrate SVN (subversion) repositories (or parts of it) to OpenCM projects. # # You have to create an OpenCM project that is used as target, prior of using # this script (cm create project proj-name). Then, use this project name as # --cm-project argument. # # USE AT YOUR OWN RISK! NO WARRANTIES! MAKE BACKUPS! # # # Copyright (C) 2003 by Michael Neumann (mneumann@ntecs.de) # # Requires: Ruby >= 1.8 # raise "Ruby version >= 1.8 required!" unless RUBY_VERSION >= '1.8' require "rexml/document" require "find" require "getoptlong" def usage STDERR.print < #{ log }`.annotate("SVN-LOG") # parse SVN logfile $svn_revs = svn_parseLog(File.read(log)) } } } } # # check OpenCM project initially out # Dir.chdir(CM_WORKSPACE) { STDOUT << `#{ cm } checkout #{ CM_PROJECT }`.annotate("CM-CHECKOUT") } # for each SVN revision do for rev in $svn_revs STDOUT << "-----------------------------\n" STDOUT << ("Revision (SVN): " + rev['rev'] + "\n") STDOUT << "-----------------------------\n" # remove all files from CM workspace iterate_CM_Workspace(CM_WORKSPACE, "rm") iterate_CM_Workspace2(CM_WORKSPACE) {|path| next if path == CM_WORKSPACE or path == CM_WORKSPACE + "/" `rm -rf #{ path }`.annotate("SHELL") } # checkout svn revision tree Dir.chdir(SVN_BASEDIR) { STDOUT << `rm -rf #{ SVN_SUBDIR }`.annotate("SHELL") STDOUT << `svn checkout --revision #{ rev['rev'] } #{ SVN_REPOS }`. annotate("SVN") Dir.chdir(SVN_SUBDIR) { # for each file (except .svn directories) do # svn info $file | parse last_mod_date # touch $file last_mod_date # end iterate_SVN_Workspace(Dir.pwd) {|path| date = `svn info #{ path }|grep "Last Changed Date"` if date =~ /(\d\d\d\d)-(\d\d)-(\d\d)\s+(\d\d):(\d\d):(\d\d)/ date = $1 + $2 + $3 + $4 + $5 + "." + $6 else raise "svn info | parse date error" end STDOUT << `touch -t #{ date } "#{ path }"`.annotate("TOUCH") } # remove all .svn directories recursively STDOUT << `find . -name ".svn" -type d | xargs rm -rf`.annotate("FIND-RM") # move all files from SVN workspace into OpenCM workspace STDOUT << `mv -f * #{ CM_WORKSPACE }`.annotate("SHELL") } } # add each file in OpenCM workspace to the OpenCM repos (cm add) iterate_CM_Workspace(CM_WORKSPACE, "add") # create temporary commit message file File.open(CM_TMP_MSGFILE, "w+") {|f| f << "svn-revison: #{ rev['rev'] }\n" f << "svn-date: #{ rev['date'] }\n" f << "\n" f << rev['msg'] } STDOUT << `cat #{ CM_TMP_MSGFILE }`.annotate("COMMIT-MSG") STDOUT << "\n" # cm commit Dir.chdir(CM_WORKSPACE) { STDOUT << `cm --force-hash --messagefile #{ CM_TMP_MSGFILE } commit`. annotate("CM") } end STDOUT << (Time.now.to_s + "\n").annotate("FINISH-TIME")