Skip to content

Instantly share code, notes, and snippets.

@jorgeuriarte
Created September 25, 2013 10:55
Show Gist options
  • Save jorgeuriarte/6698029 to your computer and use it in GitHub Desktop.
Save jorgeuriarte/6698029 to your computer and use it in GitHub Desktop.
Script to massively update Subversion logs, so you can change commit messages (in the event of some changed convention as the prefix of issues to be linked in Jira or similar) This script will generate another, bash script, containint the commands that will be sent to the real subversion.
/**
Uso:
- Llamar:
groovy updatelogs.groovy [svn url] [PREFIJO] [revinicial] [revfinal] > updatelogs.sh
- Revisar el script updatelogs.sh generado
- Lanzar:
sh updatelogs.sh
- Si quedan a medias, se puede reiniciar todo el proceso, y se generará un nuevo updatelogs.sh
con solo los cambios pendientes.
**/
if (args.size() != 4) {
println "Uso incorrecto!"
println """
groovy updatelogs.groovy [svn url] [PREFIJO] [revinicial] [revfinal] > updatelogs.sh
"""
System.exit(1)
}
// Parametrizar
def SVN_URL = args[0]
def PREFIX = args[1]
def INICIAL = args[2].toInteger()
def TOTAL = args[3].toInteger()
println "# ${INICIAL} -> ${TOTAL}"
// Inicio
def step = 50
INICIAL.step(TOTAL, step) { it ->
actualiza(SVN_URL, it, it+Math.min(step,TOTAL-it), PREFIX)
}
def actualiza(svn, r0, r1, prefix) {
def cmdlog = "svn log ${svn} -r${r0}:${r1} --xml"
def proc = cmdlog.execute()
proc.waitFor()
def log = new XmlSlurper().parseText(proc.in.text)
log.logentry.each { entry ->
def rev = entry.@revision
def msg = entry.msg.text()
if (!msg.contains(prefix) && msg.contains('#')) {
msg = msg.replaceAll(/TBMTO[0-9]+/, "")
msg = msg.replaceAll(/TBMTO-[0-9]+/, "")
msg = msg.replaceAll(/#([0-9]+)/, "#\$1 ${prefix}\$1").replaceAll('"', "'")
def cmd = "svn propset -r ${rev} --revprop svn:log \"${msg}\" ${svn}"
println cmd
}
}
}
""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment