# Author:: Nicolas Pouillard . # Copyright:: Copyright (c) 2004 LRDE. All rights reserved. # License:: GNU General Public License (GPL). # $LastChangedBy: ertai $ # $Id: header 98 2004-09-29 12:07:43Z ertai $ require 'vcs' require 'svn' class Svn @@file_st = { 'A' => 'New', 'D' => 'Remove', } @@file_st.default = '' @@prop_st = { 'M' => 'Changed property' } def mkchangelog_from_status ( *args ) result = [] from_status(*args) do |line, file_st, prop_st, copy_st, file| next if file_st =~ /[?X]/ next if file == 'ChangeLog' ls = [] ls << @@file_st[file_st] if @@file_st.has_key? file_st ls << @@prop_st[prop_st].downcase if @@prop_st.has_key? prop_st result << [file, ls.join(', ')] end raise Failure, 'No changes, so no ChangeLog entry.' if result.empty? result end private :mkchangelog_from_status end # class Svn class Vcs class MustBeFilled < Exception attr_reader :file def initialize ( file ) @file = file super("You must fill this file: `#{file.to_s}'") end end def mkchangelog ( *args ) error_handling :changelog_failed cl = ADD_CL if cl.exist? f = cl.open('r') if f.readline !~ /^===/ f.rewind return f end f.close else cl_add = mkchangelog_from_status(*args) LOG.warn "Creating a new `#{cl}' file" cl.open('w') do |f| f.puts '=== Fill this file correctly and remove this line ===' f.puts Time.now.strftime("%Y-%m-%d #{FULL_EMAIL}") f.puts cl_add.each do |file, str| f.puts "\t* #{file}: #{str}." end end end raise MustBeFilled, cl end def concat_changelog! ( *args ) error_handling :changelog_failed unless CL.exist? raise Failure, "No `#{CL}', you are probably not in a valid directory." end if cl = mkchangelog(*args) unless TMP_CL.exist? LOG.info "Moving `#{CL}' to `#{TMP_CL}' ..." CL.rename(TMP_CL) end CL.open('w') do |file| LOG.info "Prepending `#{ADD_CL}' to `#{CL}' ..." file.print cl.read file.puts file.print TMP_CL.read end end end def changelog_failed if TMP_CL.exist? LOG.info "Restoring `#{CL}' from `#{TMP_CL}' ..." TMP_CL.rename(CL) end LOG.info "#{ADD_CL}: Contains your ChangeLog entry" if ADD_CL.exist? end alias_command :mkcl, :mkchangelog alias_command :ctcl, :concat_changelog end # class Vcs