Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

rev-list command implementation for objects #135

Merged
merged 3 commits into from
Nov 25, 2016
Merged

rev-list command implementation for objects #135

merged 3 commits into from
Nov 25, 2016

Conversation

ajnavarro
Copy link
Contributor

@ajnavarro ajnavarro commented Nov 23, 2016

  • Stateless method that with a commit list and a repository object get all the reachable objects, ignoring elements into ignore hash list.
  • Added tests using basic repository commit tree.


// NewObjects returns hashes that are into the serverHas commits histories
// and not into have commits histories
func (od *ObjectsDiff) NewObjects(have []*Commit, remoteHas []*Commit) ([]plumbing.Hash, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually in git, what you have is call our and the "remote" storage is call their

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the method, maybe is better call it Diff

// NewObjects returns hashes that are into the serverHas commits histories
// and not into have commits histories
func (od *ObjectsDiff) NewObjects(have []*Commit, remoteHas []*Commit) ([]plumbing.Hash, error) {
set := map[plumbing.Hash]bool{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really prefer map initialization with make


// ObjectsDiff provides a way to compare two Commit arrays and gets the differences
// (new commits, trees or files)
type ObjectsDiff struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent of the struct is not very clear, can you expose the goals better?

"gopkg.in/src-d/go-git.v4/plumbing"
)

// ObjectsDiff provides a way to compare two Commit arrays and gets the differences
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arrays? are lists


// Diff returns hashes that are into 'their' commits histories
// and not into 'our' commits histories
func (od *ObjectsDiff) Diff(our []*Commit, their []*Commit) ([]plumbing.Hash, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a function Diff, without state. No creation of ObjectsDiff.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diff -> ObjectsHistoryDiff?

- Stateless method that with a commit list and a repository object get all the reachable objects, ignoring elements into ignore hash list.
- Added tests using basic repository commit tree.
@ajnavarro ajnavarro changed the title Compare two slices of Commits to see the differences rev-list command implementation for objects Nov 23, 2016
@ajnavarro
Copy link
Contributor Author

I refactor the entire functionality. PTAL.


// ObjectsDiff checks the differences between two Commit lists and returns a list
// of hashes that represents all the objects that are in 'their' history, but not in
// 'our' history. That hashes could be references to commits, trees or files.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not files, blobs. What about the tags?

return nil, err
}

result := map[plumbing.Hash]bool{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the makes

// RevListObjects gets all the hashes from all the reachable objects from the
// given commits. Ignore hashes are objects that you don't want back into the
// result. All that objects must be accessible from the Repository.
func RevListObjects(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since r is the context, I prefer having Repository as fist method.

@@ -0,0 +1,115 @@
package git
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer revlist.go instead of rev_list.go


// RevListObjects gets all the hashes from all the reachable objects from the
// given commits. Ignore hashes are objects that you don't want back into the
// result. All that objects must be accessible from the Repository.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't understand the phrase "Ignore hashes are objects that you don't want back into the result"

// RevListObjects gets all the hashes from all the reachable objects from the
// given commits. Ignore param are object hashes that we want to ignore on the
// result. All that objects must be accessible from the Repository.
func RevListObjects(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the operation performed by this function a complementary set?, maybe we should call it just like that.

Copy link
Contributor

@alcortesm alcortesm Nov 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or at least mention it in the comment instead of explaining what a complementary set operation is without mention it.

func RevListObjects(
r *Repository,
commits []*Commit,
ignore []plumbing.Hash) ([]plumbing.Hash, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will make more sense to pass a set of commits and a set of ignores instead of lists. What do you think?

ignore []plumbing.Hash) ([]plumbing.Hash, error) {

seen := hashListToSet(ignore)
result := make(map[plumbing.Hash]bool)
Copy link
Contributor

@alcortesm alcortesm Nov 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a set but then return a list. Lets use a list instead directly or return a set.

return result
}

func iterateCommits(commit *Commit, cb func(c *Commit) error) error {
Copy link
Contributor

@alcortesm alcortesm Nov 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got lost pretty quickly with this, it should be easy to read in a single pass.

Please add comments explaining what iterateCommits, iterateCommitTrees and iterateAll do and refactor for legibility. For example iterateAll is just calling iterateCommits with some arguments, usually you don't write a new function for something so simple unless the name is very descriptive, but in this case it is not ('All' does not transmit any meaning, is iterateAll iterating over more thing than iterateCommits, then why call it All?). Why not just substitute iterateAll with a call to iterateCommits with well explained and named arguments?

// | |/
// * | 35e8510 binary file
// |/
// * b029517 Initial commit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is awesome, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record: git log --graph --oneline --all

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if is for the record, then write this as a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@smola smola merged commit de7e2ed into src-d:master Nov 25, 2016
@ajnavarro ajnavarro deleted the feature/commit-diffs branch November 28, 2016 09:28
mcuadros pushed a commit that referenced this pull request Jan 31, 2017
* rev-list command implementation for objects

- Stateless method that with a commit list and a repository object get all the reachable objects, ignoring elements into ignore hash list.
- Added tests using basic repository commit tree.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants