gollum-rjgit_adapter 0.3.4-java → 0.4.0-java

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
  SHA256:
3
- metadata.gz: eca3d197750d25056e1be20903a959c2c48443e46827469405ddab50d46f2307
4
- data.tar.gz: 8336a3385dfcf3a58adf55c2d4e978014186ddb568179ea26e7f281408c90309
3
+ metadata.gz: 48f627d36cd5376254399d252034e79505e0e21dc125d04c77b3cabec3b4843c
4
+ data.tar.gz: de5904a088ff15a2509b3330594b2d6b9651b08541a1b8410eed820be929acd8
5
5
  SHA512:
6
- metadata.gz: 505678250b9d281a6880da42be1efab65bc339943d094a7d3efd75f73503da6384ad43b2c77dcb66ac8fb1bf8b19080b15f031ca0c99a2a92c4474d0e7275810
7
- data.tar.gz: 9afb266e98ac7261be17ade511bc99983d849f8fcc683c945e2a1a0e08b9e8823177d5489888735ab11c8720a6e9cfa4736e845e734be5b41e1782aee86a2ea5
6
+ metadata.gz: 4af0a30d70c46566ec318cfed08de9821097a91ed2e795988c461b3a8afa89aec61f48312ef2918adf5aa16744df4509145df6e2f322620491a0807fa6890cc9
7
+ data.tar.gz: 70cce95a94456a21952d22e2c9f3dbbaef7cd644d848eb9b5b80f31676f92c855557e2464eece5400a471946205ea27a46e76670a02b7daf9a3f2fca6e0c8e93
data/Gemfile CHANGED
@@ -1,8 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
- gem 'rake', '~> 10.4.2'
5
-
4
+ gem 'rake', '>= 12.3.3'
6
5
  gem 'adapter_specs', :git => 'https://github.com/gollum/adapter_specs.git'
7
6
 
8
7
  group :test do
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  gollum-lib_rjgit_adapter
2
2
  ========================
3
3
  [![Gem Version](https://badge.fury.io/rb/gollum-rjgit_adapter.svg)](http://badge.fury.io/rb/gollum-rjgit_adapter)
4
+ [![Build Status](https://travis-ci.org/gollum/rjgit_adapter.svg?branch=master)](https://travis-ci.org/gollum/rjgit_adapter)
4
5
 
5
- Adapter for Gollum to use [RJGit](https://github.com/repotag/rjgit) at the backend. This adapter is the default when your platform is JRuby, so you need only to `gem install gollum` and then use gollum normally.
6
-
7
- Note: this adapter is new. Although it passes the full test suite for gollum (and gollum-lib), it might well still contain bugs. Please let us know if you encouter any!
6
+ Adapter for Gollum to use [RJGit](https://github.com/repotag/rjgit) at the backend. The adapter requires using [JRuby](https://www.jruby.org/). This adapter is the default when your platform is JRuby, so you need only to `gem install gollum` and then use gollum normally.
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Adapter for Gollum to use RJGit at the backend.}
13
13
  s.description = %q{Adapter for Gollum to use RJGit at the backend.}
14
14
 
15
- s.add_runtime_dependency "rjgit", "~> 5.0"
15
+ s.add_runtime_dependency "rjgit", "> 5.6.0", "~> 5.6.0"
16
16
  s.add_development_dependency "rspec", "3.4.0"
17
17
 
18
18
  s.files = Dir['lib/**/*.rb'] + ["README.md", "Gemfile"]
@@ -19,7 +19,7 @@ module Gollum
19
19
  # Convert HEAD refspec to jgit canonical form
20
20
  def self.canonicalize(ref)
21
21
  return ref if sha?(ref)
22
- return "refs/heads/master" if ref.nil? || ref.to_s.upcase == "HEAD"
22
+ return 'refs/heads/master' if ref.nil? || ref.to_s.upcase == 'HEAD'
23
23
  result = ref.is_a?(Gollum::Git::Ref) ? ref.name : ref
24
24
  result = "refs/heads/#{result}" unless result =~ /^refs\/heads\//
25
25
  result
@@ -135,9 +135,28 @@ module Gollum
135
135
  def stats
136
136
  return @stats unless @stats.nil?
137
137
  rjgit_stats = @commit.stats
138
- additions = rjgit_stats[0]
139
- deletions = rjgit_stats[1]
140
- @stats = OpenStruct.new(:additions => additions, :deletions => deletions, :files => rjgit_stats[2].to_a.map {|a| a.flatten}, :id => id, :total => additions + deletions)
138
+
139
+ files = rjgit_stats[:files].map do |file|
140
+ file[:new_file] == file[:old_file] if file[:new_file] == '/dev/null' # File is deleted, display only the original, deleted path.
141
+ file.delete(:old_file) if (file[:old_file] == '/dev/null') || (file[:old_file] == file[:new_file]) # Don't include an old path when the file is new, or it's a regular update
142
+ file
143
+ end
144
+
145
+ @stats = OpenStruct.new(
146
+ :additions => rjgit_stats[:total_additions],
147
+ :deletions => rjgit_stats[:total_deletions],
148
+ :total => rjgit_stats[:total_additions] + rjgit_stats[:total_deletions],
149
+ :files => files,
150
+ :id => id
151
+ )
152
+ end
153
+
154
+ def tracked_pathname
155
+ begin
156
+ @commit.tracked_pathname
157
+ rescue NoMethodError
158
+ nil
159
+ end
141
160
  end
142
161
 
143
162
  end
@@ -152,19 +171,17 @@ module Gollum
152
171
  ::File.exists?(@git.jrepo.getDirectory.to_s)
153
172
  end
154
173
 
155
- def grep(query, options={})
174
+ def grep(query, options={}, &block)
156
175
  ref = Gollum::Git.canonicalize(options[:ref])
157
- blobs = []
176
+ results = []
177
+ walk = RevWalk.new(@git.jrepo)
158
178
  RJGit::Porcelain.ls_tree(@git.jrepo, options[:path], ref, {:recursive => true}).each do |item|
159
- walk = RevWalk.new(@git.jrepo)
160
- blobs << RJGit::Blob.new(@git.jrepo, item[:mode], item[:path], walk.lookup_blob(ObjectId.from_string(item[:id]))) if item[:type] == 'blob'
161
- end
162
- result = []
163
- blobs.each do |blob|
164
- count = blob.data.downcase.scan(/#{query}/i).length
165
- result << {:name => blob.path, :count => count} if count > 0
179
+ if item[:type] == 'blob'
180
+ blob = RJGit::Blob.new(@git.jrepo, item[:mode], item[:path], walk.lookup_blob(ObjectId.from_string(item[:id])))
181
+ results << yield(blob.path, blob.binary? ? nil : blob.data)
182
+ end
166
183
  end
167
- result
184
+ results.compact
168
185
  end
169
186
 
170
187
  def rm(path, options={})
@@ -181,34 +198,45 @@ module Gollum
181
198
 
182
199
  # rev_list({:max_count=>1}, ref)
183
200
  def rev_list(options, *refs)
184
- raise "Not implemented"
201
+ raise 'Not implemented'
185
202
  end
186
203
 
187
204
  def ls_files(query, options = {})
188
205
  ref = Gollum::Git.canonicalize(options[:ref])
189
- result = RJGit::Porcelain.ls_tree(@git.jrepo, options[:path], ref, {:recursive => true}).select {|object| object[:type] == "blob" && !!(::File.basename(object[:path]) =~ /#{query}/i) }
206
+ result = RJGit::Porcelain.ls_tree(@git.jrepo, options[:path], ref, {:recursive => true}).select {|object| object[:type] == 'blob' && !!(::File.basename(object[:path]) =~ /#{query}/i) }
190
207
  result.map do |r|
191
208
  r[:path]
192
209
  end
193
210
  end
194
211
 
195
- def apply_patch(sha, patch = nil, options = {})
196
- return false if patch.nil?
212
+ def revert_path(path, sha1, sha2, ref = 'HEAD^{commit}')
213
+ result, _paths = revert(path, sha1, sha2, ref)
214
+ result
215
+ end
216
+
217
+ def revert_commit(sha1, sha2, ref = 'HEAD^{commit}')
218
+ revert(nil, sha1, sha2, ref)
219
+ end
220
+
221
+ def revert(path, sha1, sha2, ref)
222
+ patch = generate_patch(sha1, sha2, path)
223
+ return false unless patch
197
224
  begin
198
- @git.apply_patch(patch)
199
- rescue Java::OrgEclipseJgitApiErrors::PatchApplyException
225
+ applier = RJGit::Plumbing::ApplyPatchToIndex.new(@git.jrepo, patch, ref)
226
+ applier.new_tree
227
+ rescue ::RJGit::PatchApplyException
200
228
  false
201
229
  end
202
- Tree.new(RJGit::Tree.new(@git.jrepo, nil, nil, RevWalk.new(@git.jrepo).lookup_tree(@git.jrepo.resolve("HEAD^{tree}"))))
203
230
  end
204
-
231
+
205
232
  # @repo.git.cat_file({:p => true}, sha)
206
233
  def cat_file(options, sha)
207
234
  @git.cat_file(options, sha)
208
235
  end
209
236
 
210
- def log(path = nil, ref = nil, options = {})
237
+ def log(ref = 'refs/heads/master', path = nil, options = {})
211
238
  ref = Gollum::Git.canonicalize(ref)
239
+ options[:list_renames] = true if path && options[:follow]
212
240
  @git.log(path, ref, options).map {|commit| Gollum::Git::Commit.new(commit)}
213
241
  end
214
242
  alias_method :versions_for_path, :log
@@ -225,6 +253,12 @@ module Gollum
225
253
  @git.pull(remote, branch, options)
226
254
  end
227
255
 
256
+ private
257
+
258
+ def generate_patch(sha1, sha2, path = nil)
259
+ RJGit::Plumbing::ApplyPatchToIndex.diffs_to_patch(RJGit::Porcelain.diff(@git.jrepo, patch: true, new_rev: sha1, old_rev: sha2, file_path: path))
260
+ end
261
+
228
262
  end
229
263
 
230
264
  class Index
@@ -242,9 +276,9 @@ module Gollum
242
276
  @index.add(path, data)
243
277
  end
244
278
 
245
- def commit(message, parents = nil, actor = nil, last_tree = nil, ref = "refs/heads/master")
279
+ def commit(message, parents = nil, actor = nil, last_tree = nil, ref = 'refs/heads/master')
246
280
  ref = Gollum::Git.canonicalize(ref)
247
- actor = actor ? actor.actor : RJGit::Actor.new("Gollum", "gollum@wiki")
281
+ actor = actor ? actor.actor : RJGit::Actor.new('Gollum', 'gollum@wiki')
248
282
  parents = parents.map{|parent| parent.commit} if parents
249
283
  commit_data = @index.commit(message, actor, parents, ref)
250
284
  return false if !commit_data
@@ -349,16 +383,17 @@ module Gollum
349
383
 
350
384
  # @wiki.repo.head.commit.sha
351
385
  def head
352
- Gollum::Git::Ref.new("refs/heads/master", @repo.head)
386
+ return nil unless @repo.head
387
+ Gollum::Git::Ref.new('refs/heads/master', @repo.head)
353
388
  end
354
389
 
355
390
  def index
356
391
  @index ||= Gollum::Git::Index.new(RJGit::Plumbing::Index.new(@repo))
357
392
  end
358
393
 
359
- def log(commit = 'refs/heads/master', path = nil, options = {})
394
+ def log(ref = 'refs/heads/master', path = nil, options = {})
360
395
  commit = Gollum::Git.canonicalize(commit)
361
- git.log(path, commit, options)
396
+ git.log(ref, path, options)
362
397
  end
363
398
 
364
399
  def lstree(sha, options={})
@@ -374,7 +409,7 @@ module Gollum
374
409
  @repo.path
375
410
  end
376
411
 
377
- def update_ref(ref = "refs/heads/master", commit_sha)
412
+ def update_ref(ref = 'refs/heads/master', commit_sha)
378
413
  ref = Gollum::Git.canonicalize(head)
379
414
  cm = self.commit(commit_sha)
380
415
  @repo.update_ref(cm.commit, true, ref)
@@ -1,7 +1,7 @@
1
1
  module Gollum
2
2
  module Lib
3
3
  module Git
4
- VERSION = '0.3.4'
4
+ VERSION = '0.4.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum-rjgit_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: java
6
6
  authors:
7
7
  - Bart Kamphorst, Dawa Ometto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-17 00:00:00.000000000 Z
11
+ date: 2020-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
+ - - ">"
17
+ - !ruby/object:Gem::Version
18
+ version: 5.6.0
16
19
  - - "~>"
17
20
  - !ruby/object:Gem::Version
18
- version: '5.0'
21
+ version: 5.6.0
19
22
  name: rjgit
20
23
  prerelease: false
21
24
  type: :runtime
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.6.0
24
30
  - - "~>"
25
31
  - !ruby/object:Gem::Version
26
- version: '5.0'
32
+ version: 5.6.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
@@ -72,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
78
  version: '0'
73
79
  requirements: []
74
80
  rubyforge_project:
75
- rubygems_version: 2.6.13
81
+ rubygems_version: 2.7.6
76
82
  signing_key:
77
83
  specification_version: 4
78
84
  summary: Adapter for Gollum to use RJGit at the backend.