Mercurial > hg > soundsoftware-site
comparison app/models/repository/bazaar.rb @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | 051f544170fe |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 # redMine - project management software | |
2 # Copyright (C) 2006-2007 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 require 'redmine/scm/adapters/bazaar_adapter' | |
19 | |
20 class Repository::Bazaar < Repository | |
21 attr_protected :root_url | |
22 validates_presence_of :url | |
23 | |
24 def scm_adapter | |
25 Redmine::Scm::Adapters::BazaarAdapter | |
26 end | |
27 | |
28 def self.scm_name | |
29 'Bazaar' | |
30 end | |
31 | |
32 def entries(path=nil, identifier=nil) | |
33 entries = scm.entries(path, identifier) | |
34 if entries | |
35 entries.each do |e| | |
36 next if e.lastrev.revision.blank? | |
37 # Set the filesize unless browsing a specific revision | |
38 if identifier.nil? && e.is_file? | |
39 full_path = File.join(root_url, e.path) | |
40 e.size = File.stat(full_path).size if File.file?(full_path) | |
41 end | |
42 c = Change.find(:first, | |
43 :include => :changeset, | |
44 :conditions => ["#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?", e.lastrev.revision, id], | |
45 :order => "#{Changeset.table_name}.revision DESC") | |
46 if c | |
47 e.lastrev.identifier = c.changeset.revision | |
48 e.lastrev.name = c.changeset.revision | |
49 e.lastrev.author = c.changeset.committer | |
50 end | |
51 end | |
52 end | |
53 end | |
54 | |
55 def fetch_changesets | |
56 scm_info = scm.info | |
57 if scm_info | |
58 # latest revision found in database | |
59 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0 | |
60 # latest revision in the repository | |
61 scm_revision = scm_info.lastrev.identifier.to_i | |
62 if db_revision < scm_revision | |
63 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug? | |
64 identifier_from = db_revision + 1 | |
65 while (identifier_from <= scm_revision) | |
66 # loads changesets by batches of 200 | |
67 identifier_to = [identifier_from + 199, scm_revision].min | |
68 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true) | |
69 transaction do | |
70 revisions.reverse_each do |revision| | |
71 changeset = Changeset.create(:repository => self, | |
72 :revision => revision.identifier, | |
73 :committer => revision.author, | |
74 :committed_on => revision.time, | |
75 :scmid => revision.scmid, | |
76 :comments => revision.message) | |
77 | |
78 revision.paths.each do |change| | |
79 Change.create(:changeset => changeset, | |
80 :action => change[:action], | |
81 :path => change[:path], | |
82 :revision => change[:revision]) | |
83 end | |
84 end | |
85 end unless revisions.nil? | |
86 identifier_from = identifier_to + 1 | |
87 end | |
88 end | |
89 end | |
90 end | |
91 end |