OSDN Git Service

feature #9137 Password-protected SVN repositories
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 9 Mar 2007 18:03:31 +0000 (18:03 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 9 Mar 2007 18:03:31 +0000 (18:03 +0000)
* added login and password attributes on repositories
* fixed svn calls (svn waiting for user input)

git-svn-id: http://redmine.rubyforge.org/svn/trunk@319 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository.rb
app/models/svn_repos.rb
app/views/projects/_form.rhtml
db/migrate/026_add_repository_login_and_password.rb [new file with mode: 0644]

index 29e8758..d6e0e11 100644 (file)
@@ -23,6 +23,6 @@ class Repository < ActiveRecord::Base
   @scm = nil
     
   def scm
-    @scm ||= SvnRepos::Base.new url
+    @scm ||= SvnRepos::Base.new url, login, password
   end
 end
index 7c6f5e0..aed9f1b 100644 (file)
@@ -23,9 +23,6 @@ module SvnRepos
   end\r
 \r
   class Base\r
-    @url = nil\r
-    @login = nil\r
-    @password = nil\r
         \r
     def initialize(url, login=nil, password=nil)\r
       @url = url\r
@@ -47,6 +44,7 @@ module SvnRepos
       identifier = 'HEAD' unless identifier and identifier > 0\r
       entries = Entries.new\r
       cmd = "svn list --xml #{target(path)}@#{identifier}"\r
+      cmd << " --username #{@login} --password #{@password}" if @login\r
       shellout(cmd) do |io|\r
         begin\r
           doc = REXML::Document.new(io)\r
@@ -76,8 +74,9 @@ module SvnRepos
       identifier_from = 'HEAD' unless identifier_from and identifier_from.to_i > 0\r
       identifier_to = 1 unless identifier_to and identifier_to.to_i > 0\r
       revisions = Revisions.new\r
-      cmd = "svn log --xml -r #{identifier_from}:#{identifier_to} "\r
-      cmd << "--verbose " if  options[:with_paths]\r
+      cmd = "svn log --xml -r #{identifier_from}:#{identifier_to}"\r
+      cmd << " --username #{@login} --password #{@password}" if @login\r
+      cmd << " --verbose " if  options[:with_paths]\r
       cmd << target(path)\r
       shellout(cmd) do |io|\r
         begin\r
@@ -118,6 +117,7 @@ module SvnRepos
       cmd << "#{identifier_to}:"\r
       cmd << "#{identifier_from}"\r
       cmd << "#{target(path)}@#{identifier_from}"\r
+      cmd << " --username #{@login} --password #{@password}" if @login\r
       diff = []\r
       shellout(cmd) do |io|\r
         io.each_line do |line|\r
@@ -133,6 +133,7 @@ module SvnRepos
     def cat(path, identifier=nil)\r
       identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"\r
       cmd = "svn cat #{target(path)}@#{identifier}"\r
+      cmd << " --username #{@login} --password #{@password}" if @login\r
       cat = nil\r
       shellout(cmd) do |io|\r
         cat = io.read\r
@@ -154,7 +155,8 @@ module SvnRepos
     \r
     def shellout(cmd, &block)\r
       logger.debug "Shelling out: #{cmd}" if logger && logger.debug?\r
-      IO.popen(cmd) do |io|\r
+      IO.popen(cmd, "r+") do |io|\r
+        io.close_write\r
         block.call(io) if block_given?\r
       end\r
     end\r
index 14c7a26..2191e9f 100644 (file)
@@ -31,6 +31,8 @@
 <div id="repository">
 <% fields_for :repository, @project.repository, { :builder => TabularFormBuilder, :lang => current_language} do |repository| %>
 <p><%= repository.text_field :url, :size => 60, :required => true %><br />(http://, https://, svn://, file:///)</p>
+<p><%= repository.text_field :login, :size => 30 %></p>
+<p><%= repository.password_field :password, :size => 30 %></p>
 <% end %>
 </div>
 <%= javascript_tag "Element.hide('repository');" if @project.repository.nil? %>
diff --git a/db/migrate/026_add_repository_login_and_password.rb b/db/migrate/026_add_repository_login_and_password.rb
new file mode 100644 (file)
index 0000000..5fc9197
--- /dev/null
@@ -0,0 +1,11 @@
+class AddRepositoryLoginAndPassword < ActiveRecord::Migration
+  def self.up
+    add_column :repositories, :login, :string, :limit => 60, :default => ""
+    add_column :repositories, :password, :string, :limit => 60, :default => ""
+  end
+
+  def self.down
+    remove_column :repositories, :login
+    remove_column :repositories, :password
+  end
+end