Class: GitHelpers::GitFancyDiff
Constant Summary
Constants inherited
from GitDiff
GitHelpers::GitDiff::NoNewLine
Instance Attribute Summary
Attributes inherited from GitDiff
#output
Instance Method Summary
collapse
Methods inherited from GitDiff
#change_mode, #detect_delete, #detect_diff_header, #detect_end_diff_header, #detect_end_hunk, #detect_filename, #detect_index, #detect_new_commit, #detect_new_diff_header, #detect_new_hunk, #detect_new_submodule_header, #detect_newfile, #detect_perm, #detect_rename_copy, #each, #end_hunk, #end_meta, #end_submodule, #get_file_name, #handle_commit, #handle_diff_header, #handle_hunk, #handle_meta, #handle_submodule, #handle_submodule_header, #new_hunk, #new_meta, #new_submodule, #next_mode, output, #output_line, #output_lines, #parse, #parse_hunk_header, #parse_line, #prepare_new_line, #reparse, #submodule_line, #update_mode
Constructor Details
#initialize(*args, **kw, &b) ⇒ GitFancyDiff
Returns a new instance of GitFancyDiff.
485
486
487
488
489
490
491
492
|
# File 'lib/git_helpers/diff.rb', line 485
def initialize(*args,**kw,&b)
super
cols=`tput cols`.to_i
cols==0 && cols=80 @cols=cols-1
end
|
Instance Method Details
#binary_file_differ ⇒ Object
628
629
630
631
|
# 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 ⇒ Object
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
|
# 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:]]/ output_line SimpleColor.color(bcolor.to_s + (cline.empty? ? " ": cline)+ecolor.to_s,:inverse)
else
cline.sub!(/^\s/,'') unless mode output_line bcolor.to_s+cline+ecolor.to_s
end
true
end
end
|
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
# File 'lib/git_helpers/diff.rb', line 532
def
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 ⇒ Object
597
598
599
600
|
# File 'lib/git_helpers/diff.rb', line 597
def end_commit
super
output_line meta_colorize(hhline)
end
|
564
565
566
567
568
|
# File 'lib/git_helpers/diff.rb', line 564
def
super
output_line meta_colorize()
output_line meta_colorize(hline)
end
|
583
584
585
586
587
|
# File 'lib/git_helpers/diff.rb', line 583
def
super
output_line meta_colorize()
output_line meta_colorize(hline)
end
|
#handle_line ⇒ Object
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
|
# File 'lib/git_helpers/diff.rb', line 633
def handle_line
super
case @mode
when :meta
if binary_file_differ
else output_line @orig_line
end
when :hunk
if
elsif nonewline_clean
elsif clean_hunk_col
else output_line @orig_line
end
when :submodule,:commit
output_line @orig_line
end
end
|
#hhline ⇒ Object
497
498
499
500
501
|
# File 'lib/git_helpers/diff.rb', line 497
def hhline
"═"*@cols
end
|
#hline ⇒ Object
494
495
496
|
# File 'lib/git_helpers/diff.rb', line 494
def hline
'─'*@cols
end
|
618
619
620
621
622
623
624
625
626
|
# File 'lib/git_helpers/diff.rb', line 618
def
if @mode==:hunk && @start_mode
if @hunk[:lines][0][1] && @hunk[:lines][0][1] != 0
="#{@file[:name]}:#{@hunk[:lines][0][1]}"
output_line @orig_line.sub(/(@@+\s)(.*)(\s@@+)/,"\\1#{}\\3")
end
true
end
end
|
551
552
553
554
555
556
557
|
# 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 ⇒ Object
593
594
595
596
|
# File 'lib/git_helpers/diff.rb', line 593
def new_commit
super
output_line meta_colorize(hhline)
end
|
559
560
561
562
|
# File 'lib/git_helpers/diff.rb', line 559
def
super
output_line meta_colorize(hline)
end
|
578
579
580
581
|
# File 'lib/git_helpers/diff.rb', line 578
def
super
output_line meta_colorize(hline)
end
|
#nonewline_clean ⇒ Object
589
590
591
|
# 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: ' ') ⇒ Object
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
# File 'lib/git_helpers/diff.rb', line 517
def perm_mode(m, prefix: ' ')
case m
when "040000"
prefix+"directory"
when "100644"
"" when "100755"
prefix+"executable"
when "120000"
prefix+"symlink"
when "160000"
prefix+"gitlink"
end
end
|
#short_perm_mode(m, prefix: '+') ⇒ Object
503
504
505
506
507
508
509
510
511
512
513
514
515
516
|
# File 'lib/git_helpers/diff.rb', line 503
def short_perm_mode(m, prefix: '+')
case m
when "040000"
prefix+"d" when "100644"
"" when "100755"
prefix+"x" when "120000"
prefix+"l" when "160000"
prefix+"g" end
end
|
570
571
572
573
574
575
576
|
# File 'lib/git_helpers/diff.rb', line 570
def
r="Submodule #{@submodule[:name]}"
=[@submodule[:modified] && "modified", @submodule[:untracked] && "untracked"].compact.join("+")
r<<" [#{}]" unless .empty?
r << " #{@submodule[:info]}" if @submodule[:info]
r
end
|