rakelib/scm.rb
changeset 71 68c8cccbdec5
parent 67 75b6eb7b781c
child 72 3e832d54a4af
--- a/rakelib/scm.rb	Wed Nov 02 10:39:54 2016 +0000
+++ b/rakelib/scm.rb	Thu Nov 03 22:27:02 2016 +0000
@@ -28,37 +28,37 @@
     end
   end
 
-  def self.update(repository, directory, *params)
+  def self.update(repository, directory, **kwargs)
     type = repository.type
     url = repository.canonical
-    self._check_type(type)
-    if params.size() > 0
-      p = params.last
-    else
-      p = {}
+    self._check_type(type)    
+    root = kwargs[:root] || BUILD_DIR
+    branch = kwargs[:branch]
+    if branch == nil
+      if type == :svn
+        branch = 'trunk'
+      elsif type == :hg
+        branch = 'default'
+      end
     end
-    root = p[:root] || BUILD_DIR
+
     wc = root / directory
     if (! File.exist? wc)
-      self.checkout(repository, directory, *params)
+      self.checkout(repository, directory, **kwargs)
       return
     end
     case type
-      when :svn    then _update_svn(wc)
-      when :cvs    then _update_cvs(wc)
-      when :git    then _update_git(wc, repository, directory, *params)
-      when :hg     then _update_hg(wc, repository, directory, *params)
+      when :svn    then _update_svn(repository, directory, branch, root, **kwargs)
+      when :cvs    then _update_cvs(repository, directory, branch, root, **kwargs)
+      when :git    then _update_git(repository, directory, branch, root, **kwargs)
+      when :hg     then _update_hg(repository, directory, branch, root, **kwargs)
     end
   end
 
-  def self._update_hg(wc, repository, directory = nil, *params)    
-    if directory != nil then
-      if params.size() > 0
-        p = params.last
-      else
-        p = {}
-      end
-      separator = p[:separator] || '.'
+  def self._update_hg(repository, directory, branch, root, **kwargs)
+    wc = root / directory
+    separator = kwargs[:separator] || '.'
+    if directory != nil then      
       url = "#{repository.canonical}/#{directory.gsub('/', separator)}"
     end
     hg = HG::Repository.new(wc)
@@ -86,13 +86,15 @@
   end
 
 
-  def self._update_svn(wc)    
+  def self._update_svn(repository, directory, branch, root, **kwargs)
+    wc = root / directory
     if not sh %W{svn --non-interactive --trust-server-cert update}, cwd: wc
       raise CheckoutException.new("SVN: Cannot update #{wc}")
     end
   end
 
-  def self._update_cvs(wc)
+  def self._update_cvs(repository, directory, branch, root, **kwargs)
+    wc = root / directory
     if File.directory? wc
       if not sh %W{cvs -z 9 update -A -d}, cwd: wc
         raise CheckoutException.new("CVS: Cannot update #{wc}")
@@ -104,17 +106,13 @@
     end
   end
 
-  def self.checkout(repository, directory, *params)    
+  def self.checkout(repository, directory, **kwargs)    
     type = repository.type
     url = repository.canonical
     self._check_type(type)
-    if params.size() > 0
-      p = params.last
-    else
-      p = {}
-    end
-    root = p[:root] || BUILD_DIR
-    branch = p[:branch]
+    
+    root = kwargs[:root] || BUILD_DIR
+    branch = kwargs[:branch]
     if branch == nil
       if type == :svn
         branch = 'trunk'
@@ -125,7 +123,7 @@
 
     wc = root / directory
     if (File.exist? wc)
-      self.update(repository, directory, *params)
+      self.update(repository, directory, **kwargs)
       return
     end
 
@@ -137,28 +135,23 @@
       end
     end
     case type
-      when :svn    then _checkout_svn(repository, directory, branch, root, *params)
-      when :cvs    then _checkout_cvs(repository, directory, branch, root, *params)
-      when :git    then _checkout_git(repository, directory, branch, root, *params)
-      when :hg     then _checkout_hg(repository, directory, branch, root, *params)      
+      when :svn    then _checkout_svn(repository, directory, branch, root, **kwargs)
+      when :cvs    then _checkout_cvs(repository, directory, branch, root, **kwargs)
+      when :git    then _checkout_git(repository, directory, branch, root, **kwargs)
+      when :hg     then _checkout_hg(repository, directory, branch, root, **kwargs)      
     end
 
   end
 
-  def self._checkout_svn(repository, directory, branch, root, *params)
+  def self._checkout_svn(repository, directory, branch, root, **kwargs)
     url = "#{repository.canonical}/#{directory}/#{branch}"
     if not sh %W{svn --non-interactive --trust-server-cert co #{url} #{directory}}, cwd: root
       raise CheckoutException.new("SVN: Cannot checkout from #{url}")
     end
   end
 
-  def self._checkout_hg(repository, directory, branch, root, *params)
-    if params.size() > 0
-      p = params.last
-    else
-      p = {}
-    end
-    separator = p[:separator] || '.'
+  def self._checkout_hg(repository, directory, branch, root, **kwargs)    
+    separator = kwargs[:separator] || '.'
 
     hg = HG::Repository.init(root / directory)
     paths = { 'default' => "#{repository.upstream}/#{directory.gsub('/', separator)}",
@@ -183,53 +176,50 @@
     end
   end
 
-  def self._checkout_cvs(repository, directory, branch, root, *params)    
+  def self._checkout_cvs(repository, directory, branch, root, **kwargs)    
     if not sh %W{cvs -z 9 -d #{repository.canonical} co #{directory}}, cwd: root
       raise CheckoutException.new("CVS: Cannot checkout #{directory}from #{repository.url}")
     end
   end
 end # module Rake::Stx::SCM
 
-def checkout(repo_name, directory, *params)
+def checkout(repo_name, directory, **kwargs)
   # repository should be symbolic name
   repo = Rake::Stx::Configuration::Repository::find(repo_name)
   if not repo then
       error("checkout(): No repository found (#{repo_name})")
   end  
-  if params.last.is_a? Hash 
-    params.last[:separator] = repo.separator
-  else
-    params << {:separator => repo.separator}
-  end    
-  Rake::Stx::SCM.checkout(repo, directory, *params)  
+  kwargs[:separator] = repo.separator
+  Rake::Stx::SCM.checkout(repo, directory, **kwargs)  
 end
 
-def update(repo_name, directory, *params)
+def update(repo_name, directory, **kwargs)
   # repository should be symbolic name
   repo = Rake::Stx::Configuration::Repository::find(repo_name)
   if not repo then  
     error("update(): No repository found (#{repo_name})")
   end  
-  Rake::Stx::SCM.update(repo, directory, *params)
+  kwargs[:separator] = repo.separator
+  Rake::Stx::SCM.update(repo, directory, **kwargs)
 end
 
-def cvs(url, directory, *params)
+def cvs(url, directory, **kwargs)
   repo = Rake::Stx::Configuration::Repository.new(:type => :cvs, :url => url)
-  Rake::Stx::SCM.checkout(repo, directory, *params)
+  Rake::Stx::SCM.checkout(repo, directory, **kwargs)
 end
 
-def svn(url, directory, *params)
+def svn(url, directory, **kwargs)
   repo = Rake::Stx::Configuration::Repository.new(:type => :svn, :url => url)
-  Rake::Stx::SCM.checkout(repo, directory, *params)
+  Rake::Stx::SCM.checkout(repo, directory, **kwargs)
 end
 
-def hg(url, directory, *params)
+def hg(url, directory, **kwargs)
   repo = Rake::Stx::Configuration::Repository.new(:type => :hg, :url => url)
-  Rake::Stx::SCM.checkout(repo, directory, *params)
+  Rake::Stx::SCM.checkout(repo, directory, **kwargs)
 end
 
-def git(url, directory, *params)
+def git(url, directory, **kwargs)
   repo = Rake::Stx::Configuration::Repository.new(:type => :git, :url => url)
-  Rake::Stx::SCM.checkout(repo, directory, *params)
+  Rake::Stx::SCM.checkout(repo, directory, **kwargs)
 end