diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-03-18 15:48:05 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-03-18 15:48:05 +0000 |
commit | fd37f37ee4ed83f90d4a8b597c3b5ae8070e8232 (patch) | |
tree | 1a39c1ef7bdc19515afdcd8c44d2458c267351d1 | |
parent | db3e8616c89ba34196fd12eafb3680df9479a024 (diff) | |
download | redmine-fd37f37ee4ed83f90d4a8b597c3b5ae8070e8232.tar.gz redmine-fd37f37ee4ed83f90d4a8b597c3b5ae8070e8232.zip |
fixed problems when svn path doesn't point to the root directory of the repository.
a root_url property has been added on the repository. it's automatically retrieved the first time the repository is browsed
git-svn-id: http://redmine.rubyforge.org/svn/trunk@344 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/repository.rb | 14 | ||||
-rw-r--r-- | app/models/svn_repos.rb | 33 | ||||
-rw-r--r-- | app/views/repositories/diff.rhtml | 2 | ||||
-rw-r--r-- | app/views/repositories/revision.rhtml | 2 | ||||
-rw-r--r-- | db/migrate/031_add_repository_root_url.rb | 9 |
5 files changed, 53 insertions, 7 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index d6e0e11aa..16bee25a7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -19,10 +19,18 @@ class Repository < ActiveRecord::Base belongs_to :project validates_presence_of :url validates_format_of :url, :with => /^(http|https|svn|file):\/\/.+/i - - @scm = nil def scm - @scm ||= SvnRepos::Base.new url, login, password + @scm ||= SvnRepos::Base.new url, root_url, login, password + update_attribute(:root_url, @scm.root_url) if root_url.blank? + @scm + end + + def url=(str) + unless str == self.url + self.attributes = {:root_url => nil } + @scm = nil + end + super end end diff --git a/app/models/svn_repos.rb b/app/models/svn_repos.rb index 3ed81403d..2fd907319 100644 --- a/app/models/svn_repos.rb +++ b/app/models/svn_repos.rb @@ -24,10 +24,37 @@ module SvnRepos class Base - def initialize(url, login=nil, password=nil) + def initialize(url, root_url=nil, login=nil, password=nil) @url = url @login = login if login && !login.empty? @password = (password || "") if @login + @root_url = root_url.blank? ? retrieve_root_url : root_url + end + + def root_url + @root_url + end + + def url + @url + end + + # finds the root url of the svn repository + def retrieve_root_url + cmd = "svn info --xml #{target('')}" + cmd << " --username #{@login} --password #{@password}" if @login + root_url = nil + shellout(cmd) do |io| + begin + doc = REXML::Document.new(io) + root_url = doc.elements["info/entry/repository/root"].text + rescue + end + end + return nil if $? && $?.exitstatus != 0 + root_url + rescue Errno::ENOENT => e + return nil end # Returns the entry identified by path and revision identifier @@ -146,7 +173,9 @@ module SvnRepos private def target(path) - " \"" << "#{@url}/#{path}".gsub(/["'?<>\*]/, '') << "\"" + path ||= "" + base = path.match(/^\//) ? root_url : url + " \"" << "#{base}/#{path}".gsub(/["'?<>\*]/, '') << "\"" end def logger diff --git a/app/views/repositories/diff.rhtml b/app/views/repositories/diff.rhtml index eb8777de4..1671e44df 100644 --- a/app/views/repositories/diff.rhtml +++ b/app/views/repositories/diff.rhtml @@ -1,4 +1,4 @@ -<h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => 'file', :revision => @rev } %></h2> +<h2><%= l(:label_revision) %> <%= @rev %>: <%= @path.gsub(/^.*\//, '') %></h2> <% parsing = false line_num_l = 0 diff --git a/app/views/repositories/revision.rhtml b/app/views/repositories/revision.rhtml index d017a79f7..22e965090 100644 --- a/app/views/repositories/revision.rhtml +++ b/app/views/repositories/revision.rhtml @@ -24,7 +24,7 @@ <td><div class="square action_<%= path[:action] %>"></div> <%= path[:path] %></td> <td> <% if path[:action] == "M" %> -<%= link_to 'View diff', :action => 'diff', :id => @project, :path => path[:path].gsub(/^\//, ''), :rev => @revision.identifier %> +<%= link_to 'View diff', :action => 'diff', :id => @project, :path => path[:path], :rev => @revision.identifier %> <% end %> </td> </tr> diff --git a/db/migrate/031_add_repository_root_url.rb b/db/migrate/031_add_repository_root_url.rb new file mode 100644 index 000000000..df57809c7 --- /dev/null +++ b/db/migrate/031_add_repository_root_url.rb @@ -0,0 +1,9 @@ +class AddRepositoryRootUrl < ActiveRecord::Migration + def self.up + add_column :repositories, :root_url, :string, :limit => 255, :default => "" + end + + def self.down + remove_column :repositories, :root_url + end +end |