class GitHelpers::GitFancyDiff
Public Class Methods
new(*args,**kw,&b)
click to toggle source
Calls superclass method
GitHelpers::GitDiff::new
# File lib/git_helpers/diff.rb, line 485 def initialize(*args,**kw,&b) super #when run inside a pager I get one more column so the line overflow #I don't know why cols=`tput cols`.to_i cols==0 && cols=80 #if TERM is not defined `tput cols` returns '' @cols=cols-1 end
Public Instance Methods
binary_file_differ()
click to toggle source
# File lib/git_helpers/diff.rb, line 628 def binary_file_differ @file and (@file[:mode]==:new && @line =~ %r{^Binary files /dev/null and ./#{@file[:name]} differ$} or @file[:mode]==:delete && @line =~ %r{^Binary files ./#{@file[:old_name]} and /dev/null differ$}) end
clean_hunk_col()
click to toggle source
# File lib/git_helpers/diff.rb, line 602 def clean_hunk_col if @opts[:color] && @mode==:hunk && !@start_mode && @hunk[:n]==2 bcolor,ecolor,line=SimpleColor.current_colors(@orig_line) m=line.scrub.match(/^([+-])?(.*)/) mode=m[1] cline=m[2] if mode && cline !~ /[^[:space:]]/ #detect blank line output_line SimpleColor.color(bcolor.to_s + (cline.empty? ? " ": cline)+ecolor.to_s,:inverse) else cline.sub!(/^\s/,'') unless mode #strip one blank character output_line bcolor.to_s+cline+ecolor.to_s end true end end
diff_header_summary()
click to toggle source
# File lib/git_helpers/diff.rb, line 532 def diff_header_summary r=case @file[:mode] when :modify "modified: #{@file[:name]}" when :rewrite "rewrote: #{@file[:name]} (dissimilarity: #{@file[:dissimilarity]})" when :new "added#{perm_mode(@file[:new_perm])}: #{@file[:name]}" when :delete "deleted#{perm_mode(@file[:old_perm])}: #{@file[:old_name]}" when :rename "renamed: #{@file[:old_name]} to #{@file[:name]} (similarity: #{@file[:similarity]})" when :copy "copied: #{@file[:old_name]} to #{@file[:name]} (similarity: #{@file[:similarity]})" end r<<" [#{short_perm_mode(@file[:old_perm],prefix:'-')}#{short_perm_mode(@file[:new_perm])}]" if @file[:old_perm] && @file[:new_perm] r end
end_commit()
click to toggle source
Calls superclass method
GitHelpers::GitDiff#end_commit
# File lib/git_helpers/diff.rb, line 597 def end_commit super output_line meta_colorize(hhline) end
end_diff_header()
click to toggle source
Calls superclass method
GitHelpers::GitDiff#end_diff_header
# File lib/git_helpers/diff.rb, line 564 def end_diff_header super output_line meta_colorize(diff_header_summary) output_line meta_colorize(hline) end
end_submodule_header()
click to toggle source
Calls superclass method
GitHelpers::GitDiff#end_submodule_header
# File lib/git_helpers/diff.rb, line 583 def end_submodule_header super output_line meta_colorize(submodule_header_summary) output_line meta_colorize(hline) end
handle_line()
click to toggle source
Calls superclass method
GitHelpers::GitDiff#handle_line
# File lib/git_helpers/diff.rb, line 633 def handle_line super #:diff_header and submodule_header are handled at end_* case @mode when :meta if binary_file_differ else output_line @orig_line end when :hunk if hunk_header elsif nonewline_clean elsif clean_hunk_col else output_line @orig_line end when :submodule,:commit output_line @orig_line end end
hhline()
click to toggle source
# File lib/git_helpers/diff.rb, line 497 def hhline #'⬛'*@cols #"━"*@cols "═"*@cols end
hline()
click to toggle source
# File lib/git_helpers/diff.rb, line 494 def hline '─'*@cols end
hunk_header()
click to toggle source
# File lib/git_helpers/diff.rb, line 618 def hunk_header if @mode==:hunk && @start_mode if @hunk[:lines][0][1] && @hunk[:lines][0][1] != 0 header="#{@file[:name]}:#{@hunk[:lines][0][1]}" output_line @orig_line.sub(/(@@+\s)(.*)(\s@@+)/,"\\1#{header}\\3") end true end end
meta_colorize(l)
click to toggle source
# File lib/git_helpers/diff.rb, line 551 def meta_colorize(l) if @opts[:color] l.color(*@colors[:meta]) else l end end
new_commit()
click to toggle source
Calls superclass method
GitHelpers::GitDiff#new_commit
# File lib/git_helpers/diff.rb, line 593 def new_commit super output_line meta_colorize(hhline) end
new_diff_header()
click to toggle source
Calls superclass method
GitHelpers::GitDiff#new_diff_header
# File lib/git_helpers/diff.rb, line 559 def new_diff_header super output_line meta_colorize(hline) end
new_submodule_header()
click to toggle source
Calls superclass method
GitHelpers::GitDiff#new_submodule_header
# File lib/git_helpers/diff.rb, line 578 def new_submodule_header super output_line meta_colorize(hline) end
nonewline_clean()
click to toggle source
# File lib/git_helpers/diff.rb, line 589 def nonewline_clean @mode==:hunk && @file && (@file[:perm]=="120000" or @file[:old_perm]=="120000" or @file[:new_perm]=="120000") && @line==NoNewLine end
perm_mode(m, prefix: ' ')
click to toggle source
# File lib/git_helpers/diff.rb, line 517 def perm_mode(m, prefix: ' ') case m when "040000" prefix+"directory" when "100644" "" #file when "100755" prefix+"executable" when "120000" prefix+"symlink" when "160000" prefix+"gitlink" end end
short_perm_mode(m, prefix: '+')
click to toggle source
# File lib/git_helpers/diff.rb, line 503 def short_perm_mode(m, prefix: '+') case m when "040000" prefix+"d" #directory when "100644" "" #file when "100755" prefix+"x" #executable when "120000" prefix+"l" #symlink when "160000" prefix+"g" #gitlink end end
submodule_header_summary()
click to toggle source
# File lib/git_helpers/diff.rb, line 570 def submodule_header_summary r="Submodule #{@submodule[:name]}" extra=[@submodule[:modified] && "modified", @submodule[:untracked] && "untracked"].compact.join("+") r<<" [#{extra}]" unless extra.empty? r << " #{@submodule[:info]}" if @submodule[:info] r end