Track path changes in History. Resolves #1441 (#1443)

* Track path changes in History.
* Reactivate rename following on JRuby
This commit is contained in:
Dawa Ometto
2020-03-16 01:09:42 +01:00
committed by GitHub
parent f516b1cb79
commit ee267f72a2
7 changed files with 43 additions and 23 deletions
-3
View File
@@ -1,10 +1,7 @@
source 'https://rubygems.org' source 'https://rubygems.org'
if RUBY_PLATFORM == 'java' if RUBY_PLATFORM == 'java'
gem 'gollum-rjgit_adapter', :git => 'https://github.com/gollum/rjgit_adapter' # For development purposes
gem 'warbler' gem 'warbler'
else
gem 'gollum-rugged_adapter', :git => 'https://github.com/gollum/rugged_adapter.git' # For development purposes
end end
gem 'gollum-lib', :git => 'https://github.com/gollum/gollum-lib.git', :branch => 'gollum-lib-5.x' # For development purposes gem 'gollum-lib', :git => 'https://github.com/gollum/gollum-lib.git', :branch => 'gollum-lib-5.x' # For development purposes
+16 -12
View File
@@ -92,7 +92,7 @@ module Precious
@redirects_enabled = settings.wiki_options.fetch(:redirects_enabled, true) @redirects_enabled = settings.wiki_options.fetch(:redirects_enabled, true)
@per_page_uploads = settings.wiki_options[:per_page_uploads] @per_page_uploads = settings.wiki_options[:per_page_uploads]
forbid unless @allow_editing || request.request_method == "GET" forbid unless @allow_editing || request.request_method == 'GET'
Precious::App.set(:mustache, {:templates => settings.wiki_options[:template_dir]}) if settings.wiki_options[:template_dir] Precious::App.set(:mustache, {:templates => settings.wiki_options[:template_dir]}) if settings.wiki_options[:template_dir]
@base_url = url('/', false).chomp('/').force_encoding('utf-8') @base_url = url('/', false).chomp('/').force_encoding('utf-8')
@@ -129,7 +129,7 @@ module Precious
env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '') env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '')
if @use_static_assets if @use_static_assets
env['PATH_INFO'].sub!(Sprockets::Helpers.prefix, '') if @base_url env['PATH_INFO'].sub!(Sprockets::Helpers.prefix, '') if @base_url
not_found_msg = "Not found." not_found_msg = 'Not found.'
not_found = Proc.new {[404, {'Content-Type' => 'text/html', 'Content-Length' => not_found_msg.length.to_s}, [not_found_msg]]} not_found = Proc.new {[404, {'Content-Type' => 'text/html', 'Content-Length' => not_found_msg.length.to_s}, [not_found_msg]]}
Rack::Static.new(not_found, {:root => @static_assets_path, :urls => ['']}).call(env) Rack::Static.new(not_found, {:root => @static_assets_path, :urls => ['']}).call(env)
else else
@@ -210,7 +210,7 @@ module Precious
dir = dir.sub(wiki.base_path, '') if wiki.base_path dir = dir.sub(wiki.base_path, '') if wiki.base_path
# remove file extension # remove file extension
dir = dir.sub(::File.extname(dir), '') dir = dir.sub(::File.extname(dir), '')
dir = ::File.join("uploads", dir) dir = ::File.join('uploads', dir)
else else
# store all uploads together # store all uploads together
dir = 'uploads' dir = 'uploads'
@@ -324,8 +324,8 @@ module Precious
get '/create/*' do get '/create/*' do
forbid unless @allow_editing forbid unless @allow_editing
if settings.wiki_options[:template_page] then if settings.wiki_options[:template_page] then
temppage = wiki_page("/_Template") temppage = wiki_page('/_Template')
@template_page = (temppage.page != nil) ? temppage.page.raw_data : "Template page option is set, but no /_Template page is present or committed." @template_page = (temppage.page != nil) ? temppage.page.raw_data : 'Template page option is set, but no /_Template page is present or committed.'
end end
wikip = wiki_page(params[:splat].first) wikip = wiki_page(params[:splat].first)
@name = wikip.name.to_url @name = wikip.name.to_url
@@ -380,8 +380,8 @@ module Precious
else else
sha2, sha1 = sha1, "#{sha1}^" if !sha2 sha2, sha1 = sha1, "#{sha1}^" if !sha2
@versions = [sha1, sha2] @versions = [sha1, sha2]
@diff = wiki.full_reverse_diff_for(@page, @versions.first, @versions.last) @diff = wiki.repo.diff(@versions.first, @versions.last, @page.path)
@message = "The patch does not apply." @message = 'The patch does not apply.'
mustache :compare mustache :compare
end end
end end
@@ -416,8 +416,7 @@ module Precious
@versions = @page.versions( @versions = @page.versions(
per_page: @max_count, per_page: @max_count,
page_num: @page_num, page_num: @page_num,
follow: settings.wiki_options.fetch(:follow_renames, follow: settings.wiki_options.fetch(:follow_renames, true)
::Gollum::GIT_ADAPTER == 'rjgit' ? false : true)
) )
mustache :history mustache :history
else else
@@ -461,8 +460,13 @@ module Precious
@versions = [start_version, end_version] @versions = [start_version, end_version]
wiki = wikip.wiki wiki = wikip.wiki
@page = wikip.page @page = wikip.page
@diff = wiki.full_reverse_diff_for(@page, @versions.first, @versions.last) @diff = wiki.repo.diff(@versions.first, @versions.last, @page.path)
mustache :compare if @diff.empty?
@message = 'Could not compare these two revisions, no differences were found.'
mustache :error
else
mustache :compare
end
end end
get '/search' do get '/search' do
@@ -620,4 +624,4 @@ module Precious
end end
end end
end end
+1 -1
View File
@@ -16,10 +16,10 @@
<form name="gollum-revert" action="{{revert_path}}/{{escaped_url_path}}/{{before}}/{{after}}" method="post" id="gollum-revert-form"></form> <form name="gollum-revert" action="{{revert_path}}/{{escaped_url_path}}/{{before}}/{{after}}" method="post" id="gollum-revert-form"></form>
<span class="pb-4"> <span class="pb-4">
<button class="btn btn-sm" type="submit" onclick="$('#gollum-revert-form').submit()">Revert Changes</button> <button class="btn btn-sm" type="submit" onclick="$('#gollum-revert-form').submit()">Revert Changes</button>
<a href="{{history_path}}/{{escaped_url_path}}" class="btn btn-sm action-page-history">Back to Page History</a>
</span> </span>
{{/allow_editing}} {{/allow_editing}}
{{/show_revert}} {{/show_revert}}
<a href="{{history_path}}/{{escaped_url_path}}" class="btn btn-sm action-page-history">Back to Page History</a>
</div> </div>
<div class="Box data highlight"> <div class="Box data highlight">
+1 -1
View File
@@ -18,7 +18,7 @@
<span class="float-left col-2" id="user-icons">{{>author_template}}</span> <span class="float-left col-2" id="user-icons">{{>author_template}}</span>
<span class="flex-auto col-1 text-gray-light">{{date}}</span> <span class="flex-auto col-1 text-gray-light">{{date}}</span>
<span class="flex-auto col-5">{{message}}</span> <span class="flex-auto col-5">{{message}}</span>
<span class="pl-4 float-right">[<a href="{{base_url}}/{{escaped_url_path}}/{{id}}" title="View commit">{{id7}}</a>]</span> <span class="pl-4 float-right">[<a href="{{base_url}}/{{filename}}/{{id}}" title="View commit">{{id7}}</a>]</span>
</li> </li>
{{/versions}} {{/versions}}
</ul> </ul>
+9 -5
View File
@@ -19,11 +19,15 @@ module Precious
def lines def lines
lines = [] lines = []
@diff.split("\n")[2..-1].each_with_index do |line, line_index| lines_to_parse = @diff.split("\n")[4..-1]
# If the diff is of a rename, the diff header will be one line longer than normal because it will contain a line starting with '+++' to indicate the 'new' filename.
# Make sure to skip that header line if it is present.
lines_to_parse = lines_to_parse[1..-1] if lines_to_parse[0].start_with?('+++')
lines_to_parse.each_with_index do |line, line_index|
lines << { :line => line, lines << { :line => line,
:class => line_class(line), :class => line_class(line),
:ldln => left_diff_line_number(0, line), :ldln => left_diff_line_number(line),
:rdln => right_diff_line_number(0, line) } :rdln => right_diff_line_number(line) }
end if @diff end if @diff
lines lines
end end
@@ -48,7 +52,7 @@ module Precious
@left_diff_line_number = nil @left_diff_line_number = nil
def left_diff_line_number(id, line) def left_diff_line_number(line)
if line =~ /^@@/ if line =~ /^@@/
m, li = *line.match(/\-(\d+)/) m, li = *line.match(/\-(\d+)/)
@left_diff_line_number = li.to_i @left_diff_line_number = li.to_i
@@ -70,7 +74,7 @@ module Precious
@right_diff_line_number = nil @right_diff_line_number = nil
def right_diff_line_number(id, line) def right_diff_line_number(line)
if line =~ /^@@/ if line =~ /^@@/
m, ri = *line.match(/\+(\d+)/) m, ri = *line.match(/\+(\d+)/)
@right_diff_line_number = ri.to_i @right_diff_line_number = ri.to_i
+10
View File
@@ -25,6 +25,7 @@ module Precious
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message, :message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
:date => v.authored_date.strftime("%B %d, %Y"), :date => v.authored_date.strftime("%B %d, %Y"),
:user_icon => self.user_icon_code(v.author.email), :user_icon => self.user_icon_code(v.author.email),
:filename => path_for_version(v.tracked_pathname),
:date_full => v.authored_date, :date_full => v.authored_date,
} }
end end
@@ -33,6 +34,15 @@ module Precious
def editable def editable
@editable @editable
end end
private
def path_for_version(pathname)
@preview_page ||= Gollum::PreviewPage.new(@wiki, '', '', nil)
@preview_page.path = pathname ? pathname : @name
@preview_page.escaped_url_path
end
end end
end end
end end
+6 -1
View File
@@ -19,7 +19,6 @@ context "Frontend" do
assert_equal 'μ†ℱ'.scan(/./), ["μ", "", ""] assert_equal 'μ†ℱ'.scan(/./), ["μ", "", ""]
end end
test "broken four space" do test "broken four space" do
page = 'utfh1' page = 'utfh1'
text = %( text = %(
@@ -468,6 +467,12 @@ context "Frontend" do
post "/gollum/preview", :content => 'abc', :format => 'markdown' post "/gollum/preview", :content => 'abc', :format => 'markdown'
assert last_response.ok? assert last_response.ok?
end end
test 'throws an error when comparing two identical revisions for a page' do
get '/gollum/compare/A.md/fc66539528eb96f21b2bbdbf557788fe8a1196ac...fc66539528eb96f21b2bbdbf557788fe8a1196ac'
assert last_response.ok?
assert last_response.body.include?('Could not compare these two revisions, no differences were found.')
end
=begin =begin
# Grit is broken. # Grit is broken.