aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2017-11-16 21:00:51 +0200
committerJeremy Stribling <strib@alum.mit.edu>2017-11-29 11:01:40 -0800
commitd96582a6fb7df092c2856f56decd33034fe0ade3 (patch)
treee9e0eacfa4bcea2f6aaa8017744ef51f0892eed8 /repository.go
parentfae438980c3e17cb04f84ce92b99cd3c835e3e18 (diff)
downloadgo-git-d96582a6fb7df092c2856f56decd33034fe0ade3.tar.gz
Make object repacking more configurable
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/repository.go b/repository.go
index 51cd077..999cc6d 100644
--- a/repository.go
+++ b/repository.go
@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strings"
+ "time"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/internal/revision"
@@ -1013,7 +1014,18 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
return &commit.Hash, nil
}
-func (r *Repository) RepackObjects() (err error) {
+type RepackConfig struct {
+ // UseRefDeltas configures whether packfile encoder will use reference deltas.
+ // By default OFSDeltaObject is used.
+ UseRefDeltas bool
+ // PackWindow for packing objects.
+ PackWindow uint
+ // OnlyDeletePacksOlderThan if set to non-zero value
+ // selects only objects older than the time provided.
+ OnlyDeletePacksOlderThan time.Time
+}
+
+func (r *Repository) RepackObjects(cfg *RepackConfig) (err error) {
// Get the existing object packs.
hs, err := r.Storer.ObjectPacks()
if err != nil {
@@ -1021,7 +1033,7 @@ func (r *Repository) RepackObjects() (err error) {
}
// Create a new pack.
- nh, err := r.createNewObjectPack()
+ nh, err := r.createNewObjectPack(cfg)
if err != nil {
return err
}
@@ -1032,7 +1044,7 @@ func (r *Repository) RepackObjects() (err error) {
if h == nh {
continue
}
- err = r.Storer.DeleteObjectPackAndIndex(h)
+ err = r.Storer.DeleteOldObjectPackAndIndex(h, cfg.OnlyDeletePacksOlderThan)
if err != nil {
return err
}
@@ -1044,12 +1056,12 @@ func (r *Repository) RepackObjects() (err error) {
// createNewObjectPack is a helper for RepackObjects taking care
// of creating a new pack. It is used so the the PackfileWriter
// deferred close has the right scope.
-func (r *Repository) createNewObjectPack() (h plumbing.Hash, err error) {
+func (r *Repository) createNewObjectPack(cfg *RepackConfig) (h plumbing.Hash, err error) {
pfw, ok := r.Storer.(storer.PackfileWriter)
if !ok {
return h, fmt.Errorf("Repository storer is not a storer.PackfileWriter")
}
- wc, err := pfw.PackfileWriter(nil)
+ wc, err := pfw.PackfileWriter()
if err != nil {
return h, err
}
@@ -1066,8 +1078,8 @@ func (r *Repository) createNewObjectPack() (h plumbing.Hash, err error) {
if err != nil {
return h, err
}
- enc := packfile.NewEncoder(wc, r.Storer, false)
- h, err = enc.Encode(objs, 10, nil)
+ enc := packfile.NewEncoder(wc, r.Storer, cfg.UseRefDeltas)
+ h, err = enc.Encode(objs, cfg.PackWindow)
if err != nil {
return h, err
}