@@ -1,269 +1,269 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require 'iconv' |
|
18 | require 'iconv' | |
19 | require 'redmine/codeset_util' |
|
19 | require 'redmine/codeset_util' | |
20 |
|
20 | |||
21 | module RepositoriesHelper |
|
21 | module RepositoriesHelper | |
22 | def format_revision(revision) |
|
22 | def format_revision(revision) | |
23 | if revision.respond_to? :format_identifier |
|
23 | if revision.respond_to? :format_identifier | |
24 | revision.format_identifier |
|
24 | revision.format_identifier | |
25 | else |
|
25 | else | |
26 | revision.to_s |
|
26 | revision.to_s | |
27 | end |
|
27 | end | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def truncate_at_line_break(text, length = 255) |
|
30 | def truncate_at_line_break(text, length = 255) | |
31 | if text |
|
31 | if text | |
32 | text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') |
|
32 | text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') | |
33 | end |
|
33 | end | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | def render_properties(properties) |
|
36 | def render_properties(properties) | |
37 | unless properties.nil? || properties.empty? |
|
37 | unless properties.nil? || properties.empty? | |
38 | content = '' |
|
38 | content = '' | |
39 | properties.keys.sort.each do |property| |
|
39 | properties.keys.sort.each do |property| | |
40 | content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") |
|
40 | content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") | |
41 | end |
|
41 | end | |
42 | content_tag('ul', content, :class => 'properties') |
|
42 | content_tag('ul', content, :class => 'properties') | |
43 | end |
|
43 | end | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def render_changeset_changes |
|
46 | def render_changeset_changes | |
47 | changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| |
|
47 | changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| | |
48 | case change.action |
|
48 | case change.action | |
49 | when 'A' |
|
49 | when 'A' | |
50 | # Detects moved/copied files |
|
50 | # Detects moved/copied files | |
51 | if !change.from_path.blank? |
|
51 | if !change.from_path.blank? | |
52 | change.action = |
|
52 | change.action = | |
53 | @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' |
|
53 | @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' | |
54 | end |
|
54 | end | |
55 | change |
|
55 | change | |
56 | when 'D' |
|
56 | when 'D' | |
57 | @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change |
|
57 | @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change | |
58 | else |
|
58 | else | |
59 | change |
|
59 | change | |
60 | end |
|
60 | end | |
61 | end.compact |
|
61 | end.compact | |
62 |
|
62 | |||
63 | tree = { } |
|
63 | tree = { } | |
64 | changes.each do |change| |
|
64 | changes.each do |change| | |
65 | p = tree |
|
65 | p = tree | |
66 | dirs = change.path.to_s.split('/').select {|d| !d.blank?} |
|
66 | dirs = change.path.to_s.split('/').select {|d| !d.blank?} | |
67 | path = '' |
|
67 | path = '' | |
68 | dirs.each do |dir| |
|
68 | dirs.each do |dir| | |
69 | path += '/' + dir |
|
69 | path += '/' + dir | |
70 | p[:s] ||= {} |
|
70 | p[:s] ||= {} | |
71 | p = p[:s] |
|
71 | p = p[:s] | |
72 | p[path] ||= {} |
|
72 | p[path] ||= {} | |
73 | p = p[path] |
|
73 | p = p[path] | |
74 | end |
|
74 | end | |
75 | p[:c] = change |
|
75 | p[:c] = change | |
76 | end |
|
76 | end | |
77 | render_changes_tree(tree[:s]) |
|
77 | render_changes_tree(tree[:s]) | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def render_changes_tree(tree) |
|
80 | def render_changes_tree(tree) | |
81 | return '' if tree.nil? |
|
81 | return '' if tree.nil? | |
82 | output = '' |
|
82 | output = '' | |
83 | output << '<ul>' |
|
83 | output << '<ul>' | |
84 | tree.keys.sort.each do |file| |
|
84 | tree.keys.sort.each do |file| | |
85 | style = 'change' |
|
85 | style = 'change' | |
86 | text = File.basename(h(file)) |
|
86 | text = File.basename(h(file)) | |
87 | if s = tree[file][:s] |
|
87 | if s = tree[file][:s] | |
88 | style << ' folder' |
|
88 | style << ' folder' | |
89 | path_param = to_path_param(@repository.relative_path(file)) |
|
89 | path_param = to_path_param(@repository.relative_path(file)) | |
90 | text = link_to(text, :controller => 'repositories', |
|
90 | text = link_to(text, :controller => 'repositories', | |
91 | :action => 'show', |
|
91 | :action => 'show', | |
92 | :id => @project, |
|
92 | :id => @project, | |
93 | :path => path_param, |
|
93 | :path => path_param, | |
94 | :rev => @changeset.identifier) |
|
94 | :rev => @changeset.identifier) | |
95 | output << "<li class='#{style}'>#{text}</li>" |
|
95 | output << "<li class='#{style}'>#{text}</li>" | |
96 | output << render_changes_tree(s) |
|
96 | output << render_changes_tree(s) | |
97 | elsif c = tree[file][:c] |
|
97 | elsif c = tree[file][:c] | |
98 | style << " change-#{c.action}" |
|
98 | style << " change-#{c.action}" | |
99 | path_param = to_path_param(@repository.relative_path(c.path)) |
|
99 | path_param = to_path_param(@repository.relative_path(c.path)) | |
100 | text = link_to(text, :controller => 'repositories', |
|
100 | text = link_to(text, :controller => 'repositories', | |
101 | :action => 'entry', |
|
101 | :action => 'entry', | |
102 | :id => @project, |
|
102 | :id => @project, | |
103 | :path => path_param, |
|
103 | :path => path_param, | |
104 | :rev => @changeset.identifier) unless c.action == 'D' |
|
104 | :rev => @changeset.identifier) unless c.action == 'D' | |
105 | text << " - #{c.revision}" unless c.revision.blank? |
|
105 | text << " - #{c.revision}" unless c.revision.blank? | |
106 | text << ' (' + link_to('diff', :controller => 'repositories', |
|
106 | text << ' (' + link_to('diff', :controller => 'repositories', | |
107 | :action => 'diff', |
|
107 | :action => 'diff', | |
108 | :id => @project, |
|
108 | :id => @project, | |
109 | :path => path_param, |
|
109 | :path => path_param, | |
110 | :rev => @changeset.identifier) + ') ' if c.action == 'M' |
|
110 | :rev => @changeset.identifier) + ') ' if c.action == 'M' | |
111 | text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? |
|
111 | text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? | |
112 | output << "<li class='#{style}'>#{text}</li>" |
|
112 | output << "<li class='#{style}'>#{text}</li>" | |
113 | end |
|
113 | end | |
114 | end |
|
114 | end | |
115 | output << '</ul>' |
|
115 | output << '</ul>' | |
116 | output |
|
116 | output | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def to_utf8(str) |
|
119 | def to_utf8(str) | |
120 | return str if str.nil? |
|
120 | return str if str.nil? | |
121 | str = to_utf8_internal(str) |
|
121 | str = to_utf8_internal(str) | |
122 | if str.respond_to?(:force_encoding) |
|
122 | if str.respond_to?(:force_encoding) | |
123 | str.force_encoding('UTF-8') |
|
123 | str.force_encoding('UTF-8') | |
124 | end |
|
124 | end | |
125 | str |
|
125 | str | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def to_utf8_internal(str) |
|
128 | def to_utf8_internal(str) | |
129 | return str if str.nil? |
|
129 | return str if str.nil? | |
130 | if str.respond_to?(:force_encoding) |
|
130 | if str.respond_to?(:force_encoding) | |
131 | str.force_encoding('ASCII-8BIT') |
|
131 | str.force_encoding('ASCII-8BIT') | |
132 | end |
|
132 | end | |
133 | return str if str.empty? |
|
133 | return str if str.empty? | |
134 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
|
134 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii | |
135 | if str.respond_to?(:force_encoding) |
|
135 | if str.respond_to?(:force_encoding) | |
136 | str.force_encoding('UTF-8') |
|
136 | str.force_encoding('UTF-8') | |
137 | end |
|
137 | end | |
138 | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) |
|
138 | @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) | |
139 | @encodings.each do |encoding| |
|
139 | @encodings.each do |encoding| | |
140 | begin |
|
140 | begin | |
141 | return Iconv.conv('UTF-8', encoding, str) |
|
141 | return Iconv.conv('UTF-8', encoding, str) | |
142 | rescue Iconv::Failure |
|
142 | rescue Iconv::Failure | |
143 | # do nothing here and try the next encoding |
|
143 | # do nothing here and try the next encoding | |
144 | end |
|
144 | end | |
145 | end |
|
145 | end | |
146 | str = Redmine::CodesetUtil.replace_invalid_utf8(str) |
|
146 | str = Redmine::CodesetUtil.replace_invalid_utf8(str) | |
147 | end |
|
147 | end | |
148 | private :to_utf8_internal |
|
148 | private :to_utf8_internal | |
149 |
|
149 | |||
150 | def repository_field_tags(form, repository) |
|
150 | def repository_field_tags(form, repository) | |
151 | method = repository.class.name.demodulize.underscore + "_field_tags" |
|
151 | method = repository.class.name.demodulize.underscore + "_field_tags" | |
152 | if repository.is_a?(Repository) && |
|
152 | if repository.is_a?(Repository) && | |
153 | respond_to?(method) && method != 'repository_field_tags' |
|
153 | respond_to?(method) && method != 'repository_field_tags' | |
154 | send(method, form, repository) |
|
154 | send(method, form, repository) | |
155 | end |
|
155 | end | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | def scm_select_tag(repository) |
|
158 | def scm_select_tag(repository) | |
159 | scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] |
|
159 | scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] | |
160 | Redmine::Scm::Base.all.each do |scm| |
|
160 | Redmine::Scm::Base.all.each do |scm| | |
161 | if Setting.enabled_scm.include?(scm) || |
|
161 | if Setting.enabled_scm.include?(scm) || | |
162 | (repository && repository.class.name.demodulize == scm) |
|
162 | (repository && repository.class.name.demodulize == scm) | |
163 | scm_options << ["Repository::#{scm}".constantize.scm_name, scm] |
|
163 | scm_options << ["Repository::#{scm}".constantize.scm_name, scm] | |
164 | end |
|
164 | end | |
165 | end |
|
165 | end | |
166 | select_tag('repository_scm', |
|
166 | select_tag('repository_scm', | |
167 | options_for_select(scm_options, repository.class.name.demodulize), |
|
167 | options_for_select(scm_options, repository.class.name.demodulize), | |
168 | :disabled => (repository && !repository.new_record?), |
|
168 | :disabled => (repository && !repository.new_record?), | |
169 | :onchange => remote_function( |
|
169 | :onchange => remote_function( | |
170 | :url => { |
|
170 | :url => { | |
171 | :controller => 'repositories', |
|
171 | :controller => 'repositories', | |
172 | :action => 'edit', |
|
172 | :action => 'edit', | |
173 | :id => @project |
|
173 | :id => @project | |
174 | }, |
|
174 | }, | |
175 | :method => :get, |
|
175 | :method => :get, | |
176 | :with => "Form.serialize(this.form)") |
|
176 | :with => "Form.serialize(this.form)") | |
177 | ) |
|
177 | ) | |
178 | end |
|
178 | end | |
179 |
|
179 | |||
180 | def with_leading_slash(path) |
|
180 | def with_leading_slash(path) | |
181 | path.to_s.starts_with?('/') ? path : "/#{path}" |
|
181 | path.to_s.starts_with?('/') ? path : "/#{path}" | |
182 | end |
|
182 | end | |
183 |
|
183 | |||
184 | def without_leading_slash(path) |
|
184 | def without_leading_slash(path) | |
185 | path.gsub(%r{^/+}, '') |
|
185 | path.gsub(%r{^/+}, '') | |
186 | end |
|
186 | end | |
187 |
|
187 | |||
188 | def subversion_field_tags(form, repository) |
|
188 | def subversion_field_tags(form, repository) | |
189 | content_tag('p', form.text_field(:url, :size => 60, :required => true, |
|
189 | content_tag('p', form.text_field(:url, :size => 60, :required => true, | |
190 | :disabled => (repository && !repository.root_url.blank?)) + |
|
190 | :disabled => (repository && !repository.root_url.blank?)) + | |
191 | '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + |
|
191 | '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + | |
192 | content_tag('p', form.text_field(:login, :size => 30)) + |
|
192 | content_tag('p', form.text_field(:login, :size => 30)) + | |
193 | content_tag('p', form.password_field( |
|
193 | content_tag('p', form.password_field( | |
194 | :password, :size => 30, :name => 'ignore', |
|
194 | :password, :size => 30, :name => 'ignore', | |
195 | :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), |
|
195 | :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), | |
196 | :onfocus => "this.value=''; this.name='repository[password]';", |
|
196 | :onfocus => "this.value=''; this.name='repository[password]';", | |
197 | :onchange => "this.name='repository[password]';")) |
|
197 | :onchange => "this.name='repository[password]';")) | |
198 | end |
|
198 | end | |
199 |
|
199 | |||
200 | def darcs_field_tags(form, repository) |
|
200 | def darcs_field_tags(form, repository) | |
201 |
content_tag('p', form.text_field(:url, :label => ' |
|
201 | content_tag('p', form.text_field(:url, :label => 'Path to repository', | |
202 | :size => 60, :required => true, |
|
202 | :size => 60, :required => true, | |
203 | :disabled => (repository && !repository.new_record?))) + |
|
203 | :disabled => (repository && !repository.new_record?))) + | |
204 | content_tag('p', form.select( |
|
204 | content_tag('p', form.select( | |
205 | :log_encoding, [nil] + Setting::ENCODINGS, |
|
205 | :log_encoding, [nil] + Setting::ENCODINGS, | |
206 | :label => l("field_commit_logs_encoding"), :required => true)) |
|
206 | :label => l("field_commit_logs_encoding"), :required => true)) | |
207 | end |
|
207 | end | |
208 |
|
208 | |||
209 | def mercurial_field_tags(form, repository) |
|
209 | def mercurial_field_tags(form, repository) | |
210 | content_tag('p', form.text_field(:url, :label => 'Root directory', |
|
210 | content_tag('p', form.text_field(:url, :label => 'Root directory', | |
211 | :size => 60, :required => true, |
|
211 | :size => 60, :required => true, | |
212 | :disabled => (repository && !repository.root_url.blank?)) + |
|
212 | :disabled => (repository && !repository.root_url.blank?)) + | |
213 | '<br />Local repository (e.g. /hgrepo, c:\hgrepo)' ) + |
|
213 | '<br />Local repository (e.g. /hgrepo, c:\hgrepo)' ) + | |
214 | content_tag('p', form.select( |
|
214 | content_tag('p', form.select( | |
215 | :path_encoding, [nil] + Setting::ENCODINGS, |
|
215 | :path_encoding, [nil] + Setting::ENCODINGS, | |
216 | :label => l("field_scm_path_encoding") |
|
216 | :label => l("field_scm_path_encoding") | |
217 | ) + |
|
217 | ) + | |
218 | '<br />' + l("text_scm_path_encoding_note")) |
|
218 | '<br />' + l("text_scm_path_encoding_note")) | |
219 | end |
|
219 | end | |
220 |
|
220 | |||
221 | def git_field_tags(form, repository) |
|
221 | def git_field_tags(form, repository) | |
222 | content_tag('p', form.text_field(:url, :label => 'Path to repository', |
|
222 | content_tag('p', form.text_field(:url, :label => 'Path to repository', | |
223 | :size => 60, :required => true, |
|
223 | :size => 60, :required => true, | |
224 | :disabled => (repository && !repository.root_url.blank?)) + |
|
224 | :disabled => (repository && !repository.root_url.blank?)) + | |
225 | '<br />Bare and local repository (e.g. /gitrepo, c:\gitrepo)') + |
|
225 | '<br />Bare and local repository (e.g. /gitrepo, c:\gitrepo)') + | |
226 | content_tag('p', form.select( |
|
226 | content_tag('p', form.select( | |
227 | :path_encoding, [nil] + Setting::ENCODINGS, |
|
227 | :path_encoding, [nil] + Setting::ENCODINGS, | |
228 | :label => l("field_scm_path_encoding") |
|
228 | :label => l("field_scm_path_encoding") | |
229 | ) + |
|
229 | ) + | |
230 | '<br />' + l("text_scm_path_encoding_note")) |
|
230 | '<br />' + l("text_scm_path_encoding_note")) | |
231 | end |
|
231 | end | |
232 |
|
232 | |||
233 | def cvs_field_tags(form, repository) |
|
233 | def cvs_field_tags(form, repository) | |
234 | content_tag('p', form.text_field(:root_url, |
|
234 | content_tag('p', form.text_field(:root_url, | |
235 | :label => 'CVSROOT', :size => 60, :required => true, |
|
235 | :label => 'CVSROOT', :size => 60, :required => true, | |
236 | :disabled => !repository.new_record?)) + |
|
236 | :disabled => !repository.new_record?)) + | |
237 | content_tag('p', form.text_field(:url, :label => 'Module', |
|
237 | content_tag('p', form.text_field(:url, :label => 'Module', | |
238 | :size => 30, :required => true, |
|
238 | :size => 30, :required => true, | |
239 | :disabled => !repository.new_record?)) + |
|
239 | :disabled => !repository.new_record?)) + | |
240 | content_tag('p', form.select( |
|
240 | content_tag('p', form.select( | |
241 | :log_encoding, [nil] + Setting::ENCODINGS, |
|
241 | :log_encoding, [nil] + Setting::ENCODINGS, | |
242 | :label => l("field_commit_logs_encoding"), :required => true)) + |
|
242 | :label => l("field_commit_logs_encoding"), :required => true)) + | |
243 | content_tag('p', form.select( |
|
243 | content_tag('p', form.select( | |
244 | :path_encoding, [nil] + Setting::ENCODINGS, |
|
244 | :path_encoding, [nil] + Setting::ENCODINGS, | |
245 | :label => l("field_scm_path_encoding") |
|
245 | :label => l("field_scm_path_encoding") | |
246 | ) + |
|
246 | ) + | |
247 | '<br />' + l("text_scm_path_encoding_note")) |
|
247 | '<br />' + l("text_scm_path_encoding_note")) | |
248 | end |
|
248 | end | |
249 |
|
249 | |||
250 | def bazaar_field_tags(form, repository) |
|
250 | def bazaar_field_tags(form, repository) | |
251 | content_tag('p', form.text_field(:url, :label => 'Path to repository', |
|
251 | content_tag('p', form.text_field(:url, :label => 'Path to repository', | |
252 | :size => 60, :required => true, |
|
252 | :size => 60, :required => true, | |
253 | :disabled => (repository && !repository.new_record?))) + |
|
253 | :disabled => (repository && !repository.new_record?))) + | |
254 | content_tag('p', form.select( |
|
254 | content_tag('p', form.select( | |
255 | :log_encoding, [nil] + Setting::ENCODINGS, |
|
255 | :log_encoding, [nil] + Setting::ENCODINGS, | |
256 | :label => l("field_commit_logs_encoding"), :required => true)) |
|
256 | :label => l("field_commit_logs_encoding"), :required => true)) | |
257 | end |
|
257 | end | |
258 |
|
258 | |||
259 | def filesystem_field_tags(form, repository) |
|
259 | def filesystem_field_tags(form, repository) | |
260 | content_tag('p', form.text_field(:url, :label => 'Root directory', |
|
260 | content_tag('p', form.text_field(:url, :label => 'Root directory', | |
261 | :size => 60, :required => true, |
|
261 | :size => 60, :required => true, | |
262 | :disabled => (repository && !repository.root_url.blank?))) + |
|
262 | :disabled => (repository && !repository.root_url.blank?))) + | |
263 | content_tag('p', form.select( |
|
263 | content_tag('p', form.select( | |
264 | :path_encoding, [nil] + Setting::ENCODINGS, |
|
264 | :path_encoding, [nil] + Setting::ENCODINGS, | |
265 | :label => l("field_scm_path_encoding") |
|
265 | :label => l("field_scm_path_encoding") | |
266 | ) + |
|
266 | ) + | |
267 | '<br />' + l("text_scm_path_encoding_note")) |
|
267 | '<br />' + l("text_scm_path_encoding_note")) | |
268 | end |
|
268 | end | |
269 | end |
|
269 | end |
@@ -1,112 +1,112 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require 'redmine/scm/adapters/darcs_adapter' |
|
18 | require 'redmine/scm/adapters/darcs_adapter' | |
19 |
|
19 | |||
20 | class Repository::Darcs < Repository |
|
20 | class Repository::Darcs < Repository | |
21 | validates_presence_of :url, :log_encoding |
|
21 | validates_presence_of :url, :log_encoding | |
22 |
|
22 | |||
23 | ATTRIBUTE_KEY_NAMES = { |
|
23 | ATTRIBUTE_KEY_NAMES = { | |
24 |
"url" => " |
|
24 | "url" => "Path to repository", | |
25 | } |
|
25 | } | |
26 | def self.human_attribute_name(attribute_key_name) |
|
26 | def self.human_attribute_name(attribute_key_name) | |
27 | ATTRIBUTE_KEY_NAMES[attribute_key_name] || super |
|
27 | ATTRIBUTE_KEY_NAMES[attribute_key_name] || super | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def self.scm_adapter_class |
|
30 | def self.scm_adapter_class | |
31 | Redmine::Scm::Adapters::DarcsAdapter |
|
31 | Redmine::Scm::Adapters::DarcsAdapter | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def self.scm_name |
|
34 | def self.scm_name | |
35 | 'Darcs' |
|
35 | 'Darcs' | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def supports_directory_revisions? |
|
38 | def supports_directory_revisions? | |
39 | true |
|
39 | true | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def entry(path=nil, identifier=nil) |
|
42 | def entry(path=nil, identifier=nil) | |
43 | patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) |
|
43 | patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) | |
44 | scm.entry(path, patch.nil? ? nil : patch.scmid) |
|
44 | scm.entry(path, patch.nil? ? nil : patch.scmid) | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def entries(path=nil, identifier=nil) |
|
47 | def entries(path=nil, identifier=nil) | |
48 | patch = nil |
|
48 | patch = nil | |
49 | if ! identifier.nil? |
|
49 | if ! identifier.nil? | |
50 | patch = changesets.find_by_revision(identifier) |
|
50 | patch = changesets.find_by_revision(identifier) | |
51 | return nil if patch.nil? |
|
51 | return nil if patch.nil? | |
52 | end |
|
52 | end | |
53 | entries = scm.entries(path, patch.nil? ? nil : patch.scmid) |
|
53 | entries = scm.entries(path, patch.nil? ? nil : patch.scmid) | |
54 | if entries |
|
54 | if entries | |
55 | entries.each do |entry| |
|
55 | entries.each do |entry| | |
56 | # Search the DB for the entry's last change |
|
56 | # Search the DB for the entry's last change | |
57 | if entry.lastrev && !entry.lastrev.scmid.blank? |
|
57 | if entry.lastrev && !entry.lastrev.scmid.blank? | |
58 | changeset = changesets.find_by_scmid(entry.lastrev.scmid) |
|
58 | changeset = changesets.find_by_scmid(entry.lastrev.scmid) | |
59 | end |
|
59 | end | |
60 | if changeset |
|
60 | if changeset | |
61 | entry.lastrev.identifier = changeset.revision |
|
61 | entry.lastrev.identifier = changeset.revision | |
62 | entry.lastrev.name = changeset.revision |
|
62 | entry.lastrev.name = changeset.revision | |
63 | entry.lastrev.time = changeset.committed_on |
|
63 | entry.lastrev.time = changeset.committed_on | |
64 | entry.lastrev.author = changeset.committer |
|
64 | entry.lastrev.author = changeset.committer | |
65 | end |
|
65 | end | |
66 | end |
|
66 | end | |
67 | end |
|
67 | end | |
68 | entries |
|
68 | entries | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
71 | def cat(path, identifier=nil) |
|
71 | def cat(path, identifier=nil) | |
72 | patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s) |
|
72 | patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s) | |
73 | scm.cat(path, patch.nil? ? nil : patch.scmid) |
|
73 | scm.cat(path, patch.nil? ? nil : patch.scmid) | |
74 | end |
|
74 | end | |
75 |
|
75 | |||
76 | def diff(path, rev, rev_to) |
|
76 | def diff(path, rev, rev_to) | |
77 | patch_from = changesets.find_by_revision(rev) |
|
77 | patch_from = changesets.find_by_revision(rev) | |
78 | return nil if patch_from.nil? |
|
78 | return nil if patch_from.nil? | |
79 | patch_to = changesets.find_by_revision(rev_to) if rev_to |
|
79 | patch_to = changesets.find_by_revision(rev_to) if rev_to | |
80 | if path.blank? |
|
80 | if path.blank? | |
81 | path = patch_from.changes.collect{|change| change.path}.join(' ') |
|
81 | path = patch_from.changes.collect{|change| change.path}.join(' ') | |
82 | end |
|
82 | end | |
83 | patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil |
|
83 | patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | def fetch_changesets |
|
86 | def fetch_changesets | |
87 | scm_info = scm.info |
|
87 | scm_info = scm.info | |
88 | if scm_info |
|
88 | if scm_info | |
89 | db_last_id = latest_changeset ? latest_changeset.scmid : nil |
|
89 | db_last_id = latest_changeset ? latest_changeset.scmid : nil | |
90 | next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1 |
|
90 | next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1 | |
91 | # latest revision in the repository |
|
91 | # latest revision in the repository | |
92 | scm_revision = scm_info.lastrev.scmid |
|
92 | scm_revision = scm_info.lastrev.scmid | |
93 | unless changesets.find_by_scmid(scm_revision) |
|
93 | unless changesets.find_by_scmid(scm_revision) | |
94 | revisions = scm.revisions('', db_last_id, nil, :with_path => true) |
|
94 | revisions = scm.revisions('', db_last_id, nil, :with_path => true) | |
95 | transaction do |
|
95 | transaction do | |
96 | revisions.reverse_each do |revision| |
|
96 | revisions.reverse_each do |revision| | |
97 | changeset = Changeset.create(:repository => self, |
|
97 | changeset = Changeset.create(:repository => self, | |
98 | :revision => next_rev, |
|
98 | :revision => next_rev, | |
99 | :scmid => revision.scmid, |
|
99 | :scmid => revision.scmid, | |
100 | :committer => revision.author, |
|
100 | :committer => revision.author, | |
101 | :committed_on => revision.time, |
|
101 | :committed_on => revision.time, | |
102 | :comments => revision.message) |
|
102 | :comments => revision.message) | |
103 | revision.paths.each do |change| |
|
103 | revision.paths.each do |change| | |
104 | changeset.create_change(change) |
|
104 | changeset.create_change(change) | |
105 | end |
|
105 | end | |
106 | next_rev += 1 |
|
106 | next_rev += 1 | |
107 | end if revisions |
|
107 | end if revisions | |
108 | end |
|
108 | end | |
109 | end |
|
109 | end | |
110 | end |
|
110 | end | |
111 | end |
|
111 | end | |
112 | end |
|
112 | end |
General Comments 0
You need to be logged in to leave comments.
Login now