annotate .svn/pristine/ab/ab219cc423e55ab4791b83323c88cebbfd8a0fc8.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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