Project

General

Profile

Patch #1799 ยป redmine-fix1794-allow-darcs-cat-r1747.patch

Fix #1794 agaings r1747: Allow file browsing with darcs repos - Ralph Lange, 2008-08-18 17:24

View differences:

lib/redmine/scm/adapters/darcs_adapter.rb (working copy)
25 25
        # Darcs executable name
26 26
        DARCS_BIN = "darcs"
27 27
        
28
        class << self
29
	  def client_version
30
	    @@client_version ||= (darcs_binary_version || [])
31
	  end
32
	  
33
	  def darcs_binary_version
34
	    cmd = "#{DARCS_BIN} --version"
35
	    version = nil
36
	    shellout(cmd) do |io|
37
	      # Read darcs version in first returned line
38
	      if m = io.gets.match(%r{((\d+\.)+\d+)})
39
	        version = m[0].scan(%r{\d+}).collect(&:to_i)
40
	      end
41
	    end
42
	    return nil if $? && $?.exitstatus != 0
43
            version
44
	  end
45
	end
46

  
28 47
        def initialize(url, root_url=nil, login=nil, password=nil)
29 48
          @url = url
30 49
          @root_url = url
31 50
        end
32 51

  
33
        def supports_cat?
34
          false
35
        end
36
              
37
        # Get info about the svn repository
52
        # Get info about the darcs repository
38 53
        def info
39 54
          rev = revisions(nil,nil,nil,{:limit => 1})
40 55
          rev ? Info.new({:root_url => @url, :lastrev => rev.last}) : nil
......
114 129
          diff
115 130
        end
116 131
        
132
	def cat(path, identifier=nil)
133
          # cat supported in darcs 2.0.0 and higher
134
	  return nil unless self.class.client_version_above?([2, 0, 0])
135
	  
136
	  cmd = "#{DARCS_BIN} show content --repodir #{@url}"
137
          cmd << " --match \"hash #{identifier}\"" if identifier
138
          cmd << " #{path}"
139
	  cat = nil
140
	  shellout(cmd) do |io|
141
	    io.binmode
142
	    cat = io.read
143
	  end
144
	  return nil if $? && $?.exitstatus != 0
145
	  cat
146
	end
147

  
117 148
        private
118 149
                
119 150
        def entry_from_xml(element, path_prefix)
app/models/repository/darcs.rb (working copy)
28 28
    'Darcs'
29 29
  end
30 30
  
31
  def entry(path=nil, identifier=nil)
32
    patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
33
    scm.entry(path, patch.nil? ? nil : patch.scmid)
34
  end
35
  
31 36
  def entries(path=nil, identifier=nil)
32 37
    patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
33 38
    entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
......
46 51
    entries
47 52
  end
48 53
  
54
  def cat(path, identifier=nil)
55
    patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
56
    scm.cat(path, patch.nil? ? nil : patch.scmid)
57
  end
58
  
49 59
  def diff(path, rev, rev_to)
50 60
    patch_from = changesets.find_by_revision(rev)
51 61
    return nil if patch_from.nil?
    (1-1/1)