annotate app/models/repository/bazaar.rb @ 859:9a16b2c1fd56 bug_189

Close obsolete branch bug_189
author Chris Cannam
date Tue, 12 Jul 2011 16:42:08 +0100
parents cbce1fd3b1b7
children 433d4f72a19b
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@441 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@441 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require 'redmine/scm/adapters/bazaar_adapter'
Chris@0 19
Chris@0 20 class Repository::Bazaar < Repository
Chris@0 21 attr_protected :root_url
Chris@245 22 validates_presence_of :url, :log_encoding
Chris@0 23
Chris@245 24 def self.human_attribute_name(attribute_key_name)
Chris@441 25 attr_name = attribute_key_name
Chris@441 26 if attr_name == "url"
Chris@441 27 attr_name = "path_to_repository"
Chris@441 28 end
Chris@441 29 super(attr_name)
Chris@245 30 end
Chris@245 31
Chris@245 32 def self.scm_adapter_class
Chris@0 33 Redmine::Scm::Adapters::BazaarAdapter
Chris@0 34 end
Chris@245 35
Chris@0 36 def self.scm_name
Chris@0 37 'Bazaar'
Chris@0 38 end
Chris@245 39
Chris@0 40 def entries(path=nil, identifier=nil)
Chris@0 41 entries = scm.entries(path, identifier)
Chris@0 42 if entries
Chris@0 43 entries.each do |e|
Chris@0 44 next if e.lastrev.revision.blank?
Chris@0 45 # Set the filesize unless browsing a specific revision
Chris@0 46 if identifier.nil? && e.is_file?
Chris@0 47 full_path = File.join(root_url, e.path)
Chris@0 48 e.size = File.stat(full_path).size if File.file?(full_path)
Chris@0 49 end
Chris@441 50 c = Change.find(
Chris@441 51 :first,
Chris@441 52 :include => :changeset,
Chris@441 53 :conditions => [
Chris@441 54 "#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?",
Chris@441 55 e.lastrev.revision,
Chris@441 56 id
Chris@441 57 ],
Chris@441 58 :order => "#{Changeset.table_name}.revision DESC")
Chris@0 59 if c
Chris@0 60 e.lastrev.identifier = c.changeset.revision
Chris@441 61 e.lastrev.name = c.changeset.revision
Chris@441 62 e.lastrev.author = c.changeset.committer
Chris@0 63 end
Chris@0 64 end
Chris@0 65 end
Chris@0 66 end
Chris@441 67
Chris@0 68 def fetch_changesets
Chris@0 69 scm_info = scm.info
Chris@0 70 if scm_info
Chris@0 71 # latest revision found in database
Chris@0 72 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
Chris@0 73 # latest revision in the repository
Chris@0 74 scm_revision = scm_info.lastrev.identifier.to_i
Chris@0 75 if db_revision < scm_revision
Chris@0 76 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
Chris@0 77 identifier_from = db_revision + 1
Chris@0 78 while (identifier_from <= scm_revision)
Chris@0 79 # loads changesets by batches of 200
Chris@0 80 identifier_to = [identifier_from + 199, scm_revision].min
Chris@0 81 revisions = scm.revisions('', identifier_to, identifier_from, :with_paths => true)
Chris@0 82 transaction do
Chris@0 83 revisions.reverse_each do |revision|
Chris@441 84 changeset = Changeset.create(:repository => self,
Chris@441 85 :revision => revision.identifier,
Chris@441 86 :committer => revision.author,
Chris@0 87 :committed_on => revision.time,
Chris@441 88 :scmid => revision.scmid,
Chris@441 89 :comments => revision.message)
Chris@441 90
Chris@0 91 revision.paths.each do |change|
Chris@0 92 Change.create(:changeset => changeset,
Chris@441 93 :action => change[:action],
Chris@441 94 :path => change[:path],
Chris@441 95 :revision => change[:revision])
Chris@0 96 end
Chris@0 97 end
Chris@0 98 end unless revisions.nil?
Chris@0 99 identifier_from = identifier_to + 1
Chris@0 100 end
Chris@0 101 end
Chris@0 102 end
Chris@0 103 end
Chris@0 104 end