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