app-models-repository-perforce.rb
1 |
# Redmine - project management software
|
---|---|
2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
3 |
#
|
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 |
#
|
9 |
# 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 |
#
|
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
|
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17 |
|
18 |
# Portions of this code adapted from Michael Vance, see:
|
19 |
# http://www.redmine.org/issues/339
|
20 |
# Adapted by Terry Suereth.
|
21 |
|
22 |
require 'redmine/scm/adapters/perforce_adapter'
|
23 |
|
24 |
class Repository::Perforce < Repository |
25 |
validates_presence_of :root_url, :url |
26 |
|
27 |
def self.scm_adapter_class |
28 |
Redmine::Scm::Adapters::PerforceAdapter |
29 |
end
|
30 |
|
31 |
def self.scm_name |
32 |
'Perforce'
|
33 |
end
|
34 |
|
35 |
def supports_directory_revisions? |
36 |
false
|
37 |
end
|
38 |
|
39 |
def repo_log_encoding |
40 |
'UTF-8'
|
41 |
end
|
42 |
|
43 |
def latest_changesets(path, rev, limit=10) |
44 |
revisions = scm.revisions(path, rev, nil, :limit => limit) |
45 |
revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : [] |
46 |
end
|
47 |
|
48 |
def fetch_changesets |
49 |
scm_info = scm.info |
50 |
if scm_info
|
51 |
# latest revision found in database
|
52 |
db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
|
53 |
# latest revision in the repository
|
54 |
scm_revision = scm_info.lastrev.identifier.to_i |
55 |
if db_revision < scm_revision
|
56 |
logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug? |
57 |
identifier_from = db_revision + 1
|
58 |
while (identifier_from <= scm_revision)
|
59 |
# loads changesets by batches of 200
|
60 |
identifier_to = [identifier_from + 199, scm_revision].min
|
61 |
revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true) |
62 |
revisions.reverse_each do |revision|
|
63 |
transaction do
|
64 |
changeset = Changeset.create(:repository => self, |
65 |
:revision => revision.identifier,
|
66 |
:committer => revision.author,
|
67 |
:committed_on => revision.time,
|
68 |
:comments => revision.message)
|
69 |
|
70 |
revision.paths.each do |change|
|
71 |
changeset.create_change(change) |
72 |
end unless changeset.new_record? |
73 |
end
|
74 |
end unless revisions.nil? |
75 |
identifier_from = identifier_to + 1
|
76 |
end
|
77 |
end
|
78 |
end
|
79 |
end
|
80 |
|
81 |
end
|