annotate app/models/repository/bazaar.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children 4f746d8966dd
rev   line source
Chris@441 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 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@1115 24 def self.human_attribute_name(attribute_key_name, *args)
Chris@1115 25 attr_name = attribute_key_name.to_s
Chris@441 26 if attr_name == "url"
Chris@441 27 attr_name = "path_to_repository"
Chris@441 28 end
Chris@1115 29 super(attr_name, *args)
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@1115 40 def entry(path=nil, identifier=nil)
Chris@1115 41 scm.bzr_path_encodig = log_encoding
Chris@1115 42 scm.entry(path, identifier)
Chris@1115 43 end
Chris@1115 44
Chris@1115 45 def cat(path, identifier=nil)
Chris@1115 46 scm.bzr_path_encodig = log_encoding
Chris@1115 47 scm.cat(path, identifier)
Chris@1115 48 end
Chris@1115 49
Chris@1115 50 def annotate(path, identifier=nil)
Chris@1115 51 scm.bzr_path_encodig = log_encoding
Chris@1115 52 scm.annotate(path, identifier)
Chris@1115 53 end
Chris@1115 54
Chris@1115 55 def diff(path, rev, rev_to)
Chris@1115 56 scm.bzr_path_encodig = log_encoding
Chris@1115 57 scm.diff(path, rev, rev_to)
Chris@1115 58 end
Chris@1115 59
Chris@0 60 def entries(path=nil, identifier=nil)
Chris@1115 61 scm.bzr_path_encodig = log_encoding
Chris@0 62 entries = scm.entries(path, identifier)
Chris@0 63 if entries
Chris@0 64 entries.each do |e|
Chris@0 65 next if e.lastrev.revision.blank?
Chris@0 66 # Set the filesize unless browsing a specific revision
Chris@0 67 if identifier.nil? && e.is_file?
Chris@0 68 full_path = File.join(root_url, e.path)
Chris@0 69 e.size = File.stat(full_path).size if File.file?(full_path)
Chris@0 70 end
Chris@441 71 c = Change.find(
Chris@441 72 :first,
Chris@441 73 :include => :changeset,
Chris@441 74 :conditions => [
Chris@441 75 "#{Change.table_name}.revision = ? and #{Changeset.table_name}.repository_id = ?",
Chris@441 76 e.lastrev.revision,
Chris@441 77 id
Chris@441 78 ],
Chris@441 79 :order => "#{Changeset.table_name}.revision DESC")
Chris@0 80 if c
Chris@0 81 e.lastrev.identifier = c.changeset.revision
Chris@441 82 e.lastrev.name = c.changeset.revision
Chris@441 83 e.lastrev.author = c.changeset.committer
Chris@0 84 end
Chris@0 85 end
Chris@0 86 end
Chris@1115 87 load_entries_changesets(entries)
Chris@1115 88 entries
Chris@0 89 end
Chris@441 90
Chris@0 91 def fetch_changesets
Chris@1115 92 scm.bzr_path_encodig = log_encoding
Chris@0 93 scm_info = scm.info
Chris@0 94 if scm_info
Chris@0 95 # latest revision found in database
Chris@0 96 db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
Chris@0 97 # latest revision in the repository
Chris@0 98 scm_revision = scm_info.lastrev.identifier.to_i
Chris@0 99 if db_revision < scm_revision
Chris@0 100 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
Chris@0 101 identifier_from = db_revision + 1
Chris@0 102 while (identifier_from <= scm_revision)
Chris@0 103 # loads changesets by batches of 200
Chris@0 104 identifier_to = [identifier_from + 199, scm_revision].min
Chris@1115 105 revisions = scm.revisions('', identifier_to, identifier_from)
Chris@0 106 transaction do
Chris@0 107 revisions.reverse_each do |revision|
Chris@441 108 changeset = Changeset.create(:repository => self,
Chris@441 109 :revision => revision.identifier,
Chris@441 110 :committer => revision.author,
Chris@0 111 :committed_on => revision.time,
Chris@441 112 :scmid => revision.scmid,
Chris@441 113 :comments => revision.message)
Chris@441 114
Chris@0 115 revision.paths.each do |change|
Chris@0 116 Change.create(:changeset => changeset,
Chris@441 117 :action => change[:action],
Chris@441 118 :path => change[:path],
Chris@441 119 :revision => change[:revision])
Chris@0 120 end
Chris@0 121 end
Chris@0 122 end unless revisions.nil?
Chris@0 123 identifier_from = identifier_to + 1
Chris@0 124 end
Chris@0 125 end
Chris@0 126 end
Chris@0 127 end
Chris@0 128 end