diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-01-02 06:05:54 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2011-01-02 06:05:54 +0000 |
commit | 2ae2d3ef834c4d17b1c7a4e09f299b537f91d3cc (patch) | |
tree | be5fb6d7d07e01e3df20e0430eaf3edcc9b5f8dd | |
parent | d29052f682cc1583888fe13095d0af0e2fc81a0f (diff) | |
download | redmine-2ae2d3ef834c4d17b1c7a4e09f299b537f91d3cc.tar.gz redmine-2ae2d3ef834c4d17b1c7a4e09f299b537f91d3cc.zip |
Fixed: repository: mercurial: sort changesets by revision (#3449, #3567).
In DVCS, changesets are not in date order.
Because Mercurial backend inserts changesets from eariest, 'ORDER BY id'
means 'order by revision number'.
Contributed by Yuya Nishihara.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4611 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/repository/mercurial.rb | 15 | ||||
-rw-r--r-- | test/fixtures/repositories/mercurial_repository.tar.gz | bin | 7827 -> 8058 bytes | |||
-rw-r--r-- | test/unit/repository_mercurial_test.rb | 11 |
3 files changed, 26 insertions, 0 deletions
diff --git a/app/models/repository/mercurial.rb b/app/models/repository/mercurial.rb index 107223956..9ce3b63eb 100644 --- a/app/models/repository/mercurial.rb +++ b/app/models/repository/mercurial.rb @@ -18,6 +18,9 @@ require 'redmine/scm/adapters/mercurial_adapter' class Repository::Mercurial < Repository + # sort changesets by revision number + has_many :changesets, :order => "#{Changeset.table_name}.id DESC", :foreign_key => 'repository_id' + attr_protected :root_url validates_presence_of :url @@ -52,6 +55,18 @@ class Repository::Mercurial < Repository entries end + # Returns the latest changesets for +path+; sorted by revision number + def latest_changesets(path, rev, limit=10) + if path.blank? + changesets.find(:all, :include => :user, :limit => limit) + else + changes.find(:all, :include => {:changeset => :user}, + :conditions => ["path = ?", path.with_leading_slash], + :order => "#{Changeset.table_name}.id DESC", + :limit => limit).collect(&:changeset) + end + end + def fetch_changesets scm_info = scm.info if scm_info diff --git a/test/fixtures/repositories/mercurial_repository.tar.gz b/test/fixtures/repositories/mercurial_repository.tar.gz Binary files differindex 1d8ad3057..c2a1b5874 100644 --- a/test/fixtures/repositories/mercurial_repository.tar.gz +++ b/test/fixtures/repositories/mercurial_repository.tar.gz diff --git a/test/unit/repository_mercurial_test.rb b/test/unit/repository_mercurial_test.rb index 16e72c35d..17b72cf67 100644 --- a/test/unit/repository_mercurial_test.rb +++ b/test/unit/repository_mercurial_test.rb @@ -76,6 +76,17 @@ class RepositoryMercurialTest < ActiveSupport::TestCase assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on end end + + def test_changeset_order_by_revision + @repository.fetch_changesets + @repository.reload + + c0 = @repository.latest_changeset + c1 = @repository.changesets.find_by_revision('0') + # sorted by revision (id), not by date + assert c0.revision.to_i > c1.revision.to_i + assert c0.committed_on < c1.committed_on + end else puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" def test_fake; assert true end |