gollum_rails 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5dd7344f385aa410641d4306e45816ded6fcc3ab
4
- data.tar.gz: 4c575604cbf42c6c261a282fe8bddba7d9e05b0e
3
+ metadata.gz: 8e56f1c38049b5c88e4774cd88ceb414d3a88e3c
4
+ data.tar.gz: 4238c31d63ca8597e1ed8b0e69a9aaa46a31f253
5
5
  SHA512:
6
- metadata.gz: 6ac3f7568b4f3125dd80d0bf90126216d46defc5a06c304a1ee1a241dc2f9b96f1c208ed9fa0b92c7618e92d851e2012200ab768aafc4639eba09fd69f766f57
7
- data.tar.gz: 4541dd32cf2e51123f88a4daa0970dcfa08b214099c05f86d65f7d07ec0c3a7c78fdcc5f76210ddf28635e8ff9274ed828cbe0b27cafabdfbbcdb22a97abf1ca
6
+ metadata.gz: 6599a1872724fbb09a65bb489e845eef9d2b07cfd9c7e093d82eaacdbf6af6e3633c511b147cae1600f9297ab7503f7dac1a00df97e03ff9236011f79abe4dd7
7
+ data.tar.gz: 9a6c1f70a997384592437c2295fffab178639fdb1ef1d94c2690eacc844a6cba06db48fa8070a2813845b873d7ad6ec5950604a82b15b5c3dd748392957495d9
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'coveralls', require: false
4
- gem "grit", git: "git://github.com/styx/grit.git"
4
+
5
5
 
6
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,17 +1,9 @@
1
- GIT
2
- remote: git://github.com/styx/grit.git
3
- revision: 2109888819d23f18cdc30c0fbb6280ec3208fa7d
4
- specs:
5
- grit (2.5.0)
6
- diff-lcs (~> 1.1)
7
- mime-types (~> 1.15)
8
- posix-spawn (~> 0.3.6)
9
-
10
1
  PATH
11
2
  remote: .
12
3
  specs:
13
- gollum_rails (1.0.1)
4
+ gollum_rails (1.0.2)
14
5
  activemodel (~> 3.2.13)
6
+ gitlab-grit (~> 1.0.0)
15
7
  gollum-lib (~> 1.0.0)
16
8
 
17
9
  GEM
@@ -57,6 +49,10 @@ GEM
57
49
  erubis (2.7.0)
58
50
  github-markdown (0.5.3)
59
51
  github-markup (0.7.5)
52
+ gitlab-grit (1.0.0)
53
+ diff-lcs (~> 1.1)
54
+ mime-types (~> 1.15)
55
+ posix-spawn (~> 0.3.6)
60
56
  gollum-lib (1.0.0)
61
57
  github-markdown (~> 0.5.3)
62
58
  github-markup (>= 0.7.5, < 1.0.0)
@@ -65,6 +61,10 @@ GEM
65
61
  pygments.rb (~> 0.4.2)
66
62
  sanitize (~> 2.0.3)
67
63
  stringex (~> 1.5.1)
64
+ grit (2.5.0)
65
+ diff-lcs (~> 1.1)
66
+ mime-types (~> 1.15)
67
+ posix-spawn (~> 0.3.6)
68
68
  hike (1.2.1)
69
69
  i18n (0.6.1)
70
70
  journey (1.0.4)
@@ -145,7 +145,6 @@ PLATFORMS
145
145
  DEPENDENCIES
146
146
  coveralls
147
147
  gollum_rails!
148
- grit!
149
148
  rails (~> 3.2.13)
150
149
  rr (~> 1.0.4)
151
150
  rspec (~> 2.13.0)
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 1.0.2 23th April 2013
2
+ * added standalone compability for ruby 2.0
3
+ * added patches by styx
4
+ * added string corext for ruby2
5
+ * added mutex locks for ugly threadsave
6
+
1
7
  # 1.0.1 5th April 2013
2
8
  * added find_all and all for Page
3
9
  * removed some unused functions
data/README.md CHANGED
@@ -7,7 +7,7 @@ Gollum for Rails
7
7
 
8
8
 
9
9
  gollum_rails combines the git-powered wiki software gollum with the extremely popular webframework rails.
10
- It improves the lightweight "gollum" experience which is quite awesome.
10
+ It improves the lightweight "gollum" experience which is quite awesome.
11
11
 
12
12
  with gollum_rails you can:
13
13
 
@@ -23,7 +23,6 @@ with gollum_rails you can:
23
23
  - Unix like operating system (OS X, Ubuntu, Debian, and more)
24
24
  - Will not work on Windows (see [gollum](https://github.com/github/gollum/blob/master/README.md#system-requirements))
25
25
 
26
- ## [RUBY >= 2.0 READ THIS](https://github.com/nirnanaaa/gollum_rails/wiki/Ruby#ruby-2.0)
27
26
  ## [Installation](https://github.com/nirnanaaa/gollum_rails/wiki/Installation)
28
27
 
29
28
  ## [Usage](https://github.com/nirnanaaa/gollum_rails/wiki/Usage)
@@ -37,11 +36,11 @@ Very cool. Just fork this repository and send me pull requests.
37
36
 
38
37
  Clone the repository:
39
38
 
40
- $ git clone git://github.com/nirnanaaa/gollum_rails.git
39
+ $ git clone git://github.com/nirnanaaa/gollum_rails.git
41
40
 
42
41
  Run the [Bundler](http://gembundler.com/):
43
42
 
44
- $ bundle install
43
+ $ bundle install
45
44
 
46
45
 
47
46
  ### TESTING
@@ -51,13 +50,13 @@ All tests are stored under the `spec/` directory.
51
50
 
52
51
  To run tests just use the `rspec` command:
53
52
 
54
- $ bundle exec rspec
53
+ $ bundle exec rspec
55
54
 
56
55
  ## LICENSE
57
56
 
58
57
  [![AGPLv3](http://www.gnu.org/graphics/agplv3-155x51.png)](http://www.gnu.org/licenses/agpl-3.0.en.html)
59
58
 
60
- gollum_rails is licensed under the AGPL license.
59
+ gollum_rails is licensed under the AGPL license.
61
60
 
62
61
  Copyright (C) 2013 Florian Kasper
63
62
 
@@ -73,4 +72,3 @@ GNU Affero General Public License for more details.
73
72
 
74
73
  You should have received a copy of the GNU Affero General Public License
75
74
  along with this program. If not, see <http://www.gnu.org/licenses/>.
76
-
data/gollum_rails.gemspec CHANGED
@@ -1,24 +1,20 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.rubygems_version = '>= 1.3.5'
3
-
3
+
4
4
  s.name = 'gollum_rails'
5
5
  s.rubyforge_project = s.name
6
6
 
7
- s.version = '1.0.1'
7
+ s.version = '1.0.2'
8
8
 
9
9
  s.summary = 'Combines the benefits from Gollum and Rails'
10
10
  s.description= 'Use all the benefits from Rails and combine them with the awesome Gollum wiki'
11
- #File.read(File.join(File.dirname(__FILE__), 'README.md'))
12
11
 
13
12
  s.add_dependency 'activemodel', '~> 3.2.13'
14
13
  s.add_dependency 'gollum-lib', '~> 1.0.0'
15
- #s.add_dependency 'grit', '~> 2.5.0'
16
- #s.add_dependency 'builder', '~> 3.0.0'
17
- #s.add_dependency 'rack', '~> 1.4.5'
14
+ s.add_dependency 'gitlab-grit', '~> 1.0.0'
18
15
 
19
16
  s.add_development_dependency 'rspec', '~> 2.13.0'
20
- s.add_development_dependency 'rails', '~> 3.2.13'
21
- s.add_development_dependency 'rr', '~> 1.0.4'
17
+ s.add_development_dependency 'rr', '~> 1.0.4'
22
18
  s.add_development_dependency 'rails', '~> 3.2.13'
23
19
 
24
20
  s.author = 'Florian Kasper'
@@ -37,6 +33,7 @@ Gem::Specification.new do |s|
37
33
  README.md
38
34
  Rakefile
39
35
  gollum_rails.gemspec
36
+ lib/core_ext/string.rb
40
37
  lib/generators/gollum_rails/install/install_generator.rb
41
38
  lib/generators/gollum_rails/install/templates/gollum_initializer.rb
42
39
  lib/generators/gollum_rails/language/language_generator.rb
@@ -57,6 +54,7 @@ Gem::Specification.new do |s|
57
54
  lib/gollum_rails/modules/loader.rb
58
55
  lib/gollum_rails/page.rb
59
56
  lib/gollum_rails/setup.rb
57
+ lib/grit/git-ruby/internal/pack.rb
60
58
  spec/gollum_rails/adapters/activemodel/error_spec.rb
61
59
  spec/gollum_rails/adapters/activemodel/naming_spec.rb
62
60
  spec/gollum_rails/adapters/activemodel/validation_unused.rb
@@ -77,7 +75,7 @@ Gem::Specification.new do |s|
77
75
 
78
76
 
79
77
  s.require_paths = %w[lib]
80
- s.post_install_message = <<-END
78
+ s.post_install_message = <<-END
81
79
  Important: \n
82
80
  **********************************************
83
81
  To use the installer just run the following command:
@@ -89,4 +87,3 @@ Gem::Specification.new do |s|
89
87
  **********************************************"
90
88
  END
91
89
  end
92
-
@@ -0,0 +1,10 @@
1
+ class String
2
+ if ((defined? RUBY_VERSION) && (['1.9', '2.0'].include? RUBY_VERSION[0..2]))
3
+ def getord(offset); self[offset].ord; end
4
+ else
5
+ alias :getord :[]
6
+ end
7
+
8
+
9
+
10
+ end
data/lib/gollum_rails.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'gollum-lib'
3
-
3
+ require 'grit/git-ruby/internal/pack'
4
+ require 'core_ext/string'
4
5
  # GollumRails is a RubyGem for extending Rails and the Gollum wiki powered by github
5
6
  # It has the ability to combine the benefits from a git powered wiki with Rails.
6
7
  #
@@ -12,17 +13,17 @@ require 'gollum-lib'
12
13
  module GollumRails
13
14
  autoload :Page, 'gollum_rails/page'
14
15
  autoload :Setup, 'gollum_rails/setup'
15
-
16
+
16
17
  # GollumRails version string
17
- VERSION = '1.0.1'
18
-
18
+ VERSION = '1.0.2'
19
+
19
20
  # Simplified error
20
21
  class Error < StandardError; end
21
22
 
22
23
  # For use with internal gollumGem exceptions
23
- #
24
+ #
24
25
  class GollumInternalError < Error
25
-
26
+
26
27
  end
27
28
  end
28
29
 
@@ -33,5 +34,3 @@ require File.expand_path '../gollum_rails/adapters/gollum', __FILE__
33
34
  #require File.expand_path '../gollum_rails/page', __FILE__
34
35
  # load extensions
35
36
  require File.expand_path '../gollum_rails/modules/loader', __FILE__
36
-
37
-
@@ -1,3 +1,5 @@
1
+ require 'thread'
2
+
1
3
  module GollumRails
2
4
 
3
5
  # Main class, used to interact with rails.
@@ -12,12 +14,12 @@ module GollumRails
12
14
  # * delete
13
15
  # * find_or_initialize_by_naname
14
16
  #
15
- class Page
17
+ class Page
16
18
  extend ::ActiveModel::Callbacks
17
19
  include ::ActiveModel::Validations
18
20
  include ::ActiveModel::Conversion
19
21
  extend ::ActiveModel::Naming
20
-
22
+
21
23
 
22
24
  # Callback for save
23
25
  define_model_callbacks :save
@@ -80,7 +82,7 @@ module GollumRails
80
82
  action = self.create(hash)
81
83
  action
82
84
  end
83
-
85
+
84
86
  # Finds a page based on the name and specified version
85
87
  #
86
88
  # name - the name of the page
@@ -104,6 +106,8 @@ module GollumRails
104
106
 
105
107
  end
106
108
 
109
+ # mutex lock for multithreading
110
+ attr_reader :mutex
107
111
 
108
112
  # Initializes a new Page
109
113
  #
@@ -111,6 +115,7 @@ module GollumRails
111
115
  #
112
116
  # commit must be given to perform any page action!
113
117
  def initialize(attrs = {})
118
+ @mutex = Mutex.new
114
119
  if Adapters::Gollum::Connector.enabled
115
120
  attrs.each{|k,v| self.public_send("#{k}=",v)} if attrs
116
121
  else
@@ -121,7 +126,7 @@ module GollumRails
121
126
  #########
122
127
  # Setters
123
128
  #########
124
-
129
+
125
130
 
126
131
  # Gets / Sets the pages name
127
132
  attr_accessor :name
@@ -135,7 +140,7 @@ module GollumRails
135
140
  # Sets the format
136
141
  attr_writer :format
137
142
 
138
-
143
+
139
144
  #########
140
145
  # Getters
141
146
  #########
@@ -151,7 +156,7 @@ module GollumRails
151
156
  def page
152
157
  @page ||= Adapters::Gollum::Connector.page_class.new
153
158
  end
154
-
159
+
155
160
  #############
156
161
  # activemodel
157
162
  #############
@@ -162,30 +167,32 @@ module GollumRails
162
167
  # will detect it and returns that page instead.
163
168
  #
164
169
  # Examples:
165
- #
170
+ #
166
171
  # obj = GollumRails::Page.new <params>
167
172
  # @article = obj.save
168
173
  # # => Gollum::Page
169
- #
174
+ #
170
175
  # @article.name
171
- # whatever name you have entered OR the name of the previous
176
+ # whatever name you have entered OR the name of the previous
172
177
  # created page
173
- #
178
+ #
174
179
  #
175
180
  # TODO:
176
181
  # * overriding for creation(duplicates)
177
- # * do not alias save! on save
178
- #
182
+ # * do not alias save! on save
183
+ #
179
184
  # Returns an instance of Gollum::Page or false
180
185
  def save
181
- run_callbacks :save do
182
- return false unless valid?
183
- begin
184
- page.new_page(name,content,format,commit)
185
- rescue ::Gollum::DuplicatePageError => e
186
- page.page = page.find_page(name)
186
+ mutex.synchronize do
187
+ run_callbacks :save do
188
+ return false unless valid?
189
+ begin
190
+ page.new_page(name,content,format,commit)
191
+ rescue ::Gollum::DuplicatePageError => e
192
+ page.page = page.find_page(name)
193
+ end
194
+ return page.page
187
195
  end
188
- return page.page
189
196
  end
190
197
  end
191
198
 
@@ -202,39 +209,45 @@ module GollumRails
202
209
  # to initialize the instance
203
210
  #
204
211
  #
205
- # Returns an instance of Gollum::Page
212
+ # Returns an instance of Gollum::Page
206
213
  def update_attributes(hash, commit=nil)
207
- run_callbacks :update do
208
- page.update_page hash, get_right_commit(commit)
214
+ mutex.synchronize do
215
+ run_callbacks :update do
216
+ page.update_page hash, get_right_commit(commit)
217
+ end
209
218
  end
219
+
210
220
  end
211
-
221
+
212
222
  # Deletes current page (also available static. See below)
213
223
  #
214
224
  # commit - optional. If given this commit will be used instead of that one, used
215
225
  # to initialize the instance
216
226
  #
217
- # Returns the commit id of the current action as String
227
+ # Returns the commit id of the current action as String
218
228
  def delete(commit=nil)
219
- run_callbacks :delete do
220
- page.delete_page get_right_commit(commit)
229
+ mutex.synchronize do
230
+ run_callbacks :delete do
231
+ page.delete_page get_right_commit(commit)
232
+ end
221
233
  end
234
+
222
235
  end
223
236
 
224
237
  # checks if entry already has been saved
225
- #
238
+ #
226
239
  #
227
240
  def persisted?
228
241
  return true if page.page.instance_of?(::Gollum::Page)
229
242
  return false
230
243
  end
231
244
  # Previews the page - Mostly used if you want to see what you do before saving
232
- #
245
+ #
233
246
  # This is an extremely performant method!
234
- # 1 rendering attempt take depending on the content about 0.001 (simple markdown)
247
+ # 1 rendering attempt take depending on the content about 0.001 (simple markdown)
235
248
  # upto 0.004 (1000 chars markdown) seconds, which is quite good
236
249
  #
237
- #
250
+ #
238
251
  # format - Specify the format you want to render with see {self.format_supported?}
239
252
  # for formats
240
253
  #
@@ -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
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.0.1
4
+ version: 1.0.2
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-04-05 00:00:00.000000000 Z
11
+ date: 2013-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -39,33 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.0.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: gitlab-grit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 2.13.0
48
- type: :development
47
+ version: 1.0.0
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 2.13.0
54
+ version: 1.0.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: rails
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 3.2.13
61
+ version: 2.13.0
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: 3.2.13
68
+ version: 2.13.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rr
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,7 @@ files:
108
108
  - README.md
109
109
  - Rakefile
110
110
  - gollum_rails.gemspec
111
+ - lib/core_ext/string.rb
111
112
  - lib/generators/gollum_rails/install/install_generator.rb
112
113
  - lib/generators/gollum_rails/install/templates/gollum_initializer.rb
113
114
  - lib/generators/gollum_rails/language/language_generator.rb
@@ -128,6 +129,7 @@ files:
128
129
  - lib/gollum_rails/modules/loader.rb
129
130
  - lib/gollum_rails/page.rb
130
131
  - lib/gollum_rails/setup.rb
132
+ - lib/grit/git-ruby/internal/pack.rb
131
133
  - spec/gollum_rails/adapters/activemodel/error_spec.rb
132
134
  - spec/gollum_rails/adapters/activemodel/naming_spec.rb
133
135
  - spec/gollum_rails/adapters/activemodel/validation_unused.rb