Chris@0
|
1 # redMine - project management software
|
Chris@0
|
2 # Copyright (C) 2006 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 require 'iconv'
|
Chris@0
|
19
|
Chris@0
|
20 module RepositoriesHelper
|
Chris@117
|
21 def format_revision(revision)
|
Chris@117
|
22 if revision.respond_to? :format_identifier
|
Chris@117
|
23 revision.format_identifier
|
Chris@117
|
24 else
|
Chris@117
|
25 revision.to_s
|
Chris@117
|
26 end
|
Chris@0
|
27 end
|
Chris@0
|
28
|
Chris@0
|
29 def truncate_at_line_break(text, length = 255)
|
Chris@0
|
30 if text
|
Chris@0
|
31 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
|
Chris@0
|
32 end
|
Chris@0
|
33 end
|
Chris@0
|
34
|
Chris@0
|
35 def render_properties(properties)
|
Chris@0
|
36 unless properties.nil? || properties.empty?
|
Chris@0
|
37 content = ''
|
Chris@0
|
38 properties.keys.sort.each do |property|
|
Chris@0
|
39 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>")
|
Chris@0
|
40 end
|
Chris@0
|
41 content_tag('ul', content, :class => 'properties')
|
Chris@0
|
42 end
|
Chris@0
|
43 end
|
Chris@0
|
44
|
Chris@0
|
45 def render_changeset_changes
|
Chris@0
|
46 changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
|
Chris@0
|
47 case change.action
|
Chris@0
|
48 when 'A'
|
Chris@0
|
49 # Detects moved/copied files
|
Chris@0
|
50 if !change.from_path.blank?
|
Chris@0
|
51 change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
|
Chris@0
|
52 end
|
Chris@0
|
53 change
|
Chris@0
|
54 when 'D'
|
Chris@0
|
55 @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
|
Chris@0
|
56 else
|
Chris@0
|
57 change
|
Chris@0
|
58 end
|
Chris@0
|
59 end.compact
|
Chris@0
|
60
|
Chris@0
|
61 tree = { }
|
Chris@0
|
62 changes.each do |change|
|
Chris@0
|
63 p = tree
|
Chris@0
|
64 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
|
Chris@0
|
65 path = ''
|
Chris@0
|
66 dirs.each do |dir|
|
Chris@0
|
67 path += '/' + dir
|
Chris@0
|
68 p[:s] ||= {}
|
Chris@0
|
69 p = p[:s]
|
Chris@0
|
70 p[path] ||= {}
|
Chris@0
|
71 p = p[path]
|
Chris@0
|
72 end
|
Chris@0
|
73 p[:c] = change
|
Chris@0
|
74 end
|
Chris@0
|
75
|
Chris@0
|
76 render_changes_tree(tree[:s])
|
Chris@0
|
77 end
|
Chris@0
|
78
|
Chris@0
|
79 def render_changes_tree(tree)
|
Chris@0
|
80 return '' if tree.nil?
|
Chris@0
|
81
|
Chris@0
|
82 output = ''
|
Chris@0
|
83 output << '<ul>'
|
Chris@0
|
84 tree.keys.sort.each do |file|
|
Chris@0
|
85 style = 'change'
|
Chris@0
|
86 text = File.basename(h(file))
|
Chris@0
|
87 if s = tree[file][:s]
|
Chris@0
|
88 style << ' folder'
|
Chris@0
|
89 path_param = to_path_param(@repository.relative_path(file))
|
Chris@0
|
90 text = link_to(text, :controller => 'repositories',
|
Chris@0
|
91 :action => 'show',
|
Chris@0
|
92 :id => @project,
|
Chris@0
|
93 :path => path_param,
|
Chris@117
|
94 :rev => @changeset.identifier)
|
Chris@0
|
95 output << "<li class='#{style}'>#{text}</li>"
|
Chris@0
|
96 output << render_changes_tree(s)
|
Chris@0
|
97 elsif c = tree[file][:c]
|
Chris@0
|
98 style << " change-#{c.action}"
|
Chris@0
|
99 path_param = to_path_param(@repository.relative_path(c.path))
|
Chris@0
|
100 text = link_to(text, :controller => 'repositories',
|
Chris@0
|
101 :action => 'entry',
|
Chris@0
|
102 :id => @project,
|
Chris@0
|
103 :path => path_param,
|
Chris@117
|
104 :rev => @changeset.identifier) unless c.action == 'D'
|
Chris@0
|
105 text << " - #{c.revision}" unless c.revision.blank?
|
Chris@0
|
106 text << ' (' + link_to('diff', :controller => 'repositories',
|
Chris@0
|
107 :action => 'diff',
|
Chris@0
|
108 :id => @project,
|
Chris@0
|
109 :path => path_param,
|
Chris@117
|
110 :rev => @changeset.identifier) + ') ' if c.action == 'M'
|
Chris@0
|
111 text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank?
|
Chris@0
|
112 output << "<li class='#{style}'>#{text}</li>"
|
Chris@0
|
113 end
|
Chris@0
|
114 end
|
Chris@0
|
115 output << '</ul>'
|
Chris@0
|
116 output
|
Chris@0
|
117 end
|
Chris@0
|
118
|
Chris@0
|
119 def to_utf8(str)
|
Chris@0
|
120 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
Chris@0
|
121 @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
|
Chris@0
|
122 @encodings.each do |encoding|
|
Chris@0
|
123 begin
|
Chris@0
|
124 return Iconv.conv('UTF-8', encoding, str)
|
Chris@0
|
125 rescue Iconv::Failure
|
Chris@0
|
126 # do nothing here and try the next encoding
|
Chris@0
|
127 end
|
Chris@0
|
128 end
|
Chris@0
|
129 str
|
Chris@0
|
130 end
|
Chris@0
|
131
|
Chris@0
|
132 def repository_field_tags(form, repository)
|
Chris@0
|
133 method = repository.class.name.demodulize.underscore + "_field_tags"
|
Chris@0
|
134 send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags'
|
Chris@0
|
135 end
|
Chris@0
|
136
|
Chris@0
|
137 def scm_select_tag(repository)
|
Chris@0
|
138 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
|
Chris@0
|
139 Redmine::Scm::Base.all.each do |scm|
|
Chris@0
|
140 scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm)
|
Chris@0
|
141 end
|
Chris@0
|
142
|
Chris@0
|
143 select_tag('repository_scm',
|
Chris@0
|
144 options_for_select(scm_options, repository.class.name.demodulize),
|
Chris@0
|
145 :disabled => (repository && !repository.new_record?),
|
Chris@0
|
146 :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
|
Chris@0
|
147 )
|
Chris@0
|
148 end
|
Chris@0
|
149
|
Chris@0
|
150 def with_leading_slash(path)
|
Chris@0
|
151 path.to_s.starts_with?('/') ? path : "/#{path}"
|
Chris@0
|
152 end
|
Chris@0
|
153
|
Chris@0
|
154 def without_leading_slash(path)
|
Chris@0
|
155 path.gsub(%r{^/+}, '')
|
Chris@0
|
156 end
|
Chris@0
|
157
|
Chris@0
|
158 def subversion_field_tags(form, repository)
|
Chris@0
|
159 content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) +
|
Chris@0
|
160 '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
|
Chris@0
|
161 content_tag('p', form.text_field(:login, :size => 30)) +
|
Chris@0
|
162 content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore',
|
Chris@0
|
163 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
|
Chris@0
|
164 :onfocus => "this.value=''; this.name='repository[password]';",
|
Chris@0
|
165 :onchange => "this.name='repository[password]';"))
|
Chris@0
|
166 end
|
Chris@0
|
167
|
Chris@0
|
168 def darcs_field_tags(form, repository)
|
Chris@0
|
169 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
|
Chris@0
|
170 end
|
Chris@0
|
171
|
Chris@0
|
172 def mercurial_field_tags(form, repository)
|
Chris@0
|
173 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
Chris@0
|
174 end
|
Chris@0
|
175
|
Chris@0
|
176 def git_field_tags(form, repository)
|
Chris@0
|
177 content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
Chris@0
|
178 end
|
Chris@0
|
179
|
Chris@0
|
180 def cvs_field_tags(form, repository)
|
Chris@0
|
181 content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
|
Chris@0
|
182 content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
|
Chris@0
|
183 end
|
Chris@0
|
184
|
Chris@0
|
185 def bazaar_field_tags(form, repository)
|
Chris@0
|
186 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
|
Chris@0
|
187 end
|
Chris@0
|
188
|
Chris@0
|
189 def filesystem_field_tags(form, repository)
|
Chris@0
|
190 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
Chris@0
|
191 end
|
Chris@0
|
192 end
|