Chris@1494: # Redmine - project management software Chris@1494: # Copyright (C) 2006-2014 Jean-Philippe Lang Chris@1494: # Chris@1494: # This program is free software; you can redistribute it and/or Chris@1494: # modify it under the terms of the GNU General Public License Chris@1494: # as published by the Free Software Foundation; either version 2 Chris@1494: # of the License, or (at your option) any later version. Chris@1494: # Chris@1494: # This program is distributed in the hope that it will be useful, Chris@1494: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1494: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1494: # GNU General Public License for more details. Chris@1494: # Chris@1494: # You should have received a copy of the GNU General Public License Chris@1494: # along with this program; if not, write to the Free Software Chris@1494: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1494: Chris@1494: require 'redmine/scm/adapters/bazaar_adapter' Chris@1494: Chris@1494: class Repository::Bazaar < Repository Chris@1494: attr_protected :root_url Chris@1494: validates_presence_of :url, :log_encoding Chris@1494: Chris@1494: def self.human_attribute_name(attribute_key_name, *args) Chris@1494: attr_name = attribute_key_name.to_s Chris@1494: if attr_name == "url" Chris@1494: attr_name = "path_to_repository" Chris@1494: end Chris@1494: super(attr_name, *args) Chris@1494: end Chris@1494: Chris@1494: def self.scm_adapter_class Chris@1494: Redmine::Scm::Adapters::BazaarAdapter Chris@1494: end Chris@1494: Chris@1494: def self.scm_name Chris@1494: 'Bazaar' Chris@1494: end Chris@1494: Chris@1494: def entry(path=nil, identifier=nil) Chris@1494: scm.bzr_path_encodig = log_encoding Chris@1494: scm.entry(path, identifier) Chris@1494: end Chris@1494: Chris@1494: def cat(path, identifier=nil) Chris@1494: scm.bzr_path_encodig = log_encoding Chris@1494: scm.cat(path, identifier) Chris@1494: end Chris@1494: Chris@1494: def annotate(path, identifier=nil) Chris@1494: scm.bzr_path_encodig = log_encoding Chris@1494: scm.annotate(path, identifier) Chris@1494: end Chris@1494: Chris@1494: def diff(path, rev, rev_to) Chris@1494: scm.bzr_path_encodig = log_encoding Chris@1494: scm.diff(path, rev, rev_to) Chris@1494: end Chris@1494: Chris@1494: def entries(path=nil, identifier=nil) Chris@1494: scm.bzr_path_encodig = log_encoding Chris@1494: entries = scm.entries(path, identifier) Chris@1494: if entries Chris@1494: entries.each do |e| Chris@1494: next if e.lastrev.revision.blank? Chris@1494: # Set the filesize unless browsing a specific revision Chris@1494: if identifier.nil? && e.is_file? Chris@1494: full_path = File.join(root_url, e.path) Chris@1494: e.size = File.stat(full_path).size if File.file?(full_path) Chris@1494: end Chris@1494: c = Change. Chris@1494: includes(:changeset). Chris@1494: where("#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?", e.lastrev.revision, id). Chris@1494: order("#{Changeset.table_name}.revision DESC"). Chris@1494: first Chris@1494: if c Chris@1494: e.lastrev.identifier = c.changeset.revision Chris@1494: e.lastrev.name = c.changeset.revision Chris@1494: e.lastrev.author = c.changeset.committer Chris@1494: end Chris@1494: end Chris@1494: end Chris@1494: load_entries_changesets(entries) Chris@1494: entries Chris@1494: end Chris@1494: Chris@1494: def fetch_changesets Chris@1494: scm.bzr_path_encodig = log_encoding Chris@1494: scm_info = scm.info Chris@1494: if scm_info Chris@1494: # latest revision found in database Chris@1494: db_revision = latest_changeset ? latest_changeset.revision.to_i : 0 Chris@1494: # latest revision in the repository Chris@1494: scm_revision = scm_info.lastrev.identifier.to_i Chris@1494: if db_revision < scm_revision Chris@1494: logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug? Chris@1494: identifier_from = db_revision + 1 Chris@1494: while (identifier_from <= scm_revision) Chris@1494: # loads changesets by batches of 200 Chris@1494: identifier_to = [identifier_from + 199, scm_revision].min Chris@1494: revisions = scm.revisions('', identifier_to, identifier_from) Chris@1494: transaction do Chris@1494: revisions.reverse_each do |revision| Chris@1494: changeset = Changeset.create(:repository => self, Chris@1494: :revision => revision.identifier, Chris@1494: :committer => revision.author, Chris@1494: :committed_on => revision.time, Chris@1494: :scmid => revision.scmid, Chris@1494: :comments => revision.message) Chris@1494: Chris@1494: revision.paths.each do |change| Chris@1494: Change.create(:changeset => changeset, Chris@1494: :action => change[:action], Chris@1494: :path => change[:path], Chris@1494: :revision => change[:revision]) Chris@1494: end Chris@1494: end Chris@1494: end unless revisions.nil? Chris@1494: identifier_from = identifier_to + 1 Chris@1494: end Chris@1494: end Chris@1494: end Chris@1494: end Chris@1494: end