diff --git a/commit.go b/commit.go index 52e9290..8569c74 100644 --- a/commit.go +++ b/commit.go @@ -20,7 +20,10 @@ package gogit -import "bytes" +import ( + "bytes" + "fmt" +) type Commit struct { Author *Signature @@ -132,7 +135,9 @@ l: // Find the commit object in the repository. func (repos *Repository) LookupCommit(oid *Oid) (*Commit, error) { _, _, data, err := repos.getRawObject(oid) + fmt.Println("[GoGit] Opening raw for OID", oid.String()) if err != nil { + fmt.Println("[GoGit] OID open error", err.Error()) return nil, err } ci, err := parseCommitData(data) diff --git a/repository.go b/repository.go index efabf83..cdb577f 100644 --- a/repository.go +++ b/repository.go @@ -26,6 +26,7 @@ import ( "encoding/binary" "errors" "fmt" + "io" "log" "os" "path/filepath" @@ -411,20 +412,32 @@ func getLengthZeroTerminated(b []byte) (int64, int64) { // Return the content type, the contents of the file and error, if any func readObjectFile(path string, sizeonly bool) (ot ObjectType, length int64, data []byte, err error) { file, err := os.Open(path) + fmt.Printf("[GoGit][readObjectFile] File open issue for %s: %v\n", path, err != nil) if err != nil { log.Fatal(err) } defer file.Close() r, err := zlib.NewReader(file) if err != nil { + fmt.Println("[GoGit][readObjectFile] ZLIB read error") return } defer r.Close() first_buffer_size := int64(1024) + + fmt.Println("[GoGit][readObjectFile] first_buffer_size:", first_buffer_size) + b := make([]byte, first_buffer_size) n, err := r.Read(b) if err != nil { - return + if err == io.EOF { + // Ignore EOF errors + err = nil + } else { + fmt.Println("[GoGit][readObjectFile] First buffer read error") + fmt.Println("[GoGit][readObjectFile] Bytes read", n) + return + } } spaceposition := int64(bytes.IndexByte(b, ' ')) @@ -477,9 +490,13 @@ func readObjectFile(path string, sizeonly bool) (ot ObjectType, length int64, da } func (repos *Repository) getRawObject(oid *Oid) (ObjectType, int64, []byte, error) { + fmt.Println("[GoGit] Searching for OID object. Looking in path", repos.Path) // first we need to find out where the commit is stored objpath := filepathFromSHA1(repos.Path, oid.String()) + fmt.Println("[GoGit] objPath", objpath) + _, err := os.Stat(objpath) + fmt.Println("[GoGit] os.Stat error", err != nil) if os.IsNotExist(err) { // doesn't exist, let's look if we find the object somewhere else for _, indexfile := range repos.indexfiles {