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