diff options
author | Taru Karttunen <taruti@taruti.net> | 2017-11-16 21:00:51 +0200 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-29 11:01:40 -0800 |
commit | d96582a6fb7df092c2856f56decd33034fe0ade3 (patch) | |
tree | e9e0eacfa4bcea2f6aaa8017744ef51f0892eed8 /storage | |
parent | fae438980c3e17cb04f84ce92b99cd3c835e3e18 (diff) | |
download | go-git-d96582a6fb7df092c2856f56decd33034fe0ade3.tar.gz |
Make object repacking more configurable
Diffstat (limited to 'storage')
-rw-r--r-- | storage/filesystem/internal/dotgit/dotgit.go | 16 | ||||
-rw-r--r-- | storage/filesystem/object.go | 4 | ||||
-rw-r--r-- | storage/memory/storage.go | 4 |
3 files changed, 18 insertions, 6 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go index 09688c1..cd4f517 100644 --- a/storage/filesystem/internal/dotgit/dotgit.go +++ b/storage/filesystem/internal/dotgit/dotgit.go @@ -9,6 +9,7 @@ import ( stdioutil "io/ioutil" "os" "strings" + "time" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/utils/ioutil" @@ -193,8 +194,19 @@ func (d *DotGit) ObjectPackIdx(hash plumbing.Hash) (billy.File, error) { return d.objectPackOpen(hash, `idx`) } -func (d *DotGit) DeleteObjectPackAndIndex(hash plumbing.Hash) error { - err := d.fs.Remove(d.objectPackPath(hash, `pack`)) +func (d *DotGit) DeleteOldObjectPackAndIndex(hash plumbing.Hash, t time.Time) error { + path := d.objectPackPath(hash, `pack`) + if !t.IsZero() { + fi, err := d.fs.Stat(path) + if err != nil { + return err + } + // too new, skip deletion. + if !fi.ModTime().Before(t) { + return nil + } + } + err := d.fs.Remove(path) if err != nil { return err } diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go index f235204..13b8ddb 100644 --- a/storage/filesystem/object.go +++ b/storage/filesystem/object.go @@ -508,6 +508,6 @@ func (s *ObjectStorage) ObjectPacks() ([]plumbing.Hash, error) { return s.dir.ObjectPacks() } -func (s *ObjectStorage) DeleteObjectPackAndIndex(h plumbing.Hash) error { - return s.dir.DeleteObjectPackAndIndex(h) +func (s *ObjectStorage) DeleteOldObjectPackAndIndex(h plumbing.Hash, t time.Time) error { + return s.dir.DeleteOldObjectPackAndIndex(h, t) } diff --git a/storage/memory/storage.go b/storage/memory/storage.go index 5049036..2d1a4b6 100644 --- a/storage/memory/storage.go +++ b/storage/memory/storage.go @@ -173,8 +173,8 @@ func (o *ObjectStorage) ForEachObjectHash(fun func(plumbing.Hash) error) error { func (o *ObjectStorage) ObjectPacks() ([]plumbing.Hash, error) { return nil, nil } -func (o *ObjectStorage) DeleteObjectPackAndIndex(plumbing.Hash) error { - return errNotSupported +func (o *ObjectStorage) DeleteOldObjectPackAndIndex(plumbing.Hash, time.Time) error { + return nil } var errNotSupported = fmt.Errorf("Not supported") |