annotate .svn/pristine/4c/4c99574139ce5eb61536505c034f120cc8d05585.svn-base @ 1517:dffacf8a6908 redmine-2.5

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