diff options
-rw-r--r-- | fixtures/fixtures.go | 7 | ||||
-rw-r--r-- | remote.go | 15 | ||||
-rw-r--r-- | repository.go | 6 | ||||
-rw-r--r-- | storage/filesystem/config.go | 5 | ||||
-rw-r--r-- | storage/filesystem/internal/dotgit/dotgit.go | 27 | ||||
-rw-r--r-- | storage/filesystem/internal/dotgit/refs.go | 8 | ||||
-rw-r--r-- | storage/filesystem/object.go | 10 | ||||
-rw-r--r-- | storage/filesystem/reference.go | 4 | ||||
-rw-r--r-- | storage/memory/storage.go | 6 | ||||
-rw-r--r-- | utils/fs/os.go | 14 |
10 files changed, 68 insertions, 34 deletions
diff --git a/fixtures/fixtures.go b/fixtures/fixtures.go index b85174c..59cbd2a 100644 --- a/fixtures/fixtures.go +++ b/fixtures/fixtures.go @@ -18,14 +18,14 @@ var RootFolder = "" const DataFolder = "data" var fixtures = []*Fixture{{ - Tags: []string{"ofs-delta", ".git"}, + Tags: []string{"packfile", "ofs-delta", ".git"}, URL: "https://github.com/git-fixtures/basic", Head: core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), PackfileHash: core.NewHash("a3fed42da1e8189a077c0e6846c040dcf73fc9dd"), DotGitHash: core.NewHash("0a00a25543e6d732dbf4e8e9fec55c8e65fc4e8d"), ObjectsCount: 31, }, { - Tags: []string{"ref-delta"}, + Tags: []string{"packfile", "ref-delta"}, URL: "https://github.com/git-fixtures/basic", Head: core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), PackfileHash: core.NewHash("c544593473465e6315ad4182d04d366c4592b829"), @@ -36,6 +36,7 @@ var fixtures = []*Fixture{{ DotGitHash: core.NewHash("174be6bd4292c18160542ae6dc6704b877b8a01a"), ObjectsCount: 2133, }, { + Tags: []string{"packfile"}, URL: "https://github.com/spinnaker/spinnaker", Head: core.NewHash("06ce06d0fc49646c4de733c45b7788aabad98a6f"), PackfileHash: core.NewHash("f2e0a8889a746f7600e07d2246a2e29a72f696be"), @@ -115,7 +116,7 @@ type Fixtures []*Fixture func (g Fixtures) Test(c *check.C, test func(*Fixture)) { for _, f := range g { - c.Logf("executing test at %s", f.URL) + c.Logf("executing test at %s %s", f.URL, f.Tags) test(f) } } @@ -161,9 +161,20 @@ func (r *Remote) buildRequest( } func (r *Remote) updateObjectStorage(reader io.Reader) error { - stream := packfile.NewScannerFromReader(reader) + s := r.s.ObjectStorage() + if sw, ok := s.(core.ObjectStorageWrite); ok { + w, err := sw.Writer() + if err != nil { + return err + } + + defer w.Close() + _, err = io.Copy(w, reader) + return err + } - d := packfile.NewDecoder(stream, r.s.ObjectStorage()) + stream := packfile.NewScannerFromReader(reader) + d := packfile.NewDecoder(stream, s) _, err := d.Decode() return err } diff --git a/repository.go b/repository.go index 5f5527e..cc76107 100644 --- a/repository.go +++ b/repository.go @@ -345,6 +345,10 @@ func (r *Repository) Ref(name core.ReferenceName, resolved bool) (*core.Referenc // Refs returns a map with all the References func (r *Repository) Refs() core.ReferenceIter { - i, _ := r.s.ReferenceStorage().Iter() + i, err := r.s.ReferenceStorage().Iter() + if err != nil { + panic(err) + } + return i } 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() diff --git a/utils/fs/os.go b/utils/fs/os.go index 1ae4204..51af921 100644 --- a/utils/fs/os.go +++ b/utils/fs/os.go @@ -36,7 +36,7 @@ func (fs *OS) Create(filename string) (File, error) { } return &OSFile{ - BaseFile: BaseFile{filename: fullpath}, + BaseFile: BaseFile{filename: filename}, file: f, }, nil } @@ -60,14 +60,8 @@ func (fs *OS) ReadDir(path string) ([]FileInfo, error) { } func (fs *OS) Rename(from, to string) error { - if !filepath.IsAbs(from) { - from = fs.Join(fs.RootDir, from) - } - - if !filepath.IsAbs(to) { - to = fs.Join(fs.RootDir, to) - } - + from = fs.Join(fs.RootDir, from) + to = fs.Join(fs.RootDir, to) return os.Rename(from, to) } @@ -80,7 +74,7 @@ func (fs *OS) Open(filename string) (File, error) { } return &OSFile{ - BaseFile: BaseFile{filename: fullpath}, + BaseFile: BaseFile{filename: filename}, file: f, }, nil } |