smeagol 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.index +82 -0
- data/HISTORY.md +14 -0
- data/lib/smeagol.rb +2 -1
- data/lib/smeagol/app.rb +1 -1
- data/lib/smeagol/gollum/file.rb +1 -1
- data/lib/smeagol/wiki.rb +1 -0
- data/vendor/grit/lib/grit.rb +75 -0
- data/vendor/grit/lib/grit/actor.rb +52 -0
- data/vendor/grit/lib/grit/blame.rb +70 -0
- data/vendor/grit/lib/grit/blob.rb +126 -0
- data/vendor/grit/lib/grit/commit.rb +313 -0
- data/vendor/grit/lib/grit/commit_stats.rb +128 -0
- data/vendor/grit/lib/grit/config.rb +44 -0
- data/vendor/grit/lib/grit/diff.rb +79 -0
- data/vendor/grit/lib/grit/errors.rb +10 -0
- data/vendor/grit/lib/grit/git-ruby.rb +262 -0
- data/vendor/grit/lib/grit/git-ruby/commit_db.rb +52 -0
- data/vendor/grit/lib/grit/git-ruby/git_object.rb +353 -0
- data/vendor/grit/lib/grit/git-ruby/internal/file_window.rb +58 -0
- data/vendor/grit/lib/grit/git-ruby/internal/loose.rb +137 -0
- data/vendor/grit/lib/grit/git-ruby/internal/pack.rb +397 -0
- data/vendor/grit/lib/grit/git-ruby/internal/raw_object.rb +44 -0
- data/vendor/grit/lib/grit/git-ruby/repository.rb +775 -0
- data/vendor/grit/lib/grit/git.rb +501 -0
- data/vendor/grit/lib/grit/index.rb +222 -0
- data/vendor/grit/lib/grit/lazy.rb +35 -0
- data/vendor/grit/lib/grit/merge.rb +45 -0
- data/vendor/grit/lib/grit/ref.rb +78 -0
- data/vendor/grit/lib/grit/repo.rb +709 -0
- data/vendor/grit/lib/grit/ruby1.9.rb +7 -0
- data/vendor/grit/lib/grit/status.rb +153 -0
- data/vendor/grit/lib/grit/submodule.rb +88 -0
- data/vendor/grit/lib/grit/tag.rb +102 -0
- data/vendor/grit/lib/grit/tree.rb +125 -0
- metadata +125 -56
- data/.ruby +0 -80
@@ -0,0 +1,58 @@
|
|
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
|
+
module Grit
|
13
|
+
module GitRuby
|
14
|
+
module Internal
|
15
|
+
class FileWindow
|
16
|
+
def initialize(file, version = 1)
|
17
|
+
@file = file
|
18
|
+
@offset = nil
|
19
|
+
if version == 2
|
20
|
+
@global_offset = 8
|
21
|
+
else
|
22
|
+
@global_offset = 0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def unmap
|
27
|
+
@file = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def [](*idx)
|
31
|
+
idx = idx[0] if idx.length == 1
|
32
|
+
case idx
|
33
|
+
when Range
|
34
|
+
offset = idx.first
|
35
|
+
len = idx.last - idx.first + idx.exclude_end? ? 0 : 1
|
36
|
+
when Fixnum
|
37
|
+
offset = idx
|
38
|
+
len = nil
|
39
|
+
when Array
|
40
|
+
offset, len = idx
|
41
|
+
else
|
42
|
+
raise RuntimeError, "invalid index param: #{idx.class}"
|
43
|
+
end
|
44
|
+
if @offset != offset
|
45
|
+
@file.seek(offset + @global_offset)
|
46
|
+
end
|
47
|
+
@offset = offset + len ? len : 1
|
48
|
+
if not len
|
49
|
+
@file.read(1).getord(0)
|
50
|
+
else
|
51
|
+
@file.read(len)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,137 @@
|
|
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 'digest/sha1'
|
14
|
+
require 'grit/git-ruby/internal/raw_object'
|
15
|
+
|
16
|
+
module Grit
|
17
|
+
module GitRuby
|
18
|
+
module Internal
|
19
|
+
class LooseObjectError < StandardError
|
20
|
+
end
|
21
|
+
|
22
|
+
class LooseStorage
|
23
|
+
def initialize(directory)
|
24
|
+
@directory = directory
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](sha1)
|
28
|
+
sha1 = sha1.unpack("H*")[0]
|
29
|
+
begin
|
30
|
+
return nil unless sha1[0...2] && sha1[2..39]
|
31
|
+
path = @directory + '/' + sha1[0...2] + '/' + sha1[2..39]
|
32
|
+
get_raw_object(open(path, 'rb') { |f| f.read })
|
33
|
+
rescue Errno::ENOENT
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_raw_object(buf)
|
39
|
+
if buf.bytesize < 2
|
40
|
+
raise LooseObjectError, "object file too small"
|
41
|
+
end
|
42
|
+
|
43
|
+
if legacy_loose_object?(buf)
|
44
|
+
content = Zlib::Inflate.inflate(buf)
|
45
|
+
header, content = content.split(/\0/, 2)
|
46
|
+
if !header || !content
|
47
|
+
raise LooseObjectError, "invalid object header"
|
48
|
+
end
|
49
|
+
type, size = header.split(/ /, 2)
|
50
|
+
if !%w(blob tree commit tag).include?(type) || size !~ /^\d+$/
|
51
|
+
raise LooseObjectError, "invalid object header"
|
52
|
+
end
|
53
|
+
type = type.to_sym
|
54
|
+
size = size.to_i
|
55
|
+
else
|
56
|
+
type, size, used = unpack_object_header_gently(buf)
|
57
|
+
content = Zlib::Inflate.inflate(buf[used..-1])
|
58
|
+
end
|
59
|
+
raise LooseObjectError, "size mismatch" if content.bytesize != size
|
60
|
+
return RawObject.new(type, content)
|
61
|
+
end
|
62
|
+
|
63
|
+
# currently, I'm using the legacy format because it's easier to do
|
64
|
+
# this function takes content and a type and writes out the loose object and returns a sha
|
65
|
+
def put_raw_object(content, type)
|
66
|
+
size = content.bytesize.to_s
|
67
|
+
LooseStorage.verify_header(type, size)
|
68
|
+
|
69
|
+
header = "#{type} #{size}\0"
|
70
|
+
store = header + content
|
71
|
+
|
72
|
+
sha1 = Digest::SHA1.hexdigest(store)
|
73
|
+
path = @directory+'/'+sha1[0...2]+'/'+sha1[2..40]
|
74
|
+
|
75
|
+
if !File.exists?(path)
|
76
|
+
content = Zlib::Deflate.deflate(store)
|
77
|
+
|
78
|
+
FileUtils.mkdir_p(@directory+'/'+sha1[0...2])
|
79
|
+
File.open(path, 'wb') do |f|
|
80
|
+
f.write content
|
81
|
+
end
|
82
|
+
end
|
83
|
+
return sha1
|
84
|
+
end
|
85
|
+
|
86
|
+
# simply figure out the sha
|
87
|
+
def self.calculate_sha(content, type)
|
88
|
+
size = content.bytesize.to_s
|
89
|
+
verify_header(type, size)
|
90
|
+
header = "#{type} #{size}\0"
|
91
|
+
store = header + content
|
92
|
+
|
93
|
+
Digest::SHA1.hexdigest(store)
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.verify_header(type, size)
|
97
|
+
if !%w(blob tree commit tag).include?(type) || size !~ /^\d+$/
|
98
|
+
raise LooseObjectError, "invalid object header"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# private
|
103
|
+
def unpack_object_header_gently(buf)
|
104
|
+
used = 0
|
105
|
+
c = buf.getord(used)
|
106
|
+
used += 1
|
107
|
+
|
108
|
+
type = (c >> 4) & 7;
|
109
|
+
size = c & 15;
|
110
|
+
shift = 4;
|
111
|
+
while c & 0x80 != 0
|
112
|
+
if buf.bytesize <= used
|
113
|
+
raise LooseObjectError, "object file too short"
|
114
|
+
end
|
115
|
+
c = buf.getord(used)
|
116
|
+
used += 1
|
117
|
+
|
118
|
+
size += (c & 0x7f) << shift
|
119
|
+
shift += 7
|
120
|
+
end
|
121
|
+
type = OBJ_TYPES[type]
|
122
|
+
if ![:blob, :tree, :commit, :tag].include?(type)
|
123
|
+
raise LooseObjectError, "invalid loose object type"
|
124
|
+
end
|
125
|
+
return [type, size, used]
|
126
|
+
end
|
127
|
+
private :unpack_object_header_gently
|
128
|
+
|
129
|
+
def legacy_loose_object?(buf)
|
130
|
+
word = (buf.getord(0) << 8) + buf.getord(1)
|
131
|
+
buf.getord(0) == 0x78 && word % 31 == 0
|
132
|
+
end
|
133
|
+
private :legacy_loose_object?
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,397 @@
|
|
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
|