gollum-rugged_adapter 0.1b
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +11 -0
- data/README.md +40 -0
- data/lib/rugged_adapter/git_layer_rugged.rb +622 -0
- data/lib/rugged_adapter/version.rb +7 -0
- data/lib/rugged_adapter.rb +1 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWJjMGU4NGM0ODZkMjZmZGZkNDhhOTI4YTMzYmFmNzdiZDM3ZDEwMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTNjYzk3OWE2Njk2MGQ0ODdmNTExZTMxYjlkMmY3NWIyYzkwYjQ2Nw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjI2Njg5N2EyODAyYzRiMjkzYmExZjNiYWFlZTZiZDQ3Y2VkZmRkOWEyOTNi
|
10
|
+
ZmYyNTMwMjY1MGNiOWE5ZTQ4ZGIzZGQ1MjczYzYzNGJjY2YyMWVjY2M1NDQ5
|
11
|
+
YjU0ODAxNWE5YjIzNzE4MjA1ZjBhNGUwN2FjOWI2ZWVkZTljMjE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGRlOThmMWFhMzI0M2EyZDczNzFiMzA4OTA3ZWE1NTRlOWU3YTU2OTNhNGJj
|
14
|
+
NjBiMDczZDQxNmQzZmFhOTE0NDE0MGQyNmZmNWMxM2U0YmYzMmU5NTFmN2M2
|
15
|
+
NGRkOWEwN2I5NjZhYmFlNzQyZWFjYmVmMjdlOGQ2YTQyMWY0MmE=
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/gollum-rugged_adapter.svg)](http://badge.fury.io/rb/gollum-rugged_adapter)
|
2
|
+
[![Build Status](https://travis-ci.org/gollum/rugged_adapter.svg?branch=master)](https://travis-ci.org/gollum/rugged_adapter)
|
3
|
+
[![Dependency Status](https://gemnasium.com/gollum/rugged_adapter.svg)](https://gemnasium.com/gollum/rugged_adapter)
|
4
|
+
|
5
|
+
## DESCRIPTION
|
6
|
+
|
7
|
+
Adapter for [gollum](https://github.com/gollum/gollum) to use [Rugged](https://github.com/libgit2/rugged) (libgit2) at the backend. See the [gollum wiki](https://github.com/gollum/gollum/wiki/Git-adapters) for more information on adapters. Currently gollum uses grit as a backend by default, but since that is abandonware, the plan is to make this adapter the default in the future.
|
8
|
+
|
9
|
+
**Please note that this adapter is currently in beta. It passes the unit tests for gollum and [gollum-lib](https://github.com/gollum/gollum-lib), but it needs more comprehensive testing. Please [report any issues](https://github.com/gollum/rugged_adapter/issues) that you encounter.**
|
10
|
+
|
11
|
+
## USAGE
|
12
|
+
|
13
|
+
Install the gem:
|
14
|
+
|
15
|
+
`gem install gollum-rugged_adapter`
|
16
|
+
|
17
|
+
Now run gollum as follows:
|
18
|
+
|
19
|
+
`gollum --adapter rugged`
|
20
|
+
|
21
|
+
## CONTRIBUTING
|
22
|
+
|
23
|
+
1. Start by cloning the repo [on GitHub](http://github.com/gollum/rugged_adapter).
|
24
|
+
2. From inside the repo's directory, install the (development) dependencies with `bundle install`
|
25
|
+
3. Create a thoughtfully named topic branch to contain your changes.
|
26
|
+
4. Hack away.
|
27
|
+
5. Make sure your changes pass the adapter's specs: `bundle exec rake`
|
28
|
+
6. Make sure your changes pass gollum-lib's tests
|
29
|
+
* Clone [gollum-lib](https://github.com/gollum/gollum-lib) and add your local version of the rugged adapter to the gollum-lib `Gemfile`:
|
30
|
+
|
31
|
+
`gem gollum-rugged_adapter, :path => '/path/to/rugged_adapter'`
|
32
|
+
* `bundle install`
|
33
|
+
* `bundle exec rake GIT_ADAPTER=rugged`
|
34
|
+
1. If necessary, rebase your commits into logical chunks, without errors.
|
35
|
+
1. Push the branch up to GitHub.
|
36
|
+
1. Send a pull request to the gollum/rugged_adapter project.
|
37
|
+
|
38
|
+
## RELEASING
|
39
|
+
|
40
|
+
This gem uses [Semantic Versioning](http://semver.org/).
|
@@ -0,0 +1,622 @@
|
|
1
|
+
# ~*~ encoding: utf-8 ~*~
|
2
|
+
|
3
|
+
require 'rugged'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'mime-types'
|
6
|
+
|
7
|
+
module Gollum
|
8
|
+
|
9
|
+
def self.set_git_timeout(time)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.set_git_max_filesize(size)
|
13
|
+
end
|
14
|
+
|
15
|
+
module Git
|
16
|
+
|
17
|
+
DEFAULT_MIME_TYPE = "text/plain"
|
18
|
+
class NoSuchShaFound < StandardError; end
|
19
|
+
|
20
|
+
class Actor
|
21
|
+
|
22
|
+
attr_accessor :name, :email
|
23
|
+
|
24
|
+
def self.default_actor
|
25
|
+
self.new("Gollum", "Gollum@wiki")
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(name, email)
|
29
|
+
@name = name
|
30
|
+
@email = email
|
31
|
+
end
|
32
|
+
|
33
|
+
def output(time)
|
34
|
+
# implementation from grit
|
35
|
+
offset = time.utc_offset / 60
|
36
|
+
"%s <%s> %d %+.2d%.2d" % [
|
37
|
+
@name,
|
38
|
+
@email || "null",
|
39
|
+
time.to_i,
|
40
|
+
offset / 60,
|
41
|
+
offset.abs % 60]
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_h
|
45
|
+
{:name => @name, :email => @email}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
class Blob
|
51
|
+
|
52
|
+
attr_reader :mode
|
53
|
+
attr_reader :name
|
54
|
+
attr_reader :id
|
55
|
+
|
56
|
+
def self.create(repo, options)
|
57
|
+
blob = repo.git.lookup(options[:id])
|
58
|
+
self.new(blob, options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def initialize(blob, options = {})
|
62
|
+
@blob = blob
|
63
|
+
@mode = options[:mode]
|
64
|
+
@name = options[:name]
|
65
|
+
@size = options[:size]
|
66
|
+
@id = blob.oid
|
67
|
+
end
|
68
|
+
|
69
|
+
def data
|
70
|
+
@content ||= @blob.content
|
71
|
+
end
|
72
|
+
|
73
|
+
def is_symlink
|
74
|
+
@mode == 0120000
|
75
|
+
end
|
76
|
+
|
77
|
+
def mime_type
|
78
|
+
guesses = MIME::Types.type_for(self.name) rescue []
|
79
|
+
guesses.first ? guesses.first.simplified : DEFAULT_MIME_TYPE
|
80
|
+
end
|
81
|
+
|
82
|
+
def size
|
83
|
+
@size || @blob.size
|
84
|
+
end
|
85
|
+
|
86
|
+
def symlink_target(base_path = nil)
|
87
|
+
target = data
|
88
|
+
new_path = ::File.expand_path(::File.join('..', target), base_path)
|
89
|
+
return new_path if ::File.file? new_path
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class Commit
|
95
|
+
|
96
|
+
def initialize(commit)
|
97
|
+
@commit = commit
|
98
|
+
end
|
99
|
+
|
100
|
+
def id
|
101
|
+
@commit.oid
|
102
|
+
end
|
103
|
+
alias_method :sha, :id
|
104
|
+
alias_method :to_s, :id
|
105
|
+
|
106
|
+
attr_reader :commit
|
107
|
+
|
108
|
+
def author
|
109
|
+
@author ||= Gollum::Git::Actor.new(@commit.author[:name], @commit.author[:email])
|
110
|
+
end
|
111
|
+
|
112
|
+
def authored_date
|
113
|
+
@commit.time
|
114
|
+
end
|
115
|
+
|
116
|
+
def message
|
117
|
+
@commit.message
|
118
|
+
end
|
119
|
+
|
120
|
+
def tree
|
121
|
+
Gollum::Git::Tree.new(@commit.tree)
|
122
|
+
end
|
123
|
+
|
124
|
+
def stats
|
125
|
+
@stats ||= build_stats
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def build_stats
|
131
|
+
additions = 0
|
132
|
+
deletions = 0
|
133
|
+
total = 0
|
134
|
+
files = []
|
135
|
+
diff = @commit.diff.each_patch do |patch|
|
136
|
+
new_additions = patch.stat[0]
|
137
|
+
new_deletions = patch.stat[1]
|
138
|
+
additions += new_additions
|
139
|
+
deletions += new_deletions
|
140
|
+
total += patch.changes
|
141
|
+
files << [patch.delta.new_file[:path], new_deletions, new_additions, patch.changes] # Rugged seems to generate the stat diffs in the other direciton than grit does by default, so switch the order of additions and deletions.
|
142
|
+
end
|
143
|
+
OpenStruct.new(:additions => additions, :deletions => deletions, :files => files, :id => id, :total => total)
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
class Git
|
149
|
+
|
150
|
+
# Rugged does not have a Git class, but the Repository class should allows us to do what's necessary.
|
151
|
+
def initialize(repo)
|
152
|
+
@repo = repo
|
153
|
+
end
|
154
|
+
|
155
|
+
def exist?
|
156
|
+
::File.exists?(@repo.path)
|
157
|
+
end
|
158
|
+
|
159
|
+
def grep(query, options={})
|
160
|
+
ref = options[:ref] ? options[:ref] : "HEAD"
|
161
|
+
tree = @repo.lookup(sha_from_ref(ref)).tree
|
162
|
+
tree = @repo.lookup(tree[options[:path]][:oid]) if options[:path]
|
163
|
+
results = []
|
164
|
+
tree.walk_blobs(:postorder) do |root, entry|
|
165
|
+
blob = @repo.lookup(entry[:oid])
|
166
|
+
next if blob.binary?
|
167
|
+
count = 0
|
168
|
+
blob.content.each_line do |line|
|
169
|
+
next unless line.match(/#{Regexp.escape(query)}/i)
|
170
|
+
count += 1
|
171
|
+
end
|
172
|
+
path = options[:path] ? ::File.join(options[:path], root, entry[:name]) : "#{root}#{entry[:name]}"
|
173
|
+
results << {:name => path, :count => count}
|
174
|
+
end
|
175
|
+
results
|
176
|
+
end
|
177
|
+
|
178
|
+
def rm(path, options = {})
|
179
|
+
index = @repo.index
|
180
|
+
index.write
|
181
|
+
::File.unlink ::File.join(@repo.workdir, path)
|
182
|
+
end
|
183
|
+
|
184
|
+
def cat_file(options, sha)
|
185
|
+
@repo.lookup(sha).read_raw
|
186
|
+
end
|
187
|
+
|
188
|
+
def apply_patch(head_sha = 'HEAD', patch=nil)
|
189
|
+
false # Rewrite gollum-lib's revert so that it doesn't require a direct equivalent of Grit's apply_patch
|
190
|
+
end
|
191
|
+
|
192
|
+
def checkout(path, ref = 'HEAD', options = {})
|
193
|
+
path = path.nil? ? path : [path]
|
194
|
+
options = options.merge({:paths => path, :strategy => :force})
|
195
|
+
if ref == 'HEAD'
|
196
|
+
@repo.checkout_head(options)
|
197
|
+
else
|
198
|
+
ref = "refs/heads/#{ref}" unless ref =~ /^refs\/heads\//
|
199
|
+
@repo.checkout_tree(sha_from_ref(ref), options)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def log(ref = 'refs/heads/master', path = nil, options = {})
|
204
|
+
default_options = {
|
205
|
+
:limit => options[:max_count] ? options[:max_count] : 10,
|
206
|
+
:offset => options[:skip] ? options[:skip] : 0,
|
207
|
+
:path => path,
|
208
|
+
:follow => false,
|
209
|
+
:skip_merges => false
|
210
|
+
}
|
211
|
+
options = default_options.merge(options)
|
212
|
+
options[:limit] ||= 0
|
213
|
+
options[:offset] ||= 0
|
214
|
+
sha = sha_from_ref(ref)
|
215
|
+
return [] if sha.nil?
|
216
|
+
begin
|
217
|
+
build_log(sha, options)
|
218
|
+
rescue Rugged::OdbError, Rugged::InvalidError, Rugged::ReferenceError
|
219
|
+
# Return an empty array if the ref wasn't found
|
220
|
+
[]
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def versions_for_path(path = nil, ref = nil, options = {})
|
225
|
+
options.delete :max_count
|
226
|
+
options.delete :skip
|
227
|
+
log(ref, path, options)
|
228
|
+
end
|
229
|
+
|
230
|
+
def ls_files(query, options = {})
|
231
|
+
ref = options[:ref] || "refs/heads/master"
|
232
|
+
tree = @repo.lookup(sha_from_ref(ref)).tree
|
233
|
+
tree = @repo.lookup(tree[options[:path]][:oid]) if options[:path]
|
234
|
+
results = []
|
235
|
+
tree.walk_blobs do |root, blob|
|
236
|
+
next unless blob[:name] =~ /#{query}/
|
237
|
+
path = options[:path] ? ::File.join(options[:path], root, blob[:name]) : "#{root}#{blob[:name]}"
|
238
|
+
results << path
|
239
|
+
end
|
240
|
+
results
|
241
|
+
end
|
242
|
+
|
243
|
+
def lookup(id)
|
244
|
+
@repo.lookup(id)
|
245
|
+
end
|
246
|
+
|
247
|
+
def ref_to_sha(query)
|
248
|
+
return query if sha?(query)
|
249
|
+
query = "refs/heads/#{query}" if !query.nil? && !(query =~ /^refs\/heads\//) && !(query == "HEAD")
|
250
|
+
begin
|
251
|
+
return @repo.rev_parse_oid(query)
|
252
|
+
rescue Rugged::ReferenceError, Rugged::InvalidError
|
253
|
+
return nil
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def sha_or_commit_from_ref(ref, request_kind = nil)
|
258
|
+
sha = ref_to_sha(ref)
|
259
|
+
return nil if sha.nil?
|
260
|
+
object = @repo.lookup(sha)
|
261
|
+
if object.kind_of?(Rugged::Commit) then
|
262
|
+
return Gollum::Git::Commit.new(object) if request_kind == :commit
|
263
|
+
sha
|
264
|
+
elsif object.respond_to?(:target)
|
265
|
+
sha_or_commit_from_ref(object.target.oid, request_kind)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
alias_method :sha_from_ref, :sha_or_commit_from_ref
|
269
|
+
|
270
|
+
def commit_from_ref(ref)
|
271
|
+
sha_or_commit_from_ref(ref, :commit)
|
272
|
+
end
|
273
|
+
|
274
|
+
private
|
275
|
+
|
276
|
+
def sha?(str)
|
277
|
+
!!(str =~ /^[0-9a-f]{40}$/)
|
278
|
+
end
|
279
|
+
|
280
|
+
# Return an array of log commits, given an SHA hash and a hash of
|
281
|
+
# options. From Gitlab::Git
|
282
|
+
def build_log(sha, options)
|
283
|
+
# Instantiate a Walker and add the SHA hash
|
284
|
+
walker = Rugged::Walker.new(@repo)
|
285
|
+
walker.push(sha)
|
286
|
+
commits = []
|
287
|
+
skipped = 0
|
288
|
+
current_path = options[:path]
|
289
|
+
current_path = nil if current_path == ''
|
290
|
+
limit = options[:limit].to_i
|
291
|
+
offset = options[:offset].to_i
|
292
|
+
skip_merges = options[:skip_merges]
|
293
|
+
walker.sorting(Rugged::SORT_DATE)
|
294
|
+
|
295
|
+
walker.each do |c|
|
296
|
+
break if limit > 0 && commits.length >= limit
|
297
|
+
if skip_merges
|
298
|
+
# Skip merge commits
|
299
|
+
next if c.parents.length > 1
|
300
|
+
end
|
301
|
+
|
302
|
+
if !current_path ||
|
303
|
+
commit_touches_path?(c, current_path, options[:follow], walker)
|
304
|
+
# This is a commit we care about, unless we haven't skipped enough
|
305
|
+
# yet
|
306
|
+
skipped += 1
|
307
|
+
commits.push(Gollum::Git::Commit.new(c)) if skipped > offset
|
308
|
+
end
|
309
|
+
end
|
310
|
+
walker.reset
|
311
|
+
commits
|
312
|
+
end
|
313
|
+
|
314
|
+
# Returns true if +commit+ introduced changes to +path+, using commit
|
315
|
+
# trees to make that determination. Uses the history simplification
|
316
|
+
# rules that `git log` uses by default, where a commit is omitted if it
|
317
|
+
# is TREESAME to any parent.
|
318
|
+
#
|
319
|
+
# If the +follow+ option is true and the file specified by +path+ was
|
320
|
+
# renamed, then the path value is set to the old path.
|
321
|
+
def commit_touches_path?(commit, path, follow, walker)
|
322
|
+
entry = tree_entry(commit, path)
|
323
|
+
|
324
|
+
if commit.parents.empty?
|
325
|
+
# This is the root commit, return true if it has +path+ in its tree
|
326
|
+
return entry != nil
|
327
|
+
end
|
328
|
+
|
329
|
+
num_treesame = 0
|
330
|
+
commit.parents.each do |parent|
|
331
|
+
parent_entry = tree_entry(parent, path)
|
332
|
+
|
333
|
+
# Only follow the first TREESAME parent for merge commits
|
334
|
+
if num_treesame > 0
|
335
|
+
walker.hide(parent)
|
336
|
+
next
|
337
|
+
end
|
338
|
+
|
339
|
+
if entry.nil? && parent_entry.nil?
|
340
|
+
num_treesame += 1
|
341
|
+
elsif entry && parent_entry && entry[:oid] == parent_entry[:oid]
|
342
|
+
num_treesame += 1
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
case num_treesame
|
347
|
+
when 0
|
348
|
+
detect_rename(commit, commit.parents.first, path) if follow
|
349
|
+
true
|
350
|
+
else false
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
# Find the entry for +path+ in the tree for +commit+
|
355
|
+
def tree_entry(commit, path)
|
356
|
+
pathname = Pathname.new(path)
|
357
|
+
tmp_entry = nil
|
358
|
+
|
359
|
+
pathname.each_filename do |dir|
|
360
|
+
if tmp_entry.nil?
|
361
|
+
tmp_entry = commit.tree[dir]
|
362
|
+
else
|
363
|
+
tmp_entry = @repo.lookup(tmp_entry[:oid])[dir]
|
364
|
+
end
|
365
|
+
end
|
366
|
+
tmp_entry
|
367
|
+
end
|
368
|
+
|
369
|
+
# Compare +commit+ and +parent+ for +path+. If +path+ is a file and was
|
370
|
+
# renamed in +commit+, then set +path+ to the old filename.
|
371
|
+
def detect_rename(commit, parent, path)
|
372
|
+
diff = parent.diff(commit, paths: [path], disable_pathspec_match: true)
|
373
|
+
|
374
|
+
# If +path+ is a filename, not a directory, then we should only have
|
375
|
+
# one delta. We don't need to follow renames for directories.
|
376
|
+
return nil if diff.each_delta.count > 1
|
377
|
+
|
378
|
+
delta = diff.each_delta.first
|
379
|
+
if delta.added?
|
380
|
+
full_diff = parent.diff(commit)
|
381
|
+
full_diff.find_similar!
|
382
|
+
|
383
|
+
full_diff.each_delta do |full_delta|
|
384
|
+
if full_delta.renamed? && path == full_delta.new_file[:path]
|
385
|
+
# Look for the old path in ancestors
|
386
|
+
path.replace(full_delta.old_file[:path])
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
end
|
393
|
+
|
394
|
+
class Index
|
395
|
+
|
396
|
+
def initialize(index, repo)
|
397
|
+
@index = index
|
398
|
+
@rugged_repo = repo
|
399
|
+
@treemap = {}
|
400
|
+
end
|
401
|
+
|
402
|
+
def delete(path)
|
403
|
+
@index.remove_all(path)
|
404
|
+
update_treemap(path, false)
|
405
|
+
false
|
406
|
+
end
|
407
|
+
|
408
|
+
def add(path, data)
|
409
|
+
blob = @rugged_repo.write(data, :blob)
|
410
|
+
@index.add(:path => path, :oid => blob, :mode => 0100644)
|
411
|
+
update_treemap(path, data)
|
412
|
+
data
|
413
|
+
end
|
414
|
+
|
415
|
+
def index
|
416
|
+
@index
|
417
|
+
end
|
418
|
+
|
419
|
+
def commit(message, parents = nil, actor = nil, last_tree = nil, head = 'refs/heads/master')
|
420
|
+
commit_options = {}
|
421
|
+
head = "refs/heads/#{head}" unless head =~ /^refs\/heads\//
|
422
|
+
parents = get_parents(parents, head) || []
|
423
|
+
actor = Gollum::Git::Actor.default_actor if actor.nil?
|
424
|
+
commit_options[:tree] = @index.write_tree
|
425
|
+
commit_options[:author] = actor.to_h
|
426
|
+
commit_options[:message] = message.to_s
|
427
|
+
commit_options[:parents] = parents
|
428
|
+
commit_options[:update_ref] = head
|
429
|
+
Rugged::Commit.create(@rugged_repo, commit_options)
|
430
|
+
end
|
431
|
+
|
432
|
+
def tree
|
433
|
+
@treemap
|
434
|
+
end
|
435
|
+
|
436
|
+
def read_tree(id)
|
437
|
+
id = Gollum::Git::Git.new(@rugged_repo).ref_to_sha(id)
|
438
|
+
return nil if id.nil?
|
439
|
+
current_tree = @rugged_repo.lookup(id)
|
440
|
+
current_tree = current_tree.tree unless current_tree.is_a?(Rugged::Tree)
|
441
|
+
@index.read_tree(current_tree)
|
442
|
+
@current_tree = Gollum::Git::Tree.new(current_tree)
|
443
|
+
end
|
444
|
+
|
445
|
+
def current_tree
|
446
|
+
@current_tree
|
447
|
+
end
|
448
|
+
|
449
|
+
private
|
450
|
+
|
451
|
+
def get_parents(parents, head)
|
452
|
+
if parents
|
453
|
+
parents.map!{|parent| parent.commit} if parents
|
454
|
+
elsif ref = @rugged_repo.references[head]
|
455
|
+
ref = ref.target
|
456
|
+
ref = ref.target if ref.respond_to?(:target)
|
457
|
+
[ref]
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
def update_treemap(path, data)
|
462
|
+
# From RJGit::Plumbing::Index
|
463
|
+
path = path[1..-1] if path[0] == ::File::SEPARATOR
|
464
|
+
path = path.split(::File::SEPARATOR)
|
465
|
+
last = path.pop
|
466
|
+
|
467
|
+
current = @treemap
|
468
|
+
|
469
|
+
path.each do |dir|
|
470
|
+
current[dir] ||= {}
|
471
|
+
node = current[dir]
|
472
|
+
current = node
|
473
|
+
end
|
474
|
+
|
475
|
+
current[last] = data
|
476
|
+
@treemap
|
477
|
+
end
|
478
|
+
|
479
|
+
end
|
480
|
+
|
481
|
+
class Ref
|
482
|
+
def initialize(ref)
|
483
|
+
@ref = ref
|
484
|
+
end
|
485
|
+
|
486
|
+
def name
|
487
|
+
@ref.name
|
488
|
+
end
|
489
|
+
|
490
|
+
def commit
|
491
|
+
Gollum::Git::Commit.new(@ref.target)
|
492
|
+
end
|
493
|
+
|
494
|
+
end
|
495
|
+
|
496
|
+
class Repo
|
497
|
+
|
498
|
+
def initialize(path, options)
|
499
|
+
begin
|
500
|
+
@repo = Rugged::Repository.new(path, options)
|
501
|
+
#rescue Grit::InvalidGitRepositoryError
|
502
|
+
# raise Gollum::InvalidGitRepositoryError
|
503
|
+
#rescue Grit::NoSuchPathError
|
504
|
+
# raise Gollum::NoSuchPathError
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
def self.init(path)
|
509
|
+
Rugged::Repository.init_at(path, false)
|
510
|
+
self.new(path, :is_bare => false)
|
511
|
+
end
|
512
|
+
|
513
|
+
def self.init_bare(path)
|
514
|
+
Rugged::Repository.init_at(path, true)
|
515
|
+
self.new(path, :is_bare => true)
|
516
|
+
end
|
517
|
+
|
518
|
+
def bare
|
519
|
+
@repo.bare?
|
520
|
+
end
|
521
|
+
|
522
|
+
def config
|
523
|
+
@repo.config
|
524
|
+
end
|
525
|
+
|
526
|
+
def git
|
527
|
+
@git ||= Gollum::Git::Git.new(@repo)
|
528
|
+
end
|
529
|
+
|
530
|
+
def commit(id)
|
531
|
+
git.commit_from_ref(id)
|
532
|
+
end
|
533
|
+
|
534
|
+
def commits(start = 'refs/heads/master', max_count = 10, skip = 0)
|
535
|
+
git.log(start, nil, :max_count => max_count, :skip => skip)
|
536
|
+
end
|
537
|
+
|
538
|
+
def head
|
539
|
+
Gollum::Git::Ref.new(@repo.head)
|
540
|
+
end
|
541
|
+
|
542
|
+
def index
|
543
|
+
@index ||= Gollum::Git::Index.new(@repo.index, @repo)
|
544
|
+
end
|
545
|
+
|
546
|
+
def diff(sha1, sha2, path = nil)
|
547
|
+
opts = path == nil ? {} : {:path => path}
|
548
|
+
@repo.diff(sha1, sha2, opts).patches.map {|patch| OpenStruct.new(:diff => patch.to_s.split("\n")[2..-1].join("\n"))}.reverse # First remove two superfluous lines. Rugged seems to order the diffs differently than Grit, so reverse.
|
549
|
+
end
|
550
|
+
|
551
|
+
def log(commit = 'refs/heads/master', path = nil, options = {})
|
552
|
+
git.log(commit, path, options)
|
553
|
+
end
|
554
|
+
|
555
|
+
def lstree(sha, options = {})
|
556
|
+
results = []
|
557
|
+
@repo.lookup(sha).tree.walk(:postorder) do |root, entry|
|
558
|
+
entry[:sha] = entry[:oid]
|
559
|
+
entry[:mode] = entry[:filemode].to_s(8)
|
560
|
+
entry[:type] = entry[:type].to_s
|
561
|
+
entry[:path] = "#{root}#{entry[:name]}"
|
562
|
+
results << entry
|
563
|
+
end
|
564
|
+
results
|
565
|
+
end
|
566
|
+
|
567
|
+
def path
|
568
|
+
@repo.path
|
569
|
+
end
|
570
|
+
|
571
|
+
# Checkout branch and if necessary first create it. Currently used only in gollum-lib's tests.
|
572
|
+
def update_ref(ref, commit_sha)
|
573
|
+
ref = "refs/heads/#{ref}" unless ref =~ /^refs\/heads\//
|
574
|
+
if _ref = @repo.references[ref]
|
575
|
+
@repo.references.update(_ref, commit_sha)
|
576
|
+
else
|
577
|
+
@repo.create_branch(ref, commit_sha)
|
578
|
+
@repo.checkout(ref, :strategy => :force) unless @repo.bare?
|
579
|
+
end
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
class Tree
|
584
|
+
|
585
|
+
def initialize(tree)
|
586
|
+
@tree = tree
|
587
|
+
end
|
588
|
+
|
589
|
+
def keys
|
590
|
+
@tree.map{|entry| entry[:name]}
|
591
|
+
end
|
592
|
+
|
593
|
+
def [](i)
|
594
|
+
@tree[i]
|
595
|
+
end
|
596
|
+
|
597
|
+
def id
|
598
|
+
@tree.oid
|
599
|
+
end
|
600
|
+
|
601
|
+
def /(file)
|
602
|
+
return self if file == '/'
|
603
|
+
begin
|
604
|
+
obj = @tree.path(file)
|
605
|
+
rescue Rugged::TreeError
|
606
|
+
return nil
|
607
|
+
end
|
608
|
+
return nil if obj.nil?
|
609
|
+
obj = @tree.owner.lookup(obj[:oid])
|
610
|
+
obj.is_a?(Rugged::Tree) ? Gollum::Git::Tree.new(obj) : Gollum::Git::Blob.new(obj)
|
611
|
+
end
|
612
|
+
|
613
|
+
def blobs
|
614
|
+
blobs = []
|
615
|
+
@tree.each_blob {|blob| blobs << Gollum::Git::Blob.new(@tree.owner.lookup(blob[:oid]), blob) }
|
616
|
+
blobs
|
617
|
+
end
|
618
|
+
|
619
|
+
end
|
620
|
+
|
621
|
+
end
|
622
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rugged_adapter/git_layer_rugged.rb'
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gollum-rugged_adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1b
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bart Kamphorst, Dawa Ometto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rugged
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.21.3
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.21.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.21.3
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.21.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 2.13.0
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.13.0
|
47
|
+
description: Adapter for Gollum to use Rugged (libgit2) at the backend.
|
48
|
+
email:
|
49
|
+
- repotag-dev@googlegroups.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- Gemfile
|
55
|
+
- README.md
|
56
|
+
- lib/rugged_adapter.rb
|
57
|
+
- lib/rugged_adapter/git_layer_rugged.rb
|
58
|
+
- lib/rugged_adapter/version.rb
|
59
|
+
homepage: https://github.com/gollum/rugged_adapter
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>'
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.3.1
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.1
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Adapter for Gollum to use Rugged (libgit2) at the backend.
|
83
|
+
test_files: []
|