https://svn.lrde.epita.fr/svn/lrdetools/trunk
Index: ChangeLog
from Nicolas Pouillard <ertai(a)lrde.epita.fr>
Adapt the whole Vcs to the new switches passing way.
* vcs/lib/vcs/mail.rb,
* vcs/lib/vcs/message.rb,
* vcs/lib/vcs/edit.rb,
* vcs/lib/vcs/changelog.rb,
* vcs/lib/vcs/script.rb,
* vcs/lib/vcs/diff.rb,
* vcs/lib/vcs/form.rb,
* vcs/lib/vcs/conflict.rb,
* vcs/lib/vcs/common_commit.rb: Adapt to the new way for passing
switches/options.
* vcs/lib/vcs/vcs.rb: Add VcsCmdData#to_s,
Fix OptionController#to_strings and Vcs#run_argv.
* vcs/lib/vcs/svn.rb: Change quotations.
changelog.rb | 4 ++++
common_commit.rb | 14 ++++++--------
conflict.rb | 6 +++---
diff.rb | 8 ++++----
edit.rb | 5 ++---
form.rb | 10 +++++-----
mail.rb | 13 ++++++++-----
message.rb | 8 ++++----
script.rb | 8 ++++++--
svn.rb | 4 ++--
vcs.rb | 49 +++++++++++++++++++++++++++----------------------
11 files changed, 71 insertions(+), 58 deletions(-)
Index: vcs/lib/vcs/script.rb
--- vcs/lib/vcs/script.rb (revision 243)
+++ vcs/lib/vcs/script.rb (working copy)
@@ -7,9 +7,13 @@
class Vcs
- def script! ( code, *args )
+ def script ( files=[], options={} )
+ puts script!(files, options)
+ end
+
+ def script! ( files=[], options={} )
begin
- eval(code)
+ eval(files.join(' '))
rescue Exception => ex
logger.error { 'Vcs#script: during the client execution' }
logger.error { ex.long_pp }
Index: vcs/lib/vcs/form.rb
--- vcs/lib/vcs/form.rb (revision 243)
+++ vcs/lib/vcs/form.rb (working copy)
@@ -6,7 +6,7 @@
class Vcs
def edit_form! ( *args )
- mk_from(*args)
+ mk_form(*args)
edit! Form if Form.read =~ /\A---/
if Form.read =~ /\A---/
raise Failure, "You must fill this file: `#{Form}' (and remove the first
line)"
@@ -19,7 +19,7 @@
def instanciate_form! ( *args )
with_cache! IForm, 'instanciated form (title, subject, ChangeLog entry,
diff)' do
- cl = mk_from(*args).read
+ cl = mk_form(*args).read
ls = []
YAML.each_document("--- |\n" + cl) { |x| (ls.size == 2)? break : ls
<< x }
title_subject, input = ls
@@ -42,7 +42,7 @@
@@subject_format ||= '<%= rev %>: <%= title %>'
- def mk_from! ( *args )
+ def mk_form! ( files=[], options={} )
with_cache! Form, 'complete form (title, subject, ChangeLog entry, diff)' do
puts "
@@ -55,7 +55,7 @@
|
|".head_cut!
- mk_log_entry!(*args)
+ mk_log_entry!(files)
puts "|
|--- | ########### This line, and those below, will be ignored #### 80c| # | ---
@@ -73,7 +73,7 @@
|
|".head_cut!
- diffw!(*args)
+ diffw!(files)
end
end
alias_command :mkf, :mk_form
Index: vcs/lib/vcs/mail.rb
--- vcs/lib/vcs/mail.rb (revision 243)
+++ vcs/lib/vcs/mail.rb (working copy)
@@ -10,17 +10,20 @@
MAIL = Sendmail::MAIL_FILE
MAILER = Sendmail.new
- DEFAULT_OPTIONS = %w[ --confirm --mime ]
+ DEFAULT_OPTIONS = { :confirm => true, :mime => true }
#
# Mail.
#
- def mail! ( *args )
+ # FIXME handle options properly.
+ # Delegata the option parsing to Sendmail.
+ def mail! ( files=[], options={} )
+ raise unless files.empty?
error_handling :mail_failed
unless MAIL.exist?
- options = DEFAULT_OPTIONS + args
- options << '--sign' if Vcs.user_conf.sign
- print_body(MAIL, MAILER.parse_mail_options(*options))
+ options = DEFAULT_OPTIONS.merge(options)
+ options[:signed => true] if Vcs.user_conf.sign
+ print_body(MAIL, MAILER.parse_mail_options(options))
end
MAILER.sendmail
MAIL.delete
Index: vcs/lib/vcs/common_commit.rb
--- vcs/lib/vcs/common_commit.rb (revision 243)
+++ vcs/lib/vcs/common_commit.rb (working copy)
@@ -5,21 +5,19 @@
class Vcs
- def common_commit! ( subject_format, *args, &block )
+ def common_commit! ( subject_format, files=[], opts={}, &block )
unless CL.exist?
raise Failure, "No `#{CL}', you are probably not in a valid
directory."
end
- opts, args = args.partition { |a| a =~ /^-/ }
-
@@subject_format = subject_format
update!
- Vcs.commited = edit_form!(*args)
+ Vcs.commited = edit_form!(files)
- message(*args)
+ message(files)
edit! Message
iform = nil
@@ -32,12 +30,12 @@
commit_failed
end
- concat_changelog!(*args)
+ concat_changelog!(files)
- args << 'ChangeLog' unless args.grep(/^[^-]/).empty?
+ files << 'ChangeLog' unless files.empty?
begin
- commit_!('--message', mk_log_entry(*args).read, *(opts + args))
+ commit_!(files, opts.merge(:message => mk_log_entry(files).read))
iform = YAML.load(IForm.read).merge('commited' => true)
IForm.open('w') { |f| f.print iform.to_yaml }
TMP_CL.delete if TMP_CL.exist?
Index: vcs/lib/vcs/changelog.rb
--- vcs/lib/vcs/changelog.rb (revision 243)
+++ vcs/lib/vcs/changelog.rb (working copy)
@@ -35,6 +35,7 @@
private :mk_log_entry_contents
+ # Same switches as status
def mk_log_entry! ( *args )
with_cache! LogEntry, 'Log entry' do
mk_log_entry_contents(*args).each do |file, comments|
@@ -56,6 +57,7 @@
end
private :log_to_changelog
+ # Same switches as mk_log_entry
def mk_changelog_entry! ( *args )
puts Time.now.strftime("%Y-%m-%d #{Vcs.full_email}")
puts
@@ -64,6 +66,7 @@
alias_command :mkcl, :mk_changelog_entry
+ # Same switches as mk_log_entry
def mk_message_entry! ( *args )
puts 'Index: ChangeLog'
puts "from #{Vcs.full_email}"
@@ -74,6 +77,7 @@
+ # Same switches as mk_changelog_entry
def concat_changelog! ( *args )
error_handling :concat_changelog_failed
Index: vcs/lib/vcs/edit.rb
--- vcs/lib/vcs/edit.rb (revision 243)
+++ vcs/lib/vcs/edit.rb (working copy)
@@ -7,9 +7,8 @@
class Vcs
- def edit! ( *files )
- # stringify
- cmd = Vcs.editor + files.flatten.map { |x| x.to_s } > [STDOUT, STDERR]
+ def edit! ( files=[], options={} )
+ cmd = Vcs.editor + files > [STDOUT, STDERR]
cmd.run(@runner)
end
Index: vcs/lib/vcs/diff.rb
--- vcs/lib/vcs/diff.rb (revision 243)
+++ vcs/lib/vcs/diff.rb (working copy)
@@ -22,16 +22,16 @@
class Svn < Vcs
# A diff only for your eyes
- def diffw! ( *args )
+ def diffw! ( files_orig=[], options={} )
files = Set.new
- from_status(*args) do |line, file_st, prop_st, cpy, file|
+ from_status(files_orig) do |line, file_st, prop_st, cpy, file|
next if file_st.chr =~ /[?X\\,+D]/
next if file.to_s == 'ChangeLog'
next if file.directory?
files << file
end
- return if files.empty? and not args.empty?
- diff_! '--diff-cmd', 'diff', '-x', '-NPbuw', *files
+ return if files.empty? and not files_orig.empty?
+ diff_! files.to_a, options.merge(:diff_cmd => 'diff', :extensions =>
'-NPbuw')
end
end # class Svn
Index: vcs/lib/vcs/conflict.rb
--- vcs/lib/vcs/conflict.rb (revision 243)
+++ vcs/lib/vcs/conflict.rb (working copy)
@@ -5,18 +5,18 @@
class Vcs
- def mk_conflicts_list
+ def mk_conflicts_list ( files, options={} )
ls = status.output.readlines.grep(/^C/).map! { |s| s[/^C\s+(.*)/, 1] }
raise "no conflicts" if ls.empty?
ls
end
protected :mk_conflicts_list
- def edit_conflicts!
+ def edit_conflicts! ( files, options={} )
edit! mk_conflicts_list
end
- def resolve_conflicts!
+ def resolve_conflicts! ( files, options={} )
conflicts = mk_conflicts_list
question = "Resolve these conflicts?: \n - #{conflicts.join("\n -
")}\n(y/n)"
if @h.agree question, true
Index: vcs/lib/vcs/svn.rb
--- vcs/lib/vcs/svn.rb (revision 243)
+++ vcs/lib/vcs/svn.rb (working copy)
@@ -17,7 +17,7 @@
add_basic_method(m)
end
- self.option_controller = OptionController.new Svn, %q[
+ self.option_controller = OptionController.new Svn, "
--auto-props
--config-dir DIR
--diff-cmd CMD
@@ -60,6 +60,6 @@
--verbose (-v)
--version
--xml
- ]
+ "
end # class Svn
Index: vcs/lib/vcs/vcs.rb
--- vcs/lib/vcs/vcs.rb (revision 243)
+++ vcs/lib/vcs/vcs.rb (working copy)
@@ -105,6 +105,15 @@
@out_io = @output.to_io_for_commands
end
+ def to_s
+ begin
+ @output.read
+ rescue IOError => ex
+ Vcs.logger.debug { ex.long_pp }
+ super
+ end
+ end
+
end # class VcsCmdData
class VcsCmdDataFactory < Commands::Datas::Factory
@@ -206,9 +215,14 @@
@shortcuts[short_option]
end
- def to_strings ( name, value )
- option = '--' + name.gsub('_', '-')
- [option, value.to_s]
+ def to_strings ( options )
+ result = []
+ options.each do |k, v|
+ raise if v == false
+ result << '--' + k.to_s.gsub('_', '-')
+ result << v.to_s if v != true
+ end
+ result
end
end # class OptionController
@@ -301,19 +315,10 @@
@@checkers = Set.new
- def run! ( *args )
+ def run! ( command, files=[], options={} )
flush
- cmd_args = []
- args.flatten.map do |arg|
- if arg.is_a? Hash
- arg.each do |k, v|
- cmd_args += option_controller.to_strings(k, v)
- end
- else
- cmd_args << arg
- end
- end
- (@cmd + args).run(@runner)
+ cmd_options = option_controller.to_strings(options)
+ (@cmd + command + cmd_options + files).run(@runner)
end
def sub_vcs ( out, err, &block )
@@ -348,7 +353,6 @@
end
def run_missing! ( name, orig, *args )
- return help!(*args) if name == '--help'
if name =~ /^(.*)_$/
run!($1, *args)
else
@@ -358,14 +362,15 @@
end
def run_argv ( argv )
- options, new_argv = option_controller.parse(argv)
- logger.debug { "options: #{options.inspect}, argv: #{new_argv}" }
- if new_argv.empty?
+ options, files = option_controller.parse(argv)
+ if files.empty? or options[:help]
meth = :help!
else
- meth = new_argv.shift.sub(/([^!])$/, '\1!')
+ meth = files.shift.dup
+ meth.sub!(/([^!])$/, '\1!') if meth != 'script'
end
- send(meth, *new_argv)
+ logger.debug { "meth: #{meth}, files: #{files.inspect}, options:
#{options.inspect}" }
+ result = send(meth, files, options)
end
%w[ checkout delete diff status log add update commit ].each do |m|
@@ -383,7 +388,7 @@
end
else
with_bang = meth + '!'
- return run_missing!(meth, meth, *args) unless respond_to? with_bang
+ return run_missing!(meth, *args) unless respond_to? with_bang
copy = sub_vcs_with_name(meth)
copy.send(with_bang, *args)
out = copy.cmd_data
Index: vcs/lib/vcs/message.rb
--- vcs/lib/vcs/message.rb (revision 243)
+++ vcs/lib/vcs/message.rb (working copy)
@@ -18,7 +18,7 @@
private :print_body
- def message! ( *args )
+ def message! ( files=[], options={} )
with_cache! Message, 'generated message (ChangeLog, diffstat, diff)' do
url!
if defined? COLLABOA
@@ -31,13 +31,13 @@
end
puts
flush
- mk_message_entry!(*args)
+ mk_message_entry!(files)
puts
flush
- diffstat!(*args)
+ diffstat!(files)
puts
flush
- diffw(*args).each_line do |line|
+ diffw(files).each_line do |line|
print line if line !~ /^=+$/
end
end