Fixed that git diff displays deleted files as /dev/null (#11868).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10424 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
74f7fc38f0
commit
12de6a177a
@ -15,7 +15,7 @@
|
|||||||
:onchange => "if (this.value != '') {this.form.submit()}" %>
|
:onchange => "if (this.value != '') {this.form.submit()}" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %>
|
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type, :diff_style => nil} %>
|
||||||
|
|
||||||
<% html_title @attachment.filename %>
|
<% html_title @attachment.filename %>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<% diff = Redmine::UnifiedDiff.new(
|
<% diff = Redmine::UnifiedDiff.new(
|
||||||
diff, :type => diff_type,
|
diff, :type => diff_type,
|
||||||
:max_lines => Setting.diff_max_lines_displayed.to_i) -%>
|
:max_lines => Setting.diff_max_lines_displayed.to_i,
|
||||||
|
:style => diff_style) -%>
|
||||||
|
|
||||||
<% diff.each do |table_file| -%>
|
<% diff.each do |table_file| -%>
|
||||||
<div class="autoscroll">
|
<div class="autoscroll">
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% cache(@cache_key) do -%>
|
<% cache(@cache_key) do -%>
|
||||||
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type} %>
|
<%= render :partial => 'common/diff', :locals => {:diff => @diff, :diff_type => @diff_type, :diff_style => @repository.class.scm_name} %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
<% other_formats_links do |f| %>
|
<% other_formats_links do |f| %>
|
||||||
|
@ -18,15 +18,16 @@
|
|||||||
module Redmine
|
module Redmine
|
||||||
# Class used to parse unified diffs
|
# Class used to parse unified diffs
|
||||||
class UnifiedDiff < Array
|
class UnifiedDiff < Array
|
||||||
attr_reader :diff_type
|
attr_reader :diff_type, :diff_style
|
||||||
|
|
||||||
def initialize(diff, options={})
|
def initialize(diff, options={})
|
||||||
options.assert_valid_keys(:type, :max_lines)
|
options.assert_valid_keys(:type, :style, :max_lines)
|
||||||
diff = diff.split("\n") if diff.is_a?(String)
|
diff = diff.split("\n") if diff.is_a?(String)
|
||||||
@diff_type = options[:type] || 'inline'
|
@diff_type = options[:type] || 'inline'
|
||||||
|
@diff_style = options[:style]
|
||||||
lines = 0
|
lines = 0
|
||||||
@truncated = false
|
@truncated = false
|
||||||
diff_table = DiffTable.new(@diff_type)
|
diff_table = DiffTable.new(diff_type, diff_style)
|
||||||
diff.each do |line|
|
diff.each do |line|
|
||||||
line_encoding = nil
|
line_encoding = nil
|
||||||
if line.respond_to?(:force_encoding)
|
if line.respond_to?(:force_encoding)
|
||||||
@ -39,7 +40,7 @@ module Redmine
|
|||||||
unless diff_table.add_line line
|
unless diff_table.add_line line
|
||||||
line.force_encoding(line_encoding) if line_encoding
|
line.force_encoding(line_encoding) if line_encoding
|
||||||
self << diff_table if diff_table.length > 0
|
self << diff_table if diff_table.length > 0
|
||||||
diff_table = DiffTable.new(diff_type)
|
diff_table = DiffTable.new(diff_type, diff_style)
|
||||||
end
|
end
|
||||||
lines += 1
|
lines += 1
|
||||||
if options[:max_lines] && lines > options[:max_lines]
|
if options[:max_lines] && lines > options[:max_lines]
|
||||||
@ -60,11 +61,13 @@ module Redmine
|
|||||||
|
|
||||||
# Initialize with a Diff file and the type of Diff View
|
# Initialize with a Diff file and the type of Diff View
|
||||||
# The type view must be inline or sbs (side_by_side)
|
# The type view must be inline or sbs (side_by_side)
|
||||||
def initialize(type="inline")
|
def initialize(type="inline", style=nil)
|
||||||
@parsing = false
|
@parsing = false
|
||||||
@added = 0
|
@added = 0
|
||||||
@removed = 0
|
@removed = 0
|
||||||
@type = type
|
@type = type
|
||||||
|
@style = style
|
||||||
|
@file_name = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Function for add a line of this Diff
|
# Function for add a line of this Diff
|
||||||
@ -72,7 +75,7 @@ module Redmine
|
|||||||
def add_line(line)
|
def add_line(line)
|
||||||
unless @parsing
|
unless @parsing
|
||||||
if line =~ /^(---|\+\+\+) (.*)$/
|
if line =~ /^(---|\+\+\+) (.*)$/
|
||||||
@file_name = $2
|
self.file_name = $2
|
||||||
elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
|
elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/
|
||||||
@line_num_l = $2.to_i
|
@line_num_l = $2.to_i
|
||||||
@line_num_r = $5.to_i
|
@line_num_r = $5.to_i
|
||||||
@ -112,6 +115,20 @@ module Redmine
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def file_name=(arg)
|
||||||
|
case @style
|
||||||
|
when "Git"
|
||||||
|
if file_name && arg == "/dev/null"
|
||||||
|
# keep the original file name
|
||||||
|
else
|
||||||
|
# remove leading a/ b/
|
||||||
|
@file_name = arg.sub(%r{^(a|b)/}, '')
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@file_name = arg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def diff_for_added_line
|
def diff_for_added_line
|
||||||
if @type == 'sbs' && @removed > 0 && @added < @removed
|
if @type == 'sbs' && @removed > 0 && @added < @removed
|
||||||
self[-(@removed - @added)]
|
self[-(@removed - @added)]
|
||||||
|
@ -384,6 +384,16 @@ class RepositoriesGitControllerTest < ActionController::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_diff_should_show_filenames
|
||||||
|
get :diff, :id => PRJ_ID, :rev => 'deff712f05a90d96edbd70facc47d944be5897e3', :type => 'inline'
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'diff'
|
||||||
|
# modified file
|
||||||
|
assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
|
||||||
|
# deleted file
|
||||||
|
assert_select 'th.filename', :text => 'test.txt'
|
||||||
|
end
|
||||||
|
|
||||||
def test_save_diff_type
|
def test_save_diff_type
|
||||||
@request.session[:user_id] = 1 # admin
|
@request.session[:user_id] = 1 # admin
|
||||||
user = User.find(1)
|
user = User.find(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user