Class: RepositoriesController

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

Instance Method Summary

Methods inherited from ApplicationController

accept_key_auth, #accept_key_auth_actions, #api_request?, #authorize, #authorize_global, #check_if_login_required, #check_project_privacy, #delete_broken_cookies, #deny_access, #filename_for_content_disposition, #find_current_user, #find_model_object, #find_project, #find_project_from_association, #invalid_authenticity_token, #logged_user=, model_object, #parse_qvalues, #per_page_option, #redirect_back_or_default, #render_403, #render_404, #render_attachment_warning_if_needed, #render_error, #render_feed, #require_admin, #require_login, #set_localization, #user_setup

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

Methods included from Redmine::Search::Controller

#default_search_scope, #default_search_scopes, included

Methods included from Redmine::MenuManager::MenuController

#current_menu_item, included, #menu_items, #redirect_to_project_menu_item

Instance Method Details

- (Object) annotate



126
127
128
129
130
131
132
# File 'app/controllers/repositories_controller.rb', line 126

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?
end

- (Object) changes



85
86
87
88
89
90
# File 'app/controllers/repositories_controller.rb', line 85

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)
end

- (Object) committers



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/repositories_controller.rb', line 49

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

- (Object) destroy



64
65
66
67
# File 'app/controllers/repositories_controller.rb', line 64

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

- (Object) diff



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/controllers/repositories_controller.rb', line 146

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
  end
end

- (Object) edit



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/repositories_controller.rb', line 36

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) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'}
end

- (Object) entry



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/controllers/repositories_controller.rb', line 108

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.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte)
    # Force the download
    send_data @content, :filename => @path.split('/').last
  else
    # Prevent empty lines when displaying a file with Windows style eol
    @content.gsub!("\r\n", "\n")
 end
end

- (Object) graph



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'app/controllers/repositories_controller.rb', line 176

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

- (Object) revision

Raises:



134
135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/repositories_controller.rb', line 134

def revision
  @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

- (Object) revisions



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/controllers/repositories_controller.rb', line 92

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

- (Object) show Also known as: browse



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/repositories_controller.rb', line 69

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

  @entries = @repository.entries(@path, @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

- (Object) stats



173
174
# File 'app/controllers/repositories_controller.rb', line 173

def stats  
end