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

worktree: add method #361

Merged
merged 1 commit into from
Apr 26, 2017
Merged

worktree: add method #361

merged 1 commit into from
Apr 26, 2017

Conversation

mcuadros
Copy link
Contributor

This is the bare minimum implementation of git add

return plumbing.ZeroHash, err
}

if s.File(path).Worktree == Unmodified {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if returning a zero hash when the operation is successful but unmodified is the right behavior. If it is, please, explain it in godoc, it is not that intuitive.

return plumbing.ZeroHash, err
}

return h.Sum(), nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

return h.Sum(), err to get close error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Better yet, declare error in the signature and defer a closure on it instead.

worktree_test.go Outdated
@@ -5,6 +5,7 @@ import (
"os"
"path/filepath"

billy "gopkg.in/src-d/go-billy.v2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

mixed external/internal imports

return plumbing.ZeroHash, err
}

return h.Sum(), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Better yet, declare error in the signature and defer a closure on it instead.

return w.r.Storer.SetIndex(idx)
}

func (w *Worktree) doAddFileToIndex(idx *index.Index, filename string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

change the name of this method to addFileToIndex and make it a function, instead of a method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could be a function, but since update cannot be a function I rather keep it as a method

return nil
}

func (w *Worktree) doUpdateFileToIndex(idx *index.Index, filename string, h 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.

Change the name of the method to updateFileToIndex.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it need context, and since is a very deep method I prefer having the do prefix

Copy link
Contributor

Choose a reason for hiding this comment

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

What does do mean for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is performing the action with a function is a name close to this one without the do

return err
}

for i, e := range idx.Entries {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use the Entry method here instead of looking for it again? (like we did in line 217)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, I need to know the position for overwritten it.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is part of the problem with this PR, it is too C style, everything changing other things that are sometimes several levels of indirection away.

I think you should refactor and modify the index and the entries, adding the necessary methods there util the functionality here is trivial and it is performed by the entities responsible for it instead of doing everything here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't if worth do this change, and change the other places where the index is read. When he is the only place that an entry is updated.

@mcuadros
Copy link
Contributor Author

merging this making other PR change the Index implementation

@mcuadros mcuadros merged commit 64cd72d into src-d:master Apr 26, 2017
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants