-
Notifications
You must be signed in to change notification settings - Fork 535
Submodules init and update #270
Changes from 1 commit
498dbf7
b3b6e51
b18d649
c551c29
940a16c
f8b5557
65351f8
7e990a8
09110d8
d6a6dec
ed288b3
790fbda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package filesystem | ||
|
||
import ( | ||
"srcd.works/go-git.v4/storage" | ||
"srcd.works/go-git.v4/storage/filesystem/internal/dotgit" | ||
) | ||
|
||
type ModuleStorage struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this type?, can we just make dotgit implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the pattern we are using. I prefer keep dotgit isolate |
||
dir *dotgit.DotGit | ||
} | ||
|
||
func (s *ModuleStorage) Module(name string) (storage.Storer, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests and comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is already covered by the tests. And the documentation is on the interface as in the other methods |
||
return NewStorage(s.dir.Module(name)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"srcd.works/go-git.v4/plumbing" | ||
"srcd.works/go-git.v4/plumbing/format/index" | ||
"srcd.works/go-git.v4/plumbing/storer" | ||
"srcd.works/go-git.v4/storage" | ||
) | ||
|
||
var ErrUnsupportedObjectType = fmt.Errorf("unsupported object type") | ||
|
@@ -22,6 +23,7 @@ type Storage struct { | |
ShallowStorage | ||
IndexStorage | ||
ReferenceStorage | ||
ModuleStorage | ||
} | ||
|
||
// NewStorage returns a new Storage base on memory | ||
|
@@ -37,6 +39,7 @@ func NewStorage() *Storage { | |
Blobs: make(map[plumbing.Hash]plumbing.EncodedObject, 0), | ||
Tags: make(map[plumbing.Hash]plumbing.EncodedObject, 0), | ||
}, | ||
ModuleStorage: make(ModuleStorage, 0), | ||
} | ||
} | ||
|
||
|
@@ -227,3 +230,13 @@ func (s *ShallowStorage) SetShallow(commits []plumbing.Hash) error { | |
func (s ShallowStorage) Shallow() ([]plumbing.Hash, error) { | ||
return s, nil | ||
} | ||
|
||
type ModuleStorage map[string]*Storage | ||
|
||
func (s ModuleStorage) Module(name string) (storage.Storer, error) { | ||
if _, ok := s[name]; !ok { | ||
s[name] = NewStorage() | ||
} | ||
|
||
return s[name], nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't look up twice in the map, use a variable to store the results of the first lookup. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package storage | ||
|
||
import ( | ||
"srcd.works/go-git.v4/config" | ||
"srcd.works/go-git.v4/plumbing/storer" | ||
) | ||
|
||
// Storer is a generic storage of objects, references and any information | ||
// related to a particular repository. The package srcd.works/go-git.v4/storage | ||
// contains two implementation a filesystem base implementation (such as `.git`) | ||
// and a memory implementations being ephemeral | ||
type Storer interface { | ||
storer.EncodedObjectStorer | ||
storer.ReferenceStorer | ||
storer.ShallowStorer | ||
storer.IndexStorer | ||
config.ConfigStorer | ||
ModuleStorer | ||
} | ||
|
||
type ModuleStorer interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be explained, What if the module doesn't exists? |
||
Module(name string) (Storer, error) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
"srcd.works/go-git.v4/plumbing" | ||
"srcd.works/go-git.v4/plumbing/format/index" | ||
"srcd.works/go-git.v4/plumbing/storer" | ||
"srcd.works/go-git.v4/storage" | ||
|
||
. "gopkg.in/check.v1" | ||
) | ||
|
@@ -21,6 +22,8 @@ type Storer interface { | |
storer.ShallowStorer | ||
storer.IndexStorer | ||
config.ConfigStorer | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra line here. |
||
storage.ModuleStorer | ||
} | ||
|
||
type TestObject struct { | ||
|
@@ -326,6 +329,16 @@ func (s *BaseStorageSuite) TestSetConfigInvalid(c *C) { | |
c.Assert(err, NotNil) | ||
} | ||
|
||
func (s *BaseStorageSuite) TestModule(c *C) { | ||
storer, err := s.Storer.Module("foo") | ||
c.Assert(err, IsNil) | ||
c.Assert(storer, NotNil) | ||
|
||
storer, err = s.Storer.Module("foo") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the point in calling Module twice? Actually what is the point of this whole test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests that returns a module. The function should returns a module if exists or not. The duplicate code is an error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand your answer. Can you explain what you are testing in the name of the test or on a comment? |
||
c.Assert(err, IsNil) | ||
c.Assert(storer, NotNil) | ||
} | ||
|
||
func objectEquals(a plumbing.EncodedObject, b plumbing.EncodedObject) error { | ||
ha := a.Hash() | ||
hb := b.Hash() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done