summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-08-17 16:32:24 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-08-17 16:32:24 +0000
commite10577e9ed482433ad1d80b321b89e8cc72f4c1c (patch)
tree9e9b8a9200f449d4cc3edd9b1df4a3826d8ef1e7
parenta4d7a03b142889510c910cfb983a818f61653c11 (diff)
downloadredmine-e10577e9ed482433ad1d80b321b89e8cc72f4c1c.tar.gz
redmine-e10577e9ed482433ad1d80b321b89e8cc72f4c1c.zip
SCM:
* Fixes file log for non-Git repositories (Repository#latest_changesets ignores path argument) * No longer used Repository#changesets_for_path method removed git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2844 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/repository.rb24
-rw-r--r--app/models/repository/git.rb10
-rw-r--r--app/models/repository/subversion.rb4
-rw-r--r--lib/redmine/core_ext/string.rb2
-rw-r--r--lib/redmine/core_ext/string/inflections.rb29
-rw-r--r--test/fixtures/changesets.yml42
-rw-r--r--test/functional/repositories_subversion_controller_test.rb5
-rw-r--r--test/functional/search_controller_test.rb4
-rw-r--r--test/unit/changeset_test.rb2
-rw-r--r--test/unit/repository_subversion_test.rb12
10 files changed, 105 insertions, 29 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 9ab4fbae2..8440bc685 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -87,15 +87,6 @@ class Repository < ActiveRecord::Base
scm.diff(path, rev, rev_to)
end
- # Default behaviour: we search in cached changesets
- def changesets_for_path(path, options={})
- path = "/#{path}" unless path.starts_with?('/')
- Change.find(:all, :include => {:changeset => :user},
- :conditions => ["repository_id = ? AND path = ?", id, path],
- :order => "committed_on DESC, #{Changeset.table_name}.id DESC",
- :limit => options[:limit]).collect(&:changeset)
- end
-
# Returns a path relative to the url of the repository
def relative_path(path)
path
@@ -105,8 +96,19 @@ class Repository < ActiveRecord::Base
@latest_changeset ||= changesets.find(:first)
end
- def latest_changesets(path,rev,limit=10)
- @latest_changesets ||= changesets.find(:all, :limit => limit, :order => "committed_on DESC")
+ # Returns the latest changesets for +path+
+ # 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)
+ 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)
+ end
end
def scan_changesets_for_issue_ids
diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb
index b3cdf3643..dd5e9e316 100644
--- a/app/models/repository/git.rb
+++ b/app/models/repository/git.rb
@@ -37,16 +37,6 @@ class Repository::Git < Repository
scm.tags
end
- def changesets_for_path(path, options={})
- Change.find(
- :all,
- :include => {:changeset => :user},
- :conditions => ["repository_id = ? AND path = ?", id, path],
- :order => "committed_on DESC, #{Changeset.table_name}.revision DESC",
- :limit => options[:limit]
- ).collect(&:changeset)
- end
-
# With SCM's that have a sequential commit numbering, redmine is able to be
# clever and only fetch changesets going forward from the most recent one
# it knows about. However, with git, you never know if people have merged
diff --git a/app/models/repository/subversion.rb b/app/models/repository/subversion.rb
index fdda488d1..86ac5a921 100644
--- a/app/models/repository/subversion.rb
+++ b/app/models/repository/subversion.rb
@@ -30,8 +30,8 @@ class Repository::Subversion < Repository
'Subversion'
end
- def changesets_for_path(path, options={})
- revisions = scm.revisions(path, nil, nil, :limit => options[:limit])
+ def latest_changesets(path, rev, limit=10)
+ revisions = scm.revisions(path, nil, nil, :limit => limit)
revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
end
diff --git a/lib/redmine/core_ext/string.rb b/lib/redmine/core_ext/string.rb
index ce2646fb9..2da5ffef9 100644
--- a/lib/redmine/core_ext/string.rb
+++ b/lib/redmine/core_ext/string.rb
@@ -1,5 +1,7 @@
require File.dirname(__FILE__) + '/string/conversions'
+require File.dirname(__FILE__) + '/string/inflections'
class String #:nodoc:
include Redmine::CoreExtensions::String::Conversions
+ include Redmine::CoreExtensions::String::Inflections
end
diff --git a/lib/redmine/core_ext/string/inflections.rb b/lib/redmine/core_ext/string/inflections.rb
new file mode 100644
index 000000000..a59f268fa
--- /dev/null
+++ b/lib/redmine/core_ext/string/inflections.rb
@@ -0,0 +1,29 @@
+# Redmine - project management software
+# Copyright (C) 2009 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.
+
+module Redmine #:nodoc:
+ module CoreExtensions #:nodoc:
+ module String #:nodoc:
+ # Custom string inflections
+ module Inflections
+ def with_leading_slash
+ starts_with?('/') ? self : "/#{ self }"
+ end
+ end
+ end
+ end
+end
diff --git a/test/fixtures/changesets.yml b/test/fixtures/changesets.yml
index cbc00eb83..6c13d37e5 100644
--- a/test/fixtures/changesets.yml
+++ b/test/fixtures/changesets.yml
@@ -39,4 +39,46 @@ changesets_004:
repository_id: 10
committer: dlopper
user_id: 3
+changesets_005:
+ commit_date: "2007-09-10"
+ comments: Modified one file in the folder.
+ committed_on: 2007-09-10 19:01:08
+ revision: "5"
+ id: 104
+ scmid:
+ user_id: 3
+ repository_id: 10
+ committer: dlopper
+changesets_006:
+ commit_date: "2007-09-10"
+ comments: Moved helloworld.rb from / to /folder.
+ committed_on: 2007-09-10 19:01:47
+ revision: "6"
+ id: 105
+ scmid:
+ user_id: 3
+ repository_id: 10
+ committer: dlopper
+changesets_007:
+ commit_date: "2007-09-10"
+ comments: Removed one file.
+ committed_on: 2007-09-10 19:02:16
+ revision: "7"
+ id: 106
+ scmid:
+ user_id: 3
+ repository_id: 10
+ committer: dlopper
+changesets_008:
+ commit_date: "2007-09-10"
+ comments: |-
+ This commits references an issue.
+ Refs #2
+ committed_on: 2007-09-10 19:04:35
+ revision: "8"
+ id: 107
+ scmid:
+ user_id: 3
+ repository_id: 10
+ committer: dlopper
\ No newline at end of file
diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb
index ac1438572..8e4affade 100644
--- a/test/functional/repositories_subversion_controller_test.rb
+++ b/test/functional/repositories_subversion_controller_test.rb
@@ -79,6 +79,11 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase
get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
assert_response :success
assert_template 'changes'
+
+ changesets = assigns(:changesets)
+ assert_not_nil changesets
+ assert_equal %w(6 3 2), changesets.collect(&:revision)
+
# svn properties displayed with svn >= 1.5 only
if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
assert_not_nil assigns(:properties)
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
index 0f74c537e..4f79081ae 100644
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -41,8 +41,8 @@ class SearchControllerTest < Test::Unit::TestCase
:sibling => { :tag => 'dd', :content => /should be classified by categories/ }
assert assigns(:results_by_type).is_a?(Hash)
- assert_equal 4, assigns(:results_by_type)['changesets']
- assert_tag :a, :content => 'Changesets (4)'
+ assert_equal 5, assigns(:results_by_type)['changesets']
+ assert_tag :a, :content => 'Changesets (5)'
end
def test_search_issues
diff --git a/test/unit/changeset_test.rb b/test/unit/changeset_test.rb
index 78e2339f9..e5dc6d73f 100644
--- a/test/unit/changeset_test.rb
+++ b/test/unit/changeset_test.rb
@@ -69,7 +69,7 @@ class ChangesetTest < Test::Unit::TestCase
end
def test_next_nil
- changeset = Changeset.find_by_revision('4')
+ changeset = Changeset.find_by_revision('8')
assert_nil changeset.next
end
end
diff --git a/test/unit/repository_subversion_test.rb b/test/unit/repository_subversion_test.rb
index 4054a0e41..b0eb88c01 100644
--- a/test/unit/repository_subversion_test.rb
+++ b/test/unit/repository_subversion_test.rb
@@ -49,11 +49,17 @@ class RepositorySubversionTest < Test::Unit::TestCase
assert_equal 8, @repository.changesets.count
end
- def test_changesets_for_path_with_limit
+ def test_latest_changesets_with_limit
@repository.fetch_changesets
- changesets = @repository.changesets_for_path('', :limit => 2)
+ changesets = @repository.latest_changesets('', nil, 2)
assert_equal 2, changesets.size
- assert_equal @repository.changesets_for_path('').slice(0,2), changesets
+ assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
+ end
+
+ def test_latest_changesets_with_path
+ @repository.fetch_changesets
+ changesets = @repository.latest_changesets('subversion_test/folder/helloworld.rb', nil)
+ assert_equal %w(6 3 2), changesets.collect(&:revision)
end
else
puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"