Grit::GitRuby::Internal::PackFormatError #117

Closed
SaitoWu opened this Issue May 21, 2012 · 9 comments

Comments

Projects
None yet
9 participants
@SaitoWu

SaitoWu commented May 21, 2012

[1] pry(main)> require'grit'
=> true
[2] pry(main)> Grit::Repo.new('../rails')
=> #<Grit::Repo "/Users/saito/Develop/rails/.git">
[3] pry(main)> repo=_
=> #<Grit::Repo "/Users/saito/Develop/rails/.git">
[4] pry(main)> repo.commits
Grit::GitRuby::Internal::PackFormatError: pack /Users/saito/Develop/rails/.git/objects/pack/pack-6ca3f2932648224dbf874aa14f8fce8d54e3a198.pack has discontinuous index 1
from /Users/saito/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/grit-2.5.0/lib/grit/git-ruby/internal/pack.rb:135:in `block (2 levels) in init_pack'
@fujimura

This comment has been minimized.

Show comment Hide comment
@fujimura

fujimura Jul 27, 2012

Got same error with same env(ruby 1.9.3-p194 on rbenv). any updates?

[1] pry(main)> c = Grit::Repo.new './'
=> #<Grit::Repo "/Users/dfujimura/sandbox/some-repo/.git">
[2] pry(main)> c.commits
Grit::GitRuby::Internal::PackFormatError: pack /Users/dfujimura/sandbox/some-repo/.git/objects/pack/pack-0c53037493ffa0fdb824180e05de021e66e53d63.pack has discontinuous index 1
from /Users/dfujimura/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/grit-2.5.0/lib/grit/git-ruby/internal/pack.rb:135:in `block (2 levels) in init_pack'
$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-darwin11.2.0]
  - INSTALLATION DIRECTORY: /Users/dfujimura/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /Users/dfujimura/.rbenv/versions/1.9.3-p194/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/dfujimura/.rbenv/versions/1.9.3-p194/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/dfujimura/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1
     - /Users/dfujimura/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-rdoc --no-ri"
  - REMOTE SOURCES:
     - http://rubygems.org/
$ gem list | grep grit
grit (2.5.0)
$ git --version
git version 1.7.11.3

Got same error with same env(ruby 1.9.3-p194 on rbenv). any updates?

[1] pry(main)> c = Grit::Repo.new './'
=> #<Grit::Repo "/Users/dfujimura/sandbox/some-repo/.git">
[2] pry(main)> c.commits
Grit::GitRuby::Internal::PackFormatError: pack /Users/dfujimura/sandbox/some-repo/.git/objects/pack/pack-0c53037493ffa0fdb824180e05de021e66e53d63.pack has discontinuous index 1
from /Users/dfujimura/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/grit-2.5.0/lib/grit/git-ruby/internal/pack.rb:135:in `block (2 levels) in init_pack'
$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-darwin11.2.0]
  - INSTALLATION DIRECTORY: /Users/dfujimura/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /Users/dfujimura/.rbenv/versions/1.9.3-p194/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/dfujimura/.rbenv/versions/1.9.3-p194/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/dfujimura/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1
     - /Users/dfujimura/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-rdoc --no-ri"
  - REMOTE SOURCES:
     - http://rubygems.org/
$ gem list | grep grit
grit (2.5.0)
$ git --version
git version 1.7.11.3

@gliptak gliptak referenced this issue in gitlabhq/gitlabhq Jan 17, 2013

Closed

500 error pack has discontinuous index 1 #2642

@schleyfox

This comment has been minimized.

Show comment Hide comment
@schleyfox

schleyfox Jan 30, 2013

Heh, I think I found the issue. It's encodings related.

So basically it opens the index file in binary mode. There are two formats of index/pack files: version 1 and version 2. Version 2 is marked by a 4 byte signature ("\xFFtOc" or int=4285812579) and a 4 byte version number (int=2). This 8 byte header precedes the rest of the index file. Version 1 has no header.

The index reader takes this into account and applies an 8 byte offset for all version 2 files and a 0 byte offset for all version 1 files: https://github.com/github/grit/blob/master/lib/grit/git-ruby/internal/file_window.rb#L19-L23

The determination of version is handled by comparing the signature with PACK_IDX_SIGNATURE: https://github.com/github/grit/blob/master/lib/grit/git-ruby/internal/pack.rb#L63

PACK_IDX_SIGNATURE is defined as a string literal: https://github.com/github/grit/blob/master/lib/grit/git-ruby/internal/pack.rb#L17

The 4 byte signature is read out of a file in binary, so it explicitly has an encoding of "ASCII-8BIT". PACK_IDX_SIGNATURE is a string literal, so its encoding is determined as whatever ruby wants it to be (on my mac that's ASCII-8BIT, on my server that's UTF-8). For a string to be equal both content and encoding must be equal. Hilarity ensues.

The actual error message is produced because the file is thought to be version 1, so it reads two integers from the file starting at index 0. These are 4285812579 and 2. 2 < 4285812579 so it barfs: https://github.com/github/grit/blob/master/lib/grit/git-ruby/internal/pack.rb#L134-L135

Heh, I think I found the issue. It's encodings related.

So basically it opens the index file in binary mode. There are two formats of index/pack files: version 1 and version 2. Version 2 is marked by a 4 byte signature ("\xFFtOc" or int=4285812579) and a 4 byte version number (int=2). This 8 byte header precedes the rest of the index file. Version 1 has no header.

The index reader takes this into account and applies an 8 byte offset for all version 2 files and a 0 byte offset for all version 1 files: https://github.com/github/grit/blob/master/lib/grit/git-ruby/internal/file_window.rb#L19-L23

The determination of version is handled by comparing the signature with PACK_IDX_SIGNATURE: https://github.com/github/grit/blob/master/lib/grit/git-ruby/internal/pack.rb#L63

PACK_IDX_SIGNATURE is defined as a string literal: https://github.com/github/grit/blob/master/lib/grit/git-ruby/internal/pack.rb#L17

The 4 byte signature is read out of a file in binary, so it explicitly has an encoding of "ASCII-8BIT". PACK_IDX_SIGNATURE is a string literal, so its encoding is determined as whatever ruby wants it to be (on my mac that's ASCII-8BIT, on my server that's UTF-8). For a string to be equal both content and encoding must be equal. Hilarity ensues.

The actual error message is produced because the file is thought to be version 1, so it reads two integers from the file starting at index 0. These are 4285812579 and 2. 2 < 4285812579 so it barfs: https://github.com/github/grit/blob/master/lib/grit/git-ruby/internal/pack.rb#L134-L135

@rriemann

This comment has been minimized.

Show comment Hide comment
@rriemann

rriemann Mar 18, 2013

Please fix this! Got this problem when using gollum.

Please fix this! Got this problem when using gollum.

@rriemann

This comment has been minimized.

Show comment Hide comment
@rriemann

rriemann Mar 18, 2013

Only happens for me with ruby 2.0 (installed via rvm). With ruby 1.9.3 everything seems to be fine.

Only happens for me with ruby 2.0 (installed via rvm). With ruby 1.9.3 everything seems to be fine.

@fconcklin

This comment has been minimized.

Show comment Hide comment
@fconcklin

fconcklin Mar 21, 2013

I also get this on rvm 1.18.21 (stable) when using gollum.

I also get this on rvm 1.18.21 (stable) when using gollum.

@mjaros

This comment has been minimized.

Show comment Hide comment
@mjaros

mjaros Mar 22, 2013

I can confirm that this only happens with Ruby 2.0. With 1.9.3 everything is fine.

mjaros commented Mar 22, 2013

I can confirm that this only happens with Ruby 2.0. With 1.9.3 everything is fine.

@styx

This comment has been minimized.

Show comment Hide comment
@styx

styx Mar 22, 2013

An I can confirm this always happens on 2.0 and sometimes on 1.9.3 (I have such a repo but can't share it). Also I'd wish to admit that Grit seems to be dead.

styx commented Mar 22, 2013

An I can confirm this always happens on 2.0 and sometimes on 1.9.3 (I have such a repo but can't share it). Also I'd wish to admit that Grit seems to be dead.

Voker57 added a commit to Voker57/grit that referenced this issue Dec 19, 2013

Issue #117: Fixed wrong magic comparition.
Signed-off-by: Mikhail S. Pobolovets <styx.mp@gmail.com>

Conflicts:
	lib/grit/git-ruby/internal/pack.rb

Voker57 added a commit to Voker57/grit that referenced this issue Dec 19, 2013

Issue #117: Fixed wrong magic comparition.
Signed-off-by: Mikhail S. Pobolovets <styx.mp@gmail.com>

Conflicts:
	lib/grit/git-ruby/internal/pack.rb
@paulRbr

This comment has been minimized.

Show comment Hide comment
@paulRbr

paulRbr Jan 16, 2014

This commit (https://github.com/BertramScharpf/grit/commit/6fc5006cca4f07f7f82383fb4d822c509cc516ee) solved the issue in my case.

with git 1.8.4, rvm 1.24.1, ruby 2.0.0-p353

paulRbr commented Jan 16, 2014

This commit (https://github.com/BertramScharpf/grit/commit/6fc5006cca4f07f7f82383fb4d822c509cc516ee) solved the issue in my case.

with git 1.8.4, rvm 1.24.1, ruby 2.0.0-p353

@scttnlsn scttnlsn referenced this issue in scttnlsn/dandelion Jan 29, 2014

Closed

Error deploying WordPress #60

@bkeepers

This comment has been minimized.

Show comment Hide comment
@bkeepers

bkeepers Feb 3, 2014

Collaborator

Grit is no longer maintained. See #183 and check out libgit2/rugged.

Collaborator

bkeepers commented Feb 3, 2014

Grit is no longer maintained. See #183 and check out libgit2/rugged.

@bkeepers bkeepers closed this Feb 3, 2014

balmas added a commit to sosol/sosol that referenced this issue May 13, 2015

hack to avoid grit call
calling tree to try to determine if a directory exists
exposed this error mojombo/grit#117
hacking a workaround for now to check for the readme using a
method which uses JGit instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment