##// END OF EJS Templates
scm: switch to save repository setting params in "extra_" or not (#8365, #7047)....
Toshi MARUYAMA -
r5649:ab430a13b5ae
parent child
Show More
@@ -1,359 +1,369
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'SVG/Graph/Bar'
18 require 'SVG/Graph/Bar'
19 require 'SVG/Graph/BarHorizontal'
19 require 'SVG/Graph/BarHorizontal'
20 require 'digest/sha1'
20 require 'digest/sha1'
21
21
22 class ChangesetNotFound < Exception; end
22 class ChangesetNotFound < Exception; end
23 class InvalidRevisionParam < Exception; end
23 class InvalidRevisionParam < Exception; end
24
24
25 class RepositoriesController < ApplicationController
25 class RepositoriesController < ApplicationController
26 menu_item :repository
26 menu_item :repository
27 menu_item :settings, :only => :edit
27 menu_item :settings, :only => :edit
28 default_search_scope :changesets
28 default_search_scope :changesets
29
29
30 before_filter :find_repository, :except => :edit
30 before_filter :find_repository, :except => :edit
31 before_filter :find_project, :only => :edit
31 before_filter :find_project, :only => :edit
32 before_filter :authorize
32 before_filter :authorize
33 accept_key_auth :revisions
33 accept_key_auth :revisions
34
34
35 rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
35 rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
36
36
37 def edit
37 def edit
38 @repository = @project.repository
38 @repository = @project.repository
39 if !@repository && !params[:repository_scm].blank?
39 if !@repository && !params[:repository_scm].blank?
40 @repository = Repository.factory(params[:repository_scm])
40 @repository = Repository.factory(params[:repository_scm])
41 @repository.project = @project if @repository
41 @repository.project = @project if @repository
42 end
42 end
43 if request.post? && @repository
43 if request.post? && @repository
44 @repository.attributes = params[:repository]
44 p1 = params[:repository]
45 p = {}
46 p_extra = {}
47 p1.each do |k, v|
48 if k =~ /^extra_/
49 p_extra[k] = v
50 else
51 p[k] = v
52 end
53 end
54 @repository.attributes = p
45 @repository.save
55 @repository.save
46 end
56 end
47 render(:update) do |page|
57 render(:update) do |page|
48 page.replace_html "tab-content-repository",
58 page.replace_html "tab-content-repository",
49 :partial => 'projects/settings/repository'
59 :partial => 'projects/settings/repository'
50 if @repository && !@project.repository
60 if @repository && !@project.repository
51 @project.reload # needed to reload association
61 @project.reload # needed to reload association
52 page.replace_html "main-menu", render_main_menu(@project)
62 page.replace_html "main-menu", render_main_menu(@project)
53 end
63 end
54 end
64 end
55 end
65 end
56
66
57 def committers
67 def committers
58 @committers = @repository.committers
68 @committers = @repository.committers
59 @users = @project.users
69 @users = @project.users
60 additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
70 additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
61 @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
71 @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
62 @users.compact!
72 @users.compact!
63 @users.sort!
73 @users.sort!
64 if request.post? && params[:committers].is_a?(Hash)
74 if request.post? && params[:committers].is_a?(Hash)
65 # Build a hash with repository usernames as keys and corresponding user ids as values
75 # Build a hash with repository usernames as keys and corresponding user ids as values
66 @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
76 @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
67 flash[:notice] = l(:notice_successful_update)
77 flash[:notice] = l(:notice_successful_update)
68 redirect_to :action => 'committers', :id => @project
78 redirect_to :action => 'committers', :id => @project
69 end
79 end
70 end
80 end
71
81
72 def destroy
82 def destroy
73 @repository.destroy
83 @repository.destroy
74 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
84 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
75 end
85 end
76
86
77 def show
87 def show
78 @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
88 @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
79
89
80 @entries = @repository.entries(@path, @rev)
90 @entries = @repository.entries(@path, @rev)
81 @changeset = @repository.find_changeset_by_name(@rev)
91 @changeset = @repository.find_changeset_by_name(@rev)
82 if request.xhr?
92 if request.xhr?
83 @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
93 @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
84 else
94 else
85 (show_error_not_found; return) unless @entries
95 (show_error_not_found; return) unless @entries
86 @changesets = @repository.latest_changesets(@path, @rev)
96 @changesets = @repository.latest_changesets(@path, @rev)
87 @properties = @repository.properties(@path, @rev)
97 @properties = @repository.properties(@path, @rev)
88 render :action => 'show'
98 render :action => 'show'
89 end
99 end
90 end
100 end
91
101
92 alias_method :browse, :show
102 alias_method :browse, :show
93
103
94 def changes
104 def changes
95 @entry = @repository.entry(@path, @rev)
105 @entry = @repository.entry(@path, @rev)
96 (show_error_not_found; return) unless @entry
106 (show_error_not_found; return) unless @entry
97 @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
107 @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
98 @properties = @repository.properties(@path, @rev)
108 @properties = @repository.properties(@path, @rev)
99 @changeset = @repository.find_changeset_by_name(@rev)
109 @changeset = @repository.find_changeset_by_name(@rev)
100 end
110 end
101
111
102 def revisions
112 def revisions
103 @changeset_count = @repository.changesets.count
113 @changeset_count = @repository.changesets.count
104 @changeset_pages = Paginator.new self, @changeset_count,
114 @changeset_pages = Paginator.new self, @changeset_count,
105 per_page_option,
115 per_page_option,
106 params['page']
116 params['page']
107 @changesets = @repository.changesets.find(:all,
117 @changesets = @repository.changesets.find(:all,
108 :limit => @changeset_pages.items_per_page,
118 :limit => @changeset_pages.items_per_page,
109 :offset => @changeset_pages.current.offset,
119 :offset => @changeset_pages.current.offset,
110 :include => [:user, :repository])
120 :include => [:user, :repository])
111
121
112 respond_to do |format|
122 respond_to do |format|
113 format.html { render :layout => false if request.xhr? }
123 format.html { render :layout => false if request.xhr? }
114 format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
124 format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
115 end
125 end
116 end
126 end
117
127
118 def entry
128 def entry
119 @entry = @repository.entry(@path, @rev)
129 @entry = @repository.entry(@path, @rev)
120 (show_error_not_found; return) unless @entry
130 (show_error_not_found; return) unless @entry
121
131
122 # If the entry is a dir, show the browser
132 # If the entry is a dir, show the browser
123 (show; return) if @entry.is_dir?
133 (show; return) if @entry.is_dir?
124
134
125 @content = @repository.cat(@path, @rev)
135 @content = @repository.cat(@path, @rev)
126 (show_error_not_found; return) unless @content
136 (show_error_not_found; return) unless @content
127 if 'raw' == params[:format] ||
137 if 'raw' == params[:format] ||
128 (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
138 (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
129 ! is_entry_text_data?(@content, @path)
139 ! is_entry_text_data?(@content, @path)
130 # Force the download
140 # Force the download
131 send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
141 send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
132 send_type = Redmine::MimeType.of(@path)
142 send_type = Redmine::MimeType.of(@path)
133 send_opt[:type] = send_type.to_s if send_type
143 send_opt[:type] = send_type.to_s if send_type
134 send_data @content, send_opt
144 send_data @content, send_opt
135 else
145 else
136 # Prevent empty lines when displaying a file with Windows style eol
146 # Prevent empty lines when displaying a file with Windows style eol
137 # TODO: UTF-16
147 # TODO: UTF-16
138 # Is this needs? AttachmentsController reads file simply.
148 # Is this needs? AttachmentsController reads file simply.
139 @content.gsub!("\r\n", "\n")
149 @content.gsub!("\r\n", "\n")
140 @changeset = @repository.find_changeset_by_name(@rev)
150 @changeset = @repository.find_changeset_by_name(@rev)
141 end
151 end
142 end
152 end
143
153
144 def is_entry_text_data?(ent, path)
154 def is_entry_text_data?(ent, path)
145 # UTF-16 contains "\x00".
155 # UTF-16 contains "\x00".
146 # It is very strict that file contains less than 30% of ascii symbols
156 # It is very strict that file contains less than 30% of ascii symbols
147 # in non Western Europe.
157 # in non Western Europe.
148 return true if Redmine::MimeType.is_type?('text', path)
158 return true if Redmine::MimeType.is_type?('text', path)
149 # Ruby 1.8.6 has a bug of integer divisions.
159 # Ruby 1.8.6 has a bug of integer divisions.
150 # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
160 # http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
151 return false if ent.is_binary_data?
161 return false if ent.is_binary_data?
152 true
162 true
153 end
163 end
154 private :is_entry_text_data?
164 private :is_entry_text_data?
155
165
156 def annotate
166 def annotate
157 @entry = @repository.entry(@path, @rev)
167 @entry = @repository.entry(@path, @rev)
158 (show_error_not_found; return) unless @entry
168 (show_error_not_found; return) unless @entry
159
169
160 @annotate = @repository.scm.annotate(@path, @rev)
170 @annotate = @repository.scm.annotate(@path, @rev)
161 (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty?
171 (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty?
162 @changeset = @repository.find_changeset_by_name(@rev)
172 @changeset = @repository.find_changeset_by_name(@rev)
163 end
173 end
164
174
165 def revision
175 def revision
166 raise ChangesetNotFound if @rev.blank?
176 raise ChangesetNotFound if @rev.blank?
167 @changeset = @repository.find_changeset_by_name(@rev)
177 @changeset = @repository.find_changeset_by_name(@rev)
168 raise ChangesetNotFound unless @changeset
178 raise ChangesetNotFound unless @changeset
169
179
170 respond_to do |format|
180 respond_to do |format|
171 format.html
181 format.html
172 format.js {render :layout => false}
182 format.js {render :layout => false}
173 end
183 end
174 rescue ChangesetNotFound
184 rescue ChangesetNotFound
175 show_error_not_found
185 show_error_not_found
176 end
186 end
177
187
178 def diff
188 def diff
179 if params[:format] == 'diff'
189 if params[:format] == 'diff'
180 @diff = @repository.diff(@path, @rev, @rev_to)
190 @diff = @repository.diff(@path, @rev, @rev_to)
181 (show_error_not_found; return) unless @diff
191 (show_error_not_found; return) unless @diff
182 filename = "changeset_r#{@rev}"
192 filename = "changeset_r#{@rev}"
183 filename << "_r#{@rev_to}" if @rev_to
193 filename << "_r#{@rev_to}" if @rev_to
184 send_data @diff.join, :filename => "#{filename}.diff",
194 send_data @diff.join, :filename => "#{filename}.diff",
185 :type => 'text/x-patch',
195 :type => 'text/x-patch',
186 :disposition => 'attachment'
196 :disposition => 'attachment'
187 else
197 else
188 @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
198 @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
189 @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
199 @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
190
200
191 # Save diff type as user preference
201 # Save diff type as user preference
192 if User.current.logged? && @diff_type != User.current.pref[:diff_type]
202 if User.current.logged? && @diff_type != User.current.pref[:diff_type]
193 User.current.pref[:diff_type] = @diff_type
203 User.current.pref[:diff_type] = @diff_type
194 User.current.preference.save
204 User.current.preference.save
195 end
205 end
196 @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
206 @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
197 unless read_fragment(@cache_key)
207 unless read_fragment(@cache_key)
198 @diff = @repository.diff(@path, @rev, @rev_to)
208 @diff = @repository.diff(@path, @rev, @rev_to)
199 show_error_not_found unless @diff
209 show_error_not_found unless @diff
200 end
210 end
201
211
202 @changeset = @repository.find_changeset_by_name(@rev)
212 @changeset = @repository.find_changeset_by_name(@rev)
203 @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
213 @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
204 @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
214 @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
205 end
215 end
206 end
216 end
207
217
208 def stats
218 def stats
209 end
219 end
210
220
211 def graph
221 def graph
212 data = nil
222 data = nil
213 case params[:graph]
223 case params[:graph]
214 when "commits_per_month"
224 when "commits_per_month"
215 data = graph_commits_per_month(@repository)
225 data = graph_commits_per_month(@repository)
216 when "commits_per_author"
226 when "commits_per_author"
217 data = graph_commits_per_author(@repository)
227 data = graph_commits_per_author(@repository)
218 end
228 end
219 if data
229 if data
220 headers["Content-Type"] = "image/svg+xml"
230 headers["Content-Type"] = "image/svg+xml"
221 send_data(data, :type => "image/svg+xml", :disposition => "inline")
231 send_data(data, :type => "image/svg+xml", :disposition => "inline")
222 else
232 else
223 render_404
233 render_404
224 end
234 end
225 end
235 end
226
236
227 private
237 private
228
238
229 REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
239 REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
230
240
231 def find_repository
241 def find_repository
232 @project = Project.find(params[:id])
242 @project = Project.find(params[:id])
233 @repository = @project.repository
243 @repository = @project.repository
234 (render_404; return false) unless @repository
244 (render_404; return false) unless @repository
235 @path = params[:path].join('/') unless params[:path].nil?
245 @path = params[:path].join('/') unless params[:path].nil?
236 @path ||= ''
246 @path ||= ''
237 @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip
247 @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip
238 @rev_to = params[:rev_to]
248 @rev_to = params[:rev_to]
239
249
240 unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
250 unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
241 if @repository.branches.blank?
251 if @repository.branches.blank?
242 raise InvalidRevisionParam
252 raise InvalidRevisionParam
243 end
253 end
244 end
254 end
245 rescue ActiveRecord::RecordNotFound
255 rescue ActiveRecord::RecordNotFound
246 render_404
256 render_404
247 rescue InvalidRevisionParam
257 rescue InvalidRevisionParam
248 show_error_not_found
258 show_error_not_found
249 end
259 end
250
260
251 def show_error_not_found
261 def show_error_not_found
252 render_error :message => l(:error_scm_not_found), :status => 404
262 render_error :message => l(:error_scm_not_found), :status => 404
253 end
263 end
254
264
255 # Handler for Redmine::Scm::Adapters::CommandFailed exception
265 # Handler for Redmine::Scm::Adapters::CommandFailed exception
256 def show_error_command_failed(exception)
266 def show_error_command_failed(exception)
257 render_error l(:error_scm_command_failed, exception.message)
267 render_error l(:error_scm_command_failed, exception.message)
258 end
268 end
259
269
260 def graph_commits_per_month(repository)
270 def graph_commits_per_month(repository)
261 @date_to = Date.today
271 @date_to = Date.today
262 @date_from = @date_to << 11
272 @date_from = @date_to << 11
263 @date_from = Date.civil(@date_from.year, @date_from.month, 1)
273 @date_from = Date.civil(@date_from.year, @date_from.month, 1)
264 commits_by_day = repository.changesets.count(
274 commits_by_day = repository.changesets.count(
265 :all, :group => :commit_date,
275 :all, :group => :commit_date,
266 :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
276 :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
267 commits_by_month = [0] * 12
277 commits_by_month = [0] * 12
268 commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
278 commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
269
279
270 changes_by_day = repository.changes.count(
280 changes_by_day = repository.changes.count(
271 :all, :group => :commit_date,
281 :all, :group => :commit_date,
272 :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
282 :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
273 changes_by_month = [0] * 12
283 changes_by_month = [0] * 12
274 changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
284 changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
275
285
276 fields = []
286 fields = []
277 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
287 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
278
288
279 graph = SVG::Graph::Bar.new(
289 graph = SVG::Graph::Bar.new(
280 :height => 300,
290 :height => 300,
281 :width => 800,
291 :width => 800,
282 :fields => fields.reverse,
292 :fields => fields.reverse,
283 :stack => :side,
293 :stack => :side,
284 :scale_integers => true,
294 :scale_integers => true,
285 :step_x_labels => 2,
295 :step_x_labels => 2,
286 :show_data_values => false,
296 :show_data_values => false,
287 :graph_title => l(:label_commits_per_month),
297 :graph_title => l(:label_commits_per_month),
288 :show_graph_title => true
298 :show_graph_title => true
289 )
299 )
290
300
291 graph.add_data(
301 graph.add_data(
292 :data => commits_by_month[0..11].reverse,
302 :data => commits_by_month[0..11].reverse,
293 :title => l(:label_revision_plural)
303 :title => l(:label_revision_plural)
294 )
304 )
295
305
296 graph.add_data(
306 graph.add_data(
297 :data => changes_by_month[0..11].reverse,
307 :data => changes_by_month[0..11].reverse,
298 :title => l(:label_change_plural)
308 :title => l(:label_change_plural)
299 )
309 )
300
310
301 graph.burn
311 graph.burn
302 end
312 end
303
313
304 def graph_commits_per_author(repository)
314 def graph_commits_per_author(repository)
305 commits_by_author = repository.changesets.count(:all, :group => :committer)
315 commits_by_author = repository.changesets.count(:all, :group => :committer)
306 commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
316 commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
307
317
308 changes_by_author = repository.changes.count(:all, :group => :committer)
318 changes_by_author = repository.changes.count(:all, :group => :committer)
309 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
319 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
310
320
311 fields = commits_by_author.collect {|r| r.first}
321 fields = commits_by_author.collect {|r| r.first}
312 commits_data = commits_by_author.collect {|r| r.last}
322 commits_data = commits_by_author.collect {|r| r.last}
313 changes_data = commits_by_author.collect {|r| h[r.first] || 0}
323 changes_data = commits_by_author.collect {|r| h[r.first] || 0}
314
324
315 fields = fields + [""]*(10 - fields.length) if fields.length<10
325 fields = fields + [""]*(10 - fields.length) if fields.length<10
316 commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
326 commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
317 changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
327 changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
318
328
319 # Remove email adress in usernames
329 # Remove email adress in usernames
320 fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
330 fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
321
331
322 graph = SVG::Graph::BarHorizontal.new(
332 graph = SVG::Graph::BarHorizontal.new(
323 :height => 400,
333 :height => 400,
324 :width => 800,
334 :width => 800,
325 :fields => fields,
335 :fields => fields,
326 :stack => :side,
336 :stack => :side,
327 :scale_integers => true,
337 :scale_integers => true,
328 :show_data_values => false,
338 :show_data_values => false,
329 :rotate_y_labels => false,
339 :rotate_y_labels => false,
330 :graph_title => l(:label_commits_per_author),
340 :graph_title => l(:label_commits_per_author),
331 :show_graph_title => true
341 :show_graph_title => true
332 )
342 )
333 graph.add_data(
343 graph.add_data(
334 :data => commits_data,
344 :data => commits_data,
335 :title => l(:label_revision_plural)
345 :title => l(:label_revision_plural)
336 )
346 )
337 graph.add_data(
347 graph.add_data(
338 :data => changes_data,
348 :data => changes_data,
339 :title => l(:label_change_plural)
349 :title => l(:label_change_plural)
340 )
350 )
341 graph.burn
351 graph.burn
342 end
352 end
343 end
353 end
344
354
345 class Date
355 class Date
346 def months_ago(date = Date.today)
356 def months_ago(date = Date.today)
347 (date.year - self.year)*12 + (date.month - self.month)
357 (date.year - self.year)*12 + (date.month - self.month)
348 end
358 end
349
359
350 def weeks_ago(date = Date.today)
360 def weeks_ago(date = Date.today)
351 (date.year - self.year)*52 + (date.cweek - self.cweek)
361 (date.year - self.year)*52 + (date.cweek - self.cweek)
352 end
362 end
353 end
363 end
354
364
355 class String
365 class String
356 def with_leading_slash
366 def with_leading_slash
357 starts_with?('/') ? self : "/#{self}"
367 starts_with?('/') ? self : "/#{self}"
358 end
368 end
359 end
369 end
General Comments 0
You need to be logged in to leave comments. Login now