gollum-rjgit_adapter 0.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a8a18819e637ec54da1fb7eff7701a710ce2a8b
4
+ data.tar.gz: 7711a47179c79831e2ebbf3b2188933b3a47ec35
5
+ SHA512:
6
+ metadata.gz: 35e83bd21391eb164ffbf70c478d33c4ddf42e4632d9177a85897dc2f2f15f2be00b981ece54e4a10c36dd15e2156e8be98f024905d2b8c36e0fcc7a326c1fb8
7
+ data.tar.gz: 1073d9557fdb8706000fd46df10902a2f45a66e2c65d06b1955a969ea3c148cb2e7a1db0581a6d0971ef42ffa31a99b13236517e238d27adcd252acc10e10c0c
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'rake', '~> 10.0.3'
5
+
6
+ gem 'adapter_specs', :git => 'https://github.com/gollum/adapter_specs.git'
7
+
8
+ group :test do
9
+ gem "simplecov"
10
+ end
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ gollum-lib_rjgit_adapter
2
+ ========================
3
+
4
+ Adapter for Gollum to use RJGit at the backend
@@ -0,0 +1 @@
1
+ require 'rjgit_adapter/git_layer_rjgit.rb'
@@ -0,0 +1,409 @@
1
+ # ~*~ encoding: utf-8 ~*~
2
+
3
+ require 'rjgit'
4
+ require 'ostruct'
5
+
6
+ module Gollum
7
+
8
+ def self.set_git_timeout(time)
9
+ end
10
+
11
+ def self.set_git_max_filesize(size)
12
+ end
13
+
14
+ module Git
15
+
16
+ import 'org.eclipse.jgit.revwalk.RevWalk'
17
+ import 'org.eclipse.jgit.lib.ObjectId'
18
+
19
+ # Convert HEAD refspec to jgit canonical form
20
+ def self.canonicalize(ref)
21
+ return ref if sha?(ref)
22
+ return "refs/heads/master" if ref.nil? || ref.to_s.upcase == "HEAD"
23
+ result = ref.is_a?(Gollum::Git::Ref) ? ref.name : ref
24
+ result = "refs/heads/#{result}" unless result =~ /^refs\/heads\//
25
+ result
26
+ end
27
+
28
+ def self.sha?(str)
29
+ !!(str =~ /^[0-9a-f]{40}$/)
30
+ end
31
+
32
+ class Actor
33
+
34
+ attr_accessor :name, :email
35
+ attr_reader :actor
36
+
37
+ def initialize(name, email)
38
+ @name = name
39
+ @email = email
40
+ @actor = RJGit::Actor.new(name, email)
41
+ end
42
+
43
+ def output(time)
44
+ @actor.output(time)
45
+ end
46
+
47
+ end
48
+
49
+ class Blob
50
+
51
+ attr_reader :size
52
+
53
+ # Gollum::Git::Blob.create(repo, :id => @sha, :name => name, :size => @size, :mode => @mode)
54
+ def self.create(repo, options)
55
+ blob = repo.find(options[:id], :blob)
56
+ jblob = blob.jblob unless blob.nil?
57
+ return nil if jblob.nil?
58
+ blob = self.new(RJGit::Blob.new(repo.repo, options[:mode], options[:name], jblob))
59
+ blob.set_size(options[:size]) if options[:size]
60
+ return blob
61
+ end
62
+
63
+ def initialize(blob)
64
+ @blob = blob
65
+ end
66
+
67
+ # Not required by gollum-lib. Should be private/protected?
68
+ def set_size(size)
69
+ @size = size
70
+ end
71
+
72
+ def id
73
+ @blob.id
74
+ end
75
+
76
+ def mode
77
+ @blob.mode
78
+ end
79
+
80
+ def data
81
+ @blob.data
82
+ end
83
+
84
+ def name
85
+ @blob.name
86
+ end
87
+
88
+ def mime_type
89
+ @blob.mime_type
90
+ end
91
+
92
+ def is_symlink
93
+ @blob.is_symlink?
94
+ end
95
+
96
+ def symlink_target(base_path = nil)
97
+ target = @blob.data
98
+ new_path = ::File.expand_path(::File.join('..', target), base_path)
99
+ return new_path if ::File.file? new_path
100
+ nil
101
+ end
102
+
103
+ end
104
+
105
+ class Commit
106
+ attr_reader :commit
107
+
108
+ def initialize(commit)
109
+ @commit = commit
110
+ end
111
+
112
+ def id
113
+ @commit.id
114
+ end
115
+ alias_method :sha, :id
116
+ alias_method :to_s, :id
117
+
118
+ def author
119
+ author = @commit.actor
120
+ Gollum::Git::Actor.new(author.name, author.email)
121
+ end
122
+
123
+ def authored_date
124
+ @commit.authored_date
125
+ end
126
+
127
+ def message
128
+ @commit.message
129
+ end
130
+
131
+ def tree
132
+ Gollum::Git::Tree.new(@commit.tree)
133
+ end
134
+
135
+ def stats
136
+ return @stats unless @stats.nil?
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)
141
+ end
142
+
143
+ end
144
+
145
+ class Git
146
+
147
+ def initialize(git)
148
+ @git = git
149
+ end
150
+
151
+ def exist?
152
+ ::File.exists?(@git.jrepo.getDirectory.to_s)
153
+ end
154
+
155
+ def grep(query, options={})
156
+ ref = Gollum::Git.canonicalize(options[:ref])
157
+ blobs = []
158
+ RJGit::Porcelain.ls_tree(@git.jrepo, nil, {:ref => ref, :recursive => true, :file_path => options[:path]}).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
166
+ end
167
+ result
168
+ end
169
+
170
+ def rm(path, options={})
171
+ @git.remove(path)
172
+ end
173
+
174
+ def checkout(path, ref, options = {})
175
+ ref = Gollum::Git.canonicalize(ref)
176
+ options[:paths] = [path]
177
+ options[:force] = true
178
+ options[:commit] = "#{ref}^{commit}"
179
+ @git.checkout(ref, options)
180
+ end
181
+
182
+ # rev_list({:max_count=>1}, ref)
183
+ def rev_list(options, *refs)
184
+ raise "Not implemented"
185
+ end
186
+
187
+ def ls_files(query, options = {})
188
+ ref = Gollum::Git.canonicalize(options[:ref])
189
+ result = RJGit::Porcelain.ls_tree(@git.jrepo, nil, {:ref => ref, :recursive => true, :file_path => options[:path]}).select {|object| object[:type] == "blob" && object[:path].split("/").last.scan(/#{query}/i) }
190
+ result.map do |r|
191
+ r[:path]
192
+ end
193
+ end
194
+
195
+ def apply_patch(sha, patch = nil, options = {})
196
+ return false if patch.nil?
197
+ @git.apply_patch(patch)
198
+ Tree.new(RJGit::Tree.new(@git.jrepo, nil, nil, RevWalk.new(@git.jrepo).lookup_tree(@git.jrepo.resolve("HEAD^{tree}"))))
199
+ end
200
+
201
+ # @repo.git.cat_file({:p => true}, sha)
202
+ def cat_file(options, sha)
203
+ @git.cat_file(options, sha)
204
+ end
205
+
206
+ def log(path = nil, ref = nil, options = nil)
207
+ ref = Gollum::Git.canonicalize(ref)
208
+ @git.log(path, ref, options).map {|commit| Gollum::Git::Commit.new(commit)}
209
+ end
210
+ alias_method :versions_for_path, :log
211
+
212
+ def refs(options, prefix)
213
+ @git.refs(options, prefix)
214
+ end
215
+
216
+ def push(remote, branch, options = {})
217
+ @git.push(remote, [branch].flatten, options)
218
+ end
219
+
220
+ def pull(remote, branch = nil, options = {})
221
+ @git.pull(remote, branch, options)
222
+ end
223
+
224
+ end
225
+
226
+ class Index
227
+
228
+ def initialize(index)
229
+ @index = index
230
+ @current_tree = nil
231
+ end
232
+
233
+ def delete(path)
234
+ @index.delete(path)
235
+ end
236
+
237
+ def add(path, data)
238
+ @index.add(path, data)
239
+ end
240
+
241
+ def commit(message, parents = nil, actor = nil, last_tree = nil, ref = "refs/heads/master")
242
+ ref = Gollum::Git.canonicalize(ref)
243
+ actor = actor ? actor.actor : RJGit::Actor.new("Gollum", "gollum@wiki")
244
+ parents.map!{|parent| parent.commit} if parents
245
+ commit_data = @index.commit(message, actor, parents, ref)
246
+ return false if !commit_data
247
+ commit_data[2]
248
+ end
249
+
250
+ def tree
251
+ @index.treemap
252
+ end
253
+
254
+ def read_tree(tree)
255
+ tree = tree.id if tree.is_a?(Tree)
256
+ begin
257
+ @index.current_tree = RJGit::Tree.new(@index.jrepo, nil, nil, RevWalk.new(@index.jrepo).lookup_tree(@index.jrepo.resolve("#{tree}^{tree}")))
258
+ rescue
259
+ raise Gollum::Git::NoSuchShaFound
260
+ end
261
+ @current_tree = Gollum::Git::Tree.new(@index.current_tree)
262
+ end
263
+
264
+ def current_tree
265
+ @current_tree
266
+ end
267
+
268
+ end
269
+
270
+ class Ref
271
+ def initialize(name, commit)
272
+ @name, @commit = name, commit
273
+ end
274
+
275
+ def name
276
+ @name
277
+ end
278
+
279
+ def commit
280
+ Gollum::Git::Commit.new(@commit)
281
+ end
282
+
283
+ end
284
+
285
+ class Diff
286
+ def initialize(diff)
287
+ @diff = diff
288
+ end
289
+ def diff
290
+ @diff[:patch]
291
+ end
292
+ end
293
+
294
+ class Repo
295
+
296
+ attr_reader :repo
297
+
298
+ def initialize(path, options = {})
299
+ @repo = RJGit::Repo.new(path, options)
300
+ end
301
+
302
+ def self.init(path, git_options = {}, repo_options = {})
303
+ RJGit::Repo.create(path, {:is_bare => false})
304
+ self.new(path, {:is_bare => false})
305
+ end
306
+
307
+ def self.init_bare(path, git_options = {}, repo_options = {})
308
+ RJGit::Repo.create(path, {:is_bare => true})
309
+ self.new(path, {:is_bare => true})
310
+ end
311
+
312
+ def bare
313
+ @repo.bare
314
+ end
315
+
316
+ def config
317
+ @repo.config
318
+ end
319
+
320
+ def git
321
+ @git ||= Gollum::Git::Git.new(@repo.git)
322
+ end
323
+
324
+ def commit(ref)
325
+ ref = Gollum::Git.canonicalize(ref)
326
+ objectid = @repo.jrepo.resolve(ref)
327
+ return nil if objectid.nil?
328
+ id = objectid.name
329
+ commit = @repo.find(id, :commit)
330
+ return nil if commit.nil?
331
+ Gollum::Git::Commit.new(commit)
332
+ rescue Java::OrgEclipseJgitErrors::RevisionSyntaxException
333
+ raise Gollum::Git::NoSuchShaFound
334
+ end
335
+
336
+ def commits(ref = nil, max_count = 10, skip = 0)
337
+ ref = Gollum::Git.canonicalize(ref)
338
+ @repo.commits(ref, max_count).map{|commit| Gollum::Git::Commit.new(commit)}
339
+ end
340
+
341
+ # Not required by gollum-lib
342
+ def find(sha, type)
343
+ @repo.find(sha, type)
344
+ end
345
+
346
+ # @wiki.repo.head.commit.sha
347
+ def head
348
+ Gollum::Git::Ref.new("refs/heads/master", @repo.head)
349
+ end
350
+
351
+ def index
352
+ @index ||= Gollum::Git::Index.new(RJGit::Plumbing::Index.new(@repo))
353
+ end
354
+
355
+ def log(commit = 'refs/heads/master', path = nil, options = {})
356
+ commit = Gollum::Git.canonicalize(commit)
357
+ git.log(path, commit, options)
358
+ end
359
+
360
+ def lstree(sha, options={})
361
+ entries = RJGit::Porcelain.ls_tree(@repo.jrepo, @repo.find(sha, :tree), {:recursive => options[:recursive]})
362
+ entries.map! do |entry|
363
+ entry[:mode] = entry[:mode].to_s(8)
364
+ entry[:sha] = entry[:id]
365
+ entry
366
+ end
367
+ end
368
+
369
+ def path
370
+ @repo.path
371
+ end
372
+
373
+ def update_ref(ref = "refs/heads/master", commit_sha)
374
+ ref = Gollum::Git.canonicalize(head)
375
+ cm = self.commit(commit_sha)
376
+ @repo.update_ref(cm.commit, true, ref)
377
+ end
378
+
379
+ def diff(sha1, sha2, path = nil)
380
+ RJGit::Porcelain.diff(@repo, {:old_rev => sha2, :new_rev => sha1, :file_path => path, :patch => true}).map {|d| Diff.new(d)}
381
+ end
382
+
383
+ end
384
+
385
+ class Tree
386
+
387
+ def initialize(tree)
388
+ @tree = tree
389
+ end
390
+
391
+ def id
392
+ @tree.id
393
+ end
394
+
395
+ def /(file)
396
+ @tree.send(:/, file)
397
+ end
398
+
399
+ def blobs
400
+ return Array.new if @tree == {}
401
+ @tree.blobs.map{|blob| Gollum::Git::Blob.new(blob) }
402
+ end
403
+ end
404
+
405
+ class NoSuchShaFound < StandardError
406
+ end
407
+
408
+ end
409
+ end
@@ -0,0 +1,7 @@
1
+ module Gollum
2
+ module Lib
3
+ module Git
4
+ VERSION = '0.1'
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gollum-rjgit_adapter
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: java
6
+ authors:
7
+ - Bart Kamphorst, Dawa Ometto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rjgit
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '0.3'
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.13.0
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '='
37
+ - !ruby/object:Gem::Version
38
+ version: 2.13.0
39
+ prerelease: false
40
+ type: :development
41
+ description: Adapter for Gollum to use RJGit at the backend.
42
+ email:
43
+ - repotag-dev@googlegroups.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - README.md
50
+ - lib/rjgit_adapter.rb
51
+ - lib/rjgit_adapter/git_layer_rjgit.rb
52
+ - lib/rjgit_adapter/version.rb
53
+ homepage: https://github.com/repotag/gollum-lib_rjgit_adapter
54
+ licenses: []
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.4.5
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Adapter for Gollum to use RJGit at the backend.
76
+ test_files: []