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