gollum_rails 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/Gemfile.lock +118 -92
- data/Guardfile +7 -0
- data/HISTORY.md +32 -0
- data/README.md +7 -2
- data/Rakefile +5 -5
- data/gollum_rails.gemspec +9 -13
- data/lib/gollum_rails.rb +2 -9
- data/lib/gollum_rails/adapters/gollum.rb +12 -3
- data/lib/gollum_rails/adapters/gollum/page.rb +92 -45
- data/lib/gollum_rails/adapters/gollum/wiki.rb +12 -11
- data/lib/gollum_rails/page.rb +208 -65
- data/lib/gollum_rails/setup.rb +9 -2
- data/spec/gollum_rails/adapters/gollum/connector_spec.rb +8 -2
- data/spec/gollum_rails/adapters/gollum/page_spec.rb +18 -78
- data/spec/gollum_rails/adapters/gollum/{wiki_spec.rb → wiki_spec_off.rb} +0 -0
- data/spec/gollum_rails/page_spec.rb +310 -79
- data/spec/spec_helper.rb +0 -23
- metadata +17 -23
- data/lib/core_ext/string.rb +0 -3
- data/lib/gollum_rails/modulesDEPRECATED/hash.rb +0 -33
- data/lib/gollum_rails/modulesDEPRECATED/loader.rb +0 -5
- data/lib/grit/git-ruby/internal/pack.rb +0 -397
- data/spec/gollum_rails/modulesDEPRECATED/hash.rb +0 -31
- data/spec/gollum_rails_spec.rb +0 -9
- data/spec/spec.opts +0 -3
data/spec/spec_helper.rb
CHANGED
@@ -7,37 +7,14 @@ Coveralls.wear!
|
|
7
7
|
require 'gollum_rails'
|
8
8
|
|
9
9
|
|
10
|
-
require 'benchmark'
|
11
|
-
RSpec::Matchers.define :take_less_than do |n|
|
12
|
-
chain :seconds do; end
|
13
|
-
match do |block|
|
14
|
-
@elapsed = Benchmark.realtime do
|
15
|
-
block.call
|
16
|
-
end
|
17
|
-
@elapsed <= n
|
18
|
-
end
|
19
|
-
end
|
20
10
|
|
21
11
|
RSpec.configure do |config|
|
22
12
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
23
13
|
|
24
|
-
config.backtrace_clean_patterns = [
|
25
|
-
/\/lib\d*\/ruby\//,
|
26
|
-
/bin\//,
|
27
|
-
/gems/,
|
28
|
-
/spec\/spec_helper\.rb/,
|
29
|
-
/lib\/rspec\/(core|expectations|matchers|mocks)/
|
30
|
-
]
|
31
14
|
config.before(:each) do
|
32
15
|
GollumRails::Adapters::Gollum::Connector.enabled = true
|
33
16
|
end
|
34
|
-
config.full_backtrace= false # save the console
|
35
|
-
config.color_enabled= true # save your eyes
|
36
|
-
config.formatter = :documentation
|
37
17
|
|
38
18
|
config.mock_with :rr
|
39
|
-
|
40
|
-
config.before(:each) do
|
41
|
-
end
|
42
19
|
|
43
20
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gollum_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Kasper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.2.
|
19
|
+
version: 3.2.11
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.2.
|
26
|
+
version: 3.2.11
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: gollum-lib
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0.
|
33
|
+
version: 1.0.9
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.0.
|
40
|
+
version: 1.0.9
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.1.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.1.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.2.
|
75
|
+
version: 3.2.11
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.2.
|
82
|
+
version: 3.2.11
|
83
83
|
description: include Gollum into Rails with ease
|
84
84
|
email: mosny@zyg.li
|
85
85
|
executables: []
|
@@ -88,12 +88,12 @@ extra_rdoc_files: []
|
|
88
88
|
files:
|
89
89
|
- Gemfile
|
90
90
|
- Gemfile.lock
|
91
|
+
- Guardfile
|
91
92
|
- HISTORY.md
|
92
93
|
- LICENSE
|
93
94
|
- README.md
|
94
95
|
- Rakefile
|
95
96
|
- gollum_rails.gemspec
|
96
|
-
- lib/core_ext/string.rb
|
97
97
|
- lib/generators/gollum_rails/install/install_generator.rb
|
98
98
|
- lib/generators/gollum_rails/install/templates/gollum_initializer.rb
|
99
99
|
- lib/generators/gollum_rails/language/language_generator.rb
|
@@ -109,11 +109,8 @@ files:
|
|
109
109
|
- lib/gollum_rails/adapters/gollum/error.rb
|
110
110
|
- lib/gollum_rails/adapters/gollum/page.rb
|
111
111
|
- lib/gollum_rails/adapters/gollum/wiki.rb
|
112
|
-
- lib/gollum_rails/modulesDEPRECATED/hash.rb
|
113
|
-
- lib/gollum_rails/modulesDEPRECATED/loader.rb
|
114
112
|
- lib/gollum_rails/page.rb
|
115
113
|
- lib/gollum_rails/setup.rb
|
116
|
-
- lib/grit/git-ruby/internal/pack.rb
|
117
114
|
- spec/gollum_rails/adapters/activemodel/error_spec.rb
|
118
115
|
- spec/gollum_rails/adapters/activemodel/naming_spec.rb
|
119
116
|
- spec/gollum_rails/adapters/activemodel/validation_unused.rb
|
@@ -121,15 +118,12 @@ files:
|
|
121
118
|
- spec/gollum_rails/adapters/gollum/connector_spec.rb
|
122
119
|
- spec/gollum_rails/adapters/gollum/error_spec.rb
|
123
120
|
- spec/gollum_rails/adapters/gollum/page_spec.rb
|
124
|
-
- spec/gollum_rails/adapters/gollum/
|
121
|
+
- spec/gollum_rails/adapters/gollum/wiki_spec_off.rb
|
125
122
|
- spec/gollum_rails/error_spec.rb
|
126
|
-
- spec/gollum_rails/modulesDEPRECATED/hash.rb
|
127
123
|
- spec/gollum_rails/page_spec.rb
|
128
124
|
- spec/gollum_rails/respository_spec.rb
|
129
125
|
- spec/gollum_rails/setup_spec.rb
|
130
126
|
- spec/gollum_rails/wiki_spec.rb
|
131
|
-
- spec/gollum_rails_spec.rb
|
132
|
-
- spec/spec.opts
|
133
127
|
- spec/spec_helper.rb
|
134
128
|
homepage: https://github.com/nirnanaaa/gollum_rails
|
135
129
|
licenses:
|
@@ -154,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
148
|
version: '0'
|
155
149
|
requirements: []
|
156
150
|
rubyforge_project: gollum_rails
|
157
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.1.11
|
158
152
|
signing_key:
|
159
153
|
specification_version: 4
|
160
154
|
summary: Combines Gollum and Rails
|
data/lib/core_ext/string.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# See http://ruby-doc.org/core-2.0/Hash.html for further information
|
2
|
-
#
|
3
|
-
# Extended methods:
|
4
|
-
# * object support
|
5
|
-
# * setter
|
6
|
-
# * hash setter
|
7
|
-
# * isset
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# TODO
|
11
|
-
# * implement is? method
|
12
|
-
# * improve testing
|
13
|
-
#
|
14
|
-
class ::Hash
|
15
|
-
|
16
|
-
|
17
|
-
# Public: Converts a method . into an Hash element
|
18
|
-
#
|
19
|
-
# Examples
|
20
|
-
# hash = {a: "b", b: "c", c: "d"}
|
21
|
-
# hash.a
|
22
|
-
# # => "b"
|
23
|
-
# # hash.b
|
24
|
-
# # => "c"
|
25
|
-
#
|
26
|
-
# Returns an instance of Hash if the name is the key of a new hash
|
27
|
-
def method_missing(name, *args)
|
28
|
-
return self[name] if key? name
|
29
|
-
self.each { |k,v| return v if k.to_s.to_sym == name }
|
30
|
-
super.method_missing name
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
@@ -1,397 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# converted from the gitrb project
|
3
|
-
#
|
4
|
-
# authors:
|
5
|
-
# Matthias Lederhofer <matled@gmx.net>
|
6
|
-
# Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
|
7
|
-
# Scott Chacon <schacon@gmail.com>
|
8
|
-
#
|
9
|
-
# provides native ruby access to git objects and pack files
|
10
|
-
#
|
11
|
-
|
12
|
-
require 'zlib'
|
13
|
-
require 'grit/git-ruby/internal/raw_object'
|
14
|
-
require 'grit/git-ruby/internal/file_window'
|
15
|
-
|
16
|
-
PACK_IDX_SIGNATURE = [0xFF, 0x74, 0x4F, 0x63]
|
17
|
-
|
18
|
-
module Grit
|
19
|
-
module GitRuby
|
20
|
-
module Internal
|
21
|
-
class PackFormatError < StandardError
|
22
|
-
end
|
23
|
-
|
24
|
-
class PackStorage
|
25
|
-
OBJ_OFS_DELTA = 6
|
26
|
-
OBJ_REF_DELTA = 7
|
27
|
-
|
28
|
-
FanOutCount = 256
|
29
|
-
SHA1Size = 20
|
30
|
-
IdxOffsetSize = 4
|
31
|
-
OffsetSize = 4
|
32
|
-
ExtendedOffsetSize = 8
|
33
|
-
CrcSize = 4
|
34
|
-
OffsetStart = FanOutCount * IdxOffsetSize
|
35
|
-
SHA1Start = OffsetStart + OffsetSize
|
36
|
-
EntrySize = OffsetSize + SHA1Size
|
37
|
-
EntrySizeV2 = SHA1Size + CrcSize + OffsetSize
|
38
|
-
|
39
|
-
def initialize(file)
|
40
|
-
if file =~ /\.idx$/
|
41
|
-
file = file[0...-3] + 'pack'
|
42
|
-
end
|
43
|
-
@name = file
|
44
|
-
@cache = {}
|
45
|
-
init_pack
|
46
|
-
end
|
47
|
-
|
48
|
-
def with_idx(index_file = nil)
|
49
|
-
index_file ||= @name[0...-4] + 'idx'
|
50
|
-
|
51
|
-
begin
|
52
|
-
idxfile = File.open(index_file, 'rb')
|
53
|
-
rescue Errno::ENOENT => boom
|
54
|
-
# file went away. bail out without yielding.
|
55
|
-
return
|
56
|
-
end
|
57
|
-
|
58
|
-
# read header
|
59
|
-
sig = idxfile.read(4).unpack("C*")
|
60
|
-
ver = idxfile.read(4).unpack("N")[0]
|
61
|
-
|
62
|
-
if sig == PACK_IDX_SIGNATURE
|
63
|
-
if(ver != 2)
|
64
|
-
raise PackFormatError, "pack #@name has unknown pack file version #{ver}"
|
65
|
-
end
|
66
|
-
@version = 2
|
67
|
-
else
|
68
|
-
@version = 1
|
69
|
-
end
|
70
|
-
|
71
|
-
idx = FileWindow.new(idxfile, @version)
|
72
|
-
yield idx
|
73
|
-
idx.unmap
|
74
|
-
ensure
|
75
|
-
idxfile.close if idxfile
|
76
|
-
end
|
77
|
-
|
78
|
-
def with_packfile
|
79
|
-
begin
|
80
|
-
packfile = File.open(@name, 'rb')
|
81
|
-
rescue Errno::ENOENT
|
82
|
-
# file went away. bail out without yielding.
|
83
|
-
return
|
84
|
-
end
|
85
|
-
yield packfile
|
86
|
-
ensure
|
87
|
-
packfile.close if packfile
|
88
|
-
end
|
89
|
-
|
90
|
-
def cache_objects
|
91
|
-
@cache = {}
|
92
|
-
with_packfile do |packfile|
|
93
|
-
each_entry do |sha, offset|
|
94
|
-
data, type = unpack_object(packfile, offset, {:caching => true})
|
95
|
-
if data
|
96
|
-
@cache[sha] = RawObject.new(OBJ_TYPES[type], data)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def name
|
103
|
-
@name
|
104
|
-
end
|
105
|
-
|
106
|
-
def close
|
107
|
-
# shouldnt be anything open now
|
108
|
-
end
|
109
|
-
|
110
|
-
# given an index file, list out the shas that it's packfile contains
|
111
|
-
def get_shas
|
112
|
-
shas = []
|
113
|
-
each_sha1 { |sha| shas << sha.unpack("H*")[0] }
|
114
|
-
shas
|
115
|
-
end
|
116
|
-
|
117
|
-
def [](sha1)
|
118
|
-
if obj = @cache[sha1]
|
119
|
-
return obj
|
120
|
-
end
|
121
|
-
|
122
|
-
offset = find_object(sha1)
|
123
|
-
return nil if !offset
|
124
|
-
@cache[sha1] = obj = parse_object(offset)
|
125
|
-
return obj
|
126
|
-
end
|
127
|
-
|
128
|
-
def init_pack
|
129
|
-
with_idx do |idx|
|
130
|
-
@offsets = [0]
|
131
|
-
FanOutCount.times do |i|
|
132
|
-
pos = idx[i * IdxOffsetSize,IdxOffsetSize].unpack('N')[0]
|
133
|
-
if pos < @offsets[i]
|
134
|
-
raise PackFormatError, "pack #@name has discontinuous index #{i}"
|
135
|
-
end
|
136
|
-
@offsets << pos
|
137
|
-
end
|
138
|
-
@size = @offsets[-1]
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def each_entry
|
143
|
-
with_idx do |idx|
|
144
|
-
if @version == 2
|
145
|
-
data = read_data_v2(idx)
|
146
|
-
data.each do |sha1, crc, offset|
|
147
|
-
yield sha1, offset
|
148
|
-
end
|
149
|
-
else
|
150
|
-
pos = OffsetStart
|
151
|
-
@size.times do
|
152
|
-
offset = idx[pos,OffsetSize].unpack('N')[0]
|
153
|
-
sha1 = idx[pos+OffsetSize,SHA1Size]
|
154
|
-
pos += EntrySize
|
155
|
-
yield sha1, offset
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
def read_data_v2(idx)
|
162
|
-
data = []
|
163
|
-
pos = OffsetStart
|
164
|
-
@size.times do |i|
|
165
|
-
data[i] = [idx[pos,SHA1Size], 0, 0]
|
166
|
-
pos += SHA1Size
|
167
|
-
end
|
168
|
-
@size.times do |i|
|
169
|
-
crc = idx[pos,CrcSize]
|
170
|
-
data[i][1] = crc
|
171
|
-
pos += CrcSize
|
172
|
-
end
|
173
|
-
@size.times do |i|
|
174
|
-
offset = idx[pos,OffsetSize].unpack('N')[0]
|
175
|
-
data[i][2] = offset
|
176
|
-
pos += OffsetSize
|
177
|
-
end
|
178
|
-
data
|
179
|
-
end
|
180
|
-
private :read_data_v2
|
181
|
-
|
182
|
-
def each_sha1
|
183
|
-
with_idx do |idx|
|
184
|
-
if @version == 2
|
185
|
-
data = read_data_v2(idx)
|
186
|
-
data.each do |sha1, crc, offset|
|
187
|
-
yield sha1
|
188
|
-
end
|
189
|
-
else
|
190
|
-
pos = SHA1Start
|
191
|
-
@size.times do
|
192
|
-
sha1 = idx[pos,SHA1Size]
|
193
|
-
pos += EntrySize
|
194
|
-
yield sha1
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
def find_object_in_index(idx, sha1)
|
201
|
-
slot = sha1.getord(0)
|
202
|
-
return nil if !slot
|
203
|
-
first, last = @offsets[slot,2]
|
204
|
-
while first < last
|
205
|
-
mid = (first + last) / 2
|
206
|
-
if @version == 2
|
207
|
-
midsha1 = idx[OffsetStart + (mid * SHA1Size), SHA1Size]
|
208
|
-
cmp = midsha1 <=> sha1
|
209
|
-
|
210
|
-
if cmp < 0
|
211
|
-
first = mid + 1
|
212
|
-
elsif cmp > 0
|
213
|
-
last = mid
|
214
|
-
else
|
215
|
-
pos = OffsetStart + (@size * (SHA1Size + CrcSize)) + (mid * OffsetSize)
|
216
|
-
offset = idx[pos, OffsetSize].unpack('N')[0]
|
217
|
-
if offset & 0x80000000 > 0
|
218
|
-
offset &= 0x7fffffff
|
219
|
-
pos = OffsetStart + (@size * (SHA1Size + CrcSize + OffsetSize)) + (offset * ExtendedOffsetSize)
|
220
|
-
words = idx[pos, ExtendedOffsetSize].unpack('NN')
|
221
|
-
offset = (words[0] << 32) | words[1]
|
222
|
-
end
|
223
|
-
return offset
|
224
|
-
end
|
225
|
-
else
|
226
|
-
midsha1 = idx[SHA1Start + mid * EntrySize,SHA1Size]
|
227
|
-
cmp = midsha1 <=> sha1
|
228
|
-
|
229
|
-
if cmp < 0
|
230
|
-
first = mid + 1
|
231
|
-
elsif cmp > 0
|
232
|
-
last = mid
|
233
|
-
else
|
234
|
-
pos = OffsetStart + mid * EntrySize
|
235
|
-
offset = idx[pos,OffsetSize].unpack('N')[0]
|
236
|
-
return offset
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
nil
|
241
|
-
end
|
242
|
-
|
243
|
-
def find_object(sha1)
|
244
|
-
obj = nil
|
245
|
-
with_idx do |idx|
|
246
|
-
obj = find_object_in_index(idx, sha1)
|
247
|
-
end
|
248
|
-
obj
|
249
|
-
end
|
250
|
-
private :find_object
|
251
|
-
|
252
|
-
def parse_object(offset)
|
253
|
-
obj = nil
|
254
|
-
with_packfile do |packfile|
|
255
|
-
data, type = unpack_object(packfile, offset)
|
256
|
-
obj = RawObject.new(OBJ_TYPES[type], data)
|
257
|
-
end
|
258
|
-
obj
|
259
|
-
end
|
260
|
-
protected :parse_object
|
261
|
-
|
262
|
-
def unpack_object(packfile, offset, options = {})
|
263
|
-
obj_offset = offset
|
264
|
-
packfile.seek(offset)
|
265
|
-
|
266
|
-
c = packfile.read(1).getord(0)
|
267
|
-
size = c & 0xf
|
268
|
-
type = (c >> 4) & 7
|
269
|
-
shift = 4
|
270
|
-
offset += 1
|
271
|
-
while c & 0x80 != 0
|
272
|
-
c = packfile.read(1).getord(0)
|
273
|
-
size |= ((c & 0x7f) << shift)
|
274
|
-
shift += 7
|
275
|
-
offset += 1
|
276
|
-
end
|
277
|
-
|
278
|
-
return [false, false] if !(type == OBJ_COMMIT || type == OBJ_TREE) && options[:caching]
|
279
|
-
|
280
|
-
case type
|
281
|
-
when OBJ_OFS_DELTA, OBJ_REF_DELTA
|
282
|
-
data, type = unpack_deltified(packfile, type, offset, obj_offset, size, options)
|
283
|
-
#puts type
|
284
|
-
when OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, OBJ_TAG
|
285
|
-
data = unpack_compressed(offset, size)
|
286
|
-
else
|
287
|
-
raise PackFormatError, "invalid type #{type}"
|
288
|
-
end
|
289
|
-
[data, type]
|
290
|
-
end
|
291
|
-
private :unpack_object
|
292
|
-
|
293
|
-
def unpack_deltified(packfile, type, offset, obj_offset, size, options = {})
|
294
|
-
packfile.seek(offset)
|
295
|
-
data = packfile.read(SHA1Size)
|
296
|
-
|
297
|
-
if type == OBJ_OFS_DELTA
|
298
|
-
i = 0
|
299
|
-
c = data.getord(i)
|
300
|
-
base_offset = c & 0x7f
|
301
|
-
while c & 0x80 != 0
|
302
|
-
c = data.getord(i += 1)
|
303
|
-
base_offset += 1
|
304
|
-
base_offset <<= 7
|
305
|
-
base_offset |= c & 0x7f
|
306
|
-
end
|
307
|
-
base_offset = obj_offset - base_offset
|
308
|
-
offset += i + 1
|
309
|
-
else
|
310
|
-
base_offset = find_object(data)
|
311
|
-
offset += SHA1Size
|
312
|
-
end
|
313
|
-
|
314
|
-
base, type = unpack_object(packfile, base_offset)
|
315
|
-
|
316
|
-
return [false, false] if !(type == OBJ_COMMIT || type == OBJ_TREE) && options[:caching]
|
317
|
-
|
318
|
-
delta = unpack_compressed(offset, size)
|
319
|
-
[patch_delta(base, delta), type]
|
320
|
-
end
|
321
|
-
private :unpack_deltified
|
322
|
-
|
323
|
-
def unpack_compressed(offset, destsize)
|
324
|
-
outdata = ""
|
325
|
-
with_packfile do |packfile|
|
326
|
-
packfile.seek(offset)
|
327
|
-
zstr = Zlib::Inflate.new
|
328
|
-
while outdata.size < destsize
|
329
|
-
indata = packfile.read(4096)
|
330
|
-
if indata.size == 0
|
331
|
-
raise PackFormatError, 'error reading pack data'
|
332
|
-
end
|
333
|
-
outdata << zstr.inflate(indata)
|
334
|
-
end
|
335
|
-
if outdata.size > destsize
|
336
|
-
raise PackFormatError, 'error reading pack data'
|
337
|
-
end
|
338
|
-
zstr.close
|
339
|
-
end
|
340
|
-
outdata
|
341
|
-
end
|
342
|
-
private :unpack_compressed
|
343
|
-
|
344
|
-
def patch_delta(base, delta)
|
345
|
-
src_size, pos = patch_delta_header_size(delta, 0)
|
346
|
-
if src_size != base.size
|
347
|
-
raise PackFormatError, 'invalid delta data'
|
348
|
-
end
|
349
|
-
|
350
|
-
dest_size, pos = patch_delta_header_size(delta, pos)
|
351
|
-
dest = ""
|
352
|
-
while pos < delta.size
|
353
|
-
c = delta.getord(pos)
|
354
|
-
pos += 1
|
355
|
-
if c & 0x80 != 0
|
356
|
-
pos -= 1
|
357
|
-
cp_off = cp_size = 0
|
358
|
-
cp_off = delta.getord(pos += 1) if c & 0x01 != 0
|
359
|
-
cp_off |= delta.getord(pos += 1) << 8 if c & 0x02 != 0
|
360
|
-
cp_off |= delta.getord(pos += 1) << 16 if c & 0x04 != 0
|
361
|
-
cp_off |= delta.getord(pos += 1) << 24 if c & 0x08 != 0
|
362
|
-
cp_size = delta.getord(pos += 1) if c & 0x10 != 0
|
363
|
-
cp_size |= delta.getord(pos += 1) << 8 if c & 0x20 != 0
|
364
|
-
cp_size |= delta.getord(pos += 1) << 16 if c & 0x40 != 0
|
365
|
-
cp_size = 0x10000 if cp_size == 0
|
366
|
-
pos += 1
|
367
|
-
dest << base[cp_off,cp_size]
|
368
|
-
elsif c != 0
|
369
|
-
dest << delta[pos,c]
|
370
|
-
pos += c
|
371
|
-
else
|
372
|
-
raise PackFormatError, 'invalid delta data'
|
373
|
-
end
|
374
|
-
end
|
375
|
-
dest
|
376
|
-
end
|
377
|
-
private :patch_delta
|
378
|
-
|
379
|
-
def patch_delta_header_size(delta, pos)
|
380
|
-
size = 0
|
381
|
-
shift = 0
|
382
|
-
begin
|
383
|
-
c = delta.getord(pos)
|
384
|
-
if c == nil
|
385
|
-
raise PackFormatError, 'invalid delta header'
|
386
|
-
end
|
387
|
-
pos += 1
|
388
|
-
size |= (c & 0x7f) << shift
|
389
|
-
shift += 7
|
390
|
-
end while c & 0x80 != 0
|
391
|
-
[size, pos]
|
392
|
-
end
|
393
|
-
private :patch_delta_header_size
|
394
|
-
end
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|