aboutsummaryrefslogtreecommitdiffstats
path: root/prune.go
diff options
context:
space:
mode:
Diffstat (limited to 'prune.go')
-rw-r--r--prune.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/prune.go b/prune.go
index 81f2582..04913d6 100644
--- a/prune.go
+++ b/prune.go
@@ -1,9 +1,11 @@
package git
import (
+ "errors"
"time"
"gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/storer"
)
type PruneHandler func(unreferencedObjectHash plumbing.Hash) error
@@ -15,20 +17,32 @@ type PruneOptions struct {
Handler PruneHandler
}
+var ErrLooseObjectsNotSupported = errors.New("Loose objects not supported")
+
// DeleteObject deletes an object from a repository.
// The type conveniently matches PruneHandler.
func (r *Repository) DeleteObject(hash plumbing.Hash) error {
- return r.Storer.DeleteLooseObject(hash)
+ los, ok := r.Storer.(storer.LooseObjectStorer)
+ if !ok {
+ return ErrLooseObjectsNotSupported
+ }
+
+ return los.DeleteLooseObject(hash)
}
func (r *Repository) Prune(opt PruneOptions) error {
+ los, ok := r.Storer.(storer.LooseObjectStorer)
+ if !ok {
+ return ErrLooseObjectsNotSupported
+ }
+
pw := newObjectWalker(r.Storer)
err := pw.walkAllRefs()
if err != nil {
return err
}
// Now walk all (loose) objects in storage.
- return r.Storer.ForEachObjectHash(func(hash plumbing.Hash) error {
+ return los.ForEachObjectHash(func(hash plumbing.Hash) error {
// Get out if we have seen this object.
if pw.isSeen(hash) {
return nil
@@ -38,7 +52,7 @@ func (r *Repository) Prune(opt PruneOptions) error {
if opt.OnlyObjectsOlderThan != (time.Time{}) {
// Errors here are non-fatal. The object may be e.g. packed.
// Or concurrently deleted. Skip such objects.
- t, err := r.Storer.LooseObjectTime(hash)
+ t, err := los.LooseObjectTime(hash)
if err != nil {
return nil
}