comparison app/models/repository/subversion.rb @ 1338:25603efa57b5

Merge from live branch
author Chris Cannam
date Thu, 20 Jun 2013 13:14:14 +0100
parents 51d7f3e06556
children 4f746d8966dd 51364c0cd58f
comparison
equal deleted inserted replaced
1209:1b1138f6f55e 1338:25603efa57b5
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
13 # 13 #
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require 'redmine/scm/adapters/subversion_adapter' 18 require_dependency 'redmine/scm/adapters/subversion_adapter'
19 19
20 class Repository::Subversion < Repository 20 class Repository::Subversion < Repository
21 attr_protected :root_url 21 attr_protected :root_url
22 validates_presence_of :url 22 validates_presence_of :url
23 validates_format_of :url, :with => /^(http|https|svn(\+[^\s:\/\\]+)?|file):\/\/.+/i 23 validates_format_of :url, :with => /^(http|https|svn(\+[^\s:\/\\]+)?|file):\/\/.+/i
38 'UTF-8' 38 'UTF-8'
39 end 39 end
40 40
41 def latest_changesets(path, rev, limit=10) 41 def latest_changesets(path, rev, limit=10)
42 revisions = scm.revisions(path, rev, nil, :limit => limit) 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) : [] 43 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
44 end 49 end
45 50
46 # Returns a path relative to the url of the repository 51 # Returns a path relative to the url of the repository
47 def relative_path(path) 52 def relative_path(path)
48 path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '') 53 path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '')
79 end 84 end
80 end 85 end
81 end 86 end
82 end 87 end
83 88
89 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
84 private 107 private
85 108
86 # Returns the relative url of the repository 109 # Returns the relative url of the repository
87 # Eg: root_url = file:///var/svn/foo 110 # Eg: root_url = file:///var/svn/foo
88 # url = file:///var/svn/foo/bar 111 # url = file:///var/svn/foo/bar