aboutsummaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
Diffstat (limited to 'storage')
-rw-r--r--storage/filesystem/config.go5
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go27
-rw-r--r--storage/filesystem/internal/dotgit/refs.go8
-rw-r--r--storage/filesystem/object.go10
-rw-r--r--storage/filesystem/reference.go4
-rw-r--r--storage/memory/storage.go6
6 files changed, 42 insertions, 18 deletions
diff --git a/storage/filesystem/config.go b/storage/filesystem/config.go
index c91ba58..1cff05a 100644
--- a/storage/filesystem/config.go
+++ b/storage/filesystem/config.go
@@ -44,11 +44,12 @@ func (c *ConfigStorage) Remotes() ([]*config.RemoteConfig, error) {
}
func (c *ConfigStorage) SetRemote(r *config.RemoteConfig) error {
- return fmt.Errorf("not implemented yet")
+ return nil
+ return fmt.Errorf("set remote - not implemented yet")
}
func (c *ConfigStorage) DeleteRemote(name string) error {
- return fmt.Errorf("not implemented yet")
+ return fmt.Errorf("delete - remote not implemented yet")
}
func (c *ConfigStorage) read() (*ConfigFile, error) {
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go
index d4d58d7..e22ed58 100644
--- a/storage/filesystem/internal/dotgit/dotgit.go
+++ b/storage/filesystem/internal/dotgit/dotgit.go
@@ -53,11 +53,35 @@ func New(fs fs.Filesystem) *DotGit {
return &DotGit{fs: fs}
}
+func (d *DotGit) ConfigWriter() (fs.File, error) {
+ return d.fs.Create(configPath)
+}
+
// Config returns the path of the config file
func (d *DotGit) Config() (fs.File, error) {
return d.fs.Open(configPath)
}
+func (d *DotGit) SetRef(r *core.Reference) error {
+ var content string
+ switch r.Type() {
+ case core.SymbolicReference:
+ content = fmt.Sprintf("ref: %s\n", r.Target())
+ case core.HashReference:
+ content = fmt.Sprintln(r.Hash().String())
+ }
+
+ f, err := d.fs.Create(r.Name().String())
+ if err != nil {
+ return err
+ }
+
+ if _, err := f.Write([]byte(content)); err != nil {
+ return err
+ }
+ return f.Close()
+}
+
// Refs scans the git directory collecting references, which it returns.
// Symbolic references are resolved and included in the output.
func (d *DotGit) Refs() ([]*core.Reference, error) {
@@ -129,7 +153,6 @@ func (d *DotGit) ObjectPack(hash core.Hash) (fs.File, error) {
// ObjectPackIdx returns a fs.File of the index file for a given packfile
func (d *DotGit) ObjectPackIdx(hash core.Hash) (fs.File, error) {
file := d.fs.Join(objectsPath, packPath, fmt.Sprintf("pack-%s.idx", hash.String()))
-
idx, err := d.fs.Open(file)
if err != nil {
if os.IsNotExist(err) {
@@ -253,6 +276,7 @@ func (w *PackWriter) buildIndex() {
w.checksum = checksum
w.index.PackfileChecksum = checksum
+ w.index.Version = idxfile.VersionSupported
offsets := d.Offsets()
for h, crc := range d.CRCs() {
@@ -288,7 +312,6 @@ func (w *PackWriter) Close() error {
func (w *PackWriter) save() error {
base := w.fs.Join(objectsPath, packPath, fmt.Sprintf("pack-%s", w.checksum))
-
idx, err := w.fs.Create(fmt.Sprintf("%s.idx", base))
if err != nil {
return err
diff --git a/storage/filesystem/internal/dotgit/refs.go b/storage/filesystem/internal/dotgit/refs.go
index ca11f6c..8f28332 100644
--- a/storage/filesystem/internal/dotgit/refs.go
+++ b/storage/filesystem/internal/dotgit/refs.go
@@ -81,6 +81,10 @@ func (d *DotGit) addRefsFromRefDir(refs *[]*core.Reference) error {
func (d *DotGit) walkReferencesTree(refs *[]*core.Reference, relPath string) error {
files, err := d.fs.ReadDir(relPath)
if err != nil {
+ if os.IsNotExist(err) {
+ return nil
+ }
+
return err
}
@@ -110,6 +114,10 @@ func (d *DotGit) walkReferencesTree(refs *[]*core.Reference, relPath string) err
func (d *DotGit) addRefFromHEAD(refs *[]*core.Reference) error {
ref, err := d.readReferenceFile(".", "HEAD")
if err != nil {
+ if os.IsNotExist(err) {
+ return nil
+ }
+
return err
}
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 379c359..0b82524 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -74,7 +74,7 @@ func (s *ObjectStorage) Writer() (io.WriteCloser, error) {
// yet supported, this method always returns a "not implemented yet"
// error an zero hash.
func (s *ObjectStorage) Set(core.Object) (core.Hash, error) {
- return core.ZeroHash, fmt.Errorf("not implemented yet")
+ return core.ZeroHash, fmt.Errorf("set - not implemented yet")
}
// Get returns the object with the given hash, by searching for it in
@@ -219,19 +219,19 @@ func (o *ObjectStorage) Begin() core.TxObjectStorage {
type TxObjectStorage struct{}
func (tx *TxObjectStorage) Set(obj core.Object) (core.Hash, error) {
- return core.ZeroHash, fmt.Errorf("not implemented yet")
+ return core.ZeroHash, fmt.Errorf("tx.Set - not implemented yet")
}
func (tx *TxObjectStorage) Get(core.ObjectType, core.Hash) (core.Object, error) {
- return nil, fmt.Errorf("not implemented yet")
+ return nil, fmt.Errorf("tx.Get - not implemented yet")
}
func (tx *TxObjectStorage) Commit() error {
- return fmt.Errorf("not implemented yet")
+ return fmt.Errorf("tx.Commit - not implemented yet")
}
func (tx *TxObjectStorage) Rollback() error {
- return fmt.Errorf("not implemented yet")
+ return fmt.Errorf("tx.Rollback - not implemented yet")
}
type index map[core.Hash]int64
diff --git a/storage/filesystem/reference.go b/storage/filesystem/reference.go
index c8e5434..ae78efb 100644
--- a/storage/filesystem/reference.go
+++ b/storage/filesystem/reference.go
@@ -1,8 +1,6 @@
package filesystem
import (
- "fmt"
-
"gopkg.in/src-d/go-git.v4/core"
"gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
)
@@ -13,7 +11,7 @@ type ReferenceStorage struct {
}
func (r *ReferenceStorage) Set(ref *core.Reference) error {
- return fmt.Errorf("not implemented yet")
+ return r.dir.SetRef(ref)
}
func (r *ReferenceStorage) Get(n core.ReferenceName) (*core.Reference, error) {
diff --git a/storage/memory/storage.go b/storage/memory/storage.go
index 6a56d6a..4fb6186 100644
--- a/storage/memory/storage.go
+++ b/storage/memory/storage.go
@@ -3,7 +3,6 @@ package memory
import (
"fmt"
- "io"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/core"
@@ -110,11 +109,6 @@ func (o *ObjectStorage) NewObject() core.Object {
return &core.MemoryObject{}
}
-// Writer method not supported on Memory storage
-func (o *ObjectStorage) Writer() (io.WriteCloser, error) {
- return nil, core.ErrNotImplemented
-}
-
// Set stores an object, the object should be properly filled before set it.
func (o *ObjectStorage) Set(obj core.Object) (core.Hash, error) {
h := obj.Hash()