gitlab_git 8.2.0 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b0f3419d64b2c0119bcdeb634baa4f1dfe0763b
4
- data.tar.gz: 22fcc9bd22892c98fa2c6d1c1e013f2c7ebf8204
3
+ metadata.gz: e997dc18170db77f9b2ffad597f0cc1654f457a8
4
+ data.tar.gz: d557e66cdbaa42781d0ad422c91d969cb1a91af6
5
5
  SHA512:
6
- metadata.gz: b8bdb953c22028834f1af0ed0203886b701c0c49ad0c8738037fcb0abb10e43a93d8ba56c883d678dfd238be39ebbd631fd574fa26ce73d909a76d6bfcdf39ae
7
- data.tar.gz: 3dc2d199d45f7c503c45f38d47c99d154b3f1eb2dac7ef6ae4ebf5734054824796cdac1a9787b42fb85ab5ff9c417e91086e0695b9467296e896ee709251c551
6
+ metadata.gz: cc478f222265b20bb57a26ec2f85f75863dd5f89a61cba9a9299c999e853a8a69896bcbeec880570f9c69a19fcf04b9285e87242c78519b384b05e3dbe68dd68
7
+ data.tar.gz: 753dec7e037607af0ceaf47dd260d061f8799d0b5fd0eab598a048b1765de44e3217ed8f9e0f9041d49dc1c864762b6373dbba4c74213199e5d3ec714fdeba99
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.2.0
1
+ 9.0.0
data/lib/gitlab_git.rb CHANGED
@@ -17,9 +17,11 @@ require_relative "gitlab_git/commit"
17
17
  require_relative "gitlab_git/commit_stats"
18
18
  require_relative "gitlab_git/compare"
19
19
  require_relative "gitlab_git/diff"
20
+ require_relative "gitlab_git/diff_collection"
20
21
  require_relative "gitlab_git/repository"
21
22
  require_relative "gitlab_git/tree"
22
23
  require_relative "gitlab_git/blob_snippet"
23
24
  require_relative "gitlab_git/ref"
24
25
  require_relative "gitlab_git/branch"
25
26
  require_relative "gitlab_git/tag"
27
+ require_relative "gitlab_git/util"
@@ -205,7 +205,7 @@ module Gitlab
205
205
  end
206
206
 
207
207
  def diffs(options = {})
208
- diff_from_parent(options).map { |diff| Gitlab::Git::Diff.new(diff) }
208
+ DiffCollection.new(diff_from_parent(options), options)
209
209
  end
210
210
 
211
211
  def parents
@@ -1,13 +1,12 @@
1
1
  module Gitlab
2
2
  module Git
3
3
  class Compare
4
- attr_reader :commits, :diffs, :same, :timeout, :head, :base
4
+ attr_reader :commits, :same, :head, :base
5
5
 
6
6
  def initialize(repository, base, head)
7
- @commits, @diffs = [], []
7
+ @commits = []
8
8
  @same = false
9
9
  @repository = repository
10
- @timeout = false
11
10
 
12
11
  return unless base && head
13
12
 
@@ -24,30 +23,13 @@ module Gitlab
24
23
  @commits = Gitlab::Git::Commit.between(repository, @base.id, @head.id)
25
24
  end
26
25
 
27
- def diffs(paths = nil, options = {})
26
+ def diffs(options = {})
28
27
  unless @head && @base
29
- return []
28
+ return Gitlab::Git::DiffCollection.new([])
30
29
  end
31
30
 
32
- # Try to collect diff only if diffs is empty
33
- # Otherwise return cached version
34
- if @diffs.empty? && @timeout == false
35
- begin
36
- @diffs = Gitlab::Git::Diff.between(@repository, @head.id, @base.id,
37
- options, *paths)
38
- rescue Gitlab::Git::Diff::TimeoutError => ex
39
- @diffs = []
40
- @timeout = true
41
- end
42
- end
43
-
44
- @diffs
45
- end
46
-
47
- # Check if diff is empty because it is actually empty
48
- # and not because its impossible to get it
49
- def empty_diff?
50
- diffs.empty? && timeout == false
31
+ paths = options.delete(:paths) || []
32
+ Gitlab::Git::Diff.between(@repository, @head.id, @base.id, options, *paths)
51
33
  end
52
34
  end
53
35
  end
@@ -130,7 +130,8 @@ module Gitlab
130
130
  :disable_pathspec_match, :deltas_are_icase,
131
131
  :include_untracked_content, :skip_binary_check,
132
132
  :include_typechange, :include_typechange_trees,
133
- :ignore_filemode, :recurse_ignored_dirs, :paths]
133
+ :ignore_filemode, :recurse_ignored_dirs, :paths,
134
+ :max_files, :max_lines, :all_diffs]
134
135
 
135
136
  if default_options
136
137
  actual_defaults = default_options.dup
@@ -187,6 +188,10 @@ module Gitlab
187
188
  a_mode == '160000' || b_mode == '160000'
188
189
  end
189
190
 
191
+ def line_count
192
+ @line_count ||= Util.count_lines(@diff)
193
+ end
194
+
190
195
  private
191
196
 
192
197
  def init_from_rugged(rugged)
@@ -0,0 +1,90 @@
1
+ module Gitlab
2
+ module Git
3
+ class DiffCollection
4
+ include Enumerable
5
+
6
+ DEFAULT_LIMITS = { max_files: 100, max_lines: 5000 }.freeze
7
+
8
+ def initialize(iterator, options={})
9
+ @iterator = iterator
10
+ @max_files = options.fetch(:max_files, DEFAULT_LIMITS[:max_files])
11
+ @max_lines = options.fetch(:max_lines, DEFAULT_LIMITS[:max_lines])
12
+ @all_diffs = !!options.fetch(:all_diffs, false)
13
+
14
+ @line_count = 0
15
+ @overflow = false
16
+ @array = Array.new
17
+ end
18
+
19
+ def each
20
+ @iterator.each_with_index do |raw, i|
21
+ # First yield cached Diff instances from @array
22
+ if @array[i]
23
+ yield @array[i]
24
+ next
25
+ end
26
+
27
+ # We have exhausted @array, time to create new Diff instances or stop.
28
+ break if @overflow
29
+
30
+ if !@all_diffs && i >= @max_files
31
+ @overflow = true
32
+ break
33
+ end
34
+
35
+ # Going by the number of files alone it is OK to create a new Diff instance.
36
+ diff = Gitlab::Git::Diff.new(raw)
37
+
38
+ @line_count += diff.line_count
39
+ if !@all_diffs && @line_count >= @max_lines
40
+ # This last Diff instance pushes us over the lines limit. We stop and
41
+ # discard it.
42
+ @overflow = true
43
+ break
44
+ end
45
+
46
+ yield @array[i] = diff
47
+ end
48
+ end
49
+
50
+ def empty?
51
+ !@iterator.any?
52
+ end
53
+
54
+ def overflow?
55
+ populate!
56
+ !!@overflow
57
+ end
58
+
59
+ def size
60
+ @size ||= count # forces a loop through @iterator
61
+ end
62
+
63
+ def real_size
64
+ populate!
65
+
66
+ if @overflow
67
+ "#{size}+"
68
+ else
69
+ size.to_s
70
+ end
71
+ end
72
+
73
+ def decorate!
74
+ each_with_index do |element, i|
75
+ @array[i] = yield(element)
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ def populate!
82
+ return if @populated
83
+
84
+ each { nil } # force a loop through all diffs
85
+ @populated = true
86
+ nil
87
+ end
88
+ end
89
+ end
90
+ end
@@ -320,9 +320,7 @@ module Gitlab
320
320
  # diff options. The +options+ hash can also include :break_rewrites to
321
321
  # split larger rewrites into delete/add pairs.
322
322
  def diff(from, to, options = {}, *paths)
323
- diff_patches(from, to, options, *paths).map do |p|
324
- Gitlab::Git::Diff.new(p)
325
- end
323
+ DiffCollection.new(diff_patches(from, to, options, *paths), options)
326
324
  end
327
325
 
328
326
  # Return the diff between +from+ and +to+ in a single patch string. The
@@ -0,0 +1,18 @@
1
+ module Gitlab
2
+ module Git
3
+ module Util
4
+ LINE_SEP = "\n"
5
+
6
+ def self.count_lines(string)
7
+ case string[-1]
8
+ when nil
9
+ 0
10
+ when LINE_SEP
11
+ string.count(LINE_SEP)
12
+ else
13
+ string.count(LINE_SEP) + 1
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.2.0
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Zaporozhets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github-linguist
@@ -82,6 +82,7 @@ files:
82
82
  - lib/gitlab_git/commit_stats.rb
83
83
  - lib/gitlab_git/compare.rb
84
84
  - lib/gitlab_git/diff.rb
85
+ - lib/gitlab_git/diff_collection.rb
85
86
  - lib/gitlab_git/encoding_helper.rb
86
87
  - lib/gitlab_git/path_helper.rb
87
88
  - lib/gitlab_git/popen.rb
@@ -89,6 +90,7 @@ files:
89
90
  - lib/gitlab_git/repository.rb
90
91
  - lib/gitlab_git/tag.rb
91
92
  - lib/gitlab_git/tree.rb
93
+ - lib/gitlab_git/util.rb
92
94
  homepage: http://rubygems.org/gems/gitlab_git
93
95
  licenses:
94
96
  - MIT
@@ -109,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
111
  version: '0'
110
112
  requirements: []
111
113
  rubyforge_project:
112
- rubygems_version: 2.4.8
114
+ rubygems_version: 2.2.5
113
115
  signing_key:
114
116
  specification_version: 4
115
117
  summary: Gitlab::Git library