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'
|
'Darcs'
|
||||||
end
|
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)
|
def entries(path=nil, identifier=nil)
|
||||||
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
||||||
entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
|
entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
|
||||||
|
@ -46,6 +51,11 @@ class Repository::Darcs < Repository
|
||||||
entries
|
entries
|
||||||
end
|
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)
|
def diff(path, rev, rev_to)
|
||||||
patch_from = changesets.find_by_revision(rev)
|
patch_from = changesets.find_by_revision(rev)
|
||||||
return nil if patch_from.nil?
|
return nil if patch_from.nil?
|
||||||
|
|
|
@ -24,8 +24,8 @@ Git
|
||||||
---
|
---
|
||||||
gunzip < test/fixtures/repositories/git_repository.tar.gz | tar -xv -C tmp/test
|
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
|
gunzip < test/fixtures/repositories/darcs_repository.tar.gz | tar -xv -C tmp/test
|
||||||
|
|
||||||
FileSystem
|
FileSystem
|
||||||
|
|
|
@ -25,16 +25,36 @@ module Redmine
|
||||||
# Darcs executable name
|
# Darcs executable name
|
||||||
DARCS_BIN = "darcs"
|
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)
|
def initialize(url, root_url=nil, login=nil, password=nil)
|
||||||
@url = url
|
@url = url
|
||||||
@root_url = url
|
@root_url = url
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_cat?
|
def supports_cat?
|
||||||
false
|
# cat supported in darcs 2.0.0 and higher
|
||||||
|
self.class.client_version_above?([2, 0, 0])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get info about the svn repository
|
# Get info about the darcs repository
|
||||||
def info
|
def info
|
||||||
rev = revisions(nil,nil,nil,{:limit => 1})
|
rev = revisions(nil,nil,nil,{:limit => 1})
|
||||||
rev ? Info.new({:root_url => @url, :lastrev => rev.last}) : nil
|
rev ? Info.new({:root_url => @url, :lastrev => rev.last}) : nil
|
||||||
|
@ -114,6 +134,19 @@ module Redmine
|
||||||
diff
|
diff
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def entry_from_xml(element, path_prefix)
|
def entry_from_xml(element, path_prefix)
|
||||||
|
|
|
@ -48,6 +48,13 @@ class RepositoryDarcsTest < Test::Unit::TestCase
|
||||||
@repository.fetch_changesets
|
@repository.fetch_changesets
|
||||||
assert_equal 6, @repository.changesets.count
|
assert_equal 6, @repository.changesets.count
|
||||||
end
|
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
|
else
|
||||||
puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
|
puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
|
||||||
def test_fake; assert true end
|
def test_fake; assert true end
|
||||||
|
|
Loading…
Reference in New Issue