gollum_rails 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -13
- data/HISTORY.md +7 -0
- data/README.md +5 -1
- data/gollum_rails.gemspec +2 -4
- data/lib/gollum_rails.rb +1 -4
- data/spec/gollum_rails/page_spec.rb +2 -9
- metadata +5 -7
- data/lib/core_ext/string.rb +0 -3
- data/lib/grit/git-ruby/internal/pack.rb +0 -397
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b87546f15e81ee861f432ab257ab70287196bc7c
|
4
|
+
data.tar.gz: 1ad1939ae2859a5a1ce7d7dc6e2d0d5f107d895c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd4863a15684e585c59ed92390b14f65e77edd5c84a3975d876767f98d4c939357f896291281beee631b5d729638de1eefd5789f8eee655a2f14a5d9daaa754a
|
7
|
+
data.tar.gz: 60e919e7cd76defb8b20bc9535617f6430537b7279c92f5e60a423d0cb393c807d9b9f080133b967e44f0fbfb1dac9f84f8662ab0cee9545da4a47f07f58fe77
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gollum_rails (1.4.
|
4
|
+
gollum_rails (1.4.4)
|
5
5
|
activemodel (>= 4.0.0)
|
6
|
-
gollum-lib (~> 1.0.
|
6
|
+
gollum-lib (~> 1.0.8)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -35,6 +35,7 @@ GEM
|
|
35
35
|
arel (4.0.0)
|
36
36
|
atomic (1.1.9)
|
37
37
|
builder (3.1.4)
|
38
|
+
charlock_holmes (0.6.9.4)
|
38
39
|
coderay (1.0.9)
|
39
40
|
colorize (0.5.8)
|
40
41
|
coveralls (0.6.4)
|
@@ -47,20 +48,19 @@ GEM
|
|
47
48
|
erubis (2.7.0)
|
48
49
|
ffi (1.9.0)
|
49
50
|
formatador (0.2.4)
|
50
|
-
github-markdown (0.5.3)
|
51
51
|
github-markup (0.7.5)
|
52
|
-
|
53
|
-
|
52
|
+
gitlab-grit (2.6.0)
|
53
|
+
charlock_holmes (~> 0.6.9)
|
54
|
+
diff-lcs (~> 1.1)
|
55
|
+
mime-types (~> 1.15)
|
56
|
+
posix-spawn (~> 0.3.6)
|
57
|
+
gollum-lib (1.0.8)
|
54
58
|
github-markup (>= 0.7.5, < 1.0.0)
|
55
|
-
grit (~> 2.
|
59
|
+
gitlab-grit (~> 2.6.0)
|
56
60
|
nokogiri (~> 1.6.0)
|
57
61
|
pygments.rb (~> 0.5.2)
|
58
62
|
sanitize (~> 2.0.6)
|
59
|
-
stringex (~> 2.0
|
60
|
-
grit (2.5.0)
|
61
|
-
diff-lcs (~> 1.1)
|
62
|
-
mime-types (~> 1.15)
|
63
|
-
posix-spawn (~> 0.3.6)
|
63
|
+
stringex (~> 2.1.0)
|
64
64
|
guard (1.8.0)
|
65
65
|
formatador (>= 0.2.4)
|
66
66
|
listen (>= 1.0.0)
|
@@ -82,7 +82,7 @@ GEM
|
|
82
82
|
treetop (~> 1.4.8)
|
83
83
|
method_source (0.8.1)
|
84
84
|
mime-types (1.23)
|
85
|
-
mini_portile (0.5.
|
85
|
+
mini_portile (0.5.2)
|
86
86
|
minitest (4.7.5)
|
87
87
|
multi_json (1.7.3)
|
88
88
|
nokogiri (1.6.0)
|
@@ -145,7 +145,7 @@ GEM
|
|
145
145
|
actionpack (>= 3.0)
|
146
146
|
activesupport (>= 3.0)
|
147
147
|
sprockets (~> 2.8)
|
148
|
-
stringex (2.0
|
148
|
+
stringex (2.1.0)
|
149
149
|
thor (0.18.1)
|
150
150
|
thread_safe (0.1.0)
|
151
151
|
atomic
|
data/HISTORY.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 1.4.4 31th October 2013
|
2
|
+
* Removed Monkey patch for Grit
|
3
|
+
* Upgraded Gollum lib version
|
4
|
+
* Fixed specs for new gollum behavior
|
5
|
+
* Removed String freedom patches
|
6
|
+
*
|
7
|
+
|
1
8
|
# 1.4.3 1th September 2013
|
2
9
|
* Display the current pages version (short OR long)
|
3
10
|
* Display if the page is a sub page
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Gollum for Rails
|
|
4
4
|
[![Dependency Status](https://gemnasium.com/nirnanaaa/gollum_rails.png)](https://gemnasium.com/nirnanaaa/gollum_rails)
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/gollum_rails.png)](http://badge.fury.io/rb/gollum_rails)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/nirnanaaa/gollum_rails/badge.png?branch=master)](https://coveralls.io/r/nirnanaaa/gollum_rails)
|
7
|
-
|
7
|
+
[![Code Climate](https://codeclimate.com/github/nirnanaaa/gollum_rails.png)](https://codeclimate.com/github/nirnanaaa/gollum_rails)
|
8
8
|
|
9
9
|
gollum_rails combines the git-powered wiki software gollum with the extreme popular webframework rails.
|
10
10
|
It improves the lightweight "gollum" experience which is quite awesome.
|
@@ -17,6 +17,10 @@ with gollum_rails you can:
|
|
17
17
|
* Use own preprocession e.g. background workers for data procession
|
18
18
|
* Use user authentication e.g. Devise or Authlogic
|
19
19
|
|
20
|
+
For an Editor to use with gollum_rails I personally like the [gollum_editor](https://github.com/samknight/gollum_editor)
|
21
|
+
|
22
|
+
It provides nearly the same features as the official editor.
|
23
|
+
|
20
24
|
## SYSTEM REQUIREMENTS
|
21
25
|
- Python 2.5+ (2.7.3 recommended)
|
22
26
|
- Ruby 1.9.3+ (2.0.0 recommended)
|
data/gollum_rails.gemspec
CHANGED
@@ -4,13 +4,13 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'gollum_rails'
|
5
5
|
s.rubyforge_project = s.name
|
6
6
|
|
7
|
-
s.version = '1.4.
|
7
|
+
s.version = '1.4.4'
|
8
8
|
|
9
9
|
s.summary = 'Combines Gollum and Rails'
|
10
10
|
s.description= 'include Gollum into Rails with ease'
|
11
11
|
|
12
12
|
s.add_dependency 'activemodel', '>= 4.0.0'
|
13
|
-
s.add_dependency 'gollum-lib', '~> 1.0.
|
13
|
+
s.add_dependency 'gollum-lib', '~> 1.0.8'
|
14
14
|
|
15
15
|
s.add_development_dependency 'rspec', '~> 2.13.0'
|
16
16
|
s.add_development_dependency 'rr', '~> 1.1.1'
|
@@ -34,7 +34,6 @@ Gem::Specification.new do |s|
|
|
34
34
|
README.md
|
35
35
|
Rakefile
|
36
36
|
gollum_rails.gemspec
|
37
|
-
lib/core_ext/string.rb
|
38
37
|
lib/generators/gollum_rails/install/install_generator.rb
|
39
38
|
lib/generators/gollum_rails/install/templates/gollum_initializer.rb
|
40
39
|
lib/generators/gollum_rails/language/language_generator.rb
|
@@ -52,7 +51,6 @@ Gem::Specification.new do |s|
|
|
52
51
|
lib/gollum_rails/adapters/gollum/wiki.rb
|
53
52
|
lib/gollum_rails/page.rb
|
54
53
|
lib/gollum_rails/setup.rb
|
55
|
-
lib/grit/git-ruby/internal/pack.rb
|
56
54
|
spec/gollum_rails/adapters/activemodel/error_spec.rb
|
57
55
|
spec/gollum_rails/adapters/activemodel/naming_spec.rb
|
58
56
|
spec/gollum_rails/adapters/activemodel/validation_unused.rb
|
data/lib/gollum_rails.rb
CHANGED
@@ -6,9 +6,6 @@ require 'rubygems'
|
|
6
6
|
# external
|
7
7
|
require 'gollum-lib'
|
8
8
|
|
9
|
-
# patches
|
10
|
-
require 'grit/git-ruby/internal/pack'
|
11
|
-
require 'core_ext/string'
|
12
9
|
|
13
10
|
# GollumRails is a RubyGem for extending Rails and the Gollum wiki powered by github
|
14
11
|
# It has the ability to combine the benefits from a git powered wiki with Rails.
|
@@ -23,7 +20,7 @@ module GollumRails
|
|
23
20
|
autoload :Setup, 'gollum_rails/setup'
|
24
21
|
|
25
22
|
# GollumRails version string
|
26
|
-
VERSION = '1.4.
|
23
|
+
VERSION = '1.4.4'
|
27
24
|
|
28
25
|
# Simplified error
|
29
26
|
class Error < StandardError; end
|
@@ -59,7 +59,7 @@ describe "Gollum Page" do
|
|
59
59
|
end
|
60
60
|
it "has the formatted data" do
|
61
61
|
@rr.save
|
62
|
-
@rr.html_data.should == '
|
62
|
+
@rr.html_data.should == 'content data'
|
63
63
|
end
|
64
64
|
it "was last changed by me" do
|
65
65
|
@rr.save
|
@@ -124,13 +124,6 @@ describe "Gollum Page" do
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
|
128
|
-
100.times do
|
129
|
-
it "should test the preview" do
|
130
|
-
rr = RailsModel.new :content => "# content", :name => "somepage"
|
131
|
-
rr.preview.should include("<h1>content<a class=\"anchor\" id=\"content\" href=\"#content\"></a></h1>")
|
132
|
-
end
|
133
|
-
end
|
134
127
|
|
135
128
|
it "should test exception methods" do
|
136
129
|
RailsModel.create @call
|
@@ -338,7 +331,7 @@ describe "Gollum Page" do
|
|
338
331
|
res.update_attributes("content",nil,:markdown, @commit)
|
339
332
|
diff = res.compare_commits(res.history.first)
|
340
333
|
expect(diff).to be_a String
|
341
|
-
expect(diff).to match(
|
334
|
+
expect(diff).to match(/---/)
|
342
335
|
res.delete
|
343
336
|
end
|
344
337
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gollum_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.4
|
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-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0.
|
33
|
+
version: 1.0.8
|
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.8
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,7 +94,6 @@ files:
|
|
94
94
|
- README.md
|
95
95
|
- Rakefile
|
96
96
|
- gollum_rails.gemspec
|
97
|
-
- lib/core_ext/string.rb
|
98
97
|
- lib/generators/gollum_rails/install/install_generator.rb
|
99
98
|
- lib/generators/gollum_rails/install/templates/gollum_initializer.rb
|
100
99
|
- lib/generators/gollum_rails/language/language_generator.rb
|
@@ -112,7 +111,6 @@ files:
|
|
112
111
|
- lib/gollum_rails/adapters/gollum/wiki.rb
|
113
112
|
- lib/gollum_rails/page.rb
|
114
113
|
- lib/gollum_rails/setup.rb
|
115
|
-
- lib/grit/git-ruby/internal/pack.rb
|
116
114
|
- spec/gollum_rails/adapters/activemodel/error_spec.rb
|
117
115
|
- spec/gollum_rails/adapters/activemodel/naming_spec.rb
|
118
116
|
- spec/gollum_rails/adapters/activemodel/validation_unused.rb
|
@@ -150,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
148
|
version: '0'
|
151
149
|
requirements: []
|
152
150
|
rubyforge_project: gollum_rails
|
153
|
-
rubygems_version: 2.0.
|
151
|
+
rubygems_version: 2.0.6
|
154
152
|
signing_key:
|
155
153
|
specification_version: 4
|
156
154
|
summary: Combines Gollum and Rails
|
data/lib/core_ext/string.rb
DELETED
@@ -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
|