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