diff app/models/repository/mercurial.rb @ 117:af80e5618e9b redmine-1.1

* Update to Redmine 1.1-stable branch (Redmine SVN rev 4707)
author Chris Cannam
date Thu, 13 Jan 2011 12:53:21 +0000
parents 513646585e45
children b859cc0c4fa1
line wrap: on
line diff
--- a/app/models/repository/mercurial.rb	Fri Nov 19 14:05:24 2010 +0000
+++ b/app/models/repository/mercurial.rb	Thu Jan 13 12:53:21 2011 +0000
@@ -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 @@
     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