-
Notifications
You must be signed in to change notification settings - Fork 531
Iterable ObjectStorage interface for use in Repository struct #20
Conversation
core/object.go
Outdated
| New() Object | ||
| Set(Object) Hash | ||
| Get(Hash) (Object, bool) | ||
| IterType(ObjectType) ObjectIter |
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.
I prefer call this method just Iter, is less verbose and clear enough
|
@JoshuaSjoding great job, we will merge this as soon as the minor things I commented get fixed. You can keep the PR to master, because we are using gopkg.in, is not a problem having an unreleased master. Thanks! |
… for object iterators
|
@mcuadros I think that I've addressed all of your comments with the latest commit.
I also merged in the latest work from |
Current coverage is
|
|
@mcuadros I went ahead and updated the |
72de676 to
ef6652d
Compare
Iterable ObjectStorage interface for use in Repository struct
Iterable ObjectStorage interface for use in Repository struct
Remove unused params in config
The current implementation of the Repository struct includes a pointer to core.RAWObjectStorage. This seems inappropriate because it prevents the development of alternative implementations of ObjectStorage. I presume that the direct reference was included because it provided convenient and fast access to the commit objects.
This pull request proposes the addition of one function to the ObjectStorage interface: IterType. This function returns an iterator of objects matching the given object type. The Repository is modified to make use of this new function, and RAWObjectStorage is modified to provide it.
The return value of IterType is a new interface called ObjectIter. Two implementations of ObjectIter are provided:
Additional implementations could easily be added.
Both CommitIter and TreeIter are modified to make use of the new ObjectIter interface, as is Commit.Parents(). Note that this does away with the previous channel-based iterators.
The proposed implementation of RAWObjectStorage.IterType simply flattens the map of the requested type into a slice on the fly. This is probably fine for small to medium repositories, but might cause trouble for large repositories or if it's called frequently. Further optimization should be done as warranted.
Note that this pull request modifies several public types. As such it should probably be considered breaking for v2; it may be more appropriate to pull this instead into a v3 branch. I expect that other breaking changes will be needed to meet the needs of #19, and I suspect that all such work should be carried out in a branch until it's ready to be rolled out formally as v3. Feedback on this is most welcome.