Class: RepositoriesController

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

Instance Method Summary collapse

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


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

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


90
91
92
93
94
95
96
# File 'app/controllers/repositories_controller.rb', line 90

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


53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/repositories_controller.rb', line 53

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


68
69
70
71
# File 'app/controllers/repositories_controller.rb', line 68

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

#diffObject


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
207
208
# File 'app/controllers/repositories_controller.rb', line 179

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


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

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


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

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


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

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


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

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


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/repositories_controller.rb', line 98

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


73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/repositories_controller.rb', line 73

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


210
211
# File 'app/controllers/repositories_controller.rb', line 210

def stats
end