comparison app/models/repository/bazaar.rb @ 514:7eba09d624db live

Merge
author Chris Cannam
date Thu, 14 Jul 2011 10:50:53 +0100
parents cbce1fd3b1b7
children 433d4f72a19b
comparison
equal deleted inserted replaced
512:b9aebdd7dd40 514:7eba09d624db
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 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.
8 # 8 #
9 # This program is distributed in the hope that it will be useful, 9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details. 12 # GNU General Public License for more details.
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/bazaar_adapter' 18 require 'redmine/scm/adapters/bazaar_adapter'
19 19
20 class Repository::Bazaar < Repository 20 class Repository::Bazaar < Repository
21 attr_protected :root_url 21 attr_protected :root_url
22 validates_presence_of :url 22 validates_presence_of :url, :log_encoding
23 23
24 def scm_adapter 24 def self.human_attribute_name(attribute_key_name)
25 attr_name = attribute_key_name
26 if attr_name == "url"
27 attr_name = "path_to_repository"
28 end
29 super(attr_name)
30 end
31
32 def self.scm_adapter_class
25 Redmine::Scm::Adapters::BazaarAdapter 33 Redmine::Scm::Adapters::BazaarAdapter
26 end 34 end
27 35
28 def self.scm_name 36 def self.scm_name
29 'Bazaar' 37 'Bazaar'
30 end 38 end
31 39
32 def entries(path=nil, identifier=nil) 40 def entries(path=nil, identifier=nil)
33 entries = scm.entries(path, identifier) 41 entries = scm.entries(path, identifier)
34 if entries 42 if entries
35 entries.each do |e| 43 entries.each do |e|
36 next if e.lastrev.revision.blank? 44 next if e.lastrev.revision.blank?
37 # Set the filesize unless browsing a specific revision 45 # Set the filesize unless browsing a specific revision
38 if identifier.nil? && e.is_file? 46 if identifier.nil? && e.is_file?
39 full_path = File.join(root_url, e.path) 47 full_path = File.join(root_url, e.path)
40 e.size = File.stat(full_path).size if File.file?(full_path) 48 e.size = File.stat(full_path).size if File.file?(full_path)
41 end 49 end
42 c = Change.find(:first, 50 c = Change.find(
43 :include => :changeset, 51 :first,
44 :conditions => ["#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?", e.lastrev.revision, id], 52 :include => :changeset,
45 :order => "#{Changeset.table_name}.revision DESC") 53 :conditions => [
54 "#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?",
55 e.lastrev.revision,
56 id
57 ],
58 :order => "#{Changeset.table_name}.revision DESC")
46 if c 59 if c
47 e.lastrev.identifier = c.changeset.revision 60 e.lastrev.identifier = c.changeset.revision
48 e.lastrev.name = c.changeset.revision 61 e.lastrev.name = c.changeset.revision
49 e.lastrev.author = c.changeset.committer 62 e.lastrev.author = c.changeset.committer
50 end 63 end
51 end 64 end
52 end 65 end
53 end 66 end
54 67
55 def fetch_changesets 68 def fetch_changesets
56 scm_info = scm.info 69 scm_info = scm.info
57 if scm_info 70 if scm_info
58 # latest revision found in database 71 # latest revision found in database
59 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0 72 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
66 # loads changesets by batches of 200 79 # loads changesets by batches of 200
67 identifier_to = [identifier_from + 199, scm_revision].min 80 identifier_to = [identifier_from + 199, scm_revision].min
68 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true) 81 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
69 transaction do 82 transaction do
70 revisions.reverse_each do |revision| 83 revisions.reverse_each do |revision|
71 changeset = Changeset.create(:repository => self, 84 changeset = Changeset.create(:repository => self,
72 :revision => revision.identifier, 85 :revision => revision.identifier,
73 :committer => revision.author, 86 :committer => revision.author,
74 :committed_on => revision.time, 87 :committed_on => revision.time,
75 :scmid => revision.scmid, 88 :scmid => revision.scmid,
76 :comments => revision.message) 89 :comments => revision.message)
77 90
78 revision.paths.each do |change| 91 revision.paths.each do |change|
79 Change.create(:changeset => changeset, 92 Change.create(:changeset => changeset,
80 :action => change[:action], 93 :action => change[:action],
81 :path => change[:path], 94 :path => change[:path],
82 :revision => change[:revision]) 95 :revision => change[:revision])
83 end 96 end
84 end 97 end
85 end unless revisions.nil? 98 end unless revisions.nil?
86 identifier_from = identifier_to + 1 99 identifier_from = identifier_to + 1
87 end 100 end