You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by se...@apache.org on 2020/06/17 20:05:21 UTC
[whimsy] branch master updated: Use common method to build SVN
command line
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 a5fe00d Use common method to build SVN command line
a5fe00d is described below
commit a5fe00d608ffdea6c2e33e0bc25a3487699f8362
Author: Sebb <se...@apache.org>
AuthorDate: Wed Jun 17 21:05:12 2020 +0100
Use common method to build SVN command line
---
lib/whimsy/asf/svn.rb | 128 ++++++++++++++++++--------------------------------
1 file changed, 45 insertions(+), 83 deletions(-)
diff --git a/lib/whimsy/asf/svn.rb b/lib/whimsy/asf/svn.rb
index 5907b06..d4157c4 100644
--- a/lib/whimsy/asf/svn.rb
+++ b/lib/whimsy/asf/svn.rb
@@ -263,33 +263,9 @@ module ASF
# These keys are common to svn_ and svn
VALID_KEYS=[:args, :user, :password, :verbose, :env, :dryrun, :msg, :depth]
- # low level SVN command
- # params:
- # 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]}
- # :env - environment: source for user and password
- # :user, :password - used if env is not present
- # :verbose - show command on stdout
- # :dryrun - return command array as [cmd] without executing it (excludes auth)
- # :chdir - change directory for system call
- # Returns:
- # - stdout
- # - nil, err
- # - [cmd] if :dryrun
- # May raise ArgumentError
- def self.svn(command, path , options = {})
- raise ArgumentError.new 'command must not be nil' unless command
- raise ArgumentError.new 'path must not be nil' unless path
-
- # Deal with svn-only opts
- chdir = options.delete(:chdir)
- open_opts = {}
- open_opts[:chdir] = chdir if chdir
-
+ # common routine to build SVN command line
+ # returns [cmd, stdin] where stdin is the data for stdin (if any)
+ def self._svn_build_cmd(command, path, options)
bad_keys = options.keys - VALID_KEYS
if bad_keys.size > 0
raise ArgumentError.new "Following options not recognised: #{bad_keys.inspect}"
@@ -297,6 +273,7 @@ module ASF
# build svn command
cmd = ['svn', command, '--non-interactive']
+ stdin = nil # for use with -password-from-stdin
args = options[:args]
if args
@@ -326,12 +303,12 @@ module ASF
end
# password was supplied, add credentials
if password and not options[:dryrun] # don't add auth for dryrun
- cmd += ['--username', user, '--no-auth-cache']
+ cmd << ['--username', user, '--no-auth-cache']
if self.passwordStdinOK?()
- open_opts[:stdin_data] = password
- cmd << '--password-from-stdin'
+ stdin = password
+ cmd << ['--password-from-stdin']
else
- cmd += ['--password', password]
+ cmd << ['--password', password]
end
end
@@ -343,6 +320,41 @@ module ASF
cmd << path
end
+ return cmd, stdin
+ end
+
+ # low level SVN command
+ # params:
+ # 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]}
+ # :env - environment: source for user and password
+ # :user, :password - used if env is not present
+ # :verbose - show command on stdout
+ # :dryrun - return command array as [cmd] without executing it (excludes auth)
+ # :chdir - change directory for system call
+ # Returns:
+ # - stdout
+ # - nil, err
+ # - [cmd] if :dryrun
+ # May raise ArgumentError
+ def self.svn(command, path , options = {})
+ raise ArgumentError.new 'command must not be nil' unless command
+ raise ArgumentError.new 'path must not be nil' unless path
+
+ # Deal with svn-only opts
+ chdir = options.delete(:chdir)
+ open_opts = {}
+ open_opts[:chdir] = chdir if chdir
+
+ cmd, stdin = self._svn_build_cmd(command, path, options)
+
+ cmd.flatten!
+ open_opts[:stdin_data] = stdin if stdin
+
p cmd if options[:verbose]
return [cmd] if options[:dryrun]
@@ -389,59 +401,9 @@ module ASF
# Pick off the options specific to svn_ rather than svn
sysopts = options.delete(:sysopts) || {}
- bad_keys = options.keys - VALID_KEYS
- if bad_keys.size > 0
- raise ArgumentError.new "Following options not recognised: #{bad_keys.inspect}"
- end
-
- # build svn command
- cmd = ['svn', command, '--non-interactive']
-
- 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
-
- # add credentials if required
- env = options[:env]
- if env
- password = env.password
- user = env.user
- else
- password = options[:password]
- user = options[:user] if password
- end
- # password was supplied, add credentials
- if password and not options[:dryrun] # don't add auth for dryrun
- creds = ['--no-auth-cache', '--username', user]
- if self.passwordStdinOK?()
- sysopts[:stdin] = password
- creds << '--password-from-stdin'
- else
- creds += ['--password', password]
- end
- cmd << creds
- end
-
- cmd << '--' # ensure paths cannot be mistaken for options
- if path.is_a? Array
- cmd += path
- else
- cmd << path
- end
+ cmd, stdin = self._svn_build_cmd(command, path, options)
+ sysopts[:stdin] = stdin if stdin
Wunderbar.warn cmd.inspect if options[:verbose] # includes auth