gitlab_git 2.0.1 → 2.1.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: 6153bb71b711454165303016cafd44943691bcf6
4
- data.tar.gz: 05faffaaa0c4346fbfda09b80d24692044c7a3c4
3
+ metadata.gz: 5f61306b02ce00f09ae58472e5d486e4ed676388
4
+ data.tar.gz: 823cea793f9f714ea3b2a9459a7119ad5d80ad40
5
5
  SHA512:
6
- metadata.gz: ae2038afe8f25b18e141969b0099ea3d64fcca4475bfd287f1bc5fd7089c5ee3092d7e36e2191d633b89546c2d6ac941090d7f8ee3198fe1b23e2e7d1af93066
7
- data.tar.gz: 190841dbc36231e05a999fb3c6f4a848d4e6d5d8d51b85925e3ca325dd4902851ac5493cd70bf0385be90014bb03e4ca59681db6075385eda12854b6fd39ff7d
6
+ metadata.gz: f42e53e6b8662cd00f839539348033ca9437cf15b2e3b144542502a38f3aeda9b42d7074b853604a3b4201999e6440e1859e46c890491bdafef044e6e8214a5c
7
+ data.tar.gz: 1a17eb07cc61c26c005940c308d77b3ed2987e82c4b0109727e7b7576d39d5dce15247cb183ce414e19f6d3966939ea48dba6b43d08b501702b2288806144518
@@ -91,6 +91,11 @@ module Gitlab
91
91
  end
92
92
  end
93
93
 
94
+ # Delegate Repository#find_commits
95
+ def find_all(repo, options = {})
96
+ repo.find_commits(options)
97
+ end
98
+
94
99
  def decorate(commit, ref = nil)
95
100
  Gitlab::Git::Commit.new(commit, ref)
96
101
  end
@@ -190,6 +195,24 @@ module Gitlab
190
195
  raw_commit.to_patch
191
196
  end
192
197
 
198
+ # Get refs collection(Grit::Head or Grit::Remote or Grit::Tag)
199
+ #
200
+ # Ex.
201
+ # commit.ref(repo)
202
+ #
203
+ def refs(repo)
204
+ repo.refs_hash[id]
205
+ end
206
+
207
+ # Get ref names collection
208
+ #
209
+ # Ex.
210
+ # commit.ref_names(repo)
211
+ #
212
+ def ref_names(repo)
213
+ refs(repo).map(&:name)
214
+ end
215
+
193
216
  private
194
217
 
195
218
  def init_from_grit(grit)
@@ -11,9 +11,9 @@ module Gitlab
11
11
 
12
12
  def log
13
13
  log = nil
14
- Grit::Git.with_timeout(15) do
15
- # Limit log to 8k commits to avoid timeout for huge projects
16
- args = ['-8000', '--format=%aN%x0a%aE%x0a%cd', '--date=short', '--shortstat', '--no-merges']
14
+ Grit::Git.with_timeout(30) do
15
+ # Limit log to 6k commits to avoid timeout for huge projects
16
+ args = ['-6000', '--format=%aN%x0a%aE%x0a%cd', '--date=short', '--shortstat', '--no-merges']
17
17
  log = repo.git.run(nil, 'log', nil, {}, args)
18
18
  end
19
19
 
@@ -199,6 +199,96 @@ module Gitlab
199
199
  def diff(from, to)
200
200
  raw.diff(from, to)
201
201
  end
202
+
203
+ # Returns commits collection
204
+ #
205
+ # Ex.
206
+ # repo.find_commits(
207
+ # ref: 'master',
208
+ # max_count: 10,
209
+ # skip: 5,
210
+ # order: :date
211
+ # )
212
+ #
213
+ # +options+ is a Hash of optional arguments to git
214
+ # :ref is the ref from which to begin (SHA1 or name)
215
+ # :contains is the commit contained by the refs from which to begin (SHA1 or name)
216
+ # :max_count is the maximum number of commits to fetch
217
+ # :skip is the number of commits to skip
218
+ # :order is the commits order and allowed value is :date(default) or :topo
219
+ #
220
+ def find_commits(options = {})
221
+ actual_options = options.dup
222
+
223
+ allowed_options = [:ref, :max_count, :skip, :contains, :order]
224
+
225
+ actual_options.keep_if do |key, value|
226
+ allowed_options.include?(key)
227
+ end
228
+
229
+ default_options = {pretty: 'raw', order: :date}
230
+
231
+ actual_options = default_options.merge(actual_options)
232
+
233
+ order = actual_options.delete(:order)
234
+
235
+ case order
236
+ when :date
237
+ actual_options[:date_order] = true
238
+ when :topo
239
+ actual_options[:topo_order] = true
240
+ end
241
+
242
+ ref = actual_options.delete(:ref)
243
+
244
+ containing_commit = actual_options.delete(:contains)
245
+
246
+ args = []
247
+
248
+ if ref
249
+ args.push(ref)
250
+ elsif containing_commit
251
+ args.push(*branch_names_contains(containing_commit))
252
+ else
253
+ actual_options[:all] = true
254
+ end
255
+
256
+ output = raw.git.native(:rev_list, actual_options, *args)
257
+
258
+ Grit::Commit.list_from_string(raw, output).map do |commit|
259
+ Gitlab::Git::Commit.decorate(commit)
260
+ end
261
+ rescue Grit::GitRuby::Repository::NoSuchShaFound
262
+ []
263
+ end
264
+
265
+ # Returns branch names collection that contains the special commit(SHA1 or name)
266
+ #
267
+ # Ex.
268
+ # repo.branch_names_contains('master')
269
+ #
270
+ def branch_names_contains(commit)
271
+ output = raw.git.native(:branch, {contains: true}, commit)
272
+ # The output is expected as follow
273
+ # fix-aaa
274
+ # fix-bbb
275
+ # * master
276
+ output.scan(/[^* \n]+/)
277
+ end
278
+
279
+ # Get refs hash which key is SHA1 and value is ref object(Grit::Head or Grit::Remote or Grit::Tag)
280
+ def refs_hash
281
+ # Initialize only when first call
282
+ if @refs_hash.nil?
283
+ @refs_hash = Hash.new { |h, k| h[k] = [] }
284
+
285
+ @raw.refs.each do |r|
286
+ @refs_hash[r.commit.id] << r
287
+ end
288
+ end
289
+
290
+ @refs_hash
291
+ end
202
292
  end
203
293
  end
204
294
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Zaporozhets