To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / helpers / repositories_helper.rb @ 417:6b3e9f512761
History | View | Annotate | Download (8.11 KB)
| 1 |
# redMine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006 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 'iconv'
|
| 19 |
|
| 20 |
module RepositoriesHelper |
| 21 |
# truncate rev to 8 chars if it's quite long
|
| 22 |
def truncate_long_revision_name(rev) |
| 23 |
rev.to_s.size <= 12 ? rev.to_s : rev.to_s[0, 8] |
| 24 |
end
|
| 25 |
private :truncate_long_revision_name
|
| 26 |
|
| 27 |
def format_revision(revision) |
| 28 |
if [:identifier, :revision, :scmid].all? { |e| revision.respond_to? e } |
| 29 |
if revision.scmid and revision.revision != revision.scmid and /[^\d]/ !~ revision.revision |
| 30 |
"#{revision.revision}:#{revision.scmid}" # number:hashid |
| 31 |
else
|
| 32 |
truncate_long_revision_name(revision.identifier) |
| 33 |
end
|
| 34 |
else
|
| 35 |
truncate_long_revision_name(revision) |
| 36 |
end
|
| 37 |
end
|
| 38 |
module_function :format_revision # callable as RepositoriesHelper.format_revision |
| 39 |
|
| 40 |
def truncate_at_line_break(text, length = 255) |
| 41 |
if text
|
| 42 |
text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') |
| 43 |
end
|
| 44 |
end
|
| 45 |
|
| 46 |
def render_properties(properties) |
| 47 |
unless properties.nil? || properties.empty?
|
| 48 |
content = ''
|
| 49 |
properties.keys.sort.each do |property|
|
| 50 |
content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") |
| 51 |
end
|
| 52 |
content_tag('ul', content, :class => 'properties') |
| 53 |
end
|
| 54 |
end
|
| 55 |
|
| 56 |
def render_changeset_changes |
| 57 |
changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| |
| 58 |
case change.action
|
| 59 |
when 'A' |
| 60 |
# Detects moved/copied files
|
| 61 |
if !change.from_path.blank?
|
| 62 |
change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' |
| 63 |
end
|
| 64 |
change |
| 65 |
when 'D' |
| 66 |
@changeset.changes.detect {|c| c.from_path == change.path} ? nil : change |
| 67 |
else
|
| 68 |
change |
| 69 |
end
|
| 70 |
end.compact
|
| 71 |
|
| 72 |
tree = { }
|
| 73 |
changes.each do |change|
|
| 74 |
p = tree |
| 75 |
dirs = change.path.to_s.split('/').select {|d| !d.blank?}
|
| 76 |
path = ''
|
| 77 |
dirs.each do |dir|
|
| 78 |
path += '/' + dir
|
| 79 |
p[:s] ||= {}
|
| 80 |
p = p[:s]
|
| 81 |
p[path] ||= {}
|
| 82 |
p = p[path] |
| 83 |
end
|
| 84 |
p[:c] = change
|
| 85 |
end
|
| 86 |
|
| 87 |
render_changes_tree(tree[:s])
|
| 88 |
end
|
| 89 |
|
| 90 |
def render_changes_tree(tree) |
| 91 |
return '' if tree.nil? |
| 92 |
|
| 93 |
output = ''
|
| 94 |
output << '<ul>'
|
| 95 |
tree.keys.sort.each do |file|
|
| 96 |
style = 'change'
|
| 97 |
text = File.basename(h(file))
|
| 98 |
if s = tree[file][:s] |
| 99 |
style << ' folder'
|
| 100 |
path_param = to_path_param(@repository.relative_path(file))
|
| 101 |
text = link_to(text, :controller => 'repositories', |
| 102 |
:action => 'show', |
| 103 |
:id => @project, |
| 104 |
:path => path_param,
|
| 105 |
:rev => @changeset.identifier) |
| 106 |
output << "<li class='#{style}'>#{text}</li>"
|
| 107 |
output << render_changes_tree(s) |
| 108 |
elsif c = tree[file][:c] |
| 109 |
style << " change-#{c.action}"
|
| 110 |
path_param = to_path_param(@repository.relative_path(c.path))
|
| 111 |
text = link_to(text, :controller => 'repositories', |
| 112 |
:action => 'entry', |
| 113 |
:id => @project, |
| 114 |
:path => path_param,
|
| 115 |
:rev => @changeset.identifier) unless c.action == 'D' |
| 116 |
text << " - #{c.revision}" unless c.revision.blank? |
| 117 |
text << ' (' + link_to('diff', :controller => 'repositories', |
| 118 |
:action => 'diff', |
| 119 |
:id => @project, |
| 120 |
:path => path_param,
|
| 121 |
:rev => @changeset.identifier) + ') ' if c.action == 'M' |
| 122 |
text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? |
| 123 |
output << "<li class='#{style}'>#{text}</li>"
|
| 124 |
end
|
| 125 |
end
|
| 126 |
output << '</ul>'
|
| 127 |
output |
| 128 |
end
|
| 129 |
|
| 130 |
def to_utf8(str) |
| 131 |
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
| 132 |
@encodings ||= Setting.repositories_encodings.split(',').collect(&:strip) |
| 133 |
@encodings.each do |encoding| |
| 134 |
begin
|
| 135 |
return Iconv.conv('UTF-8', encoding, str) |
| 136 |
rescue Iconv::Failure |
| 137 |
# do nothing here and try the next encoding
|
| 138 |
end
|
| 139 |
end
|
| 140 |
str |
| 141 |
end
|
| 142 |
|
| 143 |
def repository_field_tags(form, repository) |
| 144 |
method = repository.class.name.demodulize.underscore + "_field_tags"
|
| 145 |
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' |
| 146 |
end
|
| 147 |
|
| 148 |
def scm_select_tag(repository) |
| 149 |
scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] |
| 150 |
Redmine::Scm::Base.all.each do |scm| |
| 151 |
scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) |
| 152 |
end
|
| 153 |
|
| 154 |
select_tag('repository_scm',
|
| 155 |
options_for_select(scm_options, repository.class.name.demodulize), |
| 156 |
:disabled => (repository && !repository.new_record?),
|
| 157 |
:onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)") |
| 158 |
) |
| 159 |
end
|
| 160 |
|
| 161 |
def with_leading_slash(path) |
| 162 |
path.to_s.starts_with?('/') ? path : "/#{path}" |
| 163 |
end
|
| 164 |
|
| 165 |
def without_leading_slash(path) |
| 166 |
path.gsub(%r{^/+}, '') |
| 167 |
end
|
| 168 |
|
| 169 |
def subversion_field_tags(form, repository) |
| 170 |
content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) + |
| 171 |
'<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
|
| 172 |
content_tag('p', form.text_field(:login, :size => 30)) + |
| 173 |
content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore', |
| 174 |
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), |
| 175 |
:onfocus => "this.value=''; this.name='repository[password]';", |
| 176 |
:onchange => "this.name='repository[password]';")) |
| 177 |
end
|
| 178 |
|
| 179 |
def darcs_field_tags(form, repository) |
| 180 |
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) |
| 181 |
end
|
| 182 |
|
| 183 |
def mercurial_field_tags(form, repository) |
| 184 |
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => true)) |
| 185 |
# (repository && !repository.root_url.blank?)))
|
| 186 |
end
|
| 187 |
|
| 188 |
def git_field_tags(form, repository) |
| 189 |
content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
| 190 |
end
|
| 191 |
|
| 192 |
def cvs_field_tags(form, repository) |
| 193 |
content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) + |
| 194 |
content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?)) |
| 195 |
end
|
| 196 |
|
| 197 |
def bazaar_field_tags(form, repository) |
| 198 |
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) |
| 199 |
end
|
| 200 |
|
| 201 |
def filesystem_field_tags(form, repository) |
| 202 |
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) |
| 203 |
end
|
| 204 |
end
|