di 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/HISTORY +16 -0
  2. data/LICENSE +1 -1
  3. data/di.gemspec +15 -18
  4. data/lib/di.rb +69 -51
  5. metadata +9 -10
  6. data/.gitignore +0 -21
data/HISTORY CHANGED
@@ -1,3 +1,19 @@
1
+ == 0.2.0 2011-05-09
2
+
3
+ * Update the default exclude pattern list:
4
+ - Sort out file patterns and directory patterns so that (for example)
5
+ a directory named "core" is not ignored.
6
+ - Remove RCSLOG and cvslog.* which I haven't seen for decades.
7
+ - Add files generated by gtags(1): GTAGS, GRTAGS, GSYMS and GPATH.
8
+ - Add core.<pid>.
9
+ - Add *.so.<version>.
10
+ - Add *.bundle and *.dylib for OS X.
11
+ - Add *.py[co].
12
+
13
+ == 0.1.9 2010-05-06
14
+
15
+ * Make changes regarding file layout and documentation.
16
+
1
17
  == 0.1.8 2010-03-11
2
18
 
3
19
  * Fix unified diff parser.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008, 2009, 2010 Akinori MUSHA
1
+ Copyright (c) 2008, 2009, 2010, 2011 Akinori MUSHA
2
2
 
3
3
  All rights reserved.
4
4
 
data/di.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{di}
8
- s.version = "0.1.9"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Akinori MUSHA"]
12
- s.date = %q{2010-05-06}
12
+ s.date = %q{2011-05-09}
13
13
  s.default_executable = %q{di}
14
14
  s.description = %q{The di(1) command wraps around GNU diff(1) to provide reasonable
15
15
  default settings and some original features.
@@ -18,34 +18,31 @@ default settings and some original features.
18
18
  s.executables = ["di"]
19
19
  s.extra_rdoc_files = [
20
20
  "LICENSE",
21
- "README.rdoc"
21
+ "README.rdoc"
22
22
  ]
23
23
  s.files = [
24
24
  ".document",
25
- ".gitignore",
26
- "HISTORY",
27
- "LICENSE",
28
- "README.rdoc",
29
- "Rakefile",
30
- "bin/di",
31
- "di.gemspec",
32
- "lib/di.rb",
33
- "test/helper.rb",
34
- "test/test_di.rb"
25
+ "HISTORY",
26
+ "LICENSE",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "bin/di",
30
+ "di.gemspec",
31
+ "lib/di.rb",
32
+ "test/helper.rb",
33
+ "test/test_di.rb"
35
34
  ]
36
35
  s.homepage = %q{http://github.com/knu/di}
37
- s.rdoc_options = ["--charset=UTF-8"]
38
36
  s.require_paths = ["lib"]
39
37
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
40
- s.rubygems_version = %q{1.3.7.pre.1}
38
+ s.rubygems_version = %q{1.6.2}
41
39
  s.summary = %q{A wrapper around GNU diff(1)}
42
40
  s.test_files = [
43
41
  "test/helper.rb",
44
- "test/test_di.rb"
42
+ "test/test_di.rb"
45
43
  ]
46
44
 
47
45
  if s.respond_to? :specification_version then
48
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
46
  s.specification_version = 3
50
47
 
51
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
data/lib/di.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # di - a wrapper around GNU diff(1)
5
5
  #
6
- # Copyright (c) 2008, 2009, 2010 Akinori MUSHA
6
+ # Copyright (c) 2008, 2009, 2010, 2011 Akinori MUSHA
7
7
  #
8
8
  # All rights reserved.
9
9
  #
@@ -28,25 +28,31 @@
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.1.9"
31
+ MYVERSION = "0.2.0"
32
32
  MYNAME = File.basename($0)
33
- MYCOPYRIGHT = "Copyright (c) 2008, 2009, 2010 Akinori MUSHA"
33
+ MYCOPYRIGHT = "Copyright (c) 2008, 2009, 2010, 2011 Akinori MUSHA"
34
34
 
35
35
  DIFF_CMD = ENV.fetch('DIFF', 'diff')
36
36
  ENV_NAME = "#{MYNAME.tr('-a-z', '_A-Z')}_OPTIONS"
37
37
  EMPTYFILE = '/dev/null'
38
38
 
39
- RSYNC_EXCLUDE_GLOBS = %w(
40
- RCS SCCS CVS CVS.adm
41
- RCSLOG cvslog.* tags TAGS
42
- .make.state .nse_depinfo *~
43
- \#* .\#* ,* _$*
44
- *$ *.old *.bak *.BAK
45
- *.orig *.rej *.del-* *.a
46
- *.olb *.o *.obj *.so
47
- *.exe *.Z *.elc *.ln
48
- core .svn .git .bzr .hg
49
- )
39
+ RSYNC_EXCLUDE_FILE_GLOBS = [
40
+ 'tags', 'TAGS', 'GTAGS', 'GRTAGS', 'GSYMS', 'GPATH',
41
+ '.make.state', '.nse_depinfo',
42
+ '*~', '\#*', '.\#*', ',*', '_$*', '*$',
43
+ '*.old', '*.bak', '*.BAK',
44
+ '*.orig', '*.rej', '*.del-*',
45
+ '*.a', '*.olb', '*.o', '*.obj',
46
+ /\A[^.].*[^.]\.so(?:\.[0-9]+)*\z/,
47
+ '*.bundle', '*.dylib',
48
+ '*.exe', '*.Z', '*.elc', '*.py[co]', '*.ln',
49
+ /\Acore(?:\.[0-9]+)*\z/,
50
+ ]
51
+
52
+ RSYNC_EXCLUDE_DIR_GLOBS = [
53
+ 'RCS', 'SCCS', 'CVS', 'CVS.adm',
54
+ '.svn', '.git', '.bzr', '.hg',
55
+ ]
50
56
 
51
57
  FIGNORE_GLOBS = ENV.fetch('FIGNORE', '').split(':').map { |pat|
52
58
  '*' + pat
@@ -76,22 +82,18 @@ def setup
76
82
  $diff.flags = []
77
83
  $diff.format_flags = []
78
84
  $diff.format = :normal
79
- $diff.custom_format_p = false
80
- $diff.use_pager = false
81
- $diff.colorize = false
82
- $diff.highlight_whitespace = true
83
85
  $diff.colors = {
84
- :comment => "\033[1m",
85
- :file1 => "\033[1m",
86
- :file2 => "\033[1m",
87
- :header => "\033[36m",
88
- :function => "\033[m",
89
- :new => "\033[32m",
90
- :old => "\033[31m",
91
- :changed => "\033[33m",
86
+ :comment => "\e[1m",
87
+ :file1 => "\e[1m",
88
+ :file2 => "\e[1m",
89
+ :header => "\e[36m",
90
+ :function => "\e[m",
91
+ :new => "\e[32m",
92
+ :old => "\e[31m",
93
+ :changed => "\e[33m",
92
94
  :unchanged => "",
93
- :whitespace => "\033[41m",
94
- :off => "\033[m",
95
+ :whitespace => "\e[41m",
96
+ :off => "\e[m",
95
97
  }
96
98
  end
97
99
 
@@ -107,9 +109,10 @@ usage: #{MYNAME} [flags] [files]
107
109
 
108
110
  opts = OptionParser.new(banner) { |opts|
109
111
  miniTrueClass = Class.new
110
- hash = OptionParser::CompletingHash.new
111
- hash['-'] = false
112
- opts.accept(miniTrueClass, hash) {|arg, val| val == nil or val}
112
+ miniTrueClassHash = OptionParser::CompletingHash['-', false]
113
+ opts.accept(miniTrueClass, miniTrueClassHash) { |arg, val|
114
+ val == nil or val
115
+ }
113
116
 
114
117
  opts.on('--[no-]pager',
115
118
  'Pipe output into pager if stdout is a terminal. [!][*]') { |val|
@@ -119,6 +122,10 @@ usage: #{MYNAME} [flags] [files]
119
122
  'Colorize output if stdout is a terminal and the format is unified or context. [!][*]') { |val|
120
123
  $diff.colorize = val if $stdout.tty?
121
124
  }
125
+ opts.on('--[no-]highlight-whitespace',
126
+ 'Highlight suspicious whitespace differences in colorized output. [!][*]') { |val|
127
+ $diff.highlight_whitespace = val
128
+ }
122
129
  opts.on('--[no-]rsync-exclude', '--[no-]cvs-exclude',
123
130
  'Exclude some kinds of files and directories a la rsync(1). [!][*]') { |val|
124
131
  $diff.rsync_exclude = val
@@ -384,7 +391,7 @@ EOS
384
391
 
385
392
  begin
386
393
  opts.parse('--rsync-exclude', '--fignore-exclude', '--ignore-cvs-lines',
387
- '--pager', '--color',
394
+ '--pager', '--color', '--highlight-whitespace',
388
395
  '-U3', '-N', '-r', '-p', '-d')
389
396
 
390
397
  if value = ENV[ENV_NAME]
@@ -411,13 +418,13 @@ EOS
411
418
 
412
419
  begin
413
420
  if $diff.from_files
414
- $diff.to_files ||= args.dup
421
+ $diff.to_files ||= args
415
422
 
416
423
  if $diff.to_files.empty?
417
424
  raise "missing operand"
418
425
  end
419
426
  elsif $diff.to_files
420
- $diff.from_files = args.dup
427
+ $diff.from_files = args
421
428
 
422
429
  if $diff.from_files.empty?
423
430
  raise "missing operand"
@@ -427,12 +434,10 @@ EOS
427
434
  raise "missing operand"
428
435
  end
429
436
 
430
- if File.directory?(args[0])
431
- $diff.to_files = args.dup
432
- $diff.from_files = [$diff.to_files.shift]
437
+ if File.directory?(args.first)
438
+ $diff.to_files, $diff.from_files = args[0..0], args[1..-1]
433
439
  else
434
- $diff.from_files = args.dup
435
- $diff.to_files = [$diff.from_files.pop]
440
+ $diff.from_files, $diff.to_files = args[0..-2], args[-1..-1]
436
441
  end
437
442
  end
438
443
 
@@ -482,11 +487,9 @@ end
482
487
 
483
488
  def set_flag(flag, val)
484
489
  case val
485
- when false
490
+ when true, false
486
491
  $diff.flags.reject! { |f,| f == flag }
487
- when true
488
- $diff.flags.reject! { |f,| f == flag }
489
- $diff.flags << [flag]
492
+ $diff.flags << [flag] if val
490
493
  else
491
494
  $diff.flags << [flag, val]
492
495
  end
@@ -513,7 +516,7 @@ def set_format_flag(flag, *val)
513
516
  else
514
517
  $diff.format = :unknown
515
518
  end
516
- $diff.format_flags.push([flag, *val])
519
+ $diff.format_flags << [flag, *val]
517
520
  end
518
521
 
519
522
  def set_custom_format_flag(flag, *val)
@@ -522,7 +525,7 @@ def set_custom_format_flag(flag, *val)
522
525
  $diff.custom_format_p = true
523
526
  end
524
527
  $diff.format = :custom
525
- $diff.format_flags.push([flag, *val])
528
+ $diff.format_flags << [flag, *val]
526
529
  end
527
530
 
528
531
  def diff_main
@@ -657,13 +660,13 @@ end
657
660
 
658
661
  def diff_entries(dir)
659
662
  return [] if dir.nil?
660
- return Dir.entries(dir).reject { |file| diff_exclude?(file) }
663
+ return Dir.entries(dir).reject { |file| diff_exclude?(dir, file) }
661
664
  rescue => e
662
665
  warn "#{dir}: #{e}"
663
666
  return []
664
667
  end
665
668
 
666
- def diff_exclude?(basename)
669
+ def diff_exclude?(dir, basename)
667
670
  return true if basename == '.' || basename == '..'
668
671
  return false if $diff.include.any? { |pat|
669
672
  File.fnmatch(pat, basename, File::FNM_DOTMATCH)
@@ -671,12 +674,21 @@ def diff_exclude?(basename)
671
674
  return true if $diff.exclude.any? { |pat|
672
675
  File.fnmatch(pat, basename, File::FNM_DOTMATCH)
673
676
  }
674
- return true if $diff.rsync_exclude && RSYNC_EXCLUDE_GLOBS.any? { |pat|
675
- File.fnmatch(pat, basename, File::FNM_DOTMATCH)
676
- }
677
677
  return true if $diff.fignore_exclude && FIGNORE_GLOBS.any? { |pat|
678
678
  File.fnmatch(pat, basename, File::FNM_DOTMATCH)
679
679
  }
680
+ return true if $diff.rsync_exclude &&
681
+ if File.directory?(File.join(dir, basename))
682
+ RSYNC_EXCLUDE_DIR_GLOBS
683
+ else
684
+ RSYNC_EXCLUDE_FILE_GLOBS
685
+ end.any? { |pat|
686
+ if Regexp === pat
687
+ pat.match(basename)
688
+ else
689
+ File.fnmatch(pat, basename, File::FNM_DOTMATCH)
690
+ end
691
+ }
680
692
  return false
681
693
  end
682
694
 
@@ -725,6 +737,9 @@ def colorize_unified_diff(io)
725
737
  line.sub!(/([ \t]+)$/) {
726
738
  colors[:off] + colors[:whitespace] + $1
727
739
  }
740
+ true while line.sub!(/^(.[ \t]*)( +)(\t)/) {
741
+ $1 + colors[:off] + colors[:whitespace] + $2 + colors[:off] + color + $3
742
+ }
728
743
  end
729
744
  if hunk_left <= 0
730
745
  state = :comment
@@ -803,9 +818,12 @@ def colorize_context_diff(io)
803
818
  color = colors[:comment]
804
819
  end
805
820
  if check
806
- line.sub!(/^(...*)([ \t]+)$/) {
821
+ line.sub!(/^(. .*)([ \t]+)$/) {
807
822
  $1 + colors[:off] + colors[:whitespace] + $2
808
823
  }
824
+ true while line.sub!(/^(. [ \t]*)( +)(\t)/) {
825
+ $1 + colors[:off] + colors[:whitespace] + $2 + colors[:off] + color + $3
826
+ }
809
827
  end
810
828
  end
811
829
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: di
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 9
10
- version: 0.1.9
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Akinori MUSHA
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-06 00:00:00 +09:00
18
+ date: 2011-05-09 00:00:00 +09:00
19
19
  default_executable: di
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,7 +46,6 @@ extra_rdoc_files:
46
46
  - README.rdoc
47
47
  files:
48
48
  - .document
49
- - .gitignore
50
49
  - HISTORY
51
50
  - LICENSE
52
51
  - README.rdoc
@@ -61,8 +60,8 @@ homepage: http://github.com/knu/di
61
60
  licenses: []
62
61
 
63
62
  post_install_message:
64
- rdoc_options:
65
- - --charset=UTF-8
63
+ rdoc_options: []
64
+
66
65
  require_paths:
67
66
  - lib
68
67
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -88,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
87
  requirements: []
89
88
 
90
89
  rubyforge_project:
91
- rubygems_version: 1.3.7.pre.1
90
+ rubygems_version: 1.6.2
92
91
  signing_key:
93
92
  specification_version: 3
94
93
  summary: A wrapper around GNU diff(1)
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC