speedata / gogit Goto Github PK
View Code? Open in Web Editor NEWPure Go read access of a Git repository
License: Other
Pure Go read access of a Git repository
License: Other
Go Version: 1.7
GoGit @ 1396c97
readObjectFile
fails with an io.EOF
error when reading the zlib file reader into the buffer.
The attached diff patch shows what changes I made to get my program running again.
I think there either needs to be proper handling of the EOF
error, or perhaps some education on what I might have done wrong in my program. Details below...
I recently upgraded Go to 1.7 and tried re-running a project I've been working on. I've been slowly transitioning away from git2go so I can get away from the cgo dependency.
At this part of the code, I'm really just trying to open the commit pointed to by the master
ref--regardless of what branch I might currently be in--so I can compare its date with the current HEAD
.
My client code looks like this (ignore rg.maybeRunMany
. Its job is just to keep an internal error value and run the chain of functions until the first errors):
rg.maybeRunMany(
func() {
baseRef, rg.err = r.RepoGogit.LookupReference("refs/heads/master")
if rg.err != nil {
rg.msg = "unable to open master branch"
}
},
func() {
baseCommit, rg.err = r.RepoGogit.LookupCommit(baseRef.Oid)
if rg.err != nil {
rg.msg = "unable to open master commit"
}
},
func() {
headRef, rg.err = r.RepoGogit.LookupReference("HEAD")
if rg.err != nil {
rg.msg = "unable to open HEAD ref"
}
},
func() {
headCommit, rg.err = r.RepoGogit.LookupCommit(headRef.Oid)
if rg.err != nil {
rg.msg = "unable to open HEAD commit"
}
},
func() {
behind = headCommit.Committer.When.Before(baseCommit.Committer.When)
},
)
if rg.err != nil {
fmt.Println("Error in GoGit chain:", rg.msg)
fmt.Println(rg.err)
}
return behind, rg.err
The output from running this is as follows:
$ go run main.go
Error in GoGit chain: unable to open master commit
EOF
I added some logging to my gogit installation to narrow down to this function:
$ go run main.go
[GoGit] Searching for OID object. Looking in path /Users/davidpierce/Development/go/src/github.com/thedahv/git-reviewer/.git
[GoGit] objPath /Users/davidpierce/Development/go/src/github.com/thedahv/git-reviewer/.git/objects/99/01bf79f808a8339b9820c08e209f5ec9649bda
[GoGit] os.Stat error false
[GoGit][readObjectFile] File open issue for /Users/davidpierce/Development/go/src/github.com/thedahv/git-reviewer/.git/objects/99/01bf79f808a8339b9820c08e209f5ec9649bda: false
[GoGit][readObjectFile] first_buffer_size: 1024
[GoGit][readObjectFile] First buffer read error
[GoGit][readObjectFile] Bytes read 271
[GoGit] Opening raw for OID 9901bf79f808a8339b9820c08e209f5ec9649bda
[GoGit] OID open error EOF
Error in GoGit chain: unable to open master commit
EOF
There was an error determining branch state: EOF
So what do you think? Did I break something or am I misunderstanding how this should work? Why have I not seen this before upgrading to Go 1.7?
Again, handling the EOF
error in readObjectFile
fixes it for me locally. If you examine the patch, you'll see the logging I added, and a simple naive check to look for an EOF
error and ignore it when encountered.
Sometimes repository.ObjectSize
returns a false size for a given object.
In commit.go when commit object is loaded from repository, method also load the tree object.
What was the concern of doing so?
It generates additional useless overheat when collecting a commit list.
Can we modify the method to avoid usage of parseTreeData?
Your implementation doesn't support object type 0x70
but the the gogits/git repo does.
Their implementation passes in indexfiles
but maybe just making readObjectBytes
a func (repos *Repository)
would solve that? I'm not fully clear on how that part works.
Refs can be recorded in the packed-refs
file. gogit doesn't look there, which causes it to be unable to open my repo.
The README says the project is "not really actively maintained". Is a PR adding support for this likely to be reviewed? If not, I'll just use git2go...but I'd rather have pure Go if I can arrange it.
Firstly thanks for the super library. Just having an issue with accessing previous commits. For example:
ref, err := repository.LookupReference("HEAD^2")
if err != nil {
log.Fatal(err)
}
Will cause
ref not found
Even when HEAD^2 exists. Any idea how to achieve this? Or to list through all the previous commits of a reference?
It would be great to have git clone support. Are there any plans for this?
So... your library returns error vars but nonetheless you use log.Fatal
in a number of places which prevents calling code to make decisions about how to exit.
Any chance you'll reconsider that?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.