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
@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
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
'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
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
--- /dev/null
+# 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
repository_id: 10\r
committer: dlopper\r
user_id: 3\r
+changesets_005: \r
+ commit_date: "2007-09-10"\r
+ comments: Modified one file in the folder.\r
+ committed_on: 2007-09-10 19:01:08\r
+ revision: "5"\r
+ id: 104\r
+ scmid:\r
+ user_id: 3\r
+ repository_id: 10\r
+ committer: dlopper\r
+changesets_006: \r
+ commit_date: "2007-09-10"\r
+ comments: Moved helloworld.rb from / to /folder.\r
+ committed_on: 2007-09-10 19:01:47\r
+ revision: "6"\r
+ id: 105\r
+ scmid:\r
+ user_id: 3\r
+ repository_id: 10\r
+ committer: dlopper\r
+changesets_007: \r
+ commit_date: "2007-09-10"\r
+ comments: Removed one file.\r
+ committed_on: 2007-09-10 19:02:16\r
+ revision: "7"\r
+ id: 106\r
+ scmid:\r
+ user_id: 3\r
+ repository_id: 10\r
+ committer: dlopper\r
+changesets_008: \r
+ commit_date: "2007-09-10"\r
+ comments: |-\r
+ This commits references an issue.\r
+ Refs #2\r
+ committed_on: 2007-09-10 19:04:35\r
+ revision: "8"\r
+ id: 107\r
+ scmid:\r
+ user_id: 3\r
+ repository_id: 10\r
+ committer: dlopper\r
\ No newline at end of file
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)
: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
end
def test_next_nil
- changeset = Changeset.find_by_revision('4')
+ changeset = Changeset.find_by_revision('8')
assert_nil changeset.next
end
end
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 !!!"