rjgit 5.7.0.1 → 5.7.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rjgit.rb +57 -0
  3. data/lib/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee1618ecf4d5b33793cda5f7f2d4a83af873e48167ae426f144cbb21177beab0
4
- data.tar.gz: 95b32d3cbf4b5b85117986d1daa088180390d327b6503b9b042aa1055a00d20a
3
+ metadata.gz: 62cd118bda14efaa2c83c38eb7cbb3e4792fde99d4cf3962e20c9511470c2115
4
+ data.tar.gz: 82a455adf1a9dad2aed63019ea98cde3b4c0c446fab52f2e40f3a2df397eb452
5
5
  SHA512:
6
- metadata.gz: 268fecedf6964680fc7e94c8fa4b3f66333d556976c154a0db0bbbb8121ee9e23bae563c4493bab07ed798d09b7c57d677062d1a5d5561e56f0d4ab56a256eab
7
- data.tar.gz: 00bfe427f864a3aa3854c5aac56b94d1067695dbd0bd6e2dcf8f7302ad6545bd6a55c0c656e6f897bd848a921be35545067ef328fcc577aa2010b7ff1c005c1f
6
+ metadata.gz: 48340d990bfce221b2a277417e8647ce3fe5765e5bc889af7ac9edf1cf503ac6a3d15d992d0335521dc1abe99e32fea1c221297fa44b6270e9ebab1f0bc73f0b
7
+ data.tar.gz: ca53c513482e6232396f9d03c502d89d08eee2d9ff034adddf6c2083ebf6fc021fc715f0acaeb4a1a4859c3223fe9fffbc32c04d6466f2eb2a9057c3fba80ef2
data/lib/rjgit.rb CHANGED
@@ -27,12 +27,17 @@ module RJGit
27
27
 
28
28
  module Porcelain
29
29
 
30
+ import 'java.io.IOException'
30
31
  import 'org.eclipse.jgit.lib.Constants'
31
32
  import 'org.eclipse.jgit.api.AddCommand'
32
33
  import 'org.eclipse.jgit.api.CommitCommand'
33
34
  import 'org.eclipse.jgit.api.BlameCommand'
35
+ import 'org.eclipse.jgit.api.errors.RefNotFoundException'
34
36
  import 'org.eclipse.jgit.blame.BlameGenerator'
35
37
  import 'org.eclipse.jgit.blame.BlameResult'
38
+ import 'org.eclipse.jgit.errors.IncorrectObjectTypeException'
39
+ import 'org.eclipse.jgit.errors.InvalidPatternException'
40
+ import 'org.eclipse.jgit.errors.MissingObjectException'
36
41
  import 'org.eclipse.jgit.treewalk.CanonicalTreeParser'
37
42
  import 'org.eclipse.jgit.diff.DiffFormatter'
38
43
 
@@ -163,6 +168,58 @@ module RJGit
163
168
  RJGit.convert_diff_entries(diff_entries)
164
169
  end
165
170
 
171
+ def self.describe(repository, ref, options = {})
172
+ options = {:always => false, :long => false, :tags => false, :match => []}.merge(options)
173
+ repo = RJGit.repository_type(repository)
174
+ git = RubyGit.new(repo).jgit
175
+ command = git.describe.
176
+ set_always(options[:always]).
177
+ set_long(options[:long]).
178
+ set_tags(options[:tags])
179
+ begin
180
+ command = command.set_target(ref)
181
+ rescue IncorrectObjectTypeException, IOException, MissingObjectException, RefNotFoundException
182
+ return nil
183
+ end
184
+ options[:match].each do |match|
185
+ begin
186
+ command = command.set_match(match)
187
+ rescue InvalidPatternException
188
+ return nil
189
+ end
190
+ end
191
+ command.call
192
+ end
193
+
194
+ # options:
195
+ # * ref
196
+ # * path_filter
197
+ # * case_insensitive
198
+ def self.grep(repository, query, options={})
199
+ case_insensitive = options[:case_insensitive]
200
+ repo = RJGit.repository_type(repository)
201
+ walk = RevWalk.new(repo)
202
+ ls_tree_options = {:recursive => true, :path_filter => options[:path_filter]}
203
+
204
+ query = case query
205
+ when Regexp then query
206
+ when String then Regexp.new(Regexp.escape(query))
207
+ else raise "A #{query.class} was passed to #{self}.grep(). Only Regexps and Strings are supported!"
208
+ end
209
+
210
+ query = Regexp.new(query.source, query.options | Regexp::IGNORECASE) if case_insensitive
211
+
212
+ ls_tree(repo, nil, options.fetch(:ref, 'HEAD'), ls_tree_options).each_with_object({}) do |item, result|
213
+ blob = Blob.new(repo, item[:mode], item[:path], walk.lookup_blob(ObjectId.from_string(item[:id])))
214
+ next if blob.binary?
215
+
216
+ rows = blob.data.split("\n")
217
+ data = rows.grep(query)
218
+ next if data.empty?
219
+
220
+ result[blob.path] = data
221
+ end
222
+ end
166
223
  end
167
224
 
168
225
  module Plumbing
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RJGit
2
- VERSION = "5.7.0.1"
2
+ VERSION = "5.7.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.7.0.1
4
+ version: 5.7.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Engelen
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2020-04-29 00:00:00.000000000 Z
15
+ date: 2020-05-14 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  requirement: !ruby/object:Gem::Requirement