summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-12-12 19:49:22 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-12-12 19:49:22 +0000
commit633e026e4494ba5452c78288a581fca3478687fb (patch)
treebf3b43975749ffcd2c16793a7b3cec58d02fd165 /lib
parent618ab6004e3a7257cfd166e7432200e63d25a6ae (diff)
downloadredmine-633e026e4494ba5452c78288a581fca3478687fb.tar.gz
redmine-633e026e4494ba5452c78288a581fca3478687fb.zip
Merged r2110 to r2112 (diff limit) from trunk.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.8-stable@2132 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r--lib/redmine/unified_diff.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/redmine/unified_diff.rb b/lib/redmine/unified_diff.rb
index 36a36cba5..bf4dec335 100644
--- a/lib/redmine/unified_diff.rb
+++ b/lib/redmine/unified_diff.rb
@@ -18,18 +18,30 @@
module Redmine
# Class used to parse unified diffs
class UnifiedDiff < Array
- def initialize(diff, type="inline")
- diff_table = DiffTable.new type
+ def initialize(diff, options={})
+ options.assert_valid_keys(:type, :max_lines)
+ diff_type = options[:type] || 'inline'
+
+ lines = 0
+ @truncated = false
+ diff_table = DiffTable.new(diff_type)
diff.each do |line|
if line =~ /^(---|\+\+\+) (.*)$/
self << diff_table if diff_table.length > 1
- diff_table = DiffTable.new type
+ diff_table = DiffTable.new(diff_type)
+ end
+ diff_table.add_line line
+ lines += 1
+ if options[:max_lines] && lines > options[:max_lines]
+ @truncated = true
+ break
end
- a = diff_table.add_line line
end
self << diff_table unless diff_table.empty?
self
end
+
+ def truncated?; @truncated; end
end
# Class that represents a file diff