diffy 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of diffy might be problematic. Click here for more details.

data/README.md CHANGED
@@ -175,11 +175,24 @@ symbols in the output.
175
175
  </ul>
176
176
  </div>
177
177
 
178
+ ### Number of lines of context around changes
179
+
180
+ You can use the `:context` option to override the number of lines of context
181
+ that are shown around each change (this defaults to 10000 to show the full
182
+ file).
183
+
184
+ >> puts Diffy::Diff.new("foo\nfoo\nBAR\nbang\nbaz", "foo\nfoo\nbar\nbang\nbaz", :context => 1)
185
+ foo
186
+ -BAR
187
+ +bar
188
+ bang
189
+
178
190
 
179
191
  ### Overriding the command line options passed to diff.
180
192
 
181
193
  You can use the `:diff` option to override the command line options that are
182
- passed to unix diff. They default to `-U 10000`.
194
+ passed to unix diff. They default to `-U 10000`. This option will noop if
195
+ combined with the `:context` option.
183
196
 
184
197
  >> puts Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n", :diff => "-w")
185
198
  foo
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "diffy"
8
- s.version = "2.1.0"
8
+ s.version = "2.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sam Goldstein"]
12
- s.date = "2012-11-06"
12
+ s.date = "2012-12-28"
13
13
  s.description = "Convenient diffing in ruby"
14
14
  s.email = "sgrock@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -1,11 +1,15 @@
1
1
  require 'tempfile'
2
2
  require 'erb'
3
+ require 'rbconfig'
3
4
  # 1.9 compatibility
4
5
  if defined? Enumerator and ! defined? Enumerable::Enumerator
5
6
  Enumerable::Enumerator = Enumerator
6
7
  end
7
8
 
8
- module Diffy; end
9
+ module Diffy
10
+ WINDOWS = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
11
+ end
12
+ require 'open3' unless Diffy::WINDOWS
9
13
  require File.join(File.dirname(__FILE__), 'diffy', 'format')
10
14
  require File.join(File.dirname(__FILE__), 'diffy', 'html_formatter')
11
15
  require File.join(File.dirname(__FILE__), 'diffy', 'diff')
@@ -13,7 +13,8 @@ module Diffy
13
13
  :diff => '-U 10000',
14
14
  :source => 'strings',
15
15
  :include_diff_info => false,
16
- :include_plus_and_minus_in_html => false
16
+ :include_plus_and_minus_in_html => false,
17
+ :context => nil
17
18
  }
18
19
  end
19
20
 
@@ -44,9 +45,14 @@ module Diffy
44
45
  when 'files'
45
46
  [string1, string2]
46
47
  end
47
- diff_opts = options[:diff].is_a?(Array) ? options[:diff] : [options[:diff]]
48
- cmd = "#{diff_bin} #{diff_opts.join(' ')} #{paths.join(' ')}"
49
- diff = `#{cmd}`
48
+
49
+ if WINDOWS
50
+ # don't use open3 on windows
51
+ cmd = "#{diff_bin} #{diff_options.join(' ')} #{paths.join(' ')}"
52
+ diff = `#{cmd}`
53
+ else
54
+ diff = Open3.popen3(diff_bin, *(diff_options + paths)) { |i, o, e| o.read }
55
+ end
50
56
  diff.force_encoding('ASCII-8BIT') if diff.respond_to?(:valid_encoding?) && !diff.valid_encoding?
51
57
  if diff =~ /\A\s*\Z/ && !options[:allow_empty_diff]
52
58
  diff = case options[:source]
@@ -116,10 +122,14 @@ module Diffy
116
122
  end
117
123
  private
118
124
 
125
+ @@bin = nil
119
126
  def diff_bin
120
- @@bin ||=""
121
-
122
- @@bin = `which diff.exe`.chomp if @@bin.empty?
127
+ return @@bin if @@bin
128
+
129
+ @@bin ||= ""
130
+ if WINDOWS
131
+ @@bin = `which diff.exe`.chomp if @@bin.empty?
132
+ end
123
133
  @@bin = `which diff`.chomp if @@bin.empty?
124
134
 
125
135
  if @@bin.empty?
@@ -128,5 +138,10 @@ module Diffy
128
138
  @@bin
129
139
  end
130
140
 
141
+ # options pass to diff program
142
+ def diff_options
143
+ Array(options[:context] ? "-U #{options[:context]}" : options[:diff])
144
+ end
145
+
131
146
  end
132
147
  end
@@ -79,6 +79,19 @@ describe Diffy::Diff do
79
79
 
80
80
  end
81
81
 
82
+ describe "options[:context]" do
83
+ it "should limit context lines to 1" do
84
+ diff = Diffy::Diff.new("foo\nfoo\nBAR\nbang\nbaz", "foo\nfoo\nbar\nbang\nbaz", :context => 1)
85
+ puts diff
86
+ diff.to_s.should == <<-DIFF
87
+ foo
88
+ -BAR
89
+ +bar
90
+ bang
91
+ DIFF
92
+ end
93
+ end
94
+
82
95
  describe "options[:include_plus_and_minus_in_html]" do
83
96
  it "defaults to false" do
84
97
  @diffy = Diffy::Diff.new(" foo\nbar\n", "foo\nbar\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-06 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec