diff app/models/changeset.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents 5f33065ddc4b
children bb32da3bea34 622f24f53b42 261b3d9a4903
line wrap: on
line diff
--- a/app/models/changeset.rb	Wed Jun 27 14:54:18 2012 +0100
+++ b/app/models/changeset.rb	Mon Jan 07 12:01:42 2013 +0000
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2011  Jean-Philippe Lang
+# Copyright (C) 2006-2012  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
@@ -20,7 +20,7 @@
 class Changeset < ActiveRecord::Base
   belongs_to :repository
   belongs_to :user
-  has_many :changes, :dependent => :delete_all
+  has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
   has_and_belongs_to_many :issues
   has_and_belongs_to_many :parents,
                           :class_name => "Changeset",
@@ -31,10 +31,10 @@
                           :join_table => "#{table_name_prefix}changeset_parents#{table_name_suffix}",
                           :association_foreign_key => 'changeset_id', :foreign_key => 'parent_id'
 
-  acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.format_identifier}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments))},
+  acts_as_event :title => Proc.new {|o| o.title},
                 :description => :long_comments,
                 :datetime => :committed_on,
-                :url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project, :rev => o.identifier}}
+                :url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project, :repository_id => o.repository.identifier_param, :rev => o.identifier}}
 
   acts_as_searchable :columns => 'comments',
                      :include => {:repository => :project},
@@ -49,7 +49,8 @@
   validates_uniqueness_of :revision, :scope => :repository_id
   validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
 
-  named_scope :visible, lambda {|*args| { :include => {:repository => :project},
+  scope :visible,
+     lambda {|*args| { :include => {:repository => :project},
                                           :conditions => Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args) } }
 
   after_create :scan_for_issues
@@ -157,26 +158,30 @@
     else
       "r#{revision}"
     end
+    if repository && repository.identifier.present?
+      tag = "#{repository.identifier}|#{tag}"
+    end
     if ref_project && project && ref_project != project
-      tag = "#{project.identifier}:#{tag}" 
+      tag = "#{project.identifier}:#{tag}"
     end
     tag
   end
 
+  # Returns the title used for the changeset in the activity/search results
+  def title
+    repo = (repository && repository.identifier.present?) ? " (#{repository.identifier})" : ''
+    comm = short_comments.blank? ? '' : (': ' + short_comments)
+    "#{l(:label_revision)} #{format_identifier}#{repo}#{comm}"
+  end
+
   # Returns the previous changeset
   def previous
-    @previous ||= Changeset.find(:first,
-                    :conditions => ['id < ? AND repository_id = ?',
-                                    self.id, self.repository_id],
-                    :order => 'id DESC')
+    @previous ||= Changeset.where(["id < ? AND repository_id = ?", id, repository_id]).order('id DESC').first
   end
 
   # Returns the next changeset
   def next
-    @next ||= Changeset.find(:first,
-                    :conditions => ['id > ? AND repository_id = ?',
-                                    self.id, self.repository_id],
-                    :order => 'id ASC')
+    @next ||= Changeset.where(["id > ? AND repository_id = ?", id, repository_id]).order('id ASC').first
   end
 
   # Creates a new Change from it's common parameters
@@ -188,14 +193,14 @@
                   :from_revision => change[:from_revision])
   end
 
-  private
-
   # Finds an issue that can be referenced by the commit message
-  # i.e. an issue that belong to the repository project, a subproject or a parent project
   def find_referenced_issue_by_id(id)
     return nil if id.blank?
     issue = Issue.find_by_id(id.to_i, :include => :project)
-    if issue
+    if Setting.commit_cross_project_ref?
+      # all issues can be referenced/fixed
+    elsif issue
+      # issue that belong to the repository project, a subproject or a parent project only
       unless issue.project &&
                 (project == issue.project || project.is_ancestor_of?(issue.project) ||
                  project.is_descendant_of?(issue.project))
@@ -205,6 +210,8 @@
     issue
   end
 
+  private
+
   def fix_issue(issue)
     status = IssueStatus.find_by_id(Setting.commit_fix_status_id.to_i)
     if status.nil?