annotate .svn/pristine/f1/f14907428267e29aa5467d2779ca648a92fb51b3.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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