https://svn.lrde.epita.fr/svn/lrdetools/trunk
Index: ChangeLog
from Nicolas Pouillard <ertai(a)lrde.epita.fr>
A nice way to fill the subject and the news of your patches.
* vcs/lib/vcs/message.rb: Display the url on top of the ChangeLog entry.
* vcs/lib/vcs/changelog.rb, vcs/lib/vcs/mycommit.rb:
No more takes the subject as argument, provide a nice way to set the
subject of your mail and the title of your patch.
changelog.rb | 90 ++++++++++++++++++++++++++++++++++++++++++++---------------
message.rb | 8 +++--
mycommit.rb | 18 +++++++----
3 files changed, 84 insertions(+), 32 deletions(-)
Index: vcs/lib/vcs/changelog.rb
--- vcs/lib/vcs/changelog.rb (revision 219)
+++ vcs/lib/vcs/changelog.rb (working copy)
@@ -48,29 +48,67 @@
end
end
+ @@subject_format = '<%= rev %>: <%= title %>'
+
def mkchangelog! ( *args )
error_handling :changelog_failed
+ unless CL.exist?
+ raise Failure, "No `#{CL}', you are probably not in a valid
directory."
+ end
+
cl = ADD_CL
+ # Already filled if ,ChangeLog.add exists and not begin by ---
if cl.exist?
- f = cl.open('r')
- if f.readline !~ /^===/
- f.rewind
- return f
+ raise MustBeFilled, cl if cl.read =~ /\A---/
+ require 'erb'
+ ls = []
+ YAML.each_document(cl.read) { |x| (ls.size == 2)? break : ls << x }
+ header, input = ls
+ rev = revision.read.to_i
+ header.merge!('rev' => rev, 'revision' => rev)
+ header['title'].sub!(/\.$/, '')
+ b = getBinding(header)
+ header = ERB.new(header.to_yaml, $SAFE, '<-%->',
'$erbout_').result(b)
+ META.open('w') { |f| f.puts header }
+ output = ERB.new(input, $SAFE, '<-%->',
'$erbout_').result(b)
+ return output
end
- f.close
- else
+
cl_add = mkchangelog_from_status(*args)
LOG.info "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
+ head = Time.now.strftime("%Y-%m-%d #{FULL_EMAIL}")
+ f.puts "
+|--- | ########## Fill this file correctly and remove this line ########## | ---
+|title:
+|subject: '#{@@subject_format}.'
+|
+|--- | ###################### Your ChangeLog entrie ###################### | ---
+ |#{head}
+ |
+ |\t<%= title %>.
+ |
+ |".head_cut!
+
cl_add.each do |file, str|
f.puts "\t* #{file}: #{str}."
end
- end
+
+ f.puts "|
+|--- | ########### This line, and those below, will be ignored ########### | ---
+ |Instructions:
+ |\t* The first line must be removed when this file is filled.
+ |\t* After you must specify a title, for the news/mail subject.
+ |\t* The line containing <%= title %> will be replaced by your title,
+ |\t <%= subject %> by the subject line, <%= rev %> by the revision...
+ |\t* Everywhere in the document you can get/compute some values with
+ |\t these tags <%= aRubyExpression %> even some vcs specific call.
+ |\t For example <%= status.read %> will include the `svn status'
output.
+ |
+ |".head_cut!
+ with(f).diff!(*args)
end
raise MustBeFilled, cl
@@ -79,11 +117,7 @@
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)
+ if cl_entry = mkchangelog(*args)
unless TMP_CL.exist?
LOG.info "Moving `#{CL}' to `#{TMP_CL}' ..."
@@ -92,11 +126,13 @@
CL.open('w') do |file|
LOG.info "Prepending `#{ADD_CL}' to `#{CL}' ..."
- file.print cl.read
+ file.print cl_entry
file.puts
file.print TMP_CL.read
end
+ return cl_entry
+
end
end
@@ -108,6 +144,16 @@
LOG.info "#{ADD_CL}: Contains your ChangeLog entry" if ADD_CL.exist?
end
+ def getBinding ( header )
+ code = []
+ header.each do |k, v|
+ code << "#{k} = #{v.inspect}"
+ end
+ code << 'binding'
+ eval(code.join('; '))
+ end
+ protected :getBinding
+
alias_command :mkcl, :mkchangelog
alias_command :ctcl, :concat_changelog
Index: vcs/lib/vcs/mycommit.rb
--- vcs/lib/vcs/mycommit.rb (revision 219)
+++ vcs/lib/vcs/mycommit.rb (working copy)
@@ -12,10 +12,12 @@
COMMITED = Pathname.new(',commited')
- def common_commit! ( *args, &block )
+ def common_commit! ( subject_format, *args, &block )
opts, args = args.partition { |a| a =~ /^-/ }
+ @@subject_format = subject_format
+
update!
unless COMMITED.exist?
@@ -34,14 +36,16 @@
commit_failed
end
- concat_changelog!(*args)
+ cl_entry = concat_changelog!(*args)
#pager! diff
#pager! status
args << 'ChangeLog' unless args.grep(/^[^-]/).empty?
- if commit!('-F', ADD_CL, *(opts + args))
+ # FIXME simplify cl_entry contents
+
+ if commit!('--message', cl_entry, *(opts + args))
ADD_CL.rename(COMMITED)
TMP_CL.delete if TMP_CL.exist?
else
@@ -57,18 +61,18 @@
end
+ header ||= YAML::load(META.read)
- rev = revision.read.to_i
-
- block.call(rev) if block_given?
+ block[header['subject']] if block_given?
LOG.info 'Deleting junk files...'
TMP_CL.delete if TMP_CL.exist?
ADD_CL.delete if ADD_CL.exist?
COMMITED.delete if COMMITED.exist?
+ META.delete if META.exist?
messages = Pathname.new(',messages')
messages.mkpath unless messages.directory?
- message_rev = messages + "#{@@message}.#{rev}"
+ message_rev = messages + "#{@@message}.#{header['rev']}"
LOG.info "Moving `#{@@message}' to `#{message_rev}'..."
@@message.rename(message_rev)
LOG.info "You can remove `#{message_rev}' if everything is ok."
Index: vcs/lib/vcs/message.rb
--- vcs/lib/vcs/message.rb (revision 219)
+++ vcs/lib/vcs/message.rb (working copy)
@@ -39,13 +39,15 @@
error_handling :message_failed
unless @@message.exist?
- cl = mkchangelog(*args)
+ cl_entry = mkchangelog(*args)
TempPath.new('message') do |tmp|
tmp.open('w') do |f|
+ with(f).url!
+ f.puts
f.puts 'Index: ChangeLog'
- f.print cl.read.sub(/^\d+-\d+-\d+/, 'from')
+ f.print cl_entry.sub(/^\d+-\d+-\d+/, 'from')
f.puts
- f.print diffstat(*args).read
+ with(f).diffstat!(*args)
f.puts
diffw_from_status(*args).each_line do |line|
f.print line if line !~ /^=+$/