diff options
-rw-r--r-- | commit.go | 3 | ||||
-rw-r--r-- | core/object.go | 4 | ||||
-rw-r--r-- | formats/packfile/reader.go | 6 | ||||
-rw-r--r-- | formats/pktline/decoder.go | 7 | ||||
-rw-r--r-- | formats/pktline/doc.go | 4 | ||||
-rw-r--r-- | formats/pktline/encoder.go | 1 | ||||
-rw-r--r-- | objects.go | 1 | ||||
-rw-r--r-- | remote.go | 1 | ||||
-rw-r--r-- | repository.go | 25 | ||||
-rw-r--r-- | storage/memory/storage.go | 2 | ||||
-rw-r--r-- | tree.go | 18 | ||||
-rw-r--r-- | tree_walker.go | 12 |
12 files changed, 49 insertions, 35 deletions
@@ -10,6 +10,7 @@ import ( "gopkg.in/src-d/go-git.v3/core" ) +// Hash hash of an object type Hash core.Hash // Commit points to a single tree, marking it as what the project looked like @@ -28,11 +29,13 @@ type Commit struct { r *Repository } +// Tree returns the Tree from the commit func (c *Commit) Tree() *Tree { tree, _ := c.r.Tree(c.tree) // FIXME: Return error as well? return tree } +// Parents return a CommitIter to the parent Commits func (c *Commit) Parents() *CommitIter { return NewCommitIter(c.r, core.NewObjectLookupIter(c.r.Storage, c.parents)) } diff --git a/core/object.go b/core/object.go index 9958570..9dd906b 100644 --- a/core/object.go +++ b/core/object.go @@ -7,7 +7,7 @@ import ( ) var ( - ObjectNotFoundErr = errors.New("object not found") + ErrObjectNotFound = errors.New("object not found") // ErrInvalidType is returned when an invalid object type is provided. ErrInvalidType = errors.New("invalid object type") ) @@ -138,7 +138,7 @@ func NewObjectLookupIter(storage ObjectStorage, series []Hash) *ObjectLookupIter // Next returns the next object from the iterator. If the iterator has reached // the end it will return io.EOF as an error. If the object can't be found in -// the object storage, it will return ObjectNotFoundErr as an error. If the +// the object storage, it will return ErrObjectNotFound as an error. If the // object is retreieved successfully error will be nil. func (iter *ObjectLookupIter) Next() (Object, error) { if iter.pos >= len(iter.series) { diff --git a/formats/packfile/reader.go b/formats/packfile/reader.go index a013776..3f7081b 100644 --- a/formats/packfile/reader.go +++ b/formats/packfile/reader.go @@ -22,7 +22,7 @@ var ( InvalidObjectErr = newError("invalid git object") PatchingErr = newError("patching error") PackEntryNotFoundErr = newError("can't find a pack entry") - ObjectNotFoundErr = newError("can't find a object") + ErrObjectNotFound = newError("can't find a object") ZLibErr = newError("zlib reading error") ) @@ -200,8 +200,8 @@ func (r *Reader) readREFDelta(raw core.Object) (err error) { referenced, err := r.s.Get(ref) if err != nil { - if err == core.ObjectNotFoundErr { - return ObjectNotFoundErr.n("%s", ref) + if err == core.ErrObjectNotFound { + return ErrObjectNotFound.n("%s", ref) } return err } diff --git a/formats/pktline/decoder.go b/formats/pktline/decoder.go index c30be6b..34e6f51 100644 --- a/formats/pktline/decoder.go +++ b/formats/pktline/decoder.go @@ -7,9 +7,12 @@ import ( ) var ( - ErrUnderflow = errors.New("unexpected string length (underflow)") + // ErrUnderflow is triggered when a line is shorter than the described length + ErrUnderflow = errors.New("unexpected string length (underflow)") + // ErrInvalidHeader invalid pktline header ErrInvalidHeader = errors.New("invalid header") - ErrInvalidLen = errors.New("invalid length") + // ErrInvalidLen ivanlid line length found, < 0 + ErrInvalidLen = errors.New("invalid length") ) // Decoder implements a pkt-line format decoder diff --git a/formats/pktline/doc.go b/formats/pktline/doc.go index 0ae22e3..555a073 100644 --- a/formats/pktline/doc.go +++ b/formats/pktline/doc.go @@ -51,6 +51,8 @@ package pktline // https://github.com/git/git/blob/master/Documentation/technical/protocol-common.txt const ( + // HeaderLength length of the pktline header HeaderLength = 4 - MaxLength = 65524 + // MaxLength max line length + MaxLength = 65524 ) diff --git a/formats/pktline/encoder.go b/formats/pktline/encoder.go index dfa53e2..bd0ab75 100644 --- a/formats/pktline/encoder.go +++ b/formats/pktline/encoder.go @@ -7,6 +7,7 @@ import ( ) var ( + //ErrOverflow happends when the line length exceed the MaxLength ErrOverflow = errors.New("unexpected string length (overflow)") ) @@ -10,6 +10,7 @@ import ( "gopkg.in/src-d/go-git.v3/core" ) +// ErrUnsupportedObject trigger when a non-supported object is being decoded. var ErrUnsupportedObject = errors.New("unsupported object type") // Object is a generic representation of any git object. It is implemented by @@ -9,6 +9,7 @@ import ( "gopkg.in/src-d/go-git.v3/core" ) +// Remote represents a connection to a remote repository type Remote struct { Endpoint common.Endpoint Auth common.AuthMethod diff --git a/repository.go b/repository.go index 87810a6..65e0a5d 100644 --- a/repository.go +++ b/repository.go @@ -11,13 +11,16 @@ import ( ) var ( - ObjectNotFoundErr = errors.New("object not found") + // ErrObjectNotFound object not found + ErrObjectNotFound = errors.New("object not found") ) const ( + // DefaultRemoteName name of the default Remote, just like git command DefaultRemoteName = "origin" ) +// Repository git repository struct type Repository struct { Remotes map[string]*Remote Storage core.ObjectStorage @@ -104,8 +107,8 @@ func (r *Repository) PullDefault() (err error) { func (r *Repository) Commit(h core.Hash) (*Commit, error) { obj, err := r.Storage.Get(h) if err != nil { - if err == core.ObjectNotFoundErr { - return nil, ObjectNotFoundErr + if err == core.ErrObjectNotFound { + return nil, ErrObjectNotFound } return nil, err } @@ -123,8 +126,8 @@ func (r *Repository) Commits() *CommitIter { func (r *Repository) Tree(h core.Hash) (*Tree, error) { obj, err := r.Storage.Get(h) if err != nil { - if err == core.ObjectNotFoundErr { - return nil, ObjectNotFoundErr + if err == core.ErrObjectNotFound { + return nil, ErrObjectNotFound } return nil, err } @@ -137,8 +140,8 @@ func (r *Repository) Tree(h core.Hash) (*Tree, error) { func (r *Repository) Blob(h core.Hash) (*Blob, error) { obj, err := r.Storage.Get(h) if err != nil { - if err == core.ObjectNotFoundErr { - return nil, ObjectNotFoundErr + if err == core.ErrObjectNotFound { + return nil, ErrObjectNotFound } return nil, err } @@ -151,8 +154,8 @@ func (r *Repository) Blob(h core.Hash) (*Blob, error) { func (r *Repository) Tag(h core.Hash) (*Tag, error) { obj, err := r.Storage.Get(h) if err != nil { - if err == core.ObjectNotFoundErr { - return nil, ObjectNotFoundErr + if err == core.ErrObjectNotFound { + return nil, ErrObjectNotFound } return nil, err } @@ -171,8 +174,8 @@ func (r *Repository) Tags() *TagIter { func (r *Repository) Object(h core.Hash) (Object, error) { obj, err := r.Storage.Get(h) if err != nil { - if err == core.ObjectNotFoundErr { - return nil, ObjectNotFoundErr + if err == core.ErrObjectNotFound { + return nil, ErrObjectNotFound } return nil, err } diff --git a/storage/memory/storage.go b/storage/memory/storage.go index fe92256..fbf4bc4 100644 --- a/storage/memory/storage.go +++ b/storage/memory/storage.go @@ -58,7 +58,7 @@ func (o *ObjectStorage) Set(obj core.Object) (core.Hash, error) { func (o *ObjectStorage) Get(h core.Hash) (core.Object, error) { obj, ok := o.Objects[h] if !ok { - return nil, core.ObjectNotFoundErr + return nil, core.ErrObjectNotFound } return obj, nil @@ -48,7 +48,7 @@ func (t *Tree) File(path string) (*File, error) { obj, err := t.r.Storage.Get(e.Hash) if err != nil { - if err == core.ObjectNotFoundErr { + if err == core.ErrObjectNotFound { return nil, ErrFileNotFound // a git submodule } return nil, err @@ -88,7 +88,7 @@ func (t *Tree) dir(baseName string) (*Tree, error) { obj, err := t.r.Storage.Get(entry.Hash) if err != nil { - if err == core.ObjectNotFoundErr { // git submodule + if err == core.ErrObjectNotFound { // git submodule return nil, errDirNotFound } return nil, err @@ -118,6 +118,7 @@ func (t *Tree) entry(baseName string) (*TreeEntry, error) { return entry, nil } +// Files returns a FileIter allowing to iterate over the Tree func (t *Tree) Files() *FileIter { return NewFileIter(t.r, t) } @@ -200,17 +201,13 @@ func (t *Tree) buildMap() { } } -// TreeEntryIter facilitates iterating through the TreeEntry objects in a Tree. -type TreeEntryIter struct { +// treeEntryIter facilitates iterating through the TreeEntry objects in a Tree. +type treeEntryIter struct { t *Tree pos int } -func NewTreeEntryIter(t *Tree) *TreeEntryIter { - return &TreeEntryIter{t, 0} -} - -func (iter *TreeEntryIter) Next() (TreeEntry, error) { +func (iter *treeEntryIter) Next() (TreeEntry, error) { if iter.pos >= len(iter.t.Entries) { return TreeEntry{}, io.EOF } @@ -224,12 +221,14 @@ type TreeIter struct { w TreeWalker } +// NewTreeIter returns a new TreeIter instance func NewTreeIter(r *Repository, t *Tree) *TreeIter { return &TreeIter{ w: *NewTreeWalker(r, t), } } +// Next returns the next Tree from the tree. func (iter *TreeIter) Next() (*Tree, error) { for { _, _, obj, err := iter.w.Next() @@ -243,6 +242,7 @@ func (iter *TreeIter) Next() (*Tree, error) { } } +// Close closes the TreeIter func (iter *TreeIter) Close() { iter.w.Close() } diff --git a/tree_walker.go b/tree_walker.go index ff44e67..9bc1421 100644 --- a/tree_walker.go +++ b/tree_walker.go @@ -11,7 +11,7 @@ const ( // TreeWalker provides a means of walking through all of the entries in a Tree. type TreeWalker struct { - stack []TreeEntryIter + stack []treeEntryIter base string r *Repository @@ -23,11 +23,11 @@ type TreeWalker struct { // tree walker. func NewTreeWalker(r *Repository, t *Tree) *TreeWalker { w := TreeWalker{ - stack: make([]TreeEntryIter, 0, startingStackSize), + stack: make([]treeEntryIter, 0, startingStackSize), base: "", r: r, } - w.stack = append(w.stack, *NewTreeEntryIter(t)) + w.stack = append(w.stack, treeEntryIter{t, 0}) return &w } @@ -65,7 +65,7 @@ func (w *TreeWalker) Next() (name string, entry TreeEntry, obj Object, err error } obj, err = w.r.Object(entry.Hash) - if err == ObjectNotFoundErr { + if err == ErrObjectNotFound { // FIXME: Avoid doing this here in case the caller actually cares about // missing objects. err = nil @@ -81,8 +81,8 @@ func (w *TreeWalker) Next() (name string, entry TreeEntry, obj Object, err error break } - if tree, ok := obj.(*Tree); ok { - w.stack = append(w.stack, *NewTreeEntryIter(tree)) + if t, ok := obj.(*Tree); ok { + w.stack = append(w.stack, treeEntryIter{t, 0}) w.base = path.Join(w.base, entry.Name) } |