Mercurial > hg > soundsoftware-site
diff app/models/.svn/text-base/repository.rb.svn-base @ 441:cbce1fd3b1b7 redmine-1.2
Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author | Chris Cannam |
---|---|
date | Mon, 06 Jun 2011 14:24:13 +0100 |
parents | 051f544170fe |
children | 753f1380d6bc 0c939c159af4 |
line wrap: on
line diff
--- a/app/models/.svn/text-base/repository.rb.svn-base Thu Mar 03 11:42:28 2011 +0000 +++ b/app/models/.svn/text-base/repository.rb.svn-base Mon Jun 06 14:24:13 2011 +0100 @@ -1,35 +1,45 @@ -# redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2011 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class Repository < ActiveRecord::Base include Redmine::Ciphering - + belongs_to :project has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC" has_many :changes, :through => :changesets - + + serialize :extra_info + # Raw SQL to delete changesets and changes in the database # has_many :changesets, :dependent => :destroy is too slow for big repositories before_destroy :clear_changesets - + validates_length_of :password, :maximum => 255, :allow_nil => true # Checks if the SCM is enabled when creating a repository validate_on_create { |r| r.errors.add(:type, :invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) } + def self.human_attribute_name(attribute_key_name) + attr_name = attribute_key_name + if attr_name == "log_encoding" + attr_name = "commit_logs_encoding" + end + super(attr_name) + end + # Removes leading and trailing whitespace def url=(arg) write_attribute(:url, arg ? arg.to_s.strip : nil) @@ -39,11 +49,11 @@ def root_url=(arg) write_attribute(:root_url, arg ? arg.to_s.strip : nil) end - + def password read_ciphered_attribute(:password) end - + def password=(arg) write_ciphered_attribute(:password, arg) end @@ -63,6 +73,17 @@ self.class.scm_name end + def merge_extra_info(arg) + h = extra_info || {} + return h if arg.nil? + h.merge!(arg) + write_attribute(:extra_info, h) + end + + def report_last_commit + true + end + def supports_cat? scm.supports_cat? end @@ -70,11 +91,19 @@ def supports_annotate? scm.supports_annotate? end - + + def supports_all_revisions? + true + end + + def supports_directory_revisions? + false + end + def entry(path=nil, identifier=nil) scm.entry(path, identifier) end - + def entries(path=nil, identifier=nil) scm.entries(path, identifier) end @@ -90,15 +119,15 @@ def default_branch scm.default_branch end - + def properties(path, identifier=nil) scm.properties(path, identifier) end - + def cat(path, identifier=nil) scm.cat(path, identifier) end - + def diff(path, rev, rev_to) scm.diff(path, rev, rev_to) end @@ -118,7 +147,8 @@ # Finds and returns a revision with a number or the beginning of a hash def find_changeset_by_name(name) return nil if name.blank? - changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%'])) + changesets.find(:first, :conditions => (name.match(/^\d*$/) ? + ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%'])) end def latest_changeset @@ -129,26 +159,32 @@ # Default behaviour is to search in cached changesets def latest_changesets(path, rev, limit=10) if path.blank? - changesets.find(:all, :include => :user, - :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC", - :limit => limit) + changesets.find( + :all, + :include => :user, + :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC", + :limit => limit) else - changes.find(:all, :include => {:changeset => :user}, - :conditions => ["path = ?", path.with_leading_slash], - :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC", - :limit => limit).collect(&:changeset) + changes.find( + :all, + :include => {:changeset => :user}, + :conditions => ["path = ?", path.with_leading_slash], + :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC", + :limit => limit + ).collect(&:changeset) end end - + def scan_changesets_for_issue_ids self.changesets.each(&:scan_comment_for_issue_ids) end # Returns an array of committers usernames and associated user_id def committers - @committers ||= Changeset.connection.select_rows("SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}") + @committers ||= Changeset.connection.select_rows( + "SELECT DISTINCT committer, user_id FROM #{Changeset.table_name} WHERE repository_id = #{id}") end - + # Maps committers username to a user ids def committer_ids=(h) if h.is_a?(Hash) @@ -156,17 +192,19 @@ new_user_id = h[committer] if new_user_id && (new_user_id.to_i != user_id.to_i) new_user_id = (new_user_id.to_i > 0 ? new_user_id.to_i : nil) - Changeset.update_all("user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }", ["repository_id = ? AND committer = ?", id, committer]) + Changeset.update_all( + "user_id = #{ new_user_id.nil? ? 'NULL' : new_user_id }", + ["repository_id = ? AND committer = ?", id, committer]) end end - @committers = nil + @committers = nil @found_committer_users = nil true else false end end - + # Returns the Redmine User corresponding to the given +committer+ # It will return nil if the committer is not yet mapped and if no User # with the same username or email was found @@ -174,7 +212,7 @@ unless committer.blank? @found_committer_users ||= {} return @found_committer_users[committer] if @found_committer_users.has_key?(committer) - + user = nil c = changesets.find(:first, :conditions => {:committer => committer}, :include => :user) if c && c.user @@ -218,7 +256,7 @@ def self.scm_name 'Abstract' end - + def self.available_scm subclasses.collect {|klass| [klass.scm_name, klass.name]} end @@ -238,7 +276,7 @@ ret = "" begin ret = self.scm_adapter_class.client_command if self.scm_adapter_class - rescue Redmine::Scm::Adapters::CommandFailed => e + rescue Exception => e logger.error "scm: error during get command: #{e.message}" end ret @@ -248,7 +286,7 @@ ret = "" begin ret = self.scm_adapter_class.client_version_string if self.scm_adapter_class - rescue Redmine::Scm::Adapters::CommandFailed => e + rescue Exception => e logger.error "scm: error during get version string: #{e.message}" end ret @@ -257,8 +295,8 @@ def self.scm_available ret = false begin - ret = self.scm_adapter_class.client_available if self.scm_adapter_class - rescue Redmine::Scm::Adapters::CommandFailed => e + ret = self.scm_adapter_class.client_available if self.scm_adapter_class + rescue Exception => e logger.error "scm: error during get scm available: #{e.message}" end ret @@ -272,7 +310,7 @@ root_url.strip! true end - + def clear_changesets cs, ch, ci = Changeset.table_name, Change.table_name, "#{table_name_prefix}changesets_issues#{table_name_suffix}" connection.delete("DELETE FROM #{ch} WHERE #{ch}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")