comparison .svn/pristine/fc/fc277d46aec92e52e80545393ffb429147c03880.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 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, :log_encoding
23
24 def self.human_attribute_name(attribute_key_name, *args)
25 attr_name = attribute_key_name.to_s
26 if attr_name == "url"
27 attr_name = "path_to_repository"
28 end
29 super(attr_name, *args)
30 end
31
32 def self.scm_adapter_class
33 Redmine::Scm::Adapters::BazaarAdapter
34 end
35
36 def self.scm_name
37 'Bazaar'
38 end
39
40 def entry(path=nil, identifier=nil)
41 scm.bzr_path_encodig = log_encoding
42 scm.entry(path, identifier)
43 end
44
45 def cat(path, identifier=nil)
46 scm.bzr_path_encodig = log_encoding
47 scm.cat(path, identifier)
48 end
49
50 def annotate(path, identifier=nil)
51 scm.bzr_path_encodig = log_encoding
52 scm.annotate(path, identifier)
53 end
54
55 def diff(path, rev, rev_to)
56 scm.bzr_path_encodig = log_encoding
57 scm.diff(path, rev, rev_to)
58 end
59
60 def entries(path=nil, identifier=nil)
61 scm.bzr_path_encodig = log_encoding
62 entries = scm.entries(path, identifier)
63 if entries
64 entries.each do |e|
65 next if e.lastrev.revision.blank?
66 # Set the filesize unless browsing a specific revision
67 if identifier.nil? && e.is_file?
68 full_path = File.join(root_url, e.path)
69 e.size = File.stat(full_path).size if File.file?(full_path)
70 end
71 c = Change.find(
72 :first,
73 :include => :changeset,
74 :conditions => [
75 "#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?",
76 e.lastrev.revision,
77 id
78 ],
79 :order => "#{Changeset.table_name}.revision DESC")
80 if c
81 e.lastrev.identifier = c.changeset.revision
82 e.lastrev.name = c.changeset.revision
83 e.lastrev.author = c.changeset.committer
84 end
85 end
86 end
87 load_entries_changesets(entries)
88 entries
89 end
90
91 def fetch_changesets
92 scm.bzr_path_encodig = log_encoding
93 scm_info = scm.info
94 if scm_info
95 # latest revision found in database
96 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
97 # latest revision in the repository
98 scm_revision = scm_info.lastrev.identifier.to_i
99 if db_revision < scm_revision
100 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
101 identifier_from = db_revision + 1
102 while (identifier_from <= scm_revision)
103 # loads changesets by batches of 200
104 identifier_to = [identifier_from + 199, scm_revision].min
105 revisions = scm.revisions('', identifier_to, identifier_from)
106 transaction do
107 revisions.reverse_each do |revision|
108 changeset = Changeset.create(:repository => self,
109 :revision => revision.identifier,
110 :committer => revision.author,
111 :committed_on => revision.time,
112 :scmid => revision.scmid,
113 :comments => revision.message)
114
115 revision.paths.each do |change|
116 Change.create(:changeset => changeset,
117 :action => change[:action],
118 :path => change[:path],
119 :revision => change[:revision])
120 end
121 end
122 end unless revisions.nil?
123 identifier_from = identifier_to + 1
124 end
125 end
126 end
127 end
128 end