annotate app/models/repository/subversion.rb @ 245:051f544170fe

* Update to SVN trunk revision 4993
author Chris Cannam
date Thu, 03 Mar 2011 11:42:28 +0000
parents 513646585e45
children cbce1fd3b1b7
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2007 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@0 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@0 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@0 18 require '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@0 23 validates_format_of :url, :with => /^(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@245 33 def repo_log_encoding
Chris@245 34 'UTF-8'
Chris@245 35 end
Chris@245 36
Chris@0 37 def latest_changesets(path, rev, limit=10)
Chris@0 38 revisions = scm.revisions(path, rev, nil, :limit => limit)
Chris@0 39 revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
Chris@0 40 end
Chris@0 41
Chris@0 42 # Returns a path relative to the url of the repository
Chris@0 43 def relative_path(path)
Chris@0 44 path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
Chris@0 45 end
Chris@0 46
Chris@0 47 def fetch_changesets
Chris@0 48 scm_info = scm.info
Chris@0 49 if scm_info
Chris@0 50 # latest revision found in database
Chris@0 51 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
Chris@0 52 # latest revision in the repository
Chris@0 53 scm_revision = scm_info.lastrev.identifier.to_i
Chris@0 54 if db_revision < scm_revision
Chris@0 55 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
Chris@0 56 identifier_from = db_revision + 1
Chris@0 57 while (identifier_from <= scm_revision)
Chris@0 58 # loads changesets by batches of 200
Chris@0 59 identifier_to = [identifier_from + 199, scm_revision].min
Chris@0 60 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
Chris@0 61 revisions.reverse_each do |revision|
Chris@0 62 transaction do
Chris@0 63 changeset = Changeset.create(:repository => self,
Chris@0 64 :revision => revision.identifier,
Chris@0 65 :committer => revision.author,
Chris@0 66 :committed_on => revision.time,
Chris@0 67 :comments => revision.message)
Chris@0 68
Chris@0 69 revision.paths.each do |change|
Chris@0 70 changeset.create_change(change)
Chris@0 71 end unless changeset.new_record?
Chris@0 72 end
Chris@0 73 end unless revisions.nil?
Chris@0 74 identifier_from = identifier_to + 1
Chris@0 75 end
Chris@0 76 end
Chris@0 77 end
Chris@0 78 end
Chris@0 79
Chris@0 80 private
Chris@0 81
Chris@0 82 # Returns the relative url of the repository
Chris@0 83 # Eg: root_url = file:///var/svn/foo
Chris@0 84 # url = file:///var/svn/foo/bar
Chris@0 85 # => returns /bar
Chris@0 86 def relative_url
Chris@0 87 @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url || scm.root_url)}", Regexp::IGNORECASE), '')
Chris@0 88 end
Chris@0 89 end