From: Toshi MARUYAMA Date: Fri, 18 Feb 2011 05:55:02 +0000 (+0000) Subject: scm: mercurial: improvement latest_changesets without supporting tags and named branc... X-Git-Tag: 1.2.0~953 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b3c517387a74fc3f228a3f5d6937e72e0a072c3d;p=redmine.git scm: mercurial: improvement latest_changesets without supporting tags and named branches (#4455). Based on latest-changesets-improvements-2.diff of #6159. http://www.redmine.org/attachments/4332/latest-changesets-improvements-2.diff Contributed by Yuya Nishihara. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4868 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/repository/mercurial.rb b/app/models/repository/mercurial.rb index 4ee76f442..d7f58fcd1 100644 --- a/app/models/repository/mercurial.rb +++ b/app/models/repository/mercurial.rb @@ -61,14 +61,17 @@ class Repository::Mercurial < Repository end # Returns the latest changesets for +path+; sorted by revision number + # Default behavior is to search in cached changesets 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) + changesets.find(:all, :select => "DISTINCT #{Changeset.table_name}.*", + :joins => :changes, + :conditions => ["#{Change.table_name}.path = ? OR #{Change.table_name}.path LIKE ? ESCAPE ?", + path.with_leading_slash, + "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%", '\\'], + :include => :user, :limit => limit) end end