summaryrefslogtreecommitdiffstats
path: root/app/models/repository/mercurial.rb
diff options
context:
space:
mode:
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>2011-03-14 10:36:34 +0000
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>2011-03-14 10:36:34 +0000
commitc8ce22c2751a0dc5e7604c0c4e793f5d47faafac (patch)
tree53fa6feb1ced7734d11aad525065aee7547b798a /app/models/repository/mercurial.rb
parenta5e55a90536bdfdf33ccc41400da5bd4685159a6 (diff)
downloadredmine-c8ce22c2751a0dc5e7604c0c4e793f5d47faafac.tar.gz
redmine-c8ce22c2751a0dc5e7604c0c4e793f5d47faafac.zip
scm: mercurial: latest changesets improvement and supporting tag (#1981).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5123 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/repository/mercurial.rb')
-rw-r--r--app/models/repository/mercurial.rb34
1 files changed, 23 insertions, 11 deletions
diff --git a/app/models/repository/mercurial.rb b/app/models/repository/mercurial.rb
index 49fba82cf..6ea61b0c7 100644
--- a/app/models/repository/mercurial.rb
+++ b/app/models/repository/mercurial.rb
@@ -80,7 +80,6 @@ class Repository::Mercurial < Repository
end
# Returns the latest changesets for +path+; sorted by revision number
- # Default behavior is to search in cached changesets
#
# Because :order => 'id DESC' is defined at 'has_many',
# there is no need to set 'order'.
@@ -88,18 +87,31 @@ class Repository::Mercurial < Repository
# Sqlite3 and PostgreSQL pass.
# Is this MySQL bug?
def latest_changesets(path, rev, limit=10)
- if path.blank?
- changesets.find(:all, :include => :user, :limit => limit, :order => 'id DESC')
- else
- 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,
- :order => "#{Changeset.table_name}.id DESC" )
+ changesets.find(:all, :include => :user,
+ :conditions => latest_changesets_cond(path, rev, limit),
+ :limit => limit, :order => "#{Changeset.table_name}.id DESC")
+ end
+
+ def latest_changesets_cond(path, rev, limit)
+ cond, args = [], []
+
+ if last = rev ? find_changeset_by_name(scm.tagmap[rev] || rev) : nil
+ cond << "#{Changeset.table_name}.id <= ?"
+ args << last.id
end
+
+ unless path.blank?
+ cond << "EXISTS (SELECT * FROM #{Change.table_name}
+ WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id
+ AND (#{Change.table_name}.path = ?
+ OR #{Change.table_name}.path LIKE ? ESCAPE ?))"
+ args << path.with_leading_slash
+ args << "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%" << '\\'
+ end
+
+ [cond.join(' AND '), *args] unless cond.empty?
end
+ private :latest_changesets_cond
def fetch_changesets
scm_rev = scm.info.lastrev.revision.to_i