gitrb 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/gitrb.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'gitrb'
3
- s.version = '0.2.4'
3
+ s.version = '0.2.5'
4
4
  s.summary = 'Pure ruby git implementation'
5
5
  s.author = 'Daniel Mendler'
6
6
  s.email = 'mail@daniel-mendler.de'
@@ -27,6 +27,7 @@ lib/gitrb/tree.rb
27
27
  lib/gitrb/trie.rb
28
28
  lib/gitrb/user.rb
29
29
  lib/gitrb/util.rb
30
+ lib/gitrb/version.rb
30
31
  test/bare_repository_test.rb
31
32
  test/benchmark.rb
32
33
  test/commit_test.rb
@@ -1,4 +1,6 @@
1
1
  module Gitrb
2
+
3
+ # Base class for blob, tree, commit and tag
2
4
  class GitObject
3
5
  attr_accessor :repository, :id
4
6
 
@@ -27,4 +29,5 @@ module Gitrb
27
29
  klass.new(*args)
28
30
  end
29
31
  end
32
+
30
33
  end
data/lib/gitrb/pack.rb CHANGED
@@ -10,16 +10,6 @@
10
10
  #
11
11
 
12
12
  module Gitrb
13
- PACK_SIGNATURE = "PACK"
14
- PACK_IDX_SIGNATURE = "\377tOc"
15
-
16
- OBJ_NONE = 0
17
- OBJ_COMMIT = 1
18
- OBJ_TREE = 2
19
- OBJ_BLOB = 3
20
- OBJ_TAG = 4
21
-
22
- OBJ_TYPES = [nil, 'commit', 'tree', 'blob', 'tag'].freeze
23
13
 
24
14
  class FileWindow
25
15
  def initialize(file, version = 1)
@@ -42,8 +32,15 @@ module Gitrb
42
32
  class PackFormatError < StandardError; end
43
33
 
44
34
  class Pack
35
+ PACK_IDX_SIGNATURE = "\377tOc"
36
+
37
+ OBJ_COMMIT = 1
38
+ OBJ_TREE = 2
39
+ OBJ_BLOB = 3
40
+ OBJ_TAG = 4
45
41
  OBJ_OFS_DELTA = 6
46
42
  OBJ_REF_DELTA = 7
43
+ OBJ_TYPES = [nil, 'commit', 'tree', 'blob', 'tag'].freeze
47
44
 
48
45
  FanOutCount = 256
49
46
  SHA1Size = 20
@@ -55,8 +52,6 @@ module Gitrb
55
52
  EntrySize = OffsetSize + SHA1Size
56
53
  EntrySizeV2 = SHA1Size + CrcSize + OffsetSize
57
54
 
58
- attr_reader :name
59
-
60
55
  def initialize(file)
61
56
  file = file[0...-3] + 'pack' if file =~ /\.idx$/
62
57
  @name = file
@@ -100,25 +95,23 @@ module Gitrb
100
95
  ver = idxfile.read(4).unpack("N")[0]
101
96
 
102
97
  if sig == PACK_IDX_SIGNATURE
103
- if(ver != 2)
104
- raise PackFormatError, "pack #@name has unknown pack file version #{ver}"
105
- end
98
+ raise PackFormatError, "pack #@name has unknown pack file version #{ver}" if ver != 2
106
99
  @version = 2
107
100
  else
108
101
  @version = 1
109
102
  end
110
103
 
111
104
  idx = FileWindow.new(idxfile, @version)
112
- result = yield idx
105
+ yield idx
106
+ ensure
113
107
  idxfile.close
114
- result
115
108
  end
116
109
 
117
110
  def with_pack
118
111
  packfile = File.open(@name, 'rb')
119
- result = yield packfile
112
+ yield packfile
113
+ ensure
120
114
  packfile.close
121
- result
122
115
  end
123
116
 
124
117
  def init_pack
@@ -126,9 +119,7 @@ module Gitrb
126
119
  @offsets = [0]
127
120
  FanOutCount.times do |i|
128
121
  pos = idx[i * IdxOffsetSize,IdxOffsetSize].unpack('N')[0]
129
- if pos < @offsets[i]
130
- raise PackFormatError, "pack #@name has discontinuous index #{i}"
131
- end
122
+ raise PackFormatError, "pack #@name has discontinuous index #{i}" if pos < @offsets[i]
132
123
  @offsets << pos
133
124
  end
134
125
  @size = @offsets[-1]
@@ -252,27 +243,24 @@ module Gitrb
252
243
  outdata = ""
253
244
  with_pack do |packfile|
254
245
  packfile.seek(offset)
255
- zstr = Zlib::Inflate.new
256
- while outdata.size < destsize
257
- indata = packfile.read(0xFFFF)
258
- if indata.size == 0
259
- raise PackFormatError, 'error reading pack data'
246
+ begin
247
+ zstream = Zlib::Inflate.new
248
+ while outdata.size < destsize
249
+ indata = packfile.read(0xFFFF)
250
+ raise PackFormatError, 'error reading pack data' if indata.size == 0
251
+ outdata << zstream.inflate(indata)
260
252
  end
261
- outdata << zstr.inflate(indata)
262
- end
263
- if outdata.size > destsize
264
- raise PackFormatError, 'error reading pack data'
253
+ raise PackFormatError, 'error reading pack data' if outdata.size > destsize
254
+ ensure
255
+ zstream.close
265
256
  end
266
- zstr.close
267
257
  end
268
258
  outdata
269
259
  end
270
260
 
271
261
  def patch_delta(base, delta)
272
262
  src_size, pos = patch_delta_header_size(delta, 0)
273
- if src_size != base.size
274
- raise PackFormatError, 'invalid delta data'
275
- end
263
+ raise PackFormatError, 'invalid delta data' if src_size != base.size
276
264
 
277
265
  dest_size, pos = patch_delta_header_size(delta, pos)
278
266
  dest = ""
@@ -307,9 +295,7 @@ module Gitrb
307
295
  shift = 0
308
296
  begin
309
297
  c = delta[pos].ord
310
- if c == nil
311
- raise PackFormatError, 'invalid delta header'
312
- end
298
+ raise PackFormatError, 'invalid delta header' if c == nil
313
299
  pos += 1
314
300
  size |= (c & 0x7f) << shift
315
301
  shift += 7
@@ -317,4 +303,5 @@ module Gitrb
317
303
  [size, pos]
318
304
  end
319
305
  end
306
+
320
307
  end
@@ -1,4 +1,6 @@
1
1
  module Gitrb
2
+
3
+ # Reference to GitObject to support lazy-loading of git-objects
2
4
  class Reference
3
5
  undef_method :id, :type rescue nil
4
6
 
@@ -29,4 +31,5 @@ module Gitrb
29
31
  @object != nil
30
32
  end
31
33
  end
34
+
32
35
  end
@@ -1,4 +1,5 @@
1
1
  module Gitrb
2
+
2
3
  class NotFound < StandardError; end
3
4
 
4
5
  class CommandError < StandardError
@@ -420,4 +421,5 @@ module Gitrb
420
421
  buf[0].ord == 0x78 && ((buf[0].ord << 8) | buf[1].ord) % 31 == 0
421
422
  end
422
423
  end
424
+
423
425
  end
data/lib/gitrb/trie.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  module Gitrb
2
+
3
+ # Trie data structure to store sha1s
2
4
  class Trie
3
5
  include Enumerable
4
6
 
@@ -91,4 +93,5 @@ module Gitrb
91
93
  key[@key.length].ord
92
94
  end
93
95
  end
96
+
94
97
  end
data/lib/gitrb/user.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module Gitrb
2
+
2
3
  class User
3
4
  attr_reader :name, :email, :date
4
5
 
@@ -18,6 +19,6 @@ module Gitrb
18
19
  new match[1].strip, match[2].strip, Time.at(match[3].to_i)
19
20
  end
20
21
  end
21
-
22
22
  end
23
+
23
24
  end
@@ -0,0 +1,3 @@
1
+ module Gitrb
2
+ VERSION = '0.2.5'
3
+ end
data/lib/gitrb.rb CHANGED
@@ -5,6 +5,7 @@ require 'logger'
5
5
  require 'enumerator'
6
6
  require 'stringio'
7
7
 
8
+ require 'gitrb/version'
8
9
  require 'gitrb/util'
9
10
  require 'gitrb/gitobject'
10
11
  require 'gitrb/reference'
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitrb
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 29
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 4
9
- version: 0.2.4
9
+ - 5
10
+ version: 0.2.5
10
11
  platform: ruby
11
12
  authors:
12
13
  - Daniel Mendler
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-09-16 00:00:00 +02:00
18
+ date: 2010-09-23 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: bacon
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -54,6 +57,7 @@ files:
54
57
  - lib/gitrb/trie.rb
55
58
  - lib/gitrb/user.rb
56
59
  - lib/gitrb/util.rb
60
+ - lib/gitrb/version.rb
57
61
  - test/bare_repository_test.rb
58
62
  - test/benchmark.rb
59
63
  - test/commit_test.rb
@@ -73,23 +77,27 @@ rdoc_options: []
73
77
  require_paths:
74
78
  - lib
75
79
  required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
76
81
  requirements:
77
82
  - - ">="
78
83
  - !ruby/object:Gem::Version
84
+ hash: 3
79
85
  segments:
80
86
  - 0
81
87
  version: "0"
82
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
83
90
  requirements:
84
91
  - - ">="
85
92
  - !ruby/object:Gem::Version
93
+ hash: 3
86
94
  segments:
87
95
  - 0
88
96
  version: "0"
89
97
  requirements: []
90
98
 
91
99
  rubyforge_project: gitrb
92
- rubygems_version: 1.3.6
100
+ rubygems_version: 1.3.7
93
101
  signing_key:
94
102
  specification_version: 3
95
103
  summary: Pure ruby git implementation