| |   |
| 11 | 11 | class Unified::Generator |
| 12 | 12 | |
| 13 | 13 | # Extracts the line number info for a given diff section |
| 14 | | LINE_NUM_RE = /@@ [+-]([0-9]+)(?:,([0-9]+))? [+-]([0-9]+)(?:,([0-9]+))? @@/ |
| 14 | LINE_NUM_RE = /^@@ [+-]([0-9]+)(?:,([0-9]+))? [+-]([0-9]+)(?:,([0-9]+))? @@/ |
| 15 | 15 | LINE_TYPES = {'+' => :add, '-' => :rem, ' ' => :unmod} |
| 16 | 16 | |
| 17 | 17 | # Runs the generator on a diff and returns a Data object |
| … | … | |
| 88 | 88 | |
| 89 | 89 | protected |
| 90 | 90 | def is_header_line?(line) |
| 91 | | return true if ['++', '--'].include?(line[0,2]) |
| 91 | return true if ['+++ ', '--- '].include?(line[0,4]) |
| 92 | 92 | return true if line =~ /^(new|delete) file mode [0-9]+$/ |
| 93 | 93 | return true if line =~ /^diff \-\-git/ |
| 94 | 94 | return true if line =~ /^index \w+\.\.\w+ [0-9]+$/ |
| toggle raw diff |
--- a/vendor/diff-display/lib/diff/display/unified/generator.rb
+++ b/vendor/diff-display/lib/diff/display/unified/generator.rb
@@ -11,7 +11,7 @@ module Diff::Display
class Unified::Generator
# Extracts the line number info for a given diff section
- LINE_NUM_RE = /@@ [+-]([0-9]+)(?:,([0-9]+))? [+-]([0-9]+)(?:,([0-9]+))? @@/
+ LINE_NUM_RE = /^@@ [+-]([0-9]+)(?:,([0-9]+))? [+-]([0-9]+)(?:,([0-9]+))? @@/
LINE_TYPES = {'+' => :add, '-' => :rem, ' ' => :unmod}
# Runs the generator on a diff and returns a Data object
@@ -88,7 +88,7 @@ module Diff::Display
protected
def is_header_line?(line)
- return true if ['++', '--'].include?(line[0,2])
+ return true if ['+++ ', '--- '].include?(line[0,4])
return true if line =~ /^(new|delete) file mode [0-9]+$/
return true if line =~ /^diff \-\-git/
return true if line =~ /^index \w+\.\.\w+ [0-9]+$/ |
| |   |
| 1 | diff --git a/spec/fixtures/multiple_rems_then_add.diff b/spec/fixtures/multiple_rems_then_add.diff |
| 2 | new file mode 100644 |
| 3 | index 0000000..f5fd3f8 |
| 4 | --- /dev/null |
| 5 | +++ b/spec/fixtures/multiple_rems_then_add.diff |
| 6 | @@ -0,0 +1,14 @@ |
| 7 | +diff --git a/strokedb-ruby/lib/stores/chainable_storage.rb b/strokedb-ruby/lib/stores/chainable_storage.rb |
| 8 | +index 5326c92..1e2de8f 100644 |
| 9 | +--- a/strokedb-ruby/lib/stores/chainable_storage.rb |
| 10 | ++++ b/strokedb-ruby/lib/stores/chainable_storage.rb |
| 11 | +@@ -44,9 +44,7 @@ module StrokeDB |
| 12 | + def save_with_chained_storages!(chunk,source=nil) |
| 13 | + perform_save!(chunk) |
| 14 | + (@chained_storages||{}).each_pair do |storage,savings| |
| 15 | +- unless storage == chunk |
| 16 | +- savings << chunk unless savings.include?(chunk) |
| 17 | +- end |
| 18 | diff --git a/spec/fixtures/multiple_rems_then_add.diff b/spec/fixtures/multiple_rems_then_add.diff |
| 19 | new file mode 100644 |
| 20 | index 0000000..f5fd3f8 |
| 21 | --- /dev/null |
| 22 | +++ b/spec/fixtures/multiple_rems_then_add.diff |
| 23 | @@ -0,0 +1,14 @@ |
| 24 | +diff --git a/strokedb-ruby/lib/stores/chainable_storage.rb b/strokedb-ruby/lib/stores/chainable_storage.rb |
| 25 | +index 5326c92..1e2de8f 100644 |
| 26 | +--- a/strokedb-ruby/lib/stores/chainable_storage.rb |
| 27 | ++++ b/strokedb-ruby/lib/stores/chainable_storage.rb |
| 28 | +@@ -44,9 +44,7 @@ module StrokeDB |
| 29 | + def save_with_chained_storages!(chunk,source=nil) |
| 30 | + perform_save!(chunk) |
| 31 | + (@chained_storages||{}).each_pair do |storage,savings| |
| 32 | +- unless storage == chunk |
| 33 | +- savings << chunk unless savings.include?(chunk) |
| 34 | +- end |
| 35 | + end |
| 36 | + end |
| 37 | \ No newline at end of file |
| toggle raw diff |
--- /dev/null
+++ b/vendor/diff-display/spec/fixtures/pseudo_recursive.diff
@@ -0,0 +1,21 @@
+diff --git a/spec/fixtures/multiple_rems_then_add.diff b/spec/fixtures/multiple_rems_then_add.diff
+new file mode 100644
+index 0000000..f5fd3f8
+--- /dev/null
++++ b/spec/fixtures/multiple_rems_then_add.diff
+@@ -0,0 +1,14 @@
++diff --git a/strokedb-ruby/lib/stores/chainable_storage.rb b/strokedb-ruby/lib/stores/chainable_storage.rb
++index 5326c92..1e2de8f 100644
++--- a/strokedb-ruby/lib/stores/chainable_storage.rb
+++++ b/strokedb-ruby/lib/stores/chainable_storage.rb
++@@ -44,9 +44,7 @@ module StrokeDB
++ def save_with_chained_storages!(chunk,source=nil)
++ perform_save!(chunk)
++ (@chained_storages||{}).each_pair do |storage,savings|
++- unless storage == chunk
++- savings << chunk unless savings.include?(chunk)
++- end
+++ savings << chunk unless storage == chunk || savings.include?(chunk)
++ end
++ end
+\ No newline at end of file |
| |   |
| 36 | 36 | it "multiple rems and an add is in parity" do |
| 37 | 37 | diff_data = load_diff("multiple_rems_then_add") |
| 38 | 38 | data = Diff::Display::Unified::Generator.run(diff_data) |
| 39 | | #pp data |
| 40 | 39 | data.to_diff.should == diff_data.chomp |
| 41 | 40 | end |
| 42 | 41 | |
| 42 | it "doesn't parse linenumbers that isn't part if the diff" do |
| 43 | diff_data = load_diff("pseudo_recursive") |
| 44 | data = Diff::Display::Unified::Generator.run(diff_data) |
| 45 | linenos = [] |
| 46 | data.each{|blk| blk.each{|line| linenos << line.number } } |
| 47 | linenos.compact.should == (1..14).to_a |
| 48 | end |
| 49 | |
| 43 | 50 | end |
| 44 | 51 | |
| 45 | 52 | end |
| toggle raw diff |
--- a/vendor/diff-display/spec/generator_spec.rb
+++ b/vendor/diff-display/spec/generator_spec.rb
@@ -36,10 +36,17 @@ describe Diff::Display::Unified::Generator do
it "multiple rems and an add is in parity" do
diff_data = load_diff("multiple_rems_then_add")
data = Diff::Display::Unified::Generator.run(diff_data)
- #pp data
data.to_diff.should == diff_data.chomp
end
+ it "doesn't parse linenumbers that isn't part if the diff" do
+ diff_data = load_diff("pseudo_recursive")
+ data = Diff::Display::Unified::Generator.run(diff_data)
+ linenos = []
+ data.each{|blk| blk.each{|line| linenos << line.number } }
+ linenos.compact.should == (1..14).to_a
+ end
+
end
end |