@@ -80,7 +80,6 class Repository::Mercurial < Repository | |||||
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | # Returns the latest changesets for +path+; sorted by revision number |
|
82 | # Returns the latest changesets for +path+; sorted by revision number | |
83 | # Default behavior is to search in cached changesets |
|
|||
84 | # |
|
83 | # | |
85 | # Because :order => 'id DESC' is defined at 'has_many', |
|
84 | # Because :order => 'id DESC' is defined at 'has_many', | |
86 | # there is no need to set 'order'. |
|
85 | # there is no need to set 'order'. | |
@@ -88,18 +87,31 class Repository::Mercurial < Repository | |||||
88 | # Sqlite3 and PostgreSQL pass. |
|
87 | # Sqlite3 and PostgreSQL pass. | |
89 | # Is this MySQL bug? |
|
88 | # Is this MySQL bug? | |
90 | def latest_changesets(path, rev, limit=10) |
|
89 | def latest_changesets(path, rev, limit=10) | |
91 | if path.blank? |
|
90 | changesets.find(:all, :include => :user, | |
92 | changesets.find(:all, :include => :user, :limit => limit, :order => 'id DESC') |
|
91 | :conditions => latest_changesets_cond(path, rev, limit), | |
93 | else |
|
92 | :limit => limit, :order => "#{Changeset.table_name}.id DESC") | |
94 | changesets.find(:all, :select => "DISTINCT #{Changeset.table_name}.*", |
|
93 | end | |
95 | :joins => :changes, |
|
94 | ||
96 | :conditions => ["#{Change.table_name}.path = ? OR #{Change.table_name}.path LIKE ? ESCAPE ?", |
|
95 | def latest_changesets_cond(path, rev, limit) | |
97 | path.with_leading_slash, |
|
96 | cond, args = [], [] | |
98 | "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%", '\\'], |
|
97 | ||
99 | :include => :user, :limit => limit, |
|
98 | if last = rev ? find_changeset_by_name(scm.tagmap[rev] || rev) : nil | |
100 |
|
|
99 | cond << "#{Changeset.table_name}.id <= ?" | |
|
100 | args << last.id | |||
101 | end |
|
101 | end | |
|
102 | ||||
|
103 | unless path.blank? | |||
|
104 | cond << "EXISTS (SELECT * FROM #{Change.table_name} | |||
|
105 | WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id | |||
|
106 | AND (#{Change.table_name}.path = ? | |||
|
107 | OR #{Change.table_name}.path LIKE ? ESCAPE ?))" | |||
|
108 | args << path.with_leading_slash | |||
|
109 | args << "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%" << '\\' | |||
|
110 | end | |||
|
111 | ||||
|
112 | [cond.join(' AND '), *args] unless cond.empty? | |||
102 | end |
|
113 | end | |
|
114 | private :latest_changesets_cond | |||
103 |
|
115 | |||
104 | def fetch_changesets |
|
116 | def fetch_changesets | |
105 | scm_rev = scm.info.lastrev.revision.to_i |
|
117 | scm_rev = scm.info.lastrev.revision.to_i |
@@ -147,7 +147,7 class RepositoriesMercurialControllerTest < ActionController::TestCase | |||||
147 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) |
|
147 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) | |
148 | changesets = assigns(:changesets) |
|
148 | changesets = assigns(:changesets) | |
149 | assert_not_nil changesets |
|
149 | assert_not_nil changesets | |
150 |
assert_equal %w( |
|
150 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) | |
151 | end |
|
151 | end | |
152 | end |
|
152 | end | |
153 |
|
153 |
General Comments 0
You need to be logged in to leave comments.
Login now