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