gollum-grit_adapter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of gollum-grit_adapter might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDA5YTliYjA0Yjc3YmQ1N2UwNTJlMTYyZmM1MDJkYjkwYjgxOWFkMQ==
5
+ data.tar.gz: !binary |-
6
+ ZjMwMzE0NzNkNGJmOTZlODA0NmY4N2ZhMzExMzAwMDQ3ZmE4NTNjYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NzA4NjgyOGQzMGY1OGQ0ZWRlOGE3OTc3Nzc4OGI5MjYzYzQ2N2QxN2IwYjgw
10
+ ODllZGVlY2U3ZDY1MGE2YmI5NGZjZDkzNzMyNDQxMzJjN2U2MTg5NWFmZjU3
11
+ NDBjODRlZDRmNGI1M2I1YWRiZmJhN2M2MWM0ZjZlMjNjMjVhODQ=
12
+ data.tar.gz: !binary |-
13
+ ODA4NjYyZDZlNTMwMjBiZTg5Y2IxNDA0Y2JmNTI5Zjk5YzE2NWQxNGM0N2Vj
14
+ OTgwNWQ5OTYxNjVjZDA2MTVkZTFlYTViYmEzYjEwMzRhNWUxMTllYjFhNzYz
15
+ NDFlMzY0MDNlYTE4ZmYyMjc2NDg4N2VkYmY1NzZmMmJlZDY1NWU=
data/Gemfile ADDED
@@ -0,0 +1,11 @@
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 "rspec", "2.13.0"
10
+ gem "simplecov"
11
+ end
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Adapter for Gollum to use Grit at the backend
@@ -0,0 +1,381 @@
1
+ # ~*~ encoding: utf-8 ~*~
2
+
3
+ require 'grit'
4
+
5
+ module Gollum
6
+
7
+ def self.set_git_timeout(time)
8
+ Grit::Git.git_timeout = time
9
+ end
10
+
11
+ def self.set_git_max_filesize(size)
12
+ Grit::Git.git_max_size = size
13
+ end
14
+
15
+ module Git
16
+
17
+ class Actor
18
+
19
+ attr_accessor :name, :email
20
+
21
+ def initialize(name, email)
22
+ @name = name
23
+ @email = email
24
+ @actor = Grit::Actor.new(name, email)
25
+ end
26
+
27
+ def output(time)
28
+ @actor.output(time)
29
+ end
30
+
31
+ end
32
+
33
+ class Blob
34
+ def self.create(repo, options)
35
+ #Grit::Blob.create(repo, :id => @sha, :name => name, :size => @size, :mode => @mode)
36
+ blob = Grit::Blob.create(repo, options)
37
+ self.new(blob)
38
+ end
39
+
40
+ def initialize(blob)
41
+ @blob = blob
42
+ end
43
+
44
+ def id
45
+ @blob.id
46
+ end
47
+
48
+ def mode
49
+ @blob.mode
50
+ end
51
+
52
+ def size
53
+ @blob.size
54
+ end
55
+
56
+ def data
57
+ @blob.data
58
+ end
59
+
60
+ def name
61
+ @blob.name
62
+ end
63
+
64
+ def mime_type
65
+ @blob.mime_type
66
+ end
67
+
68
+ def is_symlink
69
+ @blob.is_symlink
70
+ end
71
+
72
+ def symlink_target(base_path = nil)
73
+ @blob.symlink_target(base_path)
74
+ end
75
+ end
76
+
77
+ class Commit
78
+
79
+ def initialize(commit)
80
+ @commit = commit
81
+ end
82
+
83
+ def id
84
+ @commit.id
85
+ end
86
+ alias_method :sha, :id
87
+
88
+ def to_s
89
+ @commit.id
90
+ end
91
+
92
+ def author
93
+ author = @commit.author
94
+ Gollum::Git::Actor.new(author.name, author.email)
95
+ end
96
+
97
+ def authored_date
98
+ @commit.authored_date
99
+ end
100
+
101
+ def message
102
+ @commit.message
103
+ end
104
+
105
+ def tree
106
+ Gollum::Git::Tree.new(@commit.tree)
107
+ end
108
+
109
+ # Grit::Commit.list_from_string(@wiki.repo, log)
110
+ def self.list_from_string(repo, log)
111
+ Grit::Commit.list_from_string(repo, log)
112
+ end
113
+
114
+ end
115
+
116
+ # Note that in Grit, the methods grep, rm, checkout, ls_files
117
+ # are all passed to native via method_missing. Hence the uniform
118
+ # method signatures.
119
+ class Git
120
+
121
+ def initialize(git)
122
+ @git = git
123
+ end
124
+
125
+ def exist?
126
+ @git.exist?
127
+ end
128
+
129
+ def grep(query, options={})
130
+ ref = options[:ref] ? options[:ref] : "HEAD"
131
+ args = [{}, '-i', '-c', query, ref, '--']
132
+ args << '--' << options[:path] if options[:path]
133
+ result = @git.grep(*args).split("\n")
134
+ result.map do |line|
135
+ line = line.split(":")
136
+ {:name => line[1], :count => line[2]}
137
+ end
138
+ end
139
+
140
+ # git.rm({'f' => true}, '--', path)
141
+ def rm(path, options = {}, &block)
142
+ options['f'] = true if options[:force]
143
+ @git.rm(options, '--', path, &block)
144
+ end
145
+
146
+ # git.checkout({}, 'HEAD', '--', path)
147
+ def checkout(path, ref, options = {}, &block)
148
+ @git.checkout(options, ref, '--', path, &block)
149
+ end
150
+
151
+ def rev_list(options, *refs)
152
+ @git.rev_list(options, *refs)
153
+ rescue Grit::GitRuby::Repository::NoSuchShaFound
154
+ raise Gollum::Git::NoSuchShaFound
155
+ end
156
+
157
+ def ls_files(query, options = {})
158
+ options[:ref] = options[:ref] ? options[:ref] : "HEAD"
159
+ @git.ls_files({}, "*#{query}*").split("\n")
160
+ end
161
+
162
+ def ls_tree(options={}, *args, &block)
163
+ @git.native(:ls_tree, options, *args, &block)
164
+ # {:r => true, :l => true, :z => true}, sha)
165
+ end
166
+
167
+ def apply_patch(options={}, head_sha=nil, patch=nil)
168
+ @git.apply_patch(options, head_sha, patch)
169
+ end
170
+
171
+ # @repo.git.cat_file({:p => true}, sha)
172
+ def cat_file(options, sha)
173
+ @git.cat_file(options, sha)
174
+ end
175
+
176
+ def versions_for_path(path = nil, ref = nil, options = nil)
177
+ if options[:follow]
178
+ options[:pretty] = 'raw'
179
+ options.delete :max_count
180
+ options.delete :skip
181
+ logstr = log(path, ref, options)
182
+ Gollum::Git::Commit.list_from_string(repo, logstr)
183
+ else
184
+ repo.log(ref, path, options).map {|grit_commit| Gollum::Git::Commit.new(grit_commit)}
185
+ end
186
+ end
187
+
188
+ def log(path = nil, ref = nil, options = nil, *args)
189
+ @git.native(:log, options, "--", path)
190
+ end
191
+
192
+ def refs(options, prefix)
193
+ @git.refs(options, prefix)
194
+ end
195
+
196
+ def repo
197
+ @repo ||= Grit::Repo.new(@git.git_dir)
198
+ end
199
+
200
+ end
201
+
202
+ class Index
203
+
204
+ def initialize(index)
205
+ @index = index
206
+ @tree = Gollum::Git::Tree.new(@index.tree)
207
+ @current_tree = nil
208
+ end
209
+
210
+ def delete(path)
211
+ @index.delete(path)
212
+ end
213
+
214
+ def add(path, data)
215
+ @index.add(path, data)
216
+ end
217
+
218
+ # index.commit(@options[:message], parents, actor, nil, @wiki.ref)
219
+ def commit(message, parents = nil, actor = nil, last_tree = nil, head = 'master')
220
+ @index.commit(message, parents, actor, last_tree, head)
221
+ end
222
+
223
+ def tree
224
+ @index.tree
225
+ end
226
+
227
+ def read_tree(id)
228
+ @index.read_tree(id)
229
+ @current_tree = Gollum::Git::Tree.new(@index.current_tree)
230
+ end
231
+
232
+ def current_tree
233
+ @current_tree
234
+ end
235
+
236
+ end
237
+
238
+ class Ref
239
+ def initialize(ref)
240
+ @ref = ref
241
+ end
242
+
243
+ def name
244
+ @ref.name
245
+ end
246
+
247
+ def commit
248
+ Gollum::Git::Commit.new(@ref.commit)
249
+ end
250
+
251
+ end
252
+
253
+ class Repo
254
+
255
+ def initialize(path, options)
256
+ begin
257
+ @repo = Grit::Repo.new(path, options)
258
+ rescue Grit::InvalidGitRepositoryError
259
+ raise Gollum::InvalidGitRepositoryError
260
+ rescue Grit::NoSuchPathError
261
+ raise Gollum::NoSuchPathError
262
+ end
263
+ end
264
+
265
+ def self.init(path, git_options = {}, repo_options = {})
266
+ Grit::Repo.init(path, git_options, repo_options)
267
+ self.new(path, {:is_bare => false})
268
+ end
269
+
270
+ def self.init_bare(path, git_options = {}, repo_options = {})
271
+ Grit::Repo.init_bare(path, git_options, repo_options)
272
+ self.new(path, {:is_bare => true})
273
+ end
274
+
275
+ def bare
276
+ @repo.bare
277
+ end
278
+
279
+ def config
280
+ @repo.config
281
+ end
282
+
283
+ def git
284
+ @git ||= Gollum::Git::Git.new(@repo.git)
285
+ end
286
+
287
+ def commit(id)
288
+ commit = @repo.commit(id)
289
+ return nil if commit.nil?
290
+ Gollum::Git::Commit.new(@repo.commit(id))
291
+ end
292
+
293
+ def commits(start = 'master', max_count = 10, skip = 0)
294
+ @repo.commits(start, max_count, skip).map{|commit| Gollum::Git::Commit.new(commit)}
295
+ end
296
+
297
+ # @wiki.repo.head.commit.sha
298
+ def head
299
+ Gollum::Git::Ref.new(@repo.head)
300
+ end
301
+
302
+ def index
303
+ @index ||= Gollum::Git::Index.new(@repo.index)
304
+ end
305
+
306
+ def diff(sha1, sha2, path = nil)
307
+ @repo.diff(sha1, sha2, path)
308
+ end
309
+
310
+ def log(commit = 'master', path = nil, options = {})
311
+ @repo.log(commit, path, options)
312
+ end
313
+
314
+ def lstree(sha, options = {})
315
+ @repo.lstree(sha, options)
316
+ end
317
+
318
+ def path
319
+ @repo.path
320
+ end
321
+
322
+ def update_ref(head, commit_sha)
323
+ @repo.update_ref(head, commit_sha)
324
+ end
325
+
326
+ end
327
+
328
+ class Tree
329
+
330
+ def initialize(tree)
331
+ @tree = tree
332
+ end
333
+
334
+ def keys
335
+ @tree.keys
336
+ end
337
+
338
+ def [](i)
339
+ @tree[i]
340
+ end
341
+
342
+ def id
343
+ @tree.id
344
+ end
345
+
346
+ # if index.current_tree && tree = index.current_tree / (@wiki.page_file_dir || '/')
347
+ def /(file)
348
+ @tree.send(:/, file)
349
+ end
350
+
351
+ def blobs
352
+ return Array.new if @tree == {}
353
+ @tree.blobs.map{|blob| Gollum::Git::Blob.new(blob) }
354
+ end
355
+ end
356
+
357
+ class NoSuchShaFound < StandardError
358
+ end
359
+
360
+ end
361
+ end
362
+
363
+ # Monkey patching Grit's Blob class (taken from grit_ext.rb)
364
+ module Grit
365
+ class Blob
366
+ def is_symlink
367
+ self.mode == 0120000
368
+ end
369
+
370
+ def symlink_target(base_path = nil)
371
+ target = self.data
372
+ new_path = File.expand_path(File.join('..', target), base_path)
373
+
374
+ if File.file? new_path
375
+ return new_path
376
+ end
377
+ end
378
+
379
+ nil
380
+ end
381
+ end
@@ -0,0 +1,7 @@
1
+ module Gollum
2
+ module Lib
3
+ module Git
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require 'grit_adapter/git_layer_grit.rb'
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gollum-grit_adapter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bart Kamphorst, Dawa Ometto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gitlab-grit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.6.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.6.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.13.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.13.0
41
+ description: Adapter for Gollum to use Grit 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/grit_adapter.rb
51
+ - lib/grit_adapter/git_layer_grit.rb
52
+ - lib/grit_adapter/version.rb
53
+ homepage: https://github.com/gollum/grit_adapter
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.4.1
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Adapter for Gollum to use Grit at the backend.
77
+ test_files: []