aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/internal/dotgit
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-09-10 01:48:43 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-09-10 01:48:43 +0200
commit6f1d1e00a7c615209cf6b25e314d033bda3b5d09 (patch)
tree51492dae8b010a25a2116e5c8cbeadeef1fa3726 /storage/filesystem/internal/dotgit
parente013b297b14949aadaec66deaedc130e86c30afb (diff)
downloadgo-git-6f1d1e00a7c615209cf6b25e314d033bda3b5d09.tar.gz
storage: filesystem ref storage, and not not exists file handling
Diffstat (limited to 'storage/filesystem/internal/dotgit')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go27
-rw-r--r--storage/filesystem/internal/dotgit/refs.go8
2 files changed, 33 insertions, 2 deletions
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
}