aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/idxfile/writer.go
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2018-07-20 13:01:27 +0200
committerJavi Fontan <jfontan@gmail.com>2018-07-26 14:17:56 +0200
commit65e8359db00ae79838d19e19f69594f6a262c3d4 (patch)
tree6fd7c2a50b7fe914499a5f46911901547f3bb77c /plumbing/format/idxfile/writer.go
parent4e3765aef344eae2fbcd977fefd66b6571638d59 (diff)
downloadgo-git-65e8359db00ae79838d19e19f69594f6a262c3d4.tar.gz
plumbing/idxfile: support offset64 generating indexes
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/format/idxfile/writer.go')
-rw-r--r--plumbing/format/idxfile/writer.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/plumbing/format/idxfile/writer.go b/plumbing/format/idxfile/writer.go
index 3c5a00e..ea54081 100644
--- a/plumbing/format/idxfile/writer.go
+++ b/plumbing/format/idxfile/writer.go
@@ -18,12 +18,16 @@ type Writer struct {
count uint32
checksum plumbing.Hash
objects objects
+ offset64 uint32
+ idx *MemoryIndex
}
// Create index returns a filled MemoryIndex with the information filled by
// the observer callbacks.
func (w *Writer) CreateIndex() (*MemoryIndex, error) {
idx := new(MemoryIndex)
+ w.idx = idx
+
sort.Sort(w.objects)
// unmap all fans by default
@@ -60,13 +64,13 @@ func (w *Writer) CreateIndex() (*MemoryIndex, error) {
idx.Names[bucket] = append(idx.Names[bucket], o.Hash[:]...)
- // TODO: implement 64 bit offsets
- if o.Offset > math.MaxInt32 {
- panic("64 bit offsets not implemented")
+ offset := o.Offset
+ if offset > math.MaxInt32 {
+ offset = w.addOffset64(offset)
}
buf.Truncate(0)
- binary.WriteUint32(buf, uint32(o.Offset))
+ binary.WriteUint32(buf, uint32(offset))
idx.Offset32[bucket] = append(idx.Offset32[bucket], buf.Bytes()...)
buf.Truncate(0)
@@ -78,12 +82,23 @@ func (w *Writer) CreateIndex() (*MemoryIndex, error) {
idx.Fanout[j] = uint32(len(w.objects))
}
+ idx.Version = VersionSupported
idx.PackfileChecksum = w.checksum
- // TODO: fill IdxChecksum
return idx, nil
}
+func (w *Writer) addOffset64(pos uint64) uint64 {
+ buf := new(bytes.Buffer)
+ binary.WriteUint64(buf, pos)
+ w.idx.Offset64 = append(w.idx.Offset64, buf.Bytes()...)
+
+ index := uint64(w.offset64 | (1 << 31))
+ w.offset64++
+
+ return index
+}
+
// Add appends new object data.
func (w *Writer) Add(h plumbing.Hash, pos uint64, crc uint32) {
w.objects = append(w.objects, Entry{h, crc, pos})