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

*: several windows support fixes #493

Merged
merged 13 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion plumbing/format/config/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"fmt"
"io"
"strings"
)

// An Encoder writes config files to an output stream.
Expand Down Expand Up @@ -61,7 +62,12 @@ func (e *Encoder) encodeSubsection(sectionName string, s *Subsection) error {

func (e *Encoder) encodeOptions(opts Options) error {
for _, o := range opts {
if err := e.printf("\t%s = %s\n", o.Key, o.Value); err != nil {
pattern := "\t%s = %s\n"
if strings.Index(o.Value, "\\") != -1 {
pattern = "\t%s = %q\n"
}

if err := e.printf(pattern, o.Key, o.Value); err != nil {
return err
}
}
Expand Down
4 changes: 3 additions & 1 deletion plumbing/transport/git/receive_pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ func (s *ReceivePackSuite) SetUpTest(c *C) {
}

func (s *ReceivePackSuite) TearDownTest(c *C) {
err := s.daemon.Process.Signal(os.Interrupt)
err := s.daemon.Process.Signal(os.Kill)
c.Assert(err, IsNil)

_ = s.daemon.Wait()

err = os.RemoveAll(s.base)
c.Assert(err, IsNil)
}
Expand Down
2 changes: 1 addition & 1 deletion plumbing/transport/server/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// DefaultLoader is a filesystem loader ignoring host and resolving paths to /.
var DefaultLoader = NewFilesystemLoader(osfs.New("/"))
var DefaultLoader = NewFilesystemLoader(osfs.New(""))

// Loader loads repository's storer.Storer based on an optional host and a path.
type Loader interface {
Expand Down
16 changes: 10 additions & 6 deletions storage/filesystem/internal/dotgit/dotgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ func (d *DotGit) rewritePackedRefsWithoutRef(name plumbing.ReferenceName) (err e

return err
}
defer ioutil.CheckClose(f, &err)

// Creating the temp file in the same directory as the target file
// improves our chances for rename operation to be atomic.
Expand All @@ -357,10 +356,6 @@ func (d *DotGit) rewritePackedRefsWithoutRef(name plumbing.ReferenceName) (err e
return err
}

tmpPath := tmp.Name()
defer ioutil.CheckClose(tmp, &err)
defer d.fs.Remove(tmpPath)

s := bufio.NewScanner(f)
found := false
for s.Scan() {
Expand Down Expand Up @@ -388,7 +383,16 @@ func (d *DotGit) rewritePackedRefsWithoutRef(name plumbing.ReferenceName) (err e
return nil
}

return d.fs.Rename(tmpPath, packedRefsPath)
if err := f.Close(); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use CheckClose here for both cases? Otherwise, if closing f fails, tmp is not closed.

ioutil.CheckClose(tmp, &err)
return err
}

if err := tmp.Close(); err != nil {
return err
}

return d.fs.Rename(tmp.Name(), packedRefsPath)
}

// process lines from a packed-refs file
Expand Down
1 change: 1 addition & 0 deletions storage/filesystem/internal/dotgit/dotgit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ func (s *SuiteDotGit) TestObjectPackIdx(c *C) {
idx, err := dir.ObjectPackIdx(f.PackfileHash)
c.Assert(err, IsNil)
c.Assert(filepath.Ext(idx.Name()), Equals, ".idx")
c.Assert(idx.Close(), IsNil)
}

func (s *SuiteDotGit) TestObjectPackNotFound(c *C) {
Expand Down
6 changes: 3 additions & 3 deletions utils/merkletrie/filesystem/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package filesystem
import (
"io"
"os"
"path/filepath"
"path"

"gopkg.in/src-d/go-billy.v3"
"gopkg.in/src-d/go-git.v4/plumbing"
Expand Down Expand Up @@ -53,7 +53,7 @@ func (n *node) Hash() []byte {
}

func (n *node) Name() string {
return filepath.Base(n.path)
return path.Base(n.path)
}

func (n *node) IsDir() bool {
Expand Down Expand Up @@ -107,7 +107,7 @@ func (n *node) calculateChildren() error {
}

func (n *node) newChildNode(file os.FileInfo) (*node, error) {
path := filepath.Join(n.path, file.Name())
path := path.Join(n.path, file.Name())

hash, err := n.calculateHash(path, file)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions utils/merkletrie/filesystem/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io"
"os"
"path"
"testing"

. "gopkg.in/check.v1"
Expand Down Expand Up @@ -133,18 +134,19 @@ func (s *NoderSuite) TestDiffChangeModeNotRelevant(c *C) {
}

func (s *NoderSuite) TestDiffDirectory(c *C) {
dir := path.Join("qux", "bar")
fsA := memfs.New()
fsA.MkdirAll("qux/bar", 0644)
fsA.MkdirAll(dir, 0644)

fsB := memfs.New()
fsB.MkdirAll("qux/bar", 0644)
fsB.MkdirAll(dir, 0644)

ch, err := merkletrie.DiffTree(
NewRootNode(fsA, map[string]plumbing.Hash{
"qux/bar": plumbing.NewHash("aa102815663d23f8b75a47e7a01965dcdc96468c"),
dir: plumbing.NewHash("aa102815663d23f8b75a47e7a01965dcdc96468c"),
}),
NewRootNode(fsB, map[string]plumbing.Hash{
"qux/bar": plumbing.NewHash("19102815663d23f8b75a47e7a01965dcdc96468c"),
dir: plumbing.NewHash("19102815663d23f8b75a47e7a01965dcdc96468c"),
}),
IsEquals,
)
Expand Down
18 changes: 9 additions & 9 deletions utils/merkletrie/index/node.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package index

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

"gopkg.in/src-d/go-git.v4/plumbing/format/index"
Expand All @@ -28,19 +28,19 @@ func NewRootNode(idx *index.Index) noder.Noder {
m := map[string]*node{rootNode: {isDir: true}}

for _, e := range idx.Entries {
parts := strings.Split(e.Name, string(filepath.Separator))
parts := strings.Split(e.Name, string("/"))

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

if _, ok := m[path]; ok {
if _, ok := m[fullpath]; ok {
continue
}

n := &node{path: path}
if path == e.Name {
n := &node{path: fullpath}
if fullpath == e.Name {
n.entry = e
} else {
n.isDir = true
Expand Down Expand Up @@ -74,7 +74,7 @@ func (n *node) Hash() []byte {
}

func (n *node) Name() string {
return filepath.Base(n.path)
return path.Base(n.path)
}

func (n *node) IsDir() bool {
Expand Down
29 changes: 17 additions & 12 deletions utils/merkletrie/index/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package index

import (
"bytes"
"path/filepath"
"testing"

. "gopkg.in/check.v1"
Expand Down Expand Up @@ -43,15 +44,17 @@ func (s *NoderSuite) TestDiff(c *C) {

func (s *NoderSuite) TestDiffChange(c *C) {
indexA := &index.Index{
Entries: []*index.Entry{
{Name: "bar/baz/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
},
Entries: []*index.Entry{{
Name: filepath.Join("bar", "baz", "bar"),
Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"),
}},
}

indexB := &index.Index{
Entries: []*index.Entry{
{Name: "bar/baz/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
},
Entries: []*index.Entry{{
Name: filepath.Join("bar", "baz", "foo"),
Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"),
}},
}

ch, err := merkletrie.DiffTree(NewRootNode(indexA), NewRootNode(indexB), isEquals)
Expand All @@ -61,15 +64,17 @@ func (s *NoderSuite) TestDiffChange(c *C) {

func (s *NoderSuite) TestDiffDir(c *C) {
indexA := &index.Index{
Entries: []*index.Entry{
{Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
},
Entries: []*index.Entry{{
Name: "foo",
Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"),
}},
}

indexB := &index.Index{
Entries: []*index.Entry{
{Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
},
Entries: []*index.Entry{{
Name: filepath.Join("foo", "bar"),
Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d"),
}},
}

ch, err := merkletrie.DiffTree(NewRootNode(indexA), NewRootNode(indexB), isEquals)
Expand Down
5 changes: 5 additions & 0 deletions worktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ func (w *Worktree) Submodules() (Submodules, error) {
}

c, err := w.r.Config()
if err != nil {
return nil, err
}

for _, s := range m.Submodules {
l = append(l, w.newSubmodule(s, c.Submodules[s.Name]))
}
Expand Down Expand Up @@ -498,6 +502,7 @@ func (w *Worktree) readGitmodulesFile() (*config.Modules, error) {
return nil, err
}

defer f.Close()
input, err := stdioutil.ReadAll(f)
if err != nil {
return nil, err
Expand Down
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
1 change: 0 additions & 1 deletion worktree_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
func init() {
fillSystemInfo = func(e *index.Entry, sys interface{}) {
if os, ok := sys.(*syscall.Stat_t); ok {

e.CreatedAt = time.Unix(int64(os.Ctim.Sec), int64(os.Ctim.Nsec))
e.Dev = uint32(os.Dev)
e.Inode = uint32(os.Ino)
Expand Down
20 changes: 20 additions & 0 deletions worktree_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// +build windows

package git

import (
"syscall"
"time"

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

func init() {
fillSystemInfo = func(e *index.Entry, sys interface{}) {
if os, ok := sys.(*syscall.Win32FileAttributeData); ok {
seconds := os.CreationTime.Nanoseconds() / 1000000000
nanoseconds := os.CreationTime.Nanoseconds() - seconds*1000000000
e.CreatedAt = time.Unix(seconds, nanoseconds)
}
}
}