diff_parser 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODhkM2ZjNDJhMjJkZjg3N2ZiN2YzYWU0MjA3YTEwMDM3NTVmZDlkYQ==
4
+ NjAwOWVhZjIzMzExNDMxZDEyM2M2ZDBkYjU4ZWRmNmIwMjBkYTVmOA==
5
5
  data.tar.gz: !binary |-
6
- ZDA4ZGRiMmYzODM2NTZlNzE2MDNjY2ExYWQ2ZDIxNzBkMDUzM2MwNA==
6
+ ZDAzNWVkYTIzYjE1YTJlNWRiZTg5M2Y5YjdjOTg1ODQ5ZWQxM2E5Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MGNlY2E0YWI2Yzk1N2VjYjcwNjFjN2FkOGM5YzU3NDhlMGVkMjk0OTNmODgz
10
- ODFmZjJkYzA0YTY1MzljZTE0MzcyYzhmMDc5YzMxMmVmM2RiMmJjNGNiOGVk
11
- MWMyZjUzMjQ1NDRmZTc5Yzc3Yzc3ZGVkOWNhMDk5ZmNiYmE1M2I=
9
+ NzA0YTQ0YjAzNmJjODBlNjk3ZDgzMjM5NWQ3YTk2ZjBjYmQ2MzQyNTAzZDIz
10
+ ZjBmMWI0Yzk3ZjUxMzk2ZDFmODRhZTdjM2NiYThhZmY2OWIxYjcyOTg1ZTdi
11
+ YjM4NjcyMjEwMWFhNzYxOWZiZDQ2M2VlYTVkYjkyNzdkYjgxYzA=
12
12
  data.tar.gz: !binary |-
13
- NWY5ODI1NjY2OWJlYzFlNTQ2MmIyMjJmYTBkYThhMWEzYjYxNTRjZWYwNmY3
14
- ZGVlNDFlNTExMjk4MTEyZWNlZjM2MTIwZDE5MWQxN2NjZmM2MDFlYTA1NGE4
15
- OTlhZmI3Y2MyNDRjZjMzMjEzNTgzNTg3MjJkNjdlM2U5OTI4MTY=
13
+ OTUzOTUyMWIwOGViMjhmY2MzMTllNTZlY2QwNTUxMmJiNTQxNWJmMjM3OWRk
14
+ YTE4ZmQ0MjRhYWVmMmJiZTM2OWVhYzQwYzhkZjJjY2IwMDgzNTQ0ZjMzYzJk
15
+ OTg5NGFiNmEyOWRhYmJlYWRjODI5OWY5ZWE3NmE4ZWExOWJlYjY=
@@ -22,12 +22,29 @@ module DiffParser
22
22
  if raw_line.info?
23
23
  yield current_file if current_file
24
24
  current_file = DiffParser::File.new(raw_line.full_line, diff)
25
- elsif options[:full] == current_file.path || options[:full] == true || !current_file.folded?
25
+ elsif fold_file?(current_file)
26
+ if options[:full] == current_file.path || options[:full] == true
27
+ current_file.push_line(raw_line, idx)
28
+ else
29
+ current_file.folded!
30
+ current_file.lines.empty? and (current_file.lines = [DiffLine.new(current_file.path, 'fold', nil, nil, 0, nil)])
31
+ end
32
+ else
26
33
  current_file.push_line(raw_line, idx)
27
34
  end
28
35
  end
29
36
 
30
37
  yield current_file
31
38
  end
39
+
40
+ private
41
+
42
+ def fold_file?(file)
43
+ file.file_max_changes_exceeded? || diff_size_exceeded?
44
+ end
45
+
46
+ def diff_size_exceeded?
47
+ diff.raw.bytesize > DiffParser.max_unfolded_diff_size
48
+ end
32
49
  end
33
50
  end
@@ -1,7 +1,7 @@
1
1
  module DiffParser
2
2
  class File
3
- attr_accessor :line_old, :line_new
4
- attr_reader :lines, :path, :file_info, :diff
3
+ attr_accessor :line_old, :line_new, :lines
4
+ attr_reader :path, :file_info, :diff
5
5
  delegate :additions, :deletions, to: :file_info
6
6
 
7
7
  def initialize(path, diff)
@@ -39,21 +39,20 @@ module DiffParser
39
39
  diff.sha
40
40
  end
41
41
 
42
- def folded?
43
- @folded ||= if file_max_changes_exceeded?
44
- lines << DiffLine.new(path, 'fold', nil, nil, 0, nil)
45
- true
46
- else
47
- false
48
- end
42
+ def folded!
43
+ @folded = true
49
44
  end
50
45
 
51
- private
46
+ def folded?
47
+ !!@folded
48
+ end
52
49
 
53
50
  def file_max_changes_exceeded?
54
51
  !file_info || (file_info.changes > DiffParser.max_changes_to_render)
55
52
  end
56
53
 
54
+ private
55
+
57
56
  def preprocess_path(path)
58
57
  path.split(' ').last[2..-1]
59
58
  end
@@ -1,3 +1,3 @@
1
1
  module DiffParser
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/diff_parser.rb CHANGED
@@ -9,6 +9,9 @@ module DiffParser
9
9
  mattr_accessor :max_changes_to_render
10
10
  @@max_changes_to_render = 500
11
11
 
12
+ mattr_accessor :max_unfolded_diff_size
13
+ @@max_unfolded_diff_size = 1.megabyte
14
+
12
15
  def self.setup
13
16
  yield self
14
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diff_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - stevo