##// END OF EJS Templates
Added Darcs basic support....
Jean-Philippe Lang -
r570:ba1b857197ab
parent child
Show More
@@ -0,0 +1,90
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require 'redmine/scm/adapters/darcs_adapter'
19
20 class Repository::Darcs < Repository
21 validates_presence_of :url
22
23 def scm_adapter
24 Redmine::Scm::Adapters::DarcsAdapter
25 end
26
27 def self.scm_name
28 'Darcs'
29 end
30
31 def entries(path=nil, identifier=nil)
32 entries=scm.entries(path, identifier)
33 if entries
34 entries.each do |entry|
35 # Search the DB for the entry's last change
36 changeset = changesets.find_by_scmid(entry.lastrev.scmid) if entry.lastrev && !entry.lastrev.scmid.blank?
37 if changeset
38 entry.lastrev.identifier = changeset.revision
39 entry.lastrev.name = changeset.revision
40 entry.lastrev.time = changeset.committed_on
41 entry.lastrev.author = changeset.committer
42 end
43 end
44 end
45 entries
46 end
47
48 def diff(path, rev, rev_to, type)
49 patch_from = changesets.find_by_revision(rev)
50 patch_to = changesets.find_by_revision(rev_to) if rev_to
51 if path.blank?
52 path = patch_from.changes.collect{|change| change.path}.join(' ')
53 end
54 scm.diff(path, patch_from.scmid, patch_to.scmid, type)
55 end
56
57 def fetch_changesets
58 scm_info = scm.info
59 if scm_info
60 db_last_id = latest_changeset ? latest_changeset.scmid : nil
61 next_rev = latest_changeset ? latest_changeset.revision + 1 : 1
62 # latest revision in the repository
63 scm_revision = scm_info.lastrev.scmid
64 unless changesets.find_by_scmid(scm_revision)
65 revisions = scm.revisions('', db_last_id, nil, :with_path => true)
66 transaction do
67 revisions.reverse_each do |revision|
68 changeset = Changeset.create(:repository => self,
69 :revision => next_rev,
70 :scmid => revision.scmid,
71 :committer => revision.author,
72 :committed_on => revision.time,
73 :comments => revision.message)
74
75 next if changeset.new_record?
76
77 revision.paths.each do |change|
78 Change.create(:changeset => changeset,
79 :action => change[:action],
80 :path => change[:path],
81 :from_path => change[:from_path],
82 :from_revision => change[:from_revision])
83 end
84 next_rev += 1
85 end if revisions
86 end
87 end
88 end
89 end
90 end
@@ -0,0 +1,163
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require 'redmine/scm/adapters/abstract_adapter'
19 require 'rexml/document'
20
21 module Redmine
22 module Scm
23 module Adapters
24 class DarcsAdapter < AbstractAdapter
25 # Darcs executable name
26 DARCS_BIN = "darcs"
27
28 def initialize(url, root_url=nil, login=nil, password=nil)
29 @url = url
30 @root_url = url
31 end
32
33 def supports_cat?
34 false
35 end
36
37 # Get info about the svn repository
38 def info
39 rev = revisions(nil,nil,nil,{:limit => 1})
40 rev ? Info.new({:root_url => @url, :lastrev => rev.last}) : nil
41 end
42
43 # Returns the entry identified by path and revision identifier
44 # or nil if entry doesn't exist in the repository
45 def entry(path=nil, identifier=nil)
46 e = entries(path, identifier)
47 e ? e.first : nil
48 end
49
50 # Returns an Entries collection
51 # or nil if the given path doesn't exist in the repository
52 def entries(path=nil, identifier=nil)
53 path_prefix = (path.blank? ? '' : "#{path}/")
54 path = '.' if path.blank?
55 entries = Entries.new
56 cmd = "#{DARCS_BIN} annotate --repodir #{@url} --xml-output #{path}"
57 shellout(cmd) do |io|
58 begin
59 doc = REXML::Document.new(io)
60 if doc.root.name == 'directory'
61 doc.elements.each('directory/*') do |element|
62 next unless ['file', 'directory'].include? element.name
63 entries << entry_from_xml(element, path_prefix)
64 end
65 elsif doc.root.name == 'file'
66 entries << entry_from_xml(doc.root, path_prefix)
67 end
68 rescue
69 end
70 end
71 return nil if $? && $?.exitstatus != 0
72 entries.sort_by_name
73 rescue Errno::ENOENT => e
74 raise CommandFailed
75 end
76
77 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
78 path = '.' if path.blank?
79 revisions = Revisions.new
80 cmd = "#{DARCS_BIN} changes --repodir #{@url} --xml-output"
81 cmd << " --from-match \"hash #{identifier_from}\"" if identifier_from
82 cmd << " --last #{options[:limit].to_i}" if options[:limit]
83 shellout(cmd) do |io|
84 begin
85 doc = REXML::Document.new(io)
86 doc.elements.each("changelog/patch") do |patch|
87 message = patch.elements['name'].text
88 message << "\n" + patch.elements['comment'].text.gsub(/\*\*\*END OF DESCRIPTION\*\*\*.*\z/m, '') if patch.elements['comment']
89 revisions << Revision.new({:identifier => nil,
90 :author => patch.attributes['author'],
91 :scmid => patch.attributes['hash'],
92 :time => Time.parse(patch.attributes['local_date']),
93 :message => message,
94 :paths => (options[:with_path] ? get_paths_for_patch(patch.attributes['hash']) : nil)
95 })
96 end
97 rescue
98 end
99 end
100 return nil if $? && $?.exitstatus != 0
101 revisions
102 rescue Errno::ENOENT => e
103 raise CommandFailed
104 end
105
106 def diff(path, identifier_from, identifier_to=nil, type="inline")
107 path = '*' if path.blank?
108 cmd = "#{DARCS_BIN} diff --repodir #{@url}"
109 cmd << " --to-match \"hash #{identifier_from}\""
110 cmd << " --from-match \"hash #{identifier_to}\"" if identifier_to
111 cmd << " -u #{path}"
112 diff = []
113 shellout(cmd) do |io|
114 io.each_line do |line|
115 diff << line
116 end
117 end
118 return nil if $? && $?.exitstatus != 0
119 DiffTableList.new diff, type
120 rescue Errno::ENOENT => e
121 raise CommandFailed
122 end
123
124 private
125
126 def entry_from_xml(element, path_prefix)
127 Entry.new({:name => element.attributes['name'],
128 :path => path_prefix + element.attributes['name'],
129 :kind => element.name == 'file' ? 'file' : 'dir',
130 :size => nil,
131 :lastrev => Revision.new({
132 :identifier => nil,
133 :scmid => element.elements['modified'].elements['patch'].attributes['hash']
134 })
135 })
136 end
137
138 # Retrieve changed paths for a single patch
139 def get_paths_for_patch(hash)
140 cmd = "#{DARCS_BIN} annotate --repodir #{@url} --summary --xml-output"
141 cmd << " --match \"hash #{hash}\" "
142 paths = []
143 shellout(cmd) do |io|
144 begin
145 # Darcs xml output has multiple root elements in this case (tested with darcs 1.0.7)
146 # A root element is added so that REXML doesn't raise an error
147 doc = REXML::Document.new("<fake_root>" + io.read + "</fake_root>")
148 doc.elements.each('fake_root/summary/*') do |modif|
149 paths << {:action => modif.name[0,1].upcase,
150 :path => "/" + modif.text.chomp.gsub(/^\s*/, '')
151 }
152 end
153 rescue
154 end
155 end
156 paths
157 rescue Errno::ENOENT => e
158 paths
159 end
160 end
161 end
162 end
163 end
@@ -43,6 +43,10 module RepositoriesHelper
43 43 content_tag('p', form.password_field(:password, :size => 30))
44 44 end
45 45
46 def darcs_field_tags(form, repository)
47 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
48 end
49
46 50 def mercurial_field_tags(form, repository)
47 51 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
48 52 end
@@ -23,6 +23,7 class Changeset < ActiveRecord::Base
23 23 validates_presence_of :repository_id, :revision, :committed_on, :commit_date
24 24 validates_numericality_of :revision, :only_integer => true
25 25 validates_uniqueness_of :revision, :scope => :repository_id
26 validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
26 27
27 28 def committed_on=(date)
28 29 self.commit_date = date
@@ -30,6 +30,10 class Repository < ActiveRecord::Base
30 30 self.class.scm_name
31 31 end
32 32
33 def supports_cat?
34 scm.supports_cat?
35 end
36
33 37 def entries(path=nil, identifier=nil)
34 38 scm.entries(path, identifier)
35 39 end
@@ -2,6 +2,7
2 2
3 3 <h3><%=h @entry.name %></h3>
4 4
5 <% if @repository.supports_cat? %>
5 6 <p>
6 7 <% if @entry.is_text? %>
7 8 <%= link_to l(:button_view), {:action => 'entry', :id => @project, :path => @path, :rev => @rev } %> |
@@ -9,5 +10,6
9 10 <%= link_to l(:button_download), {:action => 'entry', :id => @project, :path => @path, :rev => @rev, :format => 'raw' } %>
10 11 <%= "(#{number_to_human_size(@entry.size)})" if @entry.size %>
11 12 </p>
13 <% end %>
12 14
13 15 <%= render :partial => 'revisions', :locals => {:project => @project, :path => @path, :revisions => @changes, :entry => @entry }%>
@@ -2,4 +2,4 require 'redmine/version'
2 2 require 'redmine/mime_type'
3 3 require 'redmine/acts_as_watchable/init'
4 4
5 REDMINE_SUPPORTED_SCM = %w( Subversion Mercurial Cvs )
5 REDMINE_SUPPORTED_SCM = %w( Subversion Darcs Mercurial Cvs )
@@ -35,6 +35,10 module Redmine
35 35 'Abstract'
36 36 end
37 37
38 def supports_cat?
39 true
40 end
41
38 42 def root_url
39 43 @root_url
40 44 end
@@ -209,7 +213,7 module Redmine
209 213 def initialize (diff, type="inline")
210 214 diff_table = DiffTable.new type
211 215 diff.each do |line|
212 if line =~ /^(Index:|diff) (.*)$/
216 if line =~ /^(---|\+\+\+) (.*)$/
213 217 self << diff_table if diff_table.length > 1
214 218 diff_table = DiffTable.new type
215 219 end
@@ -237,7 +241,7 module Redmine
237 241 # Function for add a line of this Diff
238 242 def add_line(line)
239 243 unless @parsing
240 if line =~ /^(Index:|diff) (.*)$/
244 if line =~ /^(---|\+\+\+) (.*)$/
241 245 @file_name = $2
242 246 return false
243 247 elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
General Comments 0
You need to be logged in to leave comments. Login now