annotate .svn/pristine/df/df53ca9633063ed94220cdb1373cbc6a30da7896.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 require 'redmine/scm/adapters/subversion_adapter'
Chris@1517 19
Chris@1517 20 class Repository::Subversion < Repository
Chris@1517 21 attr_protected :root_url
Chris@1517 22 validates_presence_of :url
Chris@1517 23 validates_format_of :url, :with => %r{\A(http|https|svn(\+[^\s:\/\\]+)?|file):\/\/.+}i
Chris@1517 24
Chris@1517 25 def self.scm_adapter_class
Chris@1517 26 Redmine::Scm::Adapters::SubversionAdapter
Chris@1517 27 end
Chris@1517 28
Chris@1517 29 def self.scm_name
Chris@1517 30 'Subversion'
Chris@1517 31 end
Chris@1517 32
Chris@1517 33 def supports_directory_revisions?
Chris@1517 34 true
Chris@1517 35 end
Chris@1517 36
Chris@1517 37 def repo_log_encoding
Chris@1517 38 'UTF-8'
Chris@1517 39 end
Chris@1517 40
Chris@1517 41 def latest_changesets(path, rev, limit=10)
Chris@1517 42 revisions = scm.revisions(path, rev, nil, :limit => limit)
Chris@1517 43 if revisions
Chris@1517 44 identifiers = revisions.collect(&:identifier).compact
Chris@1517 45 changesets.where(:revision => identifiers).reorder("committed_on DESC").includes(:repository, :user).all
Chris@1517 46 else
Chris@1517 47 []
Chris@1517 48 end
Chris@1517 49 end
Chris@1517 50
Chris@1517 51 # Returns a path relative to the url of the repository
Chris@1517 52 def relative_path(path)
Chris@1517 53 path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
Chris@1517 54 end
Chris@1517 55
Chris@1517 56 def fetch_changesets
Chris@1517 57 scm_info = scm.info
Chris@1517 58 if scm_info
Chris@1517 59 # latest revision found in database
Chris@1517 60 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
Chris@1517 61 # latest revision in the repository
Chris@1517 62 scm_revision = scm_info.lastrev.identifier.to_i
Chris@1517 63 if db_revision < scm_revision
Chris@1517 64 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
Chris@1517 65 identifier_from = db_revision + 1
Chris@1517 66 while (identifier_from <= scm_revision)
Chris@1517 67 # loads changesets by batches of 200
Chris@1517 68 identifier_to = [identifier_from + 199, scm_revision].min
Chris@1517 69 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
Chris@1517 70 revisions.reverse_each do |revision|
Chris@1517 71 transaction do
Chris@1517 72 changeset = Changeset.create(:repository => self,
Chris@1517 73 :revision => revision.identifier,
Chris@1517 74 :committer => revision.author,
Chris@1517 75 :committed_on => revision.time,
Chris@1517 76 :comments => revision.message)
Chris@1517 77
Chris@1517 78 revision.paths.each do |change|
Chris@1517 79 changeset.create_change(change)
Chris@1517 80 end unless changeset.new_record?
Chris@1517 81 end
Chris@1517 82 end unless revisions.nil?
Chris@1517 83 identifier_from = identifier_to + 1
Chris@1517 84 end
Chris@1517 85 end
Chris@1517 86 end
Chris@1517 87 end
Chris@1517 88
Chris@1517 89 protected
Chris@1517 90
Chris@1517 91 def load_entries_changesets(entries)
Chris@1517 92 return unless entries
Chris@1517 93 entries_with_identifier =
Chris@1517 94 entries.select {|entry| entry.lastrev && entry.lastrev.identifier.present?}
Chris@1517 95 identifiers = entries_with_identifier.map {|entry| entry.lastrev.identifier}.compact.uniq
Chris@1517 96 if identifiers.any?
Chris@1517 97 changesets_by_identifier =
Chris@1517 98 changesets.where(:revision => identifiers).
Chris@1517 99 includes(:user, :repository).group_by(&:revision)
Chris@1517 100 entries_with_identifier.each do |entry|
Chris@1517 101 if m = changesets_by_identifier[entry.lastrev.identifier]
Chris@1517 102 entry.changeset = m.first
Chris@1517 103 end
Chris@1517 104 end
Chris@1517 105 end
Chris@1517 106 end
Chris@1517 107
Chris@1517 108 private
Chris@1517 109
Chris@1517 110 # Returns the relative url of the repository
Chris@1517 111 # Eg: root_url = file:///var/svn/foo
Chris@1517 112 # url = file:///var/svn/foo/bar
Chris@1517 113 # => returns /bar
Chris@1517 114 def relative_url
Chris@1517 115 @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url || scm.root_url)}", Regexp::IGNORECASE), '')
Chris@1517 116 end
Chris@1517 117 end