annotate .svn/pristine/d5/d5c42a8cf284c9057072604f567dd5624a3806d3.svn-base @ 1478:5ca1f4a47171 bibplugin_db_migrations

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