To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / models / repository / bazaar.rb @ 1532:a0460a3d154f
History | View | Annotate | Download (4.29 KB)
| 1 |
# Redmine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2014 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_dependency '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 scm_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.
|
| 72 |
includes(:changeset).
|
| 73 |
where("#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?", e.lastrev.revision, id).
|
| 74 |
order("#{Changeset.table_name}.revision DESC").
|
| 75 |
first |
| 76 |
if c
|
| 77 |
e.lastrev.identifier = c.changeset.revision |
| 78 |
e.lastrev.name = c.changeset.revision |
| 79 |
e.lastrev.author = c.changeset.committer |
| 80 |
end
|
| 81 |
end
|
| 82 |
end
|
| 83 |
entries |
| 84 |
end
|
| 85 |
protected :scm_entries
|
| 86 |
|
| 87 |
def fetch_changesets |
| 88 |
scm.bzr_path_encodig = log_encoding |
| 89 |
scm_info = scm.info |
| 90 |
if scm_info
|
| 91 |
# latest revision found in database
|
| 92 |
db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
|
| 93 |
# latest revision in the repository
|
| 94 |
scm_revision = scm_info.lastrev.identifier.to_i |
| 95 |
if db_revision < scm_revision
|
| 96 |
logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug? |
| 97 |
identifier_from = db_revision + 1
|
| 98 |
while (identifier_from <= scm_revision)
|
| 99 |
# loads changesets by batches of 200
|
| 100 |
identifier_to = [identifier_from + 199, scm_revision].min
|
| 101 |
revisions = scm.revisions('', identifier_to, identifier_from)
|
| 102 |
transaction do
|
| 103 |
revisions.reverse_each do |revision|
|
| 104 |
changeset = Changeset.create(:repository => self, |
| 105 |
:revision => revision.identifier,
|
| 106 |
:committer => revision.author,
|
| 107 |
:committed_on => revision.time,
|
| 108 |
:scmid => revision.scmid,
|
| 109 |
:comments => revision.message)
|
| 110 |
|
| 111 |
revision.paths.each do |change|
|
| 112 |
Change.create(:changeset => changeset, |
| 113 |
:action => change[:action], |
| 114 |
:path => change[:path], |
| 115 |
:revision => change[:revision]) |
| 116 |
end
|
| 117 |
end
|
| 118 |
end unless revisions.nil? |
| 119 |
identifier_from = identifier_to + 1
|
| 120 |
end
|
| 121 |
end
|
| 122 |
end
|
| 123 |
end
|
| 124 |
end
|