##// END OF EJS Templates
scm: mercurial: code clean up model....
Toshi MARUYAMA -
r5811:a267babfe806
parent child
Show More
@@ -19,12 +19,15 require 'redmine/scm/adapters/mercurial_adapter'
19
19
20 class Repository::Mercurial < Repository
20 class Repository::Mercurial < Repository
21 # sort changesets by revision number
21 # sort changesets by revision number
22 has_many :changesets, :order => "#{Changeset.table_name}.id DESC", :foreign_key => 'repository_id'
22 has_many :changesets,
23 :order => "#{Changeset.table_name}.id DESC",
24 :foreign_key => 'repository_id'
23
25
24 attr_protected :root_url
26 attr_protected :root_url
25 validates_presence_of :url
27 validates_presence_of :url
26
28
27 FETCH_AT_ONCE = 100 # number of changesets to fetch at once
29 # number of changesets to fetch at once
30 FETCH_AT_ONCE = 100
28
31
29 def self.human_attribute_name(attribute_key_name)
32 def self.human_attribute_name(attribute_key_name)
30 attr_name = attribute_key_name
33 attr_name = attribute_key_name
@@ -84,9 +87,11 class Repository::Mercurial < Repository
84 # Sqlite3 and PostgreSQL pass.
87 # Sqlite3 and PostgreSQL pass.
85 # Is this MySQL bug?
88 # Is this MySQL bug?
86 def latest_changesets(path, rev, limit=10)
89 def latest_changesets(path, rev, limit=10)
87 changesets.find(:all, :include => :user,
90 changesets.find(:all,
91 :include => :user,
88 :conditions => latest_changesets_cond(path, rev, limit),
92 :conditions => latest_changesets_cond(path, rev, limit),
89 :limit => limit, :order => "#{Changeset.table_name}.id DESC")
93 :limit => limit,
94 :order => "#{Changeset.table_name}.id DESC")
90 end
95 end
91
96
92 def latest_changesets_cond(path, rev, limit)
97 def latest_changesets_cond(path, rev, limit)
@@ -108,7 +113,6 class Repository::Mercurial < Repository
108 cond << "#{Changeset.table_name}.id <= ?"
113 cond << "#{Changeset.table_name}.id <= ?"
109 args << last.id
114 args << last.id
110 end
115 end
111
112 unless path.blank?
116 unless path.blank?
113 cond << "EXISTS (SELECT * FROM #{Change.table_name}
117 cond << "EXISTS (SELECT * FROM #{Change.table_name}
114 WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id
118 WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id
@@ -117,26 +121,25 class Repository::Mercurial < Repository
117 args << path.with_leading_slash
121 args << path.with_leading_slash
118 args << "#{path.with_leading_slash.gsub(%r{[%_\\]}) { |s| "\\#{s}" }}/%" << '\\'
122 args << "#{path.with_leading_slash.gsub(%r{[%_\\]}) { |s| "\\#{s}" }}/%" << '\\'
119 end
123 end
120
121 [cond.join(' AND '), *args] unless cond.empty?
124 [cond.join(' AND '), *args] unless cond.empty?
122 end
125 end
123 private :latest_changesets_cond
126 private :latest_changesets_cond
124
127
125 def fetch_changesets
128 def fetch_changesets
126 scm_rev = scm.info.lastrev.revision.to_i
129 scm_rev = scm.info.lastrev.revision.to_i
127 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1
130 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1
128 return unless db_rev < scm_rev # already up-to-date
131 return unless db_rev < scm_rev # already up-to-date
129
132
130 logger.debug "Fetching changesets for repository #{url}" if logger
133 logger.debug "Fetching changesets for repository #{url}" if logger
131 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
134 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
132 transaction do
135 transaction do
133 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
136 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
134 cs = Changeset.create(:repository => self,
137 cs = Changeset.create(:repository => self,
135 :revision => re.revision,
138 :revision => re.revision,
136 :scmid => re.scmid,
139 :scmid => re.scmid,
137 :committer => re.author,
140 :committer => re.author,
138 :committed_on => re.time,
141 :committed_on => re.time,
139 :comments => re.message)
142 :comments => re.message)
140 re.paths.each { |e| cs.create_change(e) }
143 re.paths.each { |e| cs.create_change(e) }
141 end
144 end
142 end
145 end
General Comments 0
You need to be logged in to leave comments. Login now