diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-29 14:15:32 -0800 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-29 14:29:19 -0800 |
commit | 4c1569511db5e1d26e42e9cd8dadb9e65ccafb20 (patch) | |
tree | 38e12de7c82d8c36d215775c13d17d3e566b2069 /prune.go | |
parent | b18457df6a1f75283d95999fde5c162ba1a19651 (diff) | |
download | go-git-4c1569511db5e1d26e42e9cd8dadb9e65ccafb20.tar.gz |
storer: separate loose and packed object mgmt into optional ifaces
Suggested by mcuadros.
Diffstat (limited to 'prune.go')
-rw-r--r-- | prune.go | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -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 } |