Skip to content

Commit

Permalink
worktree: commit, use path package instead of filepath
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Jul 18, 2017
1 parent e92973b commit 11f75e2
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions worktree_commit.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package git

import (
"path/filepath"
"path"
"strings"

"gopkg.in/src-d/go-git.v4/plumbing"
Expand Down Expand Up @@ -128,36 +128,36 @@ func (h *buildTreeHelper) BuildTree(idx *index.Index) (plumbing.Hash, error) {
}

func (h *buildTreeHelper) commitIndexEntry(e *index.Entry) error {
parts := strings.Split(e.Name, string(filepath.Separator))
parts := strings.Split(e.Name, "/")

var path string
var fullpath string
for _, part := range parts {
parent := path
path = filepath.Join(path, part)
parent := fullpath
fullpath = path.Join(fullpath, part)

h.doBuildTree(e, parent, path)
h.doBuildTree(e, parent, fullpath)
}

return nil
}

func (h *buildTreeHelper) doBuildTree(e *index.Entry, parent, path string) {
if _, ok := h.trees[path]; ok {
func (h *buildTreeHelper) doBuildTree(e *index.Entry, parent, fullpath string) {
if _, ok := h.trees[fullpath]; ok {
return
}

if _, ok := h.entries[path]; ok {
if _, ok := h.entries[fullpath]; ok {
return
}

te := object.TreeEntry{Name: filepath.Base(path)}
te := object.TreeEntry{Name: path.Base(fullpath)}

if path == e.Name {
if fullpath == e.Name {
te.Mode = e.Mode
te.Hash = e.Hash
} else {
te.Mode = filemode.Dir
h.trees[path] = &object.Tree{}
h.trees[fullpath] = &object.Tree{}
}

h.trees[parent].Entries = append(h.trees[parent].Entries, te)
Expand All @@ -169,7 +169,7 @@ func (h *buildTreeHelper) copyTreeToStorageRecursive(parent string, t *object.Tr
continue
}

path := filepath.Join(parent, e.Name)
path := path.Join(parent, e.Name)

var err error
e.Hash, err = h.copyTreeToStorageRecursive(path, h.trees[path])
Expand Down

0 comments on commit 11f75e2

Please sign in to comment.