Adds support for file viewing with Darcs 2.0+ (patch #1799 by Ralph Lange slightly edited).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1759 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
e339d0bcc0
commit
d93f96765b
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue