annotate .svn/pristine/ae/ae9b39171caeb6f8f6a13fdb73ccbb11ad433254.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # encoding: utf-8
Chris@1296 2 #
Chris@1296 3 # Redmine - project management software
Chris@1296 4 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 5 #
Chris@1296 6 # This program is free software; you can redistribute it and/or
Chris@1296 7 # modify it under the terms of the GNU General Public License
Chris@1296 8 # as published by the Free Software Foundation; either version 2
Chris@1296 9 # of the License, or (at your option) any later version.
Chris@1296 10 #
Chris@1296 11 # This program is distributed in the hope that it will be useful,
Chris@1296 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 14 # GNU General Public License for more details.
Chris@1296 15 #
Chris@1296 16 # You should have received a copy of the GNU General Public License
Chris@1296 17 # along with this program; if not, write to the Free Software
Chris@1296 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 19
Chris@1296 20 module RepositoriesHelper
Chris@1296 21 def format_revision(revision)
Chris@1296 22 if revision.respond_to? :format_identifier
Chris@1296 23 revision.format_identifier
Chris@1296 24 else
Chris@1296 25 revision.to_s
Chris@1296 26 end
Chris@1296 27 end
Chris@1296 28
Chris@1296 29 def truncate_at_line_break(text, length = 255)
Chris@1296 30 if text
Chris@1296 31 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
Chris@1296 32 end
Chris@1296 33 end
Chris@1296 34
Chris@1296 35 def render_properties(properties)
Chris@1296 36 unless properties.nil? || properties.empty?
Chris@1296 37 content = ''
Chris@1296 38 properties.keys.sort.each do |property|
Chris@1296 39 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>".html_safe)
Chris@1296 40 end
Chris@1296 41 content_tag('ul', content.html_safe, :class => 'properties')
Chris@1296 42 end
Chris@1296 43 end
Chris@1296 44
Chris@1296 45 def render_changeset_changes
Chris@1296 46 changes = @changeset.filechanges.find(:all, :limit => 1000, :order => 'path').collect do |change|
Chris@1296 47 case change.action
Chris@1296 48 when 'A'
Chris@1296 49 # Detects moved/copied files
Chris@1296 50 if !change.from_path.blank?
Chris@1296 51 change.action =
Chris@1296 52 @changeset.filechanges.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
Chris@1296 53 end
Chris@1296 54 change
Chris@1296 55 when 'D'
Chris@1296 56 @changeset.filechanges.detect {|c| c.from_path == change.path} ? nil : change
Chris@1296 57 else
Chris@1296 58 change
Chris@1296 59 end
Chris@1296 60 end.compact
Chris@1296 61
Chris@1296 62 tree = { }
Chris@1296 63 changes.each do |change|
Chris@1296 64 p = tree
Chris@1296 65 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
Chris@1296 66 path = ''
Chris@1296 67 dirs.each do |dir|
Chris@1296 68 path += '/' + dir
Chris@1296 69 p[:s] ||= {}
Chris@1296 70 p = p[:s]
Chris@1296 71 p[path] ||= {}
Chris@1296 72 p = p[path]
Chris@1296 73 end
Chris@1296 74 p[:c] = change
Chris@1296 75 end
Chris@1296 76 render_changes_tree(tree[:s])
Chris@1296 77 end
Chris@1296 78
Chris@1296 79 def render_changes_tree(tree)
Chris@1296 80 return '' if tree.nil?
Chris@1296 81 output = ''
Chris@1296 82 output << '<ul>'
Chris@1296 83 tree.keys.sort.each do |file|
Chris@1296 84 style = 'change'
Chris@1296 85 text = File.basename(h(file))
Chris@1296 86 if s = tree[file][:s]
Chris@1296 87 style << ' folder'
Chris@1296 88 path_param = to_path_param(@repository.relative_path(file))
Chris@1296 89 text = link_to(h(text), :controller => 'repositories',
Chris@1296 90 :action => 'show',
Chris@1296 91 :id => @project,
Chris@1296 92 :repository_id => @repository.identifier_param,
Chris@1296 93 :path => path_param,
Chris@1296 94 :rev => @changeset.identifier)
Chris@1296 95 output << "<li class='#{style}'>#{text}"
Chris@1296 96 output << render_changes_tree(s)
Chris@1296 97 output << "</li>"
Chris@1296 98 elsif c = tree[file][:c]
Chris@1296 99 style << " change-#{c.action}"
Chris@1296 100 path_param = to_path_param(@repository.relative_path(c.path))
Chris@1296 101 text = link_to(h(text), :controller => 'repositories',
Chris@1296 102 :action => 'entry',
Chris@1296 103 :id => @project,
Chris@1296 104 :repository_id => @repository.identifier_param,
Chris@1296 105 :path => path_param,
Chris@1296 106 :rev => @changeset.identifier) unless c.action == 'D'
Chris@1296 107 text << " - #{h(c.revision)}" unless c.revision.blank?
Chris@1296 108 text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories',
Chris@1296 109 :action => 'diff',
Chris@1296 110 :id => @project,
Chris@1296 111 :repository_id => @repository.identifier_param,
Chris@1296 112 :path => path_param,
Chris@1296 113 :rev => @changeset.identifier) + ') '.html_safe if c.action == 'M'
Chris@1296 114 text << ' '.html_safe + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
Chris@1296 115 output << "<li class='#{style}'>#{text}</li>"
Chris@1296 116 end
Chris@1296 117 end
Chris@1296 118 output << '</ul>'
Chris@1296 119 output.html_safe
Chris@1296 120 end
Chris@1296 121
Chris@1296 122 def repository_field_tags(form, repository)
Chris@1296 123 method = repository.class.name.demodulize.underscore + "_field_tags"
Chris@1296 124 if repository.is_a?(Repository) &&
Chris@1296 125 respond_to?(method) && method != 'repository_field_tags'
Chris@1296 126 send(method, form, repository)
Chris@1296 127 end
Chris@1296 128 end
Chris@1296 129
Chris@1296 130 def scm_select_tag(repository)
Chris@1296 131 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
Chris@1296 132 Redmine::Scm::Base.all.each do |scm|
Chris@1296 133 if Setting.enabled_scm.include?(scm) ||
Chris@1296 134 (repository && repository.class.name.demodulize == scm)
Chris@1296 135 scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
Chris@1296 136 end
Chris@1296 137 end
Chris@1296 138 select_tag('repository_scm',
Chris@1296 139 options_for_select(scm_options, repository.class.name.demodulize),
Chris@1296 140 :disabled => (repository && !repository.new_record?),
Chris@1296 141 :data => {:remote => true, :method => 'get'})
Chris@1296 142 end
Chris@1296 143
Chris@1296 144 def with_leading_slash(path)
Chris@1296 145 path.to_s.starts_with?('/') ? path : "/#{path}"
Chris@1296 146 end
Chris@1296 147
Chris@1296 148 def without_leading_slash(path)
Chris@1296 149 path.gsub(%r{^/+}, '')
Chris@1296 150 end
Chris@1296 151
Chris@1296 152 def subversion_field_tags(form, repository)
Chris@1296 153 content_tag('p', form.text_field(:url, :size => 60, :required => true,
Chris@1296 154 :disabled => !repository.safe_attribute?('url')) +
Chris@1296 155 '<br />'.html_safe +
Chris@1296 156 '(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
Chris@1296 157 content_tag('p', form.text_field(:login, :size => 30)) +
Chris@1296 158 content_tag('p', form.password_field(
Chris@1296 159 :password, :size => 30, :name => 'ignore',
Chris@1296 160 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
Chris@1296 161 :onfocus => "this.value=''; this.name='repository[password]';",
Chris@1296 162 :onchange => "this.name='repository[password]';"))
Chris@1296 163 end
Chris@1296 164
Chris@1296 165 def darcs_field_tags(form, repository)
Chris@1296 166 content_tag('p', form.text_field(
Chris@1296 167 :url, :label => l(:field_path_to_repository),
Chris@1296 168 :size => 60, :required => true,
Chris@1296 169 :disabled => !repository.safe_attribute?('url'))) +
Chris@1296 170 content_tag('p', form.select(
Chris@1296 171 :log_encoding, [nil] + Setting::ENCODINGS,
Chris@1296 172 :label => l(:field_commit_logs_encoding), :required => true))
Chris@1296 173 end
Chris@1296 174
Chris@1296 175 def mercurial_field_tags(form, repository)
Chris@1296 176 content_tag('p', form.text_field(
Chris@1296 177 :url, :label => l(:field_path_to_repository),
Chris@1296 178 :size => 60, :required => true,
Chris@1296 179 :disabled => !repository.safe_attribute?('url')
Chris@1296 180 ) +
Chris@1296 181 '<br />'.html_safe + l(:text_mercurial_repository_note)) +
Chris@1296 182 content_tag('p', form.select(
Chris@1296 183 :path_encoding, [nil] + Setting::ENCODINGS,
Chris@1296 184 :label => l(:field_scm_path_encoding)
Chris@1296 185 ) +
Chris@1296 186 '<br />'.html_safe + l(:text_scm_path_encoding_note))
Chris@1296 187 end
Chris@1296 188
Chris@1296 189 def git_field_tags(form, repository)
Chris@1296 190 content_tag('p', form.text_field(
Chris@1296 191 :url, :label => l(:field_path_to_repository),
Chris@1296 192 :size => 60, :required => true,
Chris@1296 193 :disabled => !repository.safe_attribute?('url')
Chris@1296 194 ) +
Chris@1296 195 '<br />'.html_safe +
Chris@1296 196 l(:text_git_repository_note)) +
Chris@1296 197 content_tag('p', form.select(
Chris@1296 198 :path_encoding, [nil] + Setting::ENCODINGS,
Chris@1296 199 :label => l(:field_scm_path_encoding)
Chris@1296 200 ) +
Chris@1296 201 '<br />'.html_safe + l(:text_scm_path_encoding_note)) +
Chris@1296 202 content_tag('p', form.check_box(
Chris@1296 203 :extra_report_last_commit,
Chris@1296 204 :label => l(:label_git_report_last_commit)
Chris@1296 205 ))
Chris@1296 206 end
Chris@1296 207
Chris@1296 208 def cvs_field_tags(form, repository)
Chris@1296 209 content_tag('p', form.text_field(
Chris@1296 210 :root_url,
Chris@1296 211 :label => l(:field_cvsroot),
Chris@1296 212 :size => 60, :required => true,
Chris@1296 213 :disabled => !repository.safe_attribute?('root_url'))) +
Chris@1296 214 content_tag('p', form.text_field(
Chris@1296 215 :url,
Chris@1296 216 :label => l(:field_cvs_module),
Chris@1296 217 :size => 30, :required => true,
Chris@1296 218 :disabled => !repository.safe_attribute?('url'))) +
Chris@1296 219 content_tag('p', form.select(
Chris@1296 220 :log_encoding, [nil] + Setting::ENCODINGS,
Chris@1296 221 :label => l(:field_commit_logs_encoding), :required => true)) +
Chris@1296 222 content_tag('p', form.select(
Chris@1296 223 :path_encoding, [nil] + Setting::ENCODINGS,
Chris@1296 224 :label => l(:field_scm_path_encoding)
Chris@1296 225 ) +
Chris@1296 226 '<br />'.html_safe + l(:text_scm_path_encoding_note))
Chris@1296 227 end
Chris@1296 228
Chris@1296 229 def bazaar_field_tags(form, repository)
Chris@1296 230 content_tag('p', form.text_field(
Chris@1296 231 :url, :label => l(:field_path_to_repository),
Chris@1296 232 :size => 60, :required => true,
Chris@1296 233 :disabled => !repository.safe_attribute?('url'))) +
Chris@1296 234 content_tag('p', form.select(
Chris@1296 235 :log_encoding, [nil] + Setting::ENCODINGS,
Chris@1296 236 :label => l(:field_commit_logs_encoding), :required => true))
Chris@1296 237 end
Chris@1296 238
Chris@1296 239 def filesystem_field_tags(form, repository)
Chris@1296 240 content_tag('p', form.text_field(
Chris@1296 241 :url, :label => l(:field_root_directory),
Chris@1296 242 :size => 60, :required => true,
Chris@1296 243 :disabled => !repository.safe_attribute?('url'))) +
Chris@1296 244 content_tag('p', form.select(
Chris@1296 245 :path_encoding, [nil] + Setting::ENCODINGS,
Chris@1296 246 :label => l(:field_scm_path_encoding)
Chris@1296 247 ) +
Chris@1296 248 '<br />'.html_safe + l(:text_scm_path_encoding_note))
Chris@1296 249 end
Chris@1296 250
Chris@1296 251 def index_commits(commits, heads)
Chris@1296 252 return nil if commits.nil? or commits.first.parents.nil?
Chris@1296 253 refs_map = {}
Chris@1296 254 heads.each do |head|
Chris@1296 255 refs_map[head.scmid] ||= []
Chris@1296 256 refs_map[head.scmid] << head
Chris@1296 257 end
Chris@1296 258 commits_by_scmid = {}
Chris@1296 259 commits.reverse.each_with_index do |commit, commit_index|
Chris@1296 260 commits_by_scmid[commit.scmid] = {
Chris@1296 261 :parent_scmids => commit.parents.collect { |parent| parent.scmid },
Chris@1296 262 :rdmid => commit_index,
Chris@1296 263 :refs => refs_map.include?(commit.scmid) ? refs_map[commit.scmid].join(" ") : nil,
Chris@1296 264 :scmid => commit.scmid,
Chris@1296 265 :href => block_given? ? yield(commit.scmid) : commit.scmid
Chris@1296 266 }
Chris@1296 267 end
Chris@1296 268 heads.sort! { |head1, head2| head1.to_s <=> head2.to_s }
Chris@1296 269 space = nil
Chris@1296 270 heads.each do |head|
Chris@1296 271 if commits_by_scmid.include? head.scmid
Chris@1296 272 space = index_head((space || -1) + 1, head, commits_by_scmid)
Chris@1296 273 end
Chris@1296 274 end
Chris@1296 275 # when no head matched anything use first commit
Chris@1296 276 space ||= index_head(0, commits.first, commits_by_scmid)
Chris@1296 277 return commits_by_scmid, space
Chris@1296 278 end
Chris@1296 279
Chris@1296 280 def index_head(space, commit, commits_by_scmid)
Chris@1296 281 stack = [[space, commits_by_scmid[commit.scmid]]]
Chris@1296 282 max_space = space
Chris@1296 283 until stack.empty?
Chris@1296 284 space, commit = stack.pop
Chris@1296 285 commit[:space] = space if commit[:space].nil?
Chris@1296 286 space -= 1
Chris@1296 287 commit[:parent_scmids].each_with_index do |parent_scmid, parent_index|
Chris@1296 288 parent_commit = commits_by_scmid[parent_scmid]
Chris@1296 289 if parent_commit and parent_commit[:space].nil?
Chris@1296 290 stack.unshift [space += 1, parent_commit]
Chris@1296 291 end
Chris@1296 292 end
Chris@1296 293 max_space = space if max_space < space
Chris@1296 294 end
Chris@1296 295 max_space
Chris@1296 296 end
Chris@1296 297 end