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