class GitHelpers::GitDiffHighlight
stolen from diff-highlight git contrib script
Public Instance Methods
end_hunk()
click to toggle source
Calls superclass method
GitHelpers::GitDiff#end_hunk
# File lib/git_helpers/diff.rb, line 426 def end_hunk super show_hunk end
handle_line()
click to toggle source
# File lib/git_helpers/diff.rb, line 464 def handle_line if @mode == :hunk && @hunk[:n]==2 linemode=@line[0] case linemode when "-" @accumulator[0] << @orig_line when "+" @accumulator[1] << @orig_line else show_hunk @accumulator=[[],[]] output_line @orig_line end else output_line @orig_line end end
highlight_pair(old,new)
click to toggle source
# File lib/git_helpers/diff.rb, line 431 def highlight_pair(old,new) oldc=SimpleColor.color_entities(old).each_with_index newc=SimpleColor.color_entities(new).each_with_index seen_pm=false #find common prefix loop do a=oldc.grep {|c| ! SimpleColor.color?(c)} b=newc.grep {|c| ! SimpleColor.color?(c)} if !seen_pm and a=="-" and b=="+" seen_pm=true elsif a==b else last end #rescue StopIteration end end
new_hunk()
click to toggle source
Calls superclass method
GitHelpers::GitDiff#new_hunk
# File lib/git_helpers/diff.rb, line 422 def new_hunk super @accumulator=[[],[]] end
show_hunk()
click to toggle source
# File lib/git_helpers/diff.rb, line 449 def show_hunk old,new=@accumulator if old.length != new.length output_lines(old+new) else newhunk=[] (0...old.length).each do |i| oldi,newi=highlight_pair(old[i],new[i]) output_line oldi newhunk << newi end output_lines(newhunk) end end