This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new 9093b05 Eliminate arbitrary :args parameter
9093b05 is described below
commit 9093b05e5b183d4a0a22056a8e83f22ebabbc983
Author: Sebb <[email protected]>
AuthorDate: Fri Jul 3 16:49:50 2020 +0100
Eliminate arbitrary :args parameter
---
lib/spec/lib/svn_spec.rb | 43 +++++++++++++++++-----------------
lib/spec/lib/svn_wunderbar_spec.rb | 27 ----------------------
lib/whimsy/asf/svn.rb | 47 +++++++++++++++++++-------------------
www/members/proxy.cgi | 2 +-
www/officers/coi.cgi | 2 +-
5 files changed, 47 insertions(+), 74 deletions(-)
diff --git a/lib/spec/lib/svn_spec.rb b/lib/spec/lib/svn_spec.rb
index de4b5df..6732f2d 100644
--- a/lib/spec/lib/svn_spec.rb
+++ b/lib/spec/lib/svn_spec.rb
@@ -243,10 +243,6 @@ describe ASF::SVN do
it "svn('st','',{xyz: true}) should raise error" do
expect { ASF::SVN.svn('st','',{xyz: true}) }.to
raise_error(ArgumentError, 'Following options not recognised: [:xyz]')
end
- it "svn('st','',{args: true}) should raise error" do
- expect { ASF::SVN.svn('st','',{args: true}) }.to
raise_error(ArgumentError, "args 'true' must be string or array")
- end
-
it "svn('info', path) should return 'Name: path'" do
repo = File.join(ASF::SVN.svnurl('attic-xdocs'),'_template.xml')
@@ -258,29 +254,13 @@ describe ASF::SVN do
out, err = ASF::SVN.svn('info',[repo])
expect(out).to match(/^Name: _template.xml$/)
end
- it "svn('info', [path1, path2], {args: ['--show-item','kind']}) should
return 'file ...'" do
+ it "svn('info', [path1, path2], {item: kind'}) should return 'file ...'" do
path1 = File.join(ASF::SVN.svnurl('attic-xdocs'),'_template.xml')
path2 = File.join(ASF::SVN.svnurl('attic-xdocs'),'jakarta.xml')
- out, err = ASF::SVN.svn('info',[path1, path2], {args:
['--show-item','kind']})
+ out, err = ASF::SVN.svn('info',[path1, path2], {item: 'kind'})
expect(out).to match(/^file +https:/)
end
- it "svn('help', 'help', {args: ['--depth','empty'], dryrun: true}) should
return the same as {depth: 'files'}" do
- out1, err1 = ASF::SVN.svn('help', 'help', {args: ['--depth','empty'],
dryrun: true})
- out2, err2 = ASF::SVN.svn('help', 'help', {depth: 'empty', dryrun: true})
- expect(out1).to eq(out2)
- expect(err1).to eq(nil)
- expect(err2).to eq(nil)
- end
-
- it "svn('help', 'help', {args: ['--message','text'], dryrun: true}) should
return the same as {msg: 'text'}" do
- out1, err1 = ASF::SVN.svn('help', 'help', {args: ['--message','text'],
dryrun: true})
- out2, err2 = ASF::SVN.svn('help', 'help', {msg: 'text', dryrun: true})
- expect(out1).to eq(out2)
- expect(err1).to eq(nil)
- expect(err2).to eq(nil)
- end
-
it "svn() should honour :chdir option" do
begin # Hack to avoid Travis fail; TODO ensure there is a suitable SVN
checkout for the test
pods = ASF::SVN['incubator-podlings']
@@ -341,6 +321,25 @@ describe ASF::SVN do
it "_svn_build_cmd('help', 'path', {_error: true}) should raise error" do
expect { ASF::SVN._svn_build_cmd('help', 'path', {_error: true}) }.to
raise_error(ArgumentError, "Following options not recognised: [:_error]")
end
+
+ it "_svn_build_cmd('help', 'path', {quiet: true}) should include --quiet"
do
+ cmd, stdin = ASF::SVN._svn_build_cmd('help', 'path', {quiet: true})
+ expect(stdin).to eq(nil)
+ expect(cmd).to eq(["svn", "help", "--non-interactive", "--quiet", "--",
"path"])
+ end
+
+ it "_svn_build_cmd('help', 'path', {item: 'url'}) should include
--show-item url" do
+ cmd, stdin = ASF::SVN._svn_build_cmd('help', 'path', {item: 'url'})
+ expect(stdin).to eq(nil)
+ expect(cmd).to eq(["svn", "help", "--non-interactive", "--show-item",
'url', "--", "path"])
+ end
+
+ it "_svn_build_cmd('help', 'path', {revision: '123'}) should include
--revision 123" do
+ cmd, stdin = ASF::SVN._svn_build_cmd('help', 'path', {revision: '123'})
+ expect(stdin).to eq(nil)
+ expect(cmd).to eq(["svn", "help", "--non-interactive", "--revision",
'123', "--", "path"])
+ end
+
end
describe "ASF::SVN.svnpath!" do
diff --git a/lib/spec/lib/svn_wunderbar_spec.rb
b/lib/spec/lib/svn_wunderbar_spec.rb
index ef6faed..fb3ed7d 100644
--- a/lib/spec/lib/svn_wunderbar_spec.rb
+++ b/lib/spec/lib/svn_wunderbar_spec.rb
@@ -43,9 +43,6 @@ describe "ASF::SVN.svn_" do
it "svn_('st','',_,{xyz: true}) should raise error" do
expect { ASF::SVN.svn_('st','',true,{xyz: true}) }.to
raise_error(ArgumentError, 'Following options not recognised: [:xyz]')
end
- it "svn_('st','',_,{args: true}) should raise error" do
- expect { ASF::SVN.svn_('st','',true,{args: true}) }.to
raise_error(ArgumentError, "args 'true' must be string or array")
- end
it "svn_('info') should return array with Name:" do
repo = File.join(ASF::SVN.svnurl('attic-xdocs'),'_template.xml')
@@ -82,30 +79,6 @@ describe "ASF::SVN.svn_" do
expect(out['transcript'].join("\n")).to match(/svn: E200009:/)
end
- it "svn_('help', 'help', _, {args: ['--depth','empty'], dryrun: true})
should return the same as {depth: 'files'}" do
- rc1, out1 = _json do |_|
- ASF::SVN.svn_('help', 'help', _, {args: ['--depth','empty'], dryrun:
true})
- end
- rc2, out2 = _json do |_|
- ASF::SVN.svn_('help', 'help', _, {depth: 'empty', dryrun: true})
- end
- expect(rc1).to eq(0)
- expect(rc2).to eq(0)
- expect(out1).to eq(out2)
- end
-
- it "svn_('help', 'help', _, {args: ['--message','text'], dryrun: true})
should return the same as {msg: 'text'}" do
- rc1, out1 = _json do |_|
- ASF::SVN.svn_('help', 'help', _, {args: ['--message','text'], dryrun:
true})
- end
- rc2, out2 = _json do |_|
- ASF::SVN.svn_('help', 'help', _, {msg: 'text', dryrun: true})
- end
- expect(rc1).to eq(0)
- expect(rc2).to eq(0)
- expect(out1).to eq(out2)
- end
-
it "auth: should override env: and user:/password:" do
rc1, out1 = _json do |_|
ASF::SVN.svn_('help', 'help', _, {auth: [['a','b']], env:
ENV_.new('c','d'), user: 'user', password: 'pass', verbose: true, dryrun: true})
diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index d13ddaa..982bdd0 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -263,7 +263,7 @@ module ASF
# Note: Path, Schedule and Depth are not currently supported
#
def self.getInfoItem(path, item, user=nil, password=nil)
- out, err = self.svn('info', path, {args: ['--show-item', item],
+ out, err = self.svn('info', path, {item: item,
user: user, password: password})
if out
if item.end_with? 'revision' # svn version 1.9.3 appends trailing
spaces to *revision items
@@ -282,7 +282,7 @@ module ASF
end
# These keys are common to svn_ and svn
- VALID_KEYS=[:args, :user, :password, :verbose, :env, :dryrun, :msg, :depth]
+ VALID_KEYS=[:user, :password, :verbose, :env, :dryrun, :msg, :depth,
:quiet, :item, :revision]
# common routine to build SVN command line
# returns [cmd, stdin] where stdin is the data for stdin (if any)
@@ -296,23 +296,20 @@ module ASF
cmd = ['svn', command, '--non-interactive']
stdin = nil # for use with -password-from-stdin
- args = options[:args]
- if args
- if args.is_a? String
- cmd << args
- elsif args.is_a? Array
- cmd += args
- else
- raise ArgumentError.new "args '#{args.inspect}' must be string or
array"
- end
- end
-
msg = options[:msg]
cmd += ['--message', msg] if msg
depth = options[:depth]
cmd += ['--depth', depth] if depth
+ cmd << '--quiet' if options[:quiet]
+
+ item = options[:item]
+ cmd += ['--show-item', item] if item
+
+ revision = options[:revision]
+ cmd += ['--revision', revision] if revision
+
# add credentials if required
env = options[:env]
if env
@@ -353,11 +350,13 @@ module ASF
# command - info, list etc
# path - the path(s) to be used - String or Array of Strings
# options - hash of:
- # :args - string or array of strings, e.g. '-v', ['--depth','empty']
- # :msg - shorthand for {args: ['--message', value]}
- # :depth - shorthand for {args: ['--depth', value]}
+ # :msg - ['--message', value]
+ # :depth - ['--depth', value]
# :env - environment: source for user and password
# :user, :password - used if env is not present
+ # :quiet - if true, apply the --quiet option
+ # :item - [--show-item, value]
+ # :revision - [--revision, value]
# :verbose - show command on stdout
# :dryrun - return command array as [cmd] without executing it (excludes
auth)
# :chdir - change directory for system call
@@ -405,9 +404,11 @@ module ASF
# path - the path(s) to be used - String or Array of Strings
# _ - wunderbar context
# options - hash of:
- # :args - string or array of strings, e.g. '-v', ['--depth','empty']
- # :msg - shorthand for {args: ['--message', value]}
- # :depth - shorthand for {args: ['--depth', value]}
+ # :msg - ['--message', value]
+ # :depth - ['--depth', value]
+ # :quiet - if true, apply the --quiet option
+ # :item - [--show-item, value]
+ # :revision - [--revision, value]
# :auth - authentication (as [['--username', etc]])
# :env - environment: source for user and password
# :user, :password - used if env is not present
@@ -514,7 +515,7 @@ module ASF
pass = env.password.dup.untaint
# checkout committers/board (this does not have many files currently)
out, err = self.svn('checkout', [ciURL, tmpdir.untaint],
- {args: '--quiet', depth: 'files',
+ {quiet: true, depth: 'files',
user: user, password: pass})
raise Exception.new("Checkout of board folder failed: #{err}") unless
out
@@ -530,7 +531,7 @@ module ASF
# commit the updated file
out, err = self.svn('commit', [file, tmpdir.untaint],
- {args: '--quiet', msg: msg,
+ {quiet: true, msg: msg,
user: user, password: pass})
raise Exception.new("Update of committee-info.txt failed: #{err}")
unless out
@@ -871,8 +872,8 @@ module ASF
# Does this host's installation of SVN support --password-from-stdin?
def self.passwordStdinOK?()
return @svnHasPasswordFromStdin unless @svnHasPasswordFromStdin.nil?
- out,err = self.svn('help','cat', {args: '-v'})
- if out
+ out, err, status = Open3.capture3('svn','help','cat', '-v')
+ if status.success? && out
@svnHasPasswordFromStdin = out.include? '--password-from-stdin'
else
@svnHasPasswordFromStdin = false
diff --git a/www/members/proxy.cgi b/www/members/proxy.cgi
index 4e98529..3bc89df 100755
--- a/www/members/proxy.cgi
+++ b/www/members/proxy.cgi
@@ -182,7 +182,7 @@ def emit_post(cur_mtg_dir, meeting, _)
svn = ASF::SVN.getInfoItem(File.join(MEETINGS,meeting),'url')
ASF::SVN.svn_('checkout',[svn.untaint, tmpdir.untaint], _,
- {args: '--quiet', user: $USER, password: $PASSWORD})
+ {quiet: true, user: $USER, password: $PASSWORD})
Dir.chdir(tmpdir) do
# write proxy form
filename = "proxies-received/#$USER.txt".untaint
diff --git a/www/officers/coi.cgi b/www/officers/coi.cgi
index 2590547..80bae8b 100755
--- a/www/officers/coi.cgi
+++ b/www/officers/coi.cgi
@@ -191,7 +191,7 @@ def emit_post(_)
_div.transcript do
Dir.mktmpdir do |tmpdir|
ASF::SVN.svn_!('checkout',[COI_CURRENT_URL, tmpdir.untaint], _,
- {args: '--quiet', user: $USER.dup.untaint, password:
$PASSWORD.dup.untaint})
+ {quiet: true, user: $USER.dup.untaint, password:
$PASSWORD.dup.untaint})
Dir.chdir(tmpdir) do
# write affirmation form
File.write(user_filename, affirmed)