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