##// END OF EJS Templates
Fixed: error when viewing a file diff from a revision view (only if repository url doesn't point to the root of the repository)....
Jean-Philippe Lang -
r525:75582f80f855
parent child
Show More
@@ -1,213 +1,213
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 RepositoriesController < ApplicationController
23 23 layout 'base'
24 24 before_filter :find_project
25 25 before_filter :authorize, :except => [:stats, :graph]
26 26 before_filter :check_project_privacy, :only => [:stats, :graph]
27 27
28 28 def show
29 29 # get entries for the browse frame
30 30 @entries = @repository.scm.entries('')
31 31 show_error and return unless @entries
32 32 # check if new revisions have been committed in the repository
33 33 scm_latestrev = @entries.revisions.latest
34 34 if Setting.autofetch_changesets? && scm_latestrev && ((@repository.latest_changeset.nil?) || (@repository.latest_changeset.revision < scm_latestrev.identifier.to_i))
35 35 @repository.fetch_changesets
36 36 @repository.reload
37 37 end
38 38 @changesets = @repository.changesets.find(:all, :limit => 5, :order => "committed_on DESC")
39 39 end
40 40
41 41 def browse
42 42 @entries = @repository.scm.entries(@path, @rev)
43 43 show_error and return unless @entries
44 44 end
45 45
46 46 def revisions
47 47 unless @path == ''
48 48 @entry = @repository.scm.entry(@path, @rev)
49 49 show_error and return unless @entry
50 50 end
51 51 @repository.changesets_with_path @path do
52 52 @changeset_count = @repository.changesets.count
53 53 @changeset_pages = Paginator.new self, @changeset_count,
54 54 25,
55 55 params['page']
56 56 @changesets = @repository.changesets.find(:all,
57 57 :limit => @changeset_pages.items_per_page,
58 58 :offset => @changeset_pages.current.offset)
59 59 end
60 60 render :action => "revisions", :layout => false if request.xhr?
61 61 end
62 62
63 63 def entry
64 64 @content = @repository.scm.cat(@path, @rev)
65 65 show_error and return unless @content
66 66 if 'raw' == params[:format]
67 67 send_data @content, :filename => @path.split('/').last
68 68 end
69 69 end
70 70
71 71 def revision
72 72 @changeset = @repository.changesets.find_by_revision(@rev)
73 73 show_error and return unless @changeset
74 74 end
75 75
76 76 def diff
77 77 @rev_to = (params[:rev_to] && params[:rev_to].to_i > 0) ? params[:rev_to].to_i : (@rev - 1)
78 78 @diff_type = ('sbs' == params[:type]) ? 'sbs' : 'inline'
79 79
80 80 @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
81 81 unless read_fragment(@cache_key)
82 82 @diff = @repository.scm.diff(@path, @rev, @rev_to, type)
83 83 show_error and return unless @diff
84 84 end
85 85 end
86 86
87 87 def stats
88 88 end
89 89
90 90 def graph
91 91 data = nil
92 92 case params[:graph]
93 93 when "commits_per_month"
94 94 data = graph_commits_per_month(@repository)
95 95 when "commits_per_author"
96 96 data = graph_commits_per_author(@repository)
97 97 end
98 98 if data
99 99 headers["Content-Type"] = "image/svg+xml"
100 100 send_data(data, :type => "image/svg+xml", :disposition => "inline")
101 101 else
102 102 render_404
103 103 end
104 104 end
105 105
106 106 private
107 107 def find_project
108 108 @project = Project.find(params[:id])
109 109 @repository = @project.repository
110 110 render_404 and return false unless @repository
111 @path = params[:path].squeeze('/').gsub(/^\//, '') if params[:path]
111 @path = params[:path].squeeze('/') if params[:path]
112 112 @path ||= ''
113 113 @rev = params[:rev].to_i if params[:rev] and params[:rev].to_i > 0
114 114 rescue ActiveRecord::RecordNotFound
115 115 render_404
116 116 end
117 117
118 118 def show_error
119 119 flash.now[:notice] = l(:notice_scm_error)
120 120 render :nothing => true, :layout => true
121 121 end
122 122
123 123 def graph_commits_per_month(repository)
124 124 @date_to = Date.today
125 125 @date_from = @date_to << 12
126 126 commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
127 127 commits_by_month = [0] * 12
128 128 commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last }
129 129
130 130 changes_by_day = repository.changes.count(:all, :group => :commit_date)
131 131 changes_by_month = [0] * 12
132 132 changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
133 133
134 134 fields = []
135 135 month_names = l(:actionview_datehelper_select_month_names_abbr).split(',')
136 136 12.times {|m| fields << month_names[((Date.today.month - 1 - m) % 12)]}
137 137
138 138 graph = SVG::Graph::Bar.new(
139 139 :height => 300,
140 140 :width => 500,
141 141 :fields => fields.reverse,
142 142 :stack => :side,
143 143 :scale_integers => true,
144 144 :step_x_labels => 2,
145 145 :show_data_values => false,
146 146 :graph_title => l(:label_commits_per_month),
147 147 :show_graph_title => true
148 148 )
149 149
150 150 graph.add_data(
151 151 :data => commits_by_month[0..11].reverse,
152 152 :title => l(:label_revision_plural)
153 153 )
154 154
155 155 graph.add_data(
156 156 :data => changes_by_month[0..11].reverse,
157 157 :title => l(:label_change_plural)
158 158 )
159 159
160 160 graph.burn
161 161 end
162 162
163 163 def graph_commits_per_author(repository)
164 164 commits_by_author = repository.changesets.count(:all, :group => :committer)
165 165 commits_by_author.sort! {|x, y| x.last <=> y.last}
166 166
167 167 changes_by_author = repository.changes.count(:all, :group => :committer)
168 168 h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
169 169
170 170 fields = commits_by_author.collect {|r| r.first}
171 171 commits_data = commits_by_author.collect {|r| r.last}
172 172 changes_data = commits_by_author.collect {|r| h[r.first] || 0}
173 173
174 174 fields = fields + [""]*(10 - fields.length) if fields.length<10
175 175 commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
176 176 changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
177 177
178 178 graph = SVG::Graph::BarHorizontal.new(
179 179 :height => 300,
180 180 :width => 500,
181 181 :fields => fields,
182 182 :stack => :side,
183 183 :scale_integers => true,
184 184 :show_data_values => false,
185 185 :rotate_y_labels => false,
186 186 :graph_title => l(:label_commits_per_author),
187 187 :show_graph_title => true
188 188 )
189 189
190 190 graph.add_data(
191 191 :data => commits_data,
192 192 :title => l(:label_revision_plural)
193 193 )
194 194
195 195 graph.add_data(
196 196 :data => changes_data,
197 197 :title => l(:label_change_plural)
198 198 )
199 199
200 200 graph.burn
201 201 end
202 202
203 203 end
204 204
205 205 class Date
206 206 def months_ago(date = Date.today)
207 207 (date.year - self.year)*12 + (date.month - self.month)
208 208 end
209 209
210 210 def weeks_ago(date = Date.today)
211 211 (date.year - self.year)*52 + (date.cweek - self.cweek)
212 212 end
213 213 end
General Comments 0
You need to be logged in to leave comments. Login now