[issue #64] Added possibility to diff and revert last commit

This commit is contained in:
George Vinogradov 2012-02-14 18:54:44 +04:00
parent 85723f7da6
commit e9c5273136
3 changed files with 45 additions and 15 deletions

View File

@ -117,19 +117,37 @@ class WikiController < ApplicationController
def compare_wiki
if request.post?
@versions = params[:versions] || []
if @versions.size < 2
redirect_to history_project_wiki_index_path(@project)
else
redirect_to compare_versions_project_wiki_index_path(@project,
sprintf('%s...%s', @versions.last, @versions.first))
versions_string = case @versions.size
when 1 then @versions.first
when 2 then sprintf('%s...%s', @versions.last, @versions.first)
else begin
redirect_to history_project_wiki_index_path(@project) and return
end
end
redirect_to compare_versions_project_wiki_index_path(@project, versions_string)
# if @versions.size < 2
# redirect_to history_project_wiki_index_path(@project)
# else
# redirect_to compare_versions_project_wiki_index_path(@project,
# sprintf('%s...%s', @versions.last, @versions.first))
# end
elsif request.get?
@versions = params[:versions].split(/\.{2,3}/)
if @versions.size < 2
redirect_to history_project_wiki_index_path(@project)
return
@versions = params[:versions].split(/\.{2,3}/) || []
@diffs = case @versions.size
when 1 then @wiki.repo.commit_diff(@versions.first)
when 2 then @wiki.repo.diff(@versions.first, @versions.last)
else begin
redirect_to history_project_wiki_index_path(@project)
return
end
end
@diffs = @wiki.repo.diff(@versions.first, @versions.last)
puts 'DIFFS'
puts @diffs.inspect
# if @versions.size < 2
# redirect_to history_project_wiki_index_path(@project)
# return
# end
# @diffs = @wiki.repo.diff(@versions.first, @versions.last)
render :compare
else
redirect_to project_wiki_path(@project, CGI.escape(@name))
@ -141,8 +159,9 @@ class WikiController < ApplicationController
@page = @wiki.page(@name)
sha1 = params[:sha1]
sha2 = params[:sha2]
sha2 = nil if params[:sha2] == 'prev'
if @wiki.revert_page(@page, sha1, sha2, {:committer => committer}).commit
if c = @wiki.revert_page(@page, sha1, sha2, {:committer => committer}) and c.commit
flash[:notice] = t("flash.wiki.revert_success")
redirect_to project_wiki_path(@project, CGI.escape(@name))
else
@ -162,14 +181,15 @@ class WikiController < ApplicationController
def revert_wiki
sha1 = params[:sha1]
sha2 = params[:sha2]
if @wiki.revert_commit(sha1, sha2, {:committer => committer}).commit
sha2 = nil if sha2 == 'prev'
if c = @wiki.revert_commit(sha1, sha2, {:committer => committer}) and c.commit
flash[:notice] = t("flash.wiki.revert_success")
redirect_to project_wiki_index_path(@project)
else
sha2, sha1 = sha1, "#{sha1}^" if !sha2
@versions = [sha1, sha2]
diffs = @wiki.repo.diff(@versions.first, @versions.last)
@diffs = [diffs.first]
@diffs = @wiki.repo.diff(@versions.first, @versions.last)
# @diffs = [diffs.first]
flash[:error] = t("flash.wiki.patch_does_not_apply")
render :compare
end

View File

@ -5,7 +5,7 @@
- if action_name != 'revert'
%ul.actions
%li.minibutton
= form_tag revert_path(@project, @versions[0][0..6], @versions[1][0..6], @name),
= form_tag revert_path(@project, @versions.first[0..6], (@versions.size == 1) ? 'prev' : @versions.last[0..6], @name),
:name => "gollum-revert", :id => "gollum-revert-form" do
= revert_button if can? :write, @project

View File

@ -47,6 +47,8 @@ module Gollum
multi_commit = false
patch = full_reverse_diff_for(page, sha1, sha2)
puts 'patch'
puts patch
committer = if obj = commit[:committer]
multi_commit = true
obj
@ -83,10 +85,18 @@ module Gollum
end
end
puts 'IN MY RELOADED FILE'
multi_commit ? committer : committer.commit
end
alias_method_chain :revert_page, :committer
def revert_commit_with_committer(sha1, sha2 = nil, commit = {})
puts "i'm here"
revert_page_with_committer(nil, sha1, sha2, commit)
end
alias_method_chain :revert_commit, :committer
private
def force_grit_encoding(str)