From 12fbd06c02d44fdb96922154476302f002783e23 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 5 Jul 2008 08:59:04 +0000 Subject: Display svn properties in the browser, svn >= 1.5.0 only (#1581). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1627 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/scm/adapters/abstract_adapter.rb | 28 ++++++++++++++++- lib/redmine/scm/adapters/subversion_adapter.rb | 43 +++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) (limited to 'lib/redmine') diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index 0bacda770..a876de937 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -24,6 +24,20 @@ module Redmine end class AbstractAdapter #:nodoc: + class << self + # Returns the version of the scm client + # Eg: [1, 5, 0] + def client_version + 'Unknown version' + end + + # Returns the version string of the scm client + # Eg: '1.5.0' + def client_version_string + client_version.is_a?(Array) ? client_version.join('.') : client_version.to_s + end + end + def initialize(url, root_url=nil, login=nil, password=nil) @url = url @login = login if login && !login.empty? @@ -77,6 +91,10 @@ module Redmine def entries(path=nil, identifier=nil) return nil end + + def properties(path, identifier=nil) + return nil + end def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) return nil @@ -131,10 +149,18 @@ module Redmine end def logger - RAILS_DEFAULT_LOGGER + self.class.logger end def shellout(cmd, &block) + self.class.shellout(cmd, &block) + end + + def self.logger + RAILS_DEFAULT_LOGGER + end + + def self.shellout(cmd, &block) logger.debug "Shelling out: #{cmd}" if logger && logger.debug? begin IO.popen(cmd, "r+") do |io| diff --git a/lib/redmine/scm/adapters/subversion_adapter.rb b/lib/redmine/scm/adapters/subversion_adapter.rb index 7c98eee8b..90940715d 100644 --- a/lib/redmine/scm/adapters/subversion_adapter.rb +++ b/lib/redmine/scm/adapters/subversion_adapter.rb @@ -26,6 +26,25 @@ module Redmine # SVN executable name SVN_BIN = "svn" + class << self + def client_version + @@client_version ||= (svn_binary_version || 'Unknown version') + end + + def svn_binary_version + cmd = "#{SVN_BIN} --version" + version = nil + shellout(cmd) do |io| + # Read svn version in first returned line + if m = io.gets.match(%r{((\d+\.)+\d+)}) + version = m[0].scan(%r{\d+}).collect(&:to_i) + end + end + return nil if $? && $?.exitstatus != 0 + version + end + end + # Get info about the svn repository def info cmd = "#{SVN_BIN} info --xml #{target('')}" @@ -87,7 +106,29 @@ module Redmine logger.debug("Found #{entries.size} entries in the repository for #{target(path)}") if logger && logger.debug? entries.sort_by_name end - + + def properties(path, identifier=nil) + # proplist xml output supported in svn 1.5.0 and higher + return nil if (self.class.client_version <=> [1, 5, 0]) < 0 + + identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD" + cmd = "#{SVN_BIN} proplist --verbose --xml #{target(path)}@#{identifier}" + cmd << credentials_string + properties = {} + shellout(cmd) do |io| + output = io.read + begin + doc = REXML::Document.new(output) + doc.elements.each("properties/target/property") do |property| + properties[ property.attributes['name'] ] = property.text + end + rescue + end + end + return nil if $? && $?.exitstatus != 0 + properties + end + def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) path ||= '' identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : "HEAD" -- cgit v1.2.3