di 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +12 -0
  3. data/lib/di.rb +59 -39
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85e6d0dda9d8ab2f37c5781743238023291f5d3a
4
- data.tar.gz: d08a5f0ea260bdd94ff720f73670490acdebf649
3
+ metadata.gz: 89485791b2612b6df2c0cce66f24856571c85dde
4
+ data.tar.gz: 8ac703cf8b70c4ccb5a680c91f64c12f8d7c21cf
5
5
  SHA512:
6
- metadata.gz: 672d1f491243ad2ede807e4176ced0c0fa216965a223e2ea8e8bf44b853cb93ea8d792fb6fa5031708c31b84603d65f2b4a8a79ce03de371bda958983ede1e17
7
- data.tar.gz: b5fd0a90f9bace17a97e72b3df21259d96f768b14042b0e1bd5623175b547f16ab2c44d9835905de9402f4c4c03bdf469c9741c221631a7c3943dbadd9c7dbde
6
+ metadata.gz: 6693cdfccee6b3787ed382feb31cd51818f548ba2e5643121920bfb81d7932632ed2ca01bb263e56d1a9c60d6a39f4077a21e988338274bb4c4baf97274d774e
7
+ data.tar.gz: 032c8c70a6851bc94f2901401b454011873419dc9cc80a6ec0e2f2de2272abe555d1682529217cb6298a7f700d3ac922bd81b8a6c7d1a0524d490b0fa90df48f
data/HISTORY CHANGED
@@ -1,3 +1,15 @@
1
+ == 0.4.1 2013-04-11
2
+
3
+ * Set better labels and disable pager if invoked by git difftool.
4
+
5
+ * Enhance the --color option like Git.
6
+
7
+ == 0.4.0 2013-04-04
8
+
9
+ * Add inline word-diff highlighting.
10
+
11
+ * Improve suspicious whitespace highlighting.
12
+
1
13
  == 0.3.2 2013-01-09
2
14
 
3
15
  * Do not choke on encoding errors when colorizing on Ruby 1.9+.
data/lib/di.rb CHANGED
@@ -28,7 +28,7 @@
28
28
  # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
29
  # SUCH DAMAGE.
30
30
 
31
- MYVERSION = "0.4.0"
31
+ MYVERSION = "0.4.1"
32
32
  MYNAME = File.basename($0)
33
33
  MYCOPYRIGHT = "Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Akinori MUSHA"
34
34
 
@@ -130,9 +130,18 @@ usage: #{MYNAME} [flags] [files]
130
130
  'Pipe output into pager if stdout is a terminal. [+][*]') { |val|
131
131
  $diff.use_pager = val if $stdout.tty?
132
132
  }
133
- opts.on('--[no-]color',
133
+ opts.on('--[no-]color[=WHEN]',
134
134
  'Colorize output if stdout is a terminal and the format is unified or context. [+][*]') { |val|
135
- $diff.colorize = val if $stdout.tty?
135
+ case val
136
+ when true, 'always'
137
+ $diff.colorize = true
138
+ when 'auto'
139
+ $diff.colorize = $stdout.tty?
140
+ when false, 'never'
141
+ $diff.colorize = false
142
+ else
143
+ raise OptionParser::ParseError, "unknown value for --color: #{val}"
144
+ end
136
145
  }
137
146
  opts.on('--[no-]highlight-whitespace',
138
147
  'Highlight whitespace differences in colorized output. [+][*]') { |val|
@@ -392,9 +401,16 @@ EOS
392
401
 
393
402
  begin
394
403
  opts.parse('--rsync-exclude', '--fignore-exclude', '--ignore-cvs-lines',
395
- '--pager', '--color', '--highlight-whitespace',
404
+ '--pager', '--color=auto', '--highlight-whitespace',
396
405
  '-U3', '-N', '-r', '-p', '-d')
397
406
 
407
+ if ENV['GIT_DIFFTOOL_EXTCMD']
408
+ if base = ENV['BASE']
409
+ opts.parse('--label', File.join('a', base), '--label', File.join('b', base))
410
+ end
411
+ opts.parse('--no-pager')
412
+ end
413
+
398
414
  if value = ENV[ENV_NAME]
399
415
  require 'shellwords'
400
416
  opts.parse(*value.shellsplit)
@@ -452,11 +468,7 @@ EOS
452
468
  end
453
469
  end
454
470
 
455
- def invoke_pager
456
- invoke_pager! if $diff.use_pager
457
- end
458
-
459
- def invoke_pager!
471
+ def invoke_filter
460
472
  $stdout.flush
461
473
  $stderr.flush
462
474
  pr, pw = IO.pipe
@@ -466,11 +478,7 @@ def invoke_pager!
466
478
  pr.close
467
479
  pw.close
468
480
  IO.select([$stdin], nil, [$stdin])
469
- begin
470
- exec(ENV['PAGER'] || 'more')
471
- rescue
472
- $stderr.puts "Pager failed."
473
- end
481
+ yield
474
482
  }
475
483
 
476
484
  $stdout.reopen(pw)
@@ -485,6 +493,35 @@ def invoke_pager!
485
493
  }
486
494
  end
487
495
 
496
+ def invoke_pager
497
+ invoke_pager! if $diff.use_pager
498
+ end
499
+
500
+ def invoke_pager!
501
+ invoke_filter {
502
+ begin
503
+ exec(ENV['PAGER'] || 'more')
504
+ rescue
505
+ $stderr.puts "Pager failed."
506
+ end
507
+ }
508
+ end
509
+
510
+ def invoke_colorizer
511
+ invoke_colorizer! if $diff.colorize
512
+ end
513
+
514
+ def invoke_colorizer!
515
+ invoke_filter {
516
+ case $diff.format
517
+ when :unified
518
+ colorize_unified_diff
519
+ when :context
520
+ colorize_context_diff
521
+ end
522
+ }
523
+ end
524
+
488
525
  def set_flag(flag, val)
489
526
  case val
490
527
  when true, false
@@ -585,21 +622,8 @@ def diff_files(file1, file2)
585
622
  end
586
623
 
587
624
  def call_diff(*args)
588
- command_args = [DIFF_CMD, $diff.flags, args].flatten
589
- if $diff.colorize
590
- case $diff.format
591
- when :unified
592
- filter = method(:colorize_unified_diff)
593
- when :context
594
- filter = method(:colorize_context_diff)
595
- end
596
- end
597
- if filter
598
- require 'shellwords'
599
- filter.call(IO.popen(command_args.shelljoin, 'r'))
600
- else
601
- system(*command_args)
602
- end
625
+ invoke_colorizer
626
+ system *[DIFF_CMD, $diff.flags, args].flatten
603
627
  status = $? >> 8
604
628
  $status = status if $status < status
605
629
  return status
@@ -709,7 +733,7 @@ def diff_exclude?(dir, basename)
709
733
  return false
710
734
  end
711
735
 
712
- def colorize_unified_diff(io)
736
+ def colorize_unified_diff
713
737
  begin
714
738
  require 'diff/lcs'
715
739
  colorize_unified_diff_hunk = method(:colorize_hunk_in_unified_diff_inline)
@@ -723,7 +747,7 @@ def colorize_unified_diff(io)
723
747
  state = :comment
724
748
  hunk_left = nil
725
749
  hunk = []
726
- io.each_line { |line|
750
+ $stdin.each_line { |line|
727
751
  line.chomp!
728
752
  replace_invalid_bytes!(line)
729
753
  case state
@@ -762,8 +786,6 @@ def colorize_unified_diff(io)
762
786
 
763
787
  print color, line, colors.off, "\n"
764
788
  }
765
-
766
- io.close
767
789
  end
768
790
 
769
791
  def colorize_hunk_in_unified_diff_normal(hunk)
@@ -893,8 +915,8 @@ def colorize_inline_diff(line1, line2)
893
915
  }
894
916
  }
895
917
 
896
- print colors.old, '-', aline1, "\n",
897
- colors.new, '+', aline2, "\n"
918
+ print colors.old, '-', aline1, colors.off, "\n",
919
+ colors.new, '+', aline2, colors.off, "\n"
898
920
  end
899
921
 
900
922
  def highlight_whitespace_in_unified_diff!(line, color)
@@ -910,13 +932,13 @@ def highlight_whitespace_in_unified_diff!(line, color)
910
932
  }
911
933
  end
912
934
 
913
- def colorize_context_diff(io)
935
+ def colorize_context_diff
914
936
  colors = $diff.colors
915
937
  colors.to_function ||= colors.off + colors.function
916
938
 
917
939
  state = :comment
918
940
  hunk_part = nil
919
- io.each_line { |line|
941
+ $stdin.each_line { |line|
920
942
  line.chomp!
921
943
  replace_invalid_bytes!(line)
922
944
  case state
@@ -982,8 +1004,6 @@ def colorize_context_diff(io)
982
1004
 
983
1005
  print color, line, colors.off, "\n"
984
1006
  }
985
-
986
- io.close
987
1007
  end
988
1008
 
989
1009
  def highlight_whitespace_in_context_diff!(line, color)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: di
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinori MUSHA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-03 00:00:00.000000000 Z
11
+ date: 2013-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  requirements: []
68
68
  rubyforge_project:
69
- rubygems_version: 2.0.3
69
+ rubygems_version: 2.0.0
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: A wrapper around GNU diff(1)