Class: RepositoriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/repositories_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

accept_key_auth, #accept_key_auth_actions, #api_key_from_request, #api_offset_and_limit, #api_request?, #authorize, #authorize_global, #back_url, #check_if_login_required, #check_project_privacy, #check_project_uniqueness, #default_template, #delete_broken_cookies, #deny_access, #filename_for_content_disposition, #find_current_user, #find_issues, #find_model_object, #find_optional_project, #find_project, #find_project_by_project_id, #find_project_from_association, #invalid_authenticity_token, #logged_user=, model_object, #object_errors_to_json, #parse_qvalues, #per_page_option, #pick_layout, #query_statement_invalid, #redirect_back_or_default, #render_403, #render_404, #render_attachment_warning_if_needed, #render_error, #render_feed, #render_validation_errors, #require_admin, #require_login, #set_flash_from_bulk_issue_save, #set_localization, #use_layout, #user_setup

Methods included from Redmine::MenuManager::MenuController

#current_menu_item, included, #menu_items, #redirect_to_project_menu_item

Methods included from Redmine::Search::Controller

#default_search_scope, #default_search_scopes, included

Methods included from Redmine::I18n

#current_language, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #ll, #month_name, #set_language_if_valid, #valid_languages

Instance Method Details

#annotateObject



155
156
157
158
159
160
161
162
# File 'app/controllers/repositories_controller.rb', line 155

def annotate
  @entry = @repository.entry(@path, @rev)
  (show_error_not_found; return) unless @entry

  @annotate = @repository.scm.annotate(@path, @rev)
  (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty?
  @changeset = @repository.find_changeset_by_name(@rev)
end

#changesObject



93
94
95
96
97
98
99
# File 'app/controllers/repositories_controller.rb', line 93

def changes
  @entry = @repository.entry(@path, @rev)
  (show_error_not_found; return) unless @entry
  @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
  @properties = @repository.properties(@path, @rev)
  @changeset = @repository.find_changeset_by_name(@rev)
end

#committersObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/repositories_controller.rb', line 56

def committers
  @committers = @repository.committers
  @users = @project.users
  additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
  @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
  @users.compact!
  @users.sort!
  if request.post? && params[:committers].is_a?(Hash)
    # Build a hash with repository usernames as keys and corresponding user ids as values
    @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
    flash[:notice] = l(:notice_successful_update)
    redirect_to :action => 'committers', :id => @project
  end
end

#destroyObject



71
72
73
74
# File 'app/controllers/repositories_controller.rb', line 71

def destroy
  @repository.destroy
  redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
end

#diffObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'app/controllers/repositories_controller.rb', line 177

def diff
  if params[:format] == 'diff'
    @diff = @repository.diff(@path, @rev, @rev_to)
    (show_error_not_found; return) unless @diff
    filename = "changeset_r#{@rev}"
    filename << "_r#{@rev_to}" if @rev_to
    send_data @diff.join, :filename => "#{filename}.diff",
                          :type => 'text/x-patch',
                          :disposition => 'attachment'
  else
    @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
    @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
    
    # Save diff type as user preference
    if User.current.logged? && @diff_type != User.current.pref[:diff_type]
      User.current.pref[:diff_type] = @diff_type
      User.current.preference.save
    end
    
    @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")    
    unless read_fragment(@cache_key)
      @diff = @repository.diff(@path, @rev, @rev_to)
      show_error_not_found unless @diff
    end

    @changeset = @repository.find_changeset_by_name(@rev)
    @changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
    @diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
  end
end

#editObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/repositories_controller.rb', line 37

def edit
  @repository = @project.repository
  if !@repository
    @repository = Repository.factory(params[:repository_scm])
    @repository.project = @project if @repository
  end
  if request.post? && @repository
    @repository.attributes = params[:repository]
    @repository.save
  end
  render(:update) do |page|
    page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'
    if @repository && !@project.repository
      @project.reload #needed to reload association
      page.replace_html "main-menu", render_main_menu(@project)
    end
  end
end

#entryObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'app/controllers/repositories_controller.rb', line 117

def entry
  @entry = @repository.entry(@path, @rev)
  (show_error_not_found; return) unless @entry

  # If the entry is a dir, show the browser
  (show; return) if @entry.is_dir?

  @content = @repository.cat(@path, @rev)
  (show_error_not_found; return) unless @content
  if 'raw' == params[:format] ||
       (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
       ! is_entry_text_data?(@content, @path)
    # Force the download
    send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
    send_type = Redmine::MimeType.of(@path)
    send_opt[:type] = send_type.to_s if send_type
    send_data @content, send_opt
  else
    # Prevent empty lines when displaying a file with Windows style eol
    # TODO: UTF-16
    # Is this needs? AttachmentsController reads file simply.
    @content.gsub!("\r\n", "\n")
    @changeset = @repository.find_changeset_by_name(@rev)
  end
end

#graphObject



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'app/controllers/repositories_controller.rb', line 211

def graph
  data = nil
  case params[:graph]
  when "commits_per_month"
    data = graph_commits_per_month(@repository)
  when "commits_per_author"
    data = graph_commits_per_author(@repository)
  end
  if data
    headers["Content-Type"] = "image/svg+xml"
    send_data(data, :type => "image/svg+xml", :disposition => "inline")
  else
    render_404
  end
end

#revisionObject



164
165
166
167
168
169
170
171
172
173
174
175
# File 'app/controllers/repositories_controller.rb', line 164

def revision
  raise ChangesetNotFound if @rev.blank?
  @changeset = @repository.find_changeset_by_name(@rev)
  raise ChangesetNotFound unless @changeset

  respond_to do |format|
    format.html
    format.js {render :layout => false}
  end
rescue ChangesetNotFound
  show_error_not_found
end

#revisionsObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/controllers/repositories_controller.rb', line 101

def revisions
  @changeset_count = @repository.changesets.count
  @changeset_pages = Paginator.new self, @changeset_count,
                                   per_page_option,
                                   params['page']
  @changesets = @repository.changesets.find(:all,
                     :limit  =>  @changeset_pages.items_per_page,
                     :offset =>  @changeset_pages.current.offset,
                     :include => [:user, :repository])

  respond_to do |format|
    format.html { render :layout => false if request.xhr? }
    format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
  end
end

#showObject Also known as: browse



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/repositories_controller.rb', line 76

def show
  @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?

  @entries = @repository.entries(@path, @rev)
  @changeset = @repository.find_changeset_by_name(@rev)
  if request.xhr?
    @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
  else
    (show_error_not_found; return) unless @entries
    @changesets = @repository.latest_changesets(@path, @rev)
    @properties = @repository.properties(@path, @rev)
    render :action => 'show'
  end
end

#statsObject



208
209
# File 'app/controllers/repositories_controller.rb', line 208

def stats
end