diff --git a/app/models/repository/darcs.rb b/app/models/repository/darcs.rb index 034c0c14..855a403f 100644 --- a/app/models/repository/darcs.rb +++ b/app/models/repository/darcs.rb @@ -28,6 +28,11 @@ class Repository::Darcs < Repository 'Darcs' end + def entry(path=nil, identifier=nil) + patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) + scm.entry(path, patch.nil? ? nil : patch.scmid) + end + def entries(path=nil, identifier=nil) patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) entries = scm.entries(path, patch.nil? ? nil : patch.scmid) @@ -46,6 +51,11 @@ class Repository::Darcs < Repository entries end + def cat(path, identifier=nil) + patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) + scm.cat(path, patch.nil? ? nil : patch.scmid) + end + def diff(path, rev, rev_to) patch_from = changesets.find_by_revision(rev) return nil if patch_from.nil? diff --git a/doc/RUNNING_TESTS b/doc/RUNNING_TESTS index fe4f9378..6ee97781 100644 --- a/doc/RUNNING_TESTS +++ b/doc/RUNNING_TESTS @@ -24,8 +24,8 @@ Git --- gunzip < test/fixtures/repositories/git_repository.tar.gz | tar -xv -C tmp/test -Darcs ------ +Darcs (2.0+ required) +--------------------- gunzip < test/fixtures/repositories/darcs_repository.tar.gz | tar -xv -C tmp/test FileSystem diff --git a/lib/redmine/scm/adapters/darcs_adapter.rb b/lib/redmine/scm/adapters/darcs_adapter.rb index b1b2a457..4a5183f7 100644 --- a/lib/redmine/scm/adapters/darcs_adapter.rb +++ b/lib/redmine/scm/adapters/darcs_adapter.rb @@ -25,16 +25,36 @@ module Redmine # Darcs executable name DARCS_BIN = "darcs" + class << self + def client_version + @@client_version ||= (darcs_binary_version || []) + end + + def darcs_binary_version + cmd = "#{DARCS_BIN} --version" + version = nil + shellout(cmd) do |io| + # Read darcs 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 + def initialize(url, root_url=nil, login=nil, password=nil) @url = url @root_url = url end def supports_cat? - false + # cat supported in darcs 2.0.0 and higher + self.class.client_version_above?([2, 0, 0]) end - - # Get info about the svn repository + + # Get info about the darcs repository def info rev = revisions(nil,nil,nil,{:limit => 1}) rev ? Info.new({:root_url => @url, :lastrev => rev.last}) : nil @@ -114,6 +134,19 @@ module Redmine diff end + def cat(path, identifier=nil) + cmd = "#{DARCS_BIN} show content --repodir #{@url}" + cmd << " --match \"hash #{identifier}\"" if identifier + cmd << " #{shell_quote path}" + cat = nil + shellout(cmd) do |io| + io.binmode + cat = io.read + end + return nil if $? && $?.exitstatus != 0 + cat + end + private def entry_from_xml(element, path_prefix) diff --git a/test/unit/repository_darcs_test.rb b/test/unit/repository_darcs_test.rb index 1c8c1b8d..ca8c267f 100644 --- a/test/unit/repository_darcs_test.rb +++ b/test/unit/repository_darcs_test.rb @@ -48,6 +48,13 @@ class RepositoryDarcsTest < Test::Unit::TestCase @repository.fetch_changesets assert_equal 6, @repository.changesets.count end + + def test_cat + @repository.fetch_changesets + cat = @repository.cat("sources/welcome_controller.rb", 2) + assert_not_nil cat + assert cat.include?('class WelcomeController < ApplicationController') + end else puts "Darcs test repository NOT FOUND. Skipping unit tests !!!" def test_fake; assert true end