Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

SaitoWu opened this issue May 21, 2012 · 9 comments

Comments

@SaitoWu
Copy link

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
Copy link

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

@schleyfox
Copy link

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
Copy link

Please fix this! Got this problem when using gollum.

@rriemann
Copy link

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

@fconcklin
Copy link

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

@mjaros
Copy link

mjaros commented Mar 22, 2013

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

@styx
Copy link

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 pushed a commit to Voker57/grit that referenced this issue Dec 19, 2013
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
Signed-off-by: Mikhail S. Pobolovets <styx.mp@gmail.com>

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

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

@bkeepers
Copy link
Collaborator

bkeepers commented Feb 3, 2014

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

@bkeepers bkeepers closed this as completed Feb 3, 2014
balmas added a commit to sosol/sosol that referenced this issue May 13, 2015
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants