To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / models / repository / .svn / text-base / subversion.rb.svn-base @ 441:cbce1fd3b1b7

History | View | Annotate | Download (3.32 KB)

1 441:cbce1fd3b1b7 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2011  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
require 'redmine/scm/adapters/subversion_adapter'
19
20
class Repository::Subversion < Repository
21
  attr_protected :root_url
22
  validates_presence_of :url
23
  validates_format_of :url, :with => /^(http|https|svn(\+[^\s:\/\\]+)?|file):\/\/.+/i
24
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
    revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
44
  end
45 441:cbce1fd3b1b7 Chris
46 0:513646585e45 Chris
  # Returns a path relative to the url of the repository
47
  def relative_path(path)
48
    path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
49
  end
50 441:cbce1fd3b1b7 Chris
51 0:513646585e45 Chris
  def fetch_changesets
52
    scm_info = scm.info
53
    if scm_info
54
      # latest revision found in database
55
      db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
56
      # latest revision in the repository
57
      scm_revision = scm_info.lastrev.identifier.to_i
58
      if db_revision < scm_revision
59
        logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
60
        identifier_from = db_revision + 1
61
        while (identifier_from <= scm_revision)
62
          # loads changesets by batches of 200
63
          identifier_to = [identifier_from + 199, scm_revision].min
64
          revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
65
          revisions.reverse_each do |revision|
66
            transaction do
67 441:cbce1fd3b1b7 Chris
              changeset = Changeset.create(:repository   => self,
68
                                           :revision     => revision.identifier,
69
                                           :committer    => revision.author,
70 0:513646585e45 Chris
                                           :committed_on => revision.time,
71 441:cbce1fd3b1b7 Chris
                                           :comments     => revision.message)
72
73 0:513646585e45 Chris
              revision.paths.each do |change|
74
                changeset.create_change(change)
75
              end unless changeset.new_record?
76
            end
77
          end unless revisions.nil?
78
          identifier_from = identifier_to + 1
79
        end
80
      end
81
    end
82
  end
83 441:cbce1fd3b1b7 Chris
84 0:513646585e45 Chris
  private
85 441:cbce1fd3b1b7 Chris
86 0:513646585e45 Chris
  # Returns the relative url of the repository
87
  # Eg: root_url = file:///var/svn/foo
88
  #     url      = file:///var/svn/foo/bar
89
  #     => returns /bar
90
  def relative_url
91
    @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url || scm.root_url)}", Regexp::IGNORECASE), '')
92
  end
93
end