2011-12-14 23:56:23 +04:00
|
|
|
# encoding: utf-8
|
|
|
|
#
|
2011-05-18 06:45:35 +04:00
|
|
|
# Redmine - project management software
|
2012-05-05 16:56:53 +04:00
|
|
|
# Copyright (C) 2006-2012 Jean-Philippe Lang
|
2006-12-24 16:38:45 +03:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-18 06:45:35 +04:00
|
|
|
#
|
2006-12-24 16:38:45 +03:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-05-18 06:45:35 +04:00
|
|
|
#
|
2006-12-24 16:38:45 +03:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2007-10-07 19:21:40 +04:00
|
|
|
require 'iconv'
|
2011-04-16 10:43:49 +04:00
|
|
|
require 'redmine/codeset_util'
|
2007-08-16 00:20:18 +04:00
|
|
|
|
2006-12-24 16:38:45 +03:00
|
|
|
module RepositoriesHelper
|
2011-01-02 12:45:05 +03:00
|
|
|
def format_revision(revision)
|
|
|
|
if revision.respond_to? :format_identifier
|
|
|
|
revision.format_identifier
|
|
|
|
else
|
|
|
|
revision.to_s
|
|
|
|
end
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
2011-03-03 06:30:10 +03:00
|
|
|
|
2008-09-22 23:50:10 +04:00
|
|
|
def truncate_at_line_break(text, length = 255)
|
|
|
|
if text
|
|
|
|
text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
|
|
|
|
end
|
|
|
|
end
|
2011-03-03 06:30:10 +03:00
|
|
|
|
2008-07-05 12:59:04 +04:00
|
|
|
def render_properties(properties)
|
|
|
|
unless properties.nil? || properties.empty?
|
|
|
|
content = ''
|
|
|
|
properties.keys.sort.each do |property|
|
2011-09-30 06:19:38 +04:00
|
|
|
content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>".html_safe)
|
2008-07-05 12:59:04 +04:00
|
|
|
end
|
2011-09-30 06:19:38 +04:00
|
|
|
content_tag('ul', content.html_safe, :class => 'properties')
|
2008-07-05 12:59:04 +04:00
|
|
|
end
|
|
|
|
end
|
2011-03-03 06:30:10 +03:00
|
|
|
|
2008-09-17 20:39:23 +04:00
|
|
|
def render_changeset_changes
|
|
|
|
changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
|
|
|
|
case change.action
|
|
|
|
when 'A'
|
|
|
|
# Detects moved/copied files
|
|
|
|
if !change.from_path.blank?
|
2011-04-20 11:16:23 +04:00
|
|
|
change.action =
|
|
|
|
@changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
|
2008-09-17 20:39:23 +04:00
|
|
|
end
|
|
|
|
change
|
|
|
|
when 'D'
|
|
|
|
@changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
|
|
|
|
else
|
|
|
|
change
|
|
|
|
end
|
2011-04-20 11:16:23 +04:00
|
|
|
end.compact
|
2011-05-18 06:45:35 +04:00
|
|
|
|
2008-09-17 20:39:23 +04:00
|
|
|
tree = { }
|
|
|
|
changes.each do |change|
|
|
|
|
p = tree
|
|
|
|
dirs = change.path.to_s.split('/').select {|d| !d.blank?}
|
2010-04-11 19:18:49 +04:00
|
|
|
path = ''
|
2008-09-17 20:39:23 +04:00
|
|
|
dirs.each do |dir|
|
2010-04-11 19:18:49 +04:00
|
|
|
path += '/' + dir
|
2008-09-17 20:39:23 +04:00
|
|
|
p[:s] ||= {}
|
|
|
|
p = p[:s]
|
2010-04-11 19:18:49 +04:00
|
|
|
p[path] ||= {}
|
|
|
|
p = p[path]
|
2008-09-17 20:39:23 +04:00
|
|
|
end
|
|
|
|
p[:c] = change
|
|
|
|
end
|
|
|
|
render_changes_tree(tree[:s])
|
|
|
|
end
|
2011-03-03 06:30:10 +03:00
|
|
|
|
2008-09-17 20:39:23 +04:00
|
|
|
def render_changes_tree(tree)
|
|
|
|
return '' if tree.nil?
|
|
|
|
output = ''
|
|
|
|
output << '<ul>'
|
|
|
|
tree.keys.sort.each do |file|
|
|
|
|
style = 'change'
|
2010-04-11 19:18:49 +04:00
|
|
|
text = File.basename(h(file))
|
|
|
|
if s = tree[file][:s]
|
|
|
|
style << ' folder'
|
|
|
|
path_param = to_path_param(@repository.relative_path(file))
|
2011-08-02 16:51:49 +04:00
|
|
|
text = link_to(h(text), :controller => 'repositories',
|
2010-04-11 19:18:49 +04:00
|
|
|
:action => 'show',
|
|
|
|
:id => @project,
|
2012-01-15 22:19:19 +04:00
|
|
|
:repository_id => @repository.identifier_param,
|
2010-04-11 19:18:49 +04:00
|
|
|
:path => path_param,
|
2011-01-02 12:45:05 +03:00
|
|
|
:rev => @changeset.identifier)
|
2012-01-04 22:34:38 +04:00
|
|
|
output << "<li class='#{style}'>#{text}"
|
2010-04-11 19:18:49 +04:00
|
|
|
output << render_changes_tree(s)
|
2012-01-04 22:34:38 +04:00
|
|
|
output << "</li>"
|
2010-04-11 19:18:49 +04:00
|
|
|
elsif c = tree[file][:c]
|
|
|
|
style << " change-#{c.action}"
|
2008-09-17 20:39:23 +04:00
|
|
|
path_param = to_path_param(@repository.relative_path(c.path))
|
2011-08-02 16:51:49 +04:00
|
|
|
text = link_to(h(text), :controller => 'repositories',
|
2008-09-17 20:39:23 +04:00
|
|
|
:action => 'entry',
|
|
|
|
:id => @project,
|
2012-01-15 22:19:19 +04:00
|
|
|
:repository_id => @repository.identifier_param,
|
2008-09-17 20:39:23 +04:00
|
|
|
:path => path_param,
|
2011-01-02 12:45:05 +03:00
|
|
|
:rev => @changeset.identifier) unless c.action == 'D'
|
2011-08-02 16:51:49 +04:00
|
|
|
text << " - #{h(c.revision)}" unless c.revision.blank?
|
2011-09-30 04:56:17 +04:00
|
|
|
text << ' ('.html_safe + link_to(l(:label_diff), :controller => 'repositories',
|
2008-09-17 20:39:23 +04:00
|
|
|
:action => 'diff',
|
|
|
|
:id => @project,
|
2012-01-15 22:19:19 +04:00
|
|
|
:repository_id => @repository.identifier_param,
|
2008-09-17 20:39:23 +04:00
|
|
|
:path => path_param,
|
2011-09-30 04:56:17 +04:00
|
|
|
:rev => @changeset.identifier) + ') '.html_safe if c.action == 'M'
|
|
|
|
text << ' '.html_safe + content_tag('span', h(c.from_path), :class => 'copied-from') unless c.from_path.blank?
|
2010-04-11 19:18:49 +04:00
|
|
|
output << "<li class='#{style}'>#{text}</li>"
|
2008-09-17 20:39:23 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
output << '</ul>'
|
2011-09-30 04:56:17 +04:00
|
|
|
output.html_safe
|
2008-09-17 20:39:23 +04:00
|
|
|
end
|
2011-03-03 06:30:10 +03:00
|
|
|
|
2011-02-22 11:16:05 +03:00
|
|
|
def repository_field_tags(form, repository)
|
2007-06-13 00:12:05 +04:00
|
|
|
method = repository.class.name.demodulize.underscore + "_field_tags"
|
2011-03-02 08:12:15 +03:00
|
|
|
if repository.is_a?(Repository) &&
|
|
|
|
respond_to?(method) && method != 'repository_field_tags'
|
|
|
|
send(method, form, repository)
|
|
|
|
end
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2011-03-02 08:12:15 +03:00
|
|
|
|
2007-09-14 15:34:08 +04:00
|
|
|
def scm_select_tag(repository)
|
2008-06-08 18:59:26 +04:00
|
|
|
scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
|
2010-02-17 01:41:59 +03:00
|
|
|
Redmine::Scm::Base.all.each do |scm|
|
2011-03-02 08:12:15 +03:00
|
|
|
if Setting.enabled_scm.include?(scm) ||
|
|
|
|
(repository && repository.class.name.demodulize == scm)
|
|
|
|
scm_options << ["Repository::#{scm}".constantize.scm_name, scm]
|
|
|
|
end
|
2008-06-08 18:59:26 +04:00
|
|
|
end
|
2011-05-03 11:33:19 +04:00
|
|
|
select_tag('repository_scm',
|
2008-06-08 18:59:26 +04:00
|
|
|
options_for_select(scm_options, repository.class.name.demodulize),
|
2007-09-14 15:34:08 +04:00
|
|
|
:disabled => (repository && !repository.new_record?),
|
2011-03-02 08:12:15 +03:00
|
|
|
:onchange => remote_function(
|
2012-01-15 18:23:06 +04:00
|
|
|
:url => new_project_repository_path(@project),
|
|
|
|
:method => :get,
|
|
|
|
:update => 'content',
|
|
|
|
:with => "Form.serialize(this.form)")
|
2011-05-03 11:33:19 +04:00
|
|
|
)
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2011-02-24 08:59:21 +03:00
|
|
|
|
2007-06-13 00:12:05 +04:00
|
|
|
def with_leading_slash(path)
|
2008-04-04 02:29:58 +04:00
|
|
|
path.to_s.starts_with?('/') ? path : "/#{path}"
|
|
|
|
end
|
2011-02-24 08:59:21 +03:00
|
|
|
|
2008-04-04 02:29:58 +04:00
|
|
|
def without_leading_slash(path)
|
|
|
|
path.gsub(%r{^/+}, '')
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def subversion_field_tags(form, repository)
|
2011-02-24 08:59:21 +03:00
|
|
|
content_tag('p', form.text_field(:url, :size => 60, :required => true,
|
|
|
|
:disabled => (repository && !repository.root_url.blank?)) +
|
2011-09-30 12:17:30 +04:00
|
|
|
'<br />'.html_safe +
|
|
|
|
'(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
|
2007-06-13 00:12:05 +04:00
|
|
|
content_tag('p', form.text_field(:login, :size => 30)) +
|
2011-03-03 06:30:10 +03:00
|
|
|
content_tag('p', form.password_field(
|
|
|
|
:password, :size => 30, :name => 'ignore',
|
|
|
|
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
|
|
|
|
:onfocus => "this.value=''; this.name='repository[password]';",
|
|
|
|
:onchange => "this.name='repository[password]';"))
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
|
|
|
|
2007-06-24 23:30:38 +04:00
|
|
|
def darcs_field_tags(form, repository)
|
2011-04-23 11:37:03 +04:00
|
|
|
content_tag('p', form.text_field(
|
2011-05-07 07:40:34 +04:00
|
|
|
:url, :label => l(:field_path_to_repository),
|
2011-04-23 04:25:03 +04:00
|
|
|
:size => 60, :required => true,
|
|
|
|
:disabled => (repository && !repository.new_record?))) +
|
2011-04-23 07:34:43 +04:00
|
|
|
content_tag('p', form.select(
|
|
|
|
:log_encoding, [nil] + Setting::ENCODINGS,
|
2011-05-07 07:40:34 +04:00
|
|
|
:label => l(:field_commit_logs_encoding), :required => true))
|
2007-06-24 23:30:38 +04:00
|
|
|
end
|
2011-02-24 08:59:21 +03:00
|
|
|
|
2007-06-13 00:12:05 +04:00
|
|
|
def mercurial_field_tags(form, repository)
|
2011-04-23 08:41:26 +04:00
|
|
|
content_tag('p', form.text_field(
|
2011-05-07 07:41:05 +04:00
|
|
|
:url, :label => l(:field_path_to_repository),
|
2011-02-24 08:59:21 +03:00
|
|
|
:size => 60, :required => true,
|
2011-04-23 08:41:26 +04:00
|
|
|
:disabled => (repository && !repository.root_url.blank?)
|
|
|
|
) +
|
2011-09-30 12:14:30 +04:00
|
|
|
'<br />'.html_safe + l(:text_mercurial_repository_note)) +
|
2011-03-04 16:39:00 +03:00
|
|
|
content_tag('p', form.select(
|
|
|
|
:path_encoding, [nil] + Setting::ENCODINGS,
|
2011-05-07 07:41:05 +04:00
|
|
|
:label => l(:field_scm_path_encoding)
|
2011-04-23 07:36:52 +04:00
|
|
|
) +
|
2011-09-30 12:14:30 +04:00
|
|
|
'<br />'.html_safe + l(:text_scm_path_encoding_note))
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
|
|
|
|
2008-03-12 23:28:49 +03:00
|
|
|
def git_field_tags(form, repository)
|
2011-04-23 11:37:03 +04:00
|
|
|
content_tag('p', form.text_field(
|
2011-05-07 07:41:46 +04:00
|
|
|
:url, :label => l(:field_path_to_repository),
|
2011-02-19 09:42:50 +03:00
|
|
|
:size => 60, :required => true,
|
2011-04-23 11:37:03 +04:00
|
|
|
:disabled => (repository && !repository.root_url.blank?)
|
|
|
|
) +
|
2011-09-30 12:15:09 +04:00
|
|
|
'<br />'.html_safe +
|
2011-08-26 09:11:01 +04:00
|
|
|
l(:text_git_repository_note)) +
|
2011-03-08 15:08:56 +03:00
|
|
|
content_tag('p', form.select(
|
|
|
|
:path_encoding, [nil] + Setting::ENCODINGS,
|
2011-05-07 07:41:46 +04:00
|
|
|
:label => l(:field_scm_path_encoding)
|
2011-04-23 07:36:52 +04:00
|
|
|
) +
|
2011-09-30 12:15:09 +04:00
|
|
|
'<br />'.html_safe + l(:text_scm_path_encoding_note)) +
|
2011-05-13 07:52:56 +04:00
|
|
|
content_tag('p', form.check_box(
|
|
|
|
:extra_report_last_commit,
|
2011-05-13 08:34:29 +04:00
|
|
|
:label => l(:label_git_report_last_commit)
|
2011-05-13 07:52:56 +04:00
|
|
|
))
|
2008-03-12 23:28:49 +03:00
|
|
|
end
|
|
|
|
|
2007-06-13 00:12:05 +04:00
|
|
|
def cvs_field_tags(form, repository)
|
2011-04-23 11:40:23 +04:00
|
|
|
content_tag('p', form.text_field(
|
|
|
|
:root_url,
|
2011-05-07 07:42:26 +04:00
|
|
|
:label => l(:field_cvsroot),
|
2011-04-23 11:40:23 +04:00
|
|
|
:size => 60, :required => true,
|
2011-04-11 08:18:13 +04:00
|
|
|
:disabled => !repository.new_record?)) +
|
2011-04-23 11:40:23 +04:00
|
|
|
content_tag('p', form.text_field(
|
|
|
|
:url,
|
2011-05-07 07:42:26 +04:00
|
|
|
:label => l(:field_cvs_module),
|
2011-04-11 08:18:13 +04:00
|
|
|
:size => 30, :required => true,
|
|
|
|
:disabled => !repository.new_record?)) +
|
2011-04-23 07:34:43 +04:00
|
|
|
content_tag('p', form.select(
|
|
|
|
:log_encoding, [nil] + Setting::ENCODINGS,
|
2011-05-07 07:42:26 +04:00
|
|
|
:label => l(:field_commit_logs_encoding), :required => true)) +
|
2011-04-15 11:18:10 +04:00
|
|
|
content_tag('p', form.select(
|
2011-04-23 07:36:52 +04:00
|
|
|
:path_encoding, [nil] + Setting::ENCODINGS,
|
2011-05-07 07:42:26 +04:00
|
|
|
:label => l(:field_scm_path_encoding)
|
2011-04-23 07:36:52 +04:00
|
|
|
) +
|
2011-09-30 12:16:05 +04:00
|
|
|
'<br />'.html_safe + l(:text_scm_path_encoding_note))
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2007-12-03 20:40:43 +03:00
|
|
|
|
|
|
|
def bazaar_field_tags(form, repository)
|
2011-04-23 11:37:03 +04:00
|
|
|
content_tag('p', form.text_field(
|
2011-05-07 07:43:17 +04:00
|
|
|
:url, :label => l(:field_path_to_repository),
|
2011-04-11 08:18:13 +04:00
|
|
|
:size => 60, :required => true,
|
|
|
|
:disabled => (repository && !repository.new_record?))) +
|
2011-04-23 07:34:43 +04:00
|
|
|
content_tag('p', form.select(
|
|
|
|
:log_encoding, [nil] + Setting::ENCODINGS,
|
2011-05-07 07:43:17 +04:00
|
|
|
:label => l(:field_commit_logs_encoding), :required => true))
|
2007-12-03 20:40:43 +03:00
|
|
|
end
|
2011-02-24 08:59:21 +03:00
|
|
|
|
2008-06-08 19:40:24 +04:00
|
|
|
def filesystem_field_tags(form, repository)
|
2011-04-23 11:38:32 +04:00
|
|
|
content_tag('p', form.text_field(
|
2011-05-07 07:43:58 +04:00
|
|
|
:url, :label => l(:field_root_directory),
|
2011-02-24 08:59:21 +03:00
|
|
|
:size => 60, :required => true,
|
2011-02-24 10:00:41 +03:00
|
|
|
:disabled => (repository && !repository.root_url.blank?))) +
|
2011-03-02 10:11:00 +03:00
|
|
|
content_tag('p', form.select(
|
2011-04-23 07:36:52 +04:00
|
|
|
:path_encoding, [nil] + Setting::ENCODINGS,
|
2011-05-07 07:43:58 +04:00
|
|
|
:label => l(:field_scm_path_encoding)
|
2011-04-23 07:36:52 +04:00
|
|
|
) +
|
2011-09-30 12:16:46 +04:00
|
|
|
'<br />'.html_safe + l(:text_scm_path_encoding_note))
|
2008-06-08 19:40:24 +04:00
|
|
|
end
|
2011-11-03 15:36:12 +04:00
|
|
|
|
2012-02-04 18:02:31 +04:00
|
|
|
def index_commits(commits, heads)
|
2011-11-03 15:36:12 +04:00
|
|
|
return nil if commits.nil? or commits.first.parents.nil?
|
2012-02-04 18:02:31 +04:00
|
|
|
|
2011-11-03 15:36:12 +04:00
|
|
|
refs_map = {}
|
2012-02-04 18:02:31 +04:00
|
|
|
heads.each do |head|
|
|
|
|
refs_map[head.scmid] ||= []
|
|
|
|
refs_map[head.scmid] << head
|
2011-11-03 15:36:12 +04:00
|
|
|
end
|
2012-02-04 18:02:31 +04:00
|
|
|
|
|
|
|
commits_by_scmid = {}
|
|
|
|
commits.reverse.each_with_index do |commit, commit_index|
|
|
|
|
|
|
|
|
commits_by_scmid[commit.scmid] = {
|
|
|
|
:parent_scmids => commit.parents.collect { |parent| parent.scmid },
|
|
|
|
:rdmid => commit_index,
|
|
|
|
:refs => refs_map.include?(commit.scmid) ? refs_map[commit.scmid].join(" ") : nil,
|
|
|
|
:scmid => commit.scmid,
|
|
|
|
:href => block_given? ? yield(commit.scmid) : commit.scmid
|
|
|
|
}
|
2011-11-03 15:36:12 +04:00
|
|
|
end
|
2012-02-04 18:02:31 +04:00
|
|
|
|
|
|
|
heads.sort! { |head1, head2| head1.to_s <=> head2.to_s }
|
|
|
|
|
2012-02-11 18:57:44 +04:00
|
|
|
space = nil
|
2012-02-04 18:02:31 +04:00
|
|
|
heads.each do |head|
|
|
|
|
if commits_by_scmid.include? head.scmid
|
2012-02-11 18:57:44 +04:00
|
|
|
space = index_head((space || -1) + 1, head, commits_by_scmid)
|
2011-11-03 15:36:12 +04:00
|
|
|
end
|
|
|
|
end
|
2012-02-11 18:57:44 +04:00
|
|
|
|
2011-11-03 15:36:12 +04:00
|
|
|
# when no head matched anything use first commit
|
2012-02-11 18:57:44 +04:00
|
|
|
space ||= index_head(0, commits.first, commits_by_scmid)
|
|
|
|
|
|
|
|
return commits_by_scmid, space
|
2011-11-03 15:36:12 +04:00
|
|
|
end
|
|
|
|
|
2012-02-11 18:57:44 +04:00
|
|
|
def index_head(space, commit, commits_by_scmid)
|
2012-02-04 18:02:31 +04:00
|
|
|
|
2012-02-11 18:57:44 +04:00
|
|
|
stack = [[space, commits_by_scmid[commit.scmid]]]
|
|
|
|
max_space = space
|
2012-02-04 18:02:31 +04:00
|
|
|
|
2011-11-03 15:36:12 +04:00
|
|
|
until stack.empty?
|
2012-02-11 18:57:44 +04:00
|
|
|
space, commit = stack.pop
|
|
|
|
commit[:space] = space if commit[:space].nil?
|
2012-02-04 18:02:31 +04:00
|
|
|
|
2012-02-11 18:57:44 +04:00
|
|
|
space -= 1
|
2012-02-04 18:02:31 +04:00
|
|
|
commit[:parent_scmids].each_with_index do |parent_scmid, parent_index|
|
|
|
|
|
|
|
|
parent_commit = commits_by_scmid[parent_scmid]
|
|
|
|
|
2012-02-11 18:57:44 +04:00
|
|
|
if parent_commit and parent_commit[:space].nil?
|
2012-02-04 18:02:31 +04:00
|
|
|
|
2012-02-11 18:57:44 +04:00
|
|
|
stack.unshift [space += 1, parent_commit]
|
2011-11-03 15:36:12 +04:00
|
|
|
end
|
|
|
|
end
|
2012-02-11 18:57:44 +04:00
|
|
|
max_space = space if max_space < space
|
2011-11-03 15:36:12 +04:00
|
|
|
end
|
2012-02-11 18:57:44 +04:00
|
|
|
max_space
|
2011-11-03 15:36:12 +04:00
|
|
|
end
|
2006-12-24 16:38:45 +03:00
|
|
|
end
|