Feature #4455 » hg-changeset-order.patch
| app/models/repository/mercurial.rb | ||
|---|---|---|
| 18 | 18 | require 'redmine/scm/adapters/mercurial_adapter' | 
| 19 | 19 | |
| 20 | 20 | class Repository::Mercurial < Repository | 
| 21 | # sort changesets by revision number | |
| 22 |   has_many :changesets, :order => "#{Changeset.table_name}.id DESC", :foreign_key => 'repository_id' | |
| 23 | ||
| 21 | 24 | attr_protected :root_url | 
| 22 | 25 | validates_presence_of :url | 
| 23 | 26 | |
| ... | ... | |
| 52 | 55 | entries | 
| 53 | 56 | end | 
| 54 | 57 | |
| 58 | # Returns the latest changesets for +path+; sorted by revision number | |
| 59 | def latest_changesets(path, rev, limit=10) | |
| 60 | if path.blank? | |
| 61 | changesets.find(:all, :include => :user, :limit => limit) | |
| 62 | else | |
| 63 |       changes.find(:all, :include => {:changeset => :user}, | |
| 64 | :conditions => ["path = ?", path.with_leading_slash], | |
| 65 |                          :order => "#{Changeset.table_name}.id DESC", | |
| 66 | :limit => limit).collect(&:changeset) | |
| 67 | end | |
| 68 | end | |
| 69 | ||
| 55 | 70 | def fetch_changesets | 
| 56 | 71 | scm_info = scm.info | 
| 57 | 72 | if scm_info | 
| test/unit/repository_mercurial_test.rb | ||
|---|---|---|
| 75 | 75 |       assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on | 
| 76 | 76 | end | 
| 77 | 77 | |
| 78 | def test_changeset_order_by_revision | |
| 79 | @repository.fetch_changesets | |
| 80 | @repository.reload | |
| 81 | c0 = @repository.latest_changeset | |
| 82 | c1 = @repository.changesets(nil, nil)[1] | |
| 83 | # sorted by revision (id), not by date | |
| 84 | assert c0.revision.to_i > c1.revision.to_i | |
| 85 | assert c0.committed_on < c1.committed_on | |
| 86 | end | |
| 87 | ||
| 78 | 88 | else | 
| 79 | 89 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | 
| 80 | 90 | def test_fake; assert true end |