diff --git a/Gemfile b/Gemfile index 95707df3..ba61a1d1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,7 @@ source 'https://rubygems.org' if RUBY_PLATFORM == 'java' - gem 'gollum-rjgit_adapter', :git => 'https://github.com/gollum/rjgit_adapter' # For development purposes gem 'warbler' -else - gem 'gollum-rugged_adapter', :git => 'https://github.com/gollum/rugged_adapter.git' # For development purposes end gem 'gollum-lib', :git => 'https://github.com/gollum/gollum-lib.git', :branch => 'gollum-lib-5.x' # For development purposes diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index b283df48..8d4abd89 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -92,7 +92,7 @@ module Precious @redirects_enabled = settings.wiki_options.fetch(:redirects_enabled, true) @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] @base_url = url('/', false).chomp('/').force_encoding('utf-8') @@ -129,7 +129,7 @@ module Precious env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '') if @use_static_assets 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]]} Rack::Static.new(not_found, {:root => @static_assets_path, :urls => ['']}).call(env) else @@ -210,7 +210,7 @@ module Precious dir = dir.sub(wiki.base_path, '') if wiki.base_path # remove file extension dir = dir.sub(::File.extname(dir), '') - dir = ::File.join("uploads", dir) + dir = ::File.join('uploads', dir) else # store all uploads together dir = 'uploads' @@ -324,8 +324,8 @@ module Precious get '/create/*' do forbid unless @allow_editing if settings.wiki_options[:template_page] then - 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." + 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.' end wikip = wiki_page(params[:splat].first) @name = wikip.name.to_url @@ -380,8 +380,8 @@ module Precious else sha2, sha1 = sha1, "#{sha1}^" if !sha2 @versions = [sha1, sha2] - @diff = wiki.full_reverse_diff_for(@page, @versions.first, @versions.last) - @message = "The patch does not apply." + @diff = wiki.repo.diff(@versions.first, @versions.last, @page.path) + @message = 'The patch does not apply.' mustache :compare end end @@ -416,8 +416,7 @@ module Precious @versions = @page.versions( per_page: @max_count, page_num: @page_num, - follow: settings.wiki_options.fetch(:follow_renames, - ::Gollum::GIT_ADAPTER == 'rjgit' ? false : true) + follow: settings.wiki_options.fetch(:follow_renames, true) ) mustache :history else @@ -461,8 +460,13 @@ module Precious @versions = [start_version, end_version] wiki = wikip.wiki @page = wikip.page - @diff = wiki.full_reverse_diff_for(@page, @versions.first, @versions.last) - mustache :compare + @diff = wiki.repo.diff(@versions.first, @versions.last, @page.path) + if @diff.empty? + @message = 'Could not compare these two revisions, no differences were found.' + mustache :error + else + mustache :compare + end end get '/search' do @@ -620,4 +624,4 @@ module Precious end end -end +end \ No newline at end of file diff --git a/lib/gollum/templates/compare.mustache b/lib/gollum/templates/compare.mustache index 03934bc9..bd5950e3 100644 --- a/lib/gollum/templates/compare.mustache +++ b/lib/gollum/templates/compare.mustache @@ -16,10 +16,10 @@
- Back to Page History {{/allow_editing}} {{/show_revert}} + Back to Page History
diff --git a/lib/gollum/templates/history.mustache b/lib/gollum/templates/history.mustache index fe3138bf..3429e868 100644 --- a/lib/gollum/templates/history.mustache +++ b/lib/gollum/templates/history.mustache @@ -18,7 +18,7 @@ {{>author_template}} {{date}} {{message}} - [{{id7}}] + [{{id7}}] {{/versions}} diff --git a/lib/gollum/views/compare.rb b/lib/gollum/views/compare.rb index 01352cbf..f4ca21d9 100644 --- a/lib/gollum/views/compare.rb +++ b/lib/gollum/views/compare.rb @@ -19,11 +19,15 @@ module Precious def 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, :class => line_class(line), - :ldln => left_diff_line_number(0, line), - :rdln => right_diff_line_number(0, line) } + :ldln => left_diff_line_number(line), + :rdln => right_diff_line_number(line) } end if @diff lines end @@ -48,7 +52,7 @@ module Precious @left_diff_line_number = nil - def left_diff_line_number(id, line) + def left_diff_line_number(line) if line =~ /^@@/ m, li = *line.match(/\-(\d+)/) @left_diff_line_number = li.to_i @@ -70,7 +74,7 @@ module Precious @right_diff_line_number = nil - def right_diff_line_number(id, line) + def right_diff_line_number(line) if line =~ /^@@/ m, ri = *line.match(/\+(\d+)/) @right_diff_line_number = ri.to_i diff --git a/lib/gollum/views/history.rb b/lib/gollum/views/history.rb index 9cb40f41..d362c269 100644 --- a/lib/gollum/views/history.rb +++ b/lib/gollum/views/history.rb @@ -25,6 +25,7 @@ module Precious :message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message, :date => v.authored_date.strftime("%B %d, %Y"), :user_icon => self.user_icon_code(v.author.email), + :filename => path_for_version(v.tracked_pathname), :date_full => v.authored_date, } end @@ -33,6 +34,15 @@ module Precious def editable @editable 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 diff --git a/test/test_app.rb b/test/test_app.rb index 92274b5d..d7555414 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -19,7 +19,6 @@ context "Frontend" do assert_equal 'μ†ℱ'.scan(/./), ["μ", "†", "ℱ"] end - test "broken four space" do page = 'utfh1' text = %( @@ -468,6 +467,12 @@ context "Frontend" do post "/gollum/preview", :content => 'abc', :format => 'markdown' assert last_response.ok? 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 # Grit is broken.