diff options
author | Santiago M. Mola <santi@mola.io> | 2017-07-25 10:08:36 +0200 |
---|---|---|
committer | Santiago M. Mola <santi@mola.io> | 2017-07-26 10:56:59 +0200 |
commit | c64eb817d5e5cbaec10dea1342e1ec95721e886b (patch) | |
tree | 952839005580551bf9042ded89e2dcda56d779fc /storage/filesystem/internal/dotgit/writers.go | |
parent | fbf2a4ab4588c78e3d9d0265dba774ae6b388b5f (diff) | |
download | go-git-c64eb817d5e5cbaec10dea1342e1ec95721e886b.tar.gz |
packfile: create packfile.Index and reuse it
There was an internal type (i.e. storage/filesystem.idx) to
use as in-memory index for packfiles. This was not convenient
to reuse in the packfile.
This commit creates a new representation (format/packfile.Index)
that can be converted to and from idxfile.Idxfile.
A packfile.Index now contains the functionality that was scattered
on storage/filesystem.idx and packfile.Decoder's internals.
storage/filesystem now reuses packfile.Index instances and this
also results in higher cache hit ratios when resolving deltas.
Diffstat (limited to 'storage/filesystem/internal/dotgit/writers.go')
-rw-r--r-- | storage/filesystem/internal/dotgit/writers.go | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/storage/filesystem/internal/dotgit/writers.go b/storage/filesystem/internal/dotgit/writers.go index 531259b..a7525d4 100644 --- a/storage/filesystem/internal/dotgit/writers.go +++ b/storage/filesystem/internal/dotgit/writers.go @@ -20,13 +20,13 @@ import ( // is renamed/moved (depends on the Filesystem implementation) to the final // location, if the PackWriter is not used, nothing is written type PackWriter struct { - Notify func(h plumbing.Hash, i idxfile.Idxfile) + Notify func(plumbing.Hash, *packfile.Index) fs billy.Filesystem fr, fw billy.File synced *syncedReader checksum plumbing.Hash - index idxfile.Idxfile + index *packfile.Index result chan error } @@ -68,14 +68,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() { - w.index.Add(h, uint64(offsets[h]), crc) - } - + w.index = d.Index() w.result <- err } @@ -122,7 +115,7 @@ func (w *PackWriter) Close() error { return err } - if len(w.index.Entries) == 0 { + if w.index == nil || w.index.Size() == 0 { return w.clean() } @@ -152,8 +145,11 @@ func (w *PackWriter) save() error { } func (w *PackWriter) encodeIdx(writer io.Writer) error { + idx := w.index.ToIdxFile() + idx.PackfileChecksum = w.checksum + idx.Version = idxfile.VersionSupported e := idxfile.NewEncoder(writer) - _, err := e.Encode(&w.index) + _, err := e.Encode(idx) return err } |