gitrb 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/gitrb.gemspec +2 -1
- data/lib/gitrb/commit.rb +5 -4
- data/lib/gitrb/object.rb +4 -0
- data/lib/gitrb/pack.rb +14 -20
- data/lib/gitrb/repository.rb +23 -4
- data/lib/gitrb/tag.rb +2 -2
- data/lib/gitrb/tree.rb +3 -23
- data/lib/gitrb/util.rb +25 -0
- metadata +3 -2
data/gitrb.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'gitrb'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.4'
|
4
4
|
s.summary = 'Pure ruby git implementation'
|
5
5
|
s.author = 'Daniel Mendler'
|
6
6
|
s.email = 'mail@daniel-mendler.de'
|
@@ -28,6 +28,7 @@ lib/gitrb/tag.rb
|
|
28
28
|
lib/gitrb/tree.rb
|
29
29
|
lib/gitrb/trie.rb
|
30
30
|
lib/gitrb/user.rb
|
31
|
+
lib/gitrb/util.rb
|
31
32
|
test/bare_repository_spec.rb
|
32
33
|
test/benchmark.rb
|
33
34
|
test/commit_spec.rb
|
data/lib/gitrb/commit.rb
CHANGED
@@ -47,19 +47,20 @@ module Gitrb
|
|
47
47
|
|
48
48
|
def parse(data)
|
49
49
|
headers, @message = data.split("\n\n", 2)
|
50
|
+
repository.encode(@message)
|
50
51
|
|
51
52
|
headers.split("\n").each do |header|
|
52
53
|
key, value = header.split(' ', 2)
|
53
54
|
|
54
55
|
case key
|
55
56
|
when 'parent'
|
56
|
-
@parent << Reference.new(:repository => repository, :id => value)
|
57
|
+
@parent << Reference.new(:repository => repository, :id => repository.encode(value))
|
57
58
|
when 'author'
|
58
|
-
@author = User.parse(value)
|
59
|
+
@author = User.parse(repository.encode(value))
|
59
60
|
when 'committer'
|
60
|
-
@committer = User.parse(value)
|
61
|
+
@committer = User.parse(repository.encode(value))
|
61
62
|
when 'tree'
|
62
|
-
@tree = Reference.new(:repository => repository, :id => value)
|
63
|
+
@tree = Reference.new(:repository => repository, :id => repository.encode(value))
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
data/lib/gitrb/object.rb
CHANGED
data/lib/gitrb/pack.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- coding: us-ascii -*-
|
2
|
-
|
3
1
|
#
|
4
2
|
# converted from the gitrb project
|
5
3
|
#
|
@@ -13,10 +11,6 @@
|
|
13
11
|
|
14
12
|
require 'zlib'
|
15
13
|
|
16
|
-
class String
|
17
|
-
def getord(i); self[i].ord; end
|
18
|
-
end
|
19
|
-
|
20
14
|
module Gitrb
|
21
15
|
PACK_SIGNATURE = "PACK"
|
22
16
|
PACK_IDX_SIGNATURE = "\377tOc"
|
@@ -165,7 +159,7 @@ module Gitrb
|
|
165
159
|
|
166
160
|
def find_object(sha1)
|
167
161
|
with_idx do |idx|
|
168
|
-
slot =
|
162
|
+
slot = Util.ord(sha1, 0)
|
169
163
|
return nil if !slot
|
170
164
|
first, last = @offsets[slot,2]
|
171
165
|
while first < last
|
@@ -206,13 +200,13 @@ module Gitrb
|
|
206
200
|
obj_offset = offset
|
207
201
|
packfile.seek(offset)
|
208
202
|
|
209
|
-
c = packfile.read(1)
|
203
|
+
c = Util.ord(packfile.read(1), 0)
|
210
204
|
size = c & 0xf
|
211
205
|
type = (c >> 4) & 7
|
212
206
|
shift = 4
|
213
207
|
offset += 1
|
214
208
|
while c & 0x80 != 0
|
215
|
-
c = packfile.read(1)
|
209
|
+
c = Util.ord(packfile.read(1), 0)
|
216
210
|
size |= ((c & 0x7f) << shift)
|
217
211
|
shift += 7
|
218
212
|
offset += 1
|
@@ -235,10 +229,10 @@ module Gitrb
|
|
235
229
|
|
236
230
|
if type == OBJ_OFS_DELTA
|
237
231
|
i = 0
|
238
|
-
c =
|
232
|
+
c = Util.ord(data, i)
|
239
233
|
base_offset = c & 0x7f
|
240
234
|
while c & 0x80 != 0
|
241
|
-
c =
|
235
|
+
c = Util.ord(data, i += 1)
|
242
236
|
base_offset += 1
|
243
237
|
base_offset <<= 7
|
244
238
|
base_offset |= c & 0x7f
|
@@ -285,18 +279,18 @@ module Gitrb
|
|
285
279
|
dest_size, pos = patch_delta_header_size(delta, pos)
|
286
280
|
dest = ""
|
287
281
|
while pos < delta.size
|
288
|
-
c =
|
282
|
+
c = Util.ord(delta, pos)
|
289
283
|
pos += 1
|
290
284
|
if c & 0x80 != 0
|
291
285
|
pos -= 1
|
292
286
|
cp_off = cp_size = 0
|
293
|
-
cp_off =
|
294
|
-
cp_off |=
|
295
|
-
cp_off |=
|
296
|
-
cp_off |=
|
297
|
-
cp_size =
|
298
|
-
cp_size |=
|
299
|
-
cp_size |=
|
287
|
+
cp_off = Util.ord(delta, pos += 1) if c & 0x01 != 0
|
288
|
+
cp_off |= Util.ord(delta, pos += 1) << 8 if c & 0x02 != 0
|
289
|
+
cp_off |= Util.ord(delta, pos += 1) << 16 if c & 0x04 != 0
|
290
|
+
cp_off |= Util.ord(delta, pos += 1) << 24 if c & 0x08 != 0
|
291
|
+
cp_size = Util.ord(delta, pos += 1) if c & 0x10 != 0
|
292
|
+
cp_size |= Util.ord(delta, pos += 1) << 8 if c & 0x20 != 0
|
293
|
+
cp_size |= Util.ord(delta, pos += 1) << 16 if c & 0x40 != 0
|
300
294
|
cp_size = 0x10000 if cp_size == 0
|
301
295
|
pos += 1
|
302
296
|
dest << base[cp_off,cp_size]
|
@@ -314,7 +308,7 @@ module Gitrb
|
|
314
308
|
size = 0
|
315
309
|
shift = 0
|
316
310
|
begin
|
317
|
-
c =
|
311
|
+
c = Util.ord(delta, pos)
|
318
312
|
if c == nil
|
319
313
|
raise PackFormatError, 'invalid delta header'
|
320
314
|
end
|
data/lib/gitrb/repository.rb
CHANGED
@@ -4,6 +4,7 @@ require 'yaml'
|
|
4
4
|
require 'fileutils'
|
5
5
|
require 'logger'
|
6
6
|
|
7
|
+
require 'gitrb/util'
|
7
8
|
require 'gitrb/repository'
|
8
9
|
require 'gitrb/object'
|
9
10
|
require 'gitrb/blob'
|
@@ -19,13 +20,14 @@ module Gitrb
|
|
19
20
|
class NotFound < StandardError; end
|
20
21
|
|
21
22
|
class Repository
|
22
|
-
attr_reader :path, :index, :root, :branch, :lock_file, :head, :
|
23
|
+
attr_reader :path, :index, :root, :branch, :lock_file, :head, :encoding
|
23
24
|
|
24
25
|
# Initialize a repository.
|
25
26
|
def initialize(options = {})
|
26
27
|
@bare = options[:bare] || false
|
27
28
|
@branch = options[:branch] || 'master'
|
28
29
|
@logger = options[:logger] || Logger.new(nil)
|
30
|
+
@encoding = options[:encoding] || 'utf-8'
|
29
31
|
|
30
32
|
@path = options[:path]
|
31
33
|
@path.chomp!('/')
|
@@ -47,6 +49,23 @@ module Gitrb
|
|
47
49
|
load
|
48
50
|
end
|
49
51
|
|
52
|
+
# Encode string
|
53
|
+
if RUBY_VERSION > '1.9'
|
54
|
+
def encode(s)
|
55
|
+
# We have binary data which has to be encoded
|
56
|
+
s.force_encoding(@encoding)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
def encode(s)
|
60
|
+
s
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Bare repository?
|
65
|
+
def bare?
|
66
|
+
@bare
|
67
|
+
end
|
68
|
+
|
50
69
|
# Switch branch
|
51
70
|
def branch=(branch)
|
52
71
|
@branch = branch
|
@@ -167,7 +186,7 @@ module Gitrb
|
|
167
186
|
raise NotFound, "Bad object: #{id}" if content.length != size.to_i
|
168
187
|
else
|
169
188
|
list = @packs.find(id).to_a
|
170
|
-
|
189
|
+
raise NotFound, "Object not found" if list.size != 1
|
171
190
|
|
172
191
|
pack, offset = list.first
|
173
192
|
content, type = pack.get_object(offset)
|
@@ -177,7 +196,7 @@ module Gitrb
|
|
177
196
|
|
178
197
|
@logger.debug "gitrb: Loaded #{id}"
|
179
198
|
|
180
|
-
object = Gitrb::Object.factory(type, :repository => self, :id => id, :data => content)
|
199
|
+
object = Gitrb::Object.factory(type, :repository => self, :id => encode(id), :data => content)
|
181
200
|
@objects.insert(id, object)
|
182
201
|
object
|
183
202
|
end
|
@@ -366,7 +385,7 @@ module Gitrb
|
|
366
385
|
end
|
367
386
|
|
368
387
|
def legacy_loose_object?(buf)
|
369
|
-
|
388
|
+
Util.ord(buf, 0) == 0x78 && ((Util.ord(buf, 0) << 8) + Util.ord(buf, 1)) % 31 == 0
|
370
389
|
end
|
371
390
|
|
372
391
|
end
|
data/lib/gitrb/tag.rb
CHANGED
@@ -21,9 +21,9 @@ module Gitrb
|
|
21
21
|
when 'type'
|
22
22
|
@tagtype = value
|
23
23
|
when 'object'
|
24
|
-
@object = Reference.new(:repository => repository, :id => value)
|
24
|
+
@object = Reference.new(:repository => repository, :id => repository.encode(value))
|
25
25
|
when 'tagger'
|
26
|
-
@tagger = User.parse(value)
|
26
|
+
@tagger = User.parse(repository.encode(value))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
data/lib/gitrb/tree.rb
CHANGED
@@ -1,23 +1,3 @@
|
|
1
|
-
class StringIO
|
2
|
-
if RUBY_VERSION > '1.9'
|
3
|
-
def read_bytes_until(char)
|
4
|
-
str = ''
|
5
|
-
while ((ch = getc) != char) && !eof
|
6
|
-
str << ch
|
7
|
-
end
|
8
|
-
str
|
9
|
-
end
|
10
|
-
else
|
11
|
-
def read_bytes_until(char)
|
12
|
-
str = ''
|
13
|
-
while ((ch = getc.chr) != char) && !eof
|
14
|
-
str << ch
|
15
|
-
end
|
16
|
-
str
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
1
|
module Gitrb
|
22
2
|
|
23
3
|
class Tree < Gitrb::Object
|
@@ -157,9 +137,9 @@ module Gitrb
|
|
157
137
|
@children.clear
|
158
138
|
data = StringIO.new(data)
|
159
139
|
while !data.eof?
|
160
|
-
mode =
|
161
|
-
name =
|
162
|
-
id = data.read(20).unpack("H*").first
|
140
|
+
mode = repository.encode Util.read_bytes_until(data, ' ')
|
141
|
+
name = repository.encode Util.read_bytes_until(data, "\0")
|
142
|
+
id = repository.encode data.read(20).unpack("H*").first
|
163
143
|
@children[name] = Reference.new(:repository => repository, :id => id, :mode => mode)
|
164
144
|
end
|
165
145
|
end
|
data/lib/gitrb/util.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Gitrb
|
2
|
+
module Util
|
3
|
+
if RUBY_VERSION > '1.9'
|
4
|
+
def self.read_bytes_until(io, char)
|
5
|
+
str = ''
|
6
|
+
while ((ch = io.getc) != char) && !io.eof
|
7
|
+
str << ch
|
8
|
+
end
|
9
|
+
str
|
10
|
+
end
|
11
|
+
else
|
12
|
+
def self.read_bytes_until(io, char)
|
13
|
+
str = ''
|
14
|
+
while ((ch = io.getc.chr) != char) && !io.eof
|
15
|
+
str << ch
|
16
|
+
end
|
17
|
+
str
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.ord(s, i)
|
22
|
+
s[i].ord
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Mendler
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-20 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/gitrb/tree.rb
|
38
38
|
- lib/gitrb/trie.rb
|
39
39
|
- lib/gitrb/user.rb
|
40
|
+
- lib/gitrb/util.rb
|
40
41
|
- test/bare_repository_spec.rb
|
41
42
|
- test/benchmark.rb
|
42
43
|
- test/commit_spec.rb
|