gitlab_git 10.6.3 → 10.6.4

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: d7297d7f12907c147d8b039f91aa75a16487a906
4
- data.tar.gz: 1de3808442341ecfad0353eef558ba61324f658c
3
+ metadata.gz: 5415dadf9d220102e60808ce90da48ae04c01d51
4
+ data.tar.gz: 0d50f0dca69aa08ebf13668edc93bbce2a10ea53
5
5
  SHA512:
6
- metadata.gz: 8c9dfac728a81523ed04bdf3342e9e1a332348246db2ef10013f70f793170858c5900ed9add33c969d5f93031b402f157ec92cab2ad813e04dfb10205d51332b
7
- data.tar.gz: 0ebaf2bd41d9ce8bf6babdc4d8a4859d6f80c233606cf108cc9dbdf57dc2685819afaea35f431a540f1eeeafc4d93c35fe2d2939e76405c2a7b8eef50247621e
6
+ metadata.gz: 55e01cc03c7a744321cb825c568200df8ba55e20f830f85a0b2ffcfb1fba416b399220cce1a444bb5e68cd2d3677a8dc8d61071dd58032dc872240da7f0f654d
7
+ data.tar.gz: 8e3c8701cb9f258b0252d9976113d5db8f3185a3e41e9dea0343a229c5265622310232ee5ca79a243620da156319d38bbb628b2b587d11f6f5787ddfef292ceb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 10.6.3
1
+ 10.6.4
@@ -13,7 +13,7 @@ module Gitlab
13
13
  # blob data should use load_all_data!.
14
14
  MAX_DATA_DISPLAY_SIZE = 10485760
15
15
 
16
- attr_accessor :name, :path, :size, :data, :mode, :id, :commit_id, :loaded_size
16
+ attr_accessor :name, :path, :size, :data, :mode, :id, :commit_id, :loaded_size, :binary
17
17
 
18
18
  class << self
19
19
  def find(repository, sha, path)
@@ -38,6 +38,7 @@ module Gitlab
38
38
  mode: blob_entry[:filemode].to_s(8),
39
39
  path: path,
40
40
  commit_id: sha,
41
+ binary: blob.binary?
41
42
  )
42
43
  end
43
44
  end
@@ -50,6 +51,7 @@ module Gitlab
50
51
  id: blob.oid,
51
52
  size: blob.size,
52
53
  data: blob.content(MAX_DATA_DISPLAY_SIZE),
54
+ binary: blob.binary?
53
55
  )
54
56
  end
55
57
 
@@ -247,7 +249,7 @@ module Gitlab
247
249
  end
248
250
 
249
251
  def initialize(options)
250
- %w(id name path size data mode commit_id).each do |key|
252
+ %w(id name path size data mode commit_id binary).each do |key|
251
253
  self.send("#{key}=", options[key.to_sym])
252
254
  end
253
255
 
@@ -256,6 +258,10 @@ module Gitlab
256
258
  @loaded_size = @data.bytesize if @data
257
259
  end
258
260
 
261
+ def binary?
262
+ @binary.nil? ? super : @binary == true
263
+ end
264
+
259
265
  def empty?
260
266
  !data || data == ''
261
267
  end
@@ -13,6 +13,12 @@ module Gitlab
13
13
 
14
14
  attr_accessor :too_large
15
15
 
16
+ # The maximum size of a diff to display.
17
+ DIFF_SIZE_LIMIT = 102400 # 100 KB
18
+
19
+ # The maximum size before a diff is collapsed.
20
+ DIFF_COLLAPSE_LIMIT = 10240 # 10 KB
21
+
16
22
  class << self
17
23
  def between(repo, head, base, options = {}, *paths)
18
24
  # Only show what is new in the source branch compared to the target branch, not the other way around.
@@ -158,12 +164,12 @@ module Gitlab
158
164
  end
159
165
  end
160
166
 
161
- def initialize(raw_diff)
167
+ def initialize(raw_diff, collapse: false)
162
168
  case raw_diff
163
169
  when Hash
164
- init_from_hash(raw_diff)
170
+ init_from_hash(raw_diff, collapse: collapse)
165
171
  when Rugged::Patch, Rugged::Diff::Delta
166
- init_from_rugged(raw_diff)
172
+ init_from_rugged(raw_diff, collapse: collapse)
167
173
  when nil
168
174
  raise "Nil as raw diff passed"
169
175
  else
@@ -197,12 +203,16 @@ module Gitlab
197
203
 
198
204
  def too_large?
199
205
  if @too_large.nil?
200
- @too_large = @diff.bytesize >= 102400 # 100 KB
206
+ @too_large = @diff.bytesize >= DIFF_SIZE_LIMIT
201
207
  else
202
208
  @too_large
203
209
  end
204
210
  end
205
211
 
212
+ def collapsible?
213
+ @diff.bytesize >= DIFF_COLLAPSE_LIMIT
214
+ end
215
+
206
216
  def prune_large_diff!
207
217
  @diff = ''
208
218
  @line_count = 0
@@ -214,10 +224,6 @@ module Gitlab
214
224
  false
215
225
  end
216
226
 
217
- def collapsible?
218
- @diff.bytesize >= 10240 # 10 KB
219
- end
220
-
221
227
  def prune_collapsed_diff!
222
228
  @diff = ''
223
229
  @line_count = 0
@@ -226,9 +232,9 @@ module Gitlab
226
232
 
227
233
  private
228
234
 
229
- def init_from_rugged(rugged)
235
+ def init_from_rugged(rugged, collapse: false)
230
236
  if rugged.is_a?(Rugged::Patch)
231
- @diff = encode!(strip_diff_headers(rugged.to_s))
237
+ init_from_rugged_patch(rugged, collapse: collapse)
232
238
  d = rugged.delta
233
239
  else
234
240
  d = rugged
@@ -243,12 +249,46 @@ module Gitlab
243
249
  @deleted_file = d.deleted?
244
250
  end
245
251
 
246
- def init_from_hash(hash)
252
+ def init_from_rugged_patch(patch, collapse: false)
253
+ # Don't bother initializing diffs that are too large. If a diff is
254
+ # binary we're not going to display anything so we skip the size check.
255
+ unless patch.delta.binary?
256
+ diff_size = patch_size(patch)
257
+
258
+ if diff_size >= DIFF_SIZE_LIMIT
259
+ prune_large_diff!
260
+ return
261
+ elsif collapse && diff_size >= DIFF_COLLAPSE_LIMIT
262
+ prune_collapsed_diff!
263
+ return
264
+ end
265
+ end
266
+
267
+ @diff = encode!(strip_diff_headers(patch.to_s))
268
+ end
269
+
270
+ def init_from_hash(hash, collapse: false)
247
271
  raw_diff = hash.symbolize_keys
248
272
 
249
273
  serialize_keys.each do |key|
250
274
  send(:"#{key}=", raw_diff[key.to_sym])
251
275
  end
276
+
277
+ prune_large_diff! if too_large?
278
+ prune_collapsed_diff! if collapse && collapsible?
279
+ end
280
+
281
+ # Returns the size of a diff without taking any diff markers into account.
282
+ def patch_size(patch)
283
+ size = 0
284
+
285
+ patch.each_hunk do |hunk|
286
+ hunk.each_line do |line|
287
+ size += line.content.bytesize
288
+ end
289
+ end
290
+
291
+ size
252
292
  end
253
293
 
254
294
  # Strip out the information at the beginning of the patch's text to match
@@ -103,23 +103,12 @@ module Gitlab
103
103
  break
104
104
  end
105
105
 
106
- # Going by the number of files alone it is OK to create a new Diff instance.
107
- diff = Gitlab::Git::Diff.new(raw)
108
-
109
- # If a diff is too large we still want to display some information
110
- # about it (e.g. the file path) without keeping the raw data around
111
- # (as this would be a waste of memory usage).
112
- #
113
- # This also removes the line count (from the diff itself) so it
114
- # doesn't add up to the total amount of lines.
115
- if diff.too_large?
116
- diff.prune_large_diff!
117
- end
106
+ collapse = !@all_diffs && !@no_collapse
107
+
108
+ diff = Gitlab::Git::Diff.new(raw, collapse: collapse)
118
109
 
119
- if !@all_diffs && !@no_collapse
120
- if diff.collapsible? || over_safe_limits?(i)
121
- diff.prune_collapsed_diff!
122
- end
110
+ if collapse && over_safe_limits?(i)
111
+ diff.prune_collapsed_diff!
123
112
  end
124
113
 
125
114
  @line_count += diff.line_count
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: 10.6.3
4
+ version: 10.6.4
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-09-06 00:00:00.000000000 Z
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: github-linguist