Skip to content

Instantly share code, notes, and snippets.

@dlip
Created August 4, 2010 08:00
Show Gist options
  • Save dlip/507815 to your computer and use it in GitHub Desktop.
Save dlip/507815 to your computer and use it in GitHub Desktop.
Increments the trac ticket numbers in the svn log and replaces "ticket:" with # for Redmine multi project
@repo = "file:///path_to_svn_repo"
#How much each ticket should be incremented by
@increment_ticket = 100
#If the incremented ticket is above or below these numbers it will not increment
#Useful if you have a svn repository which refers to tickets in another project
@ticket_min = 0
@ticket_max = 100000
class SvnEntry
attr_accessor :revision, :log
def initialize
@log = String.new
@revision = String.new
end
end
def get_revisions
mode = :none
svn_entry = nil
svn_out = `svn log #{@repo}`
svn_out.each do |line|
if line =~ /^\-+\-$/
yield svn_entry if svn_entry
mode = :new_revision
next
end
if mode == :new_revision
svn_entry = SvnEntry.new
svn_entry.revision = line.scan(/^r(\d+)/)[0][0]
mode = :read_commit_info_skip_blank
next
end
if mode == :read_commit_info_skip_blank
mode = :read_commit_info
next
end
if mode == :read_commit_info
svn_entry.log << line
next
end
end
end
def get_incremented_ticket(ticket_no)
ticket_no = ticket_no.to_i
incremented_ticket_no = ticket_no + @increment_ticket
case incremented_ticket_no
when @ticket_min..@ticket_max
ticket_no = incremented_ticket_no
end
"#" + ticket_no.to_s
end
get_revisions do |r|
if r.log =~ /#\d+/ || r.log =~ /ticket:\d+/
puts r.log
puts "~~~~~~~~~~~~~~~~~~~~"
r.log = r.log.gsub(/#(\d+)/) { get_incremented_ticket $1 }
r.log = r.log.gsub(/ticket:(\d+)/) { get_incremented_ticket $1 }
puts r.log
puts "----------------"
logfile = File.new("outfile", "w")
logfile.syswrite(r.log)
command = `svn propset --revprop -r #{r.revision} svn:log -F outfile #{@repo}`
puts command
logfile.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment