Encode writes an index into the commit-graph file Deprecated: This package uses the wrong types for Generation and Index in CommitData. Use the v2 package instead.
(idx Index)
| 33 | // Deprecated: This package uses the wrong types for Generation and Index in CommitData. |
| 34 | // Use the v2 package instead. |
| 35 | func (e *Encoder) Encode(idx Index) error { |
| 36 | // Get all the hashes in the input index |
| 37 | hashes := idx.Hashes() |
| 38 | |
| 39 | // Sort the inout and prepare helper structures we'll need for encoding |
| 40 | hashToIndex, fanout, extraEdgesCount := e.prepare(idx, hashes) |
| 41 | |
| 42 | chunkSignatures := [][]byte{oidFanoutSignature, oidLookupSignature, commitDataSignature} |
| 43 | chunkSizes := []uint64{4 * 256, uint64(len(hashes)) * hash.Size, uint64(len(hashes)) * (hash.Size + commitDataSize)} |
| 44 | if extraEdgesCount > 0 { |
| 45 | chunkSignatures = append(chunkSignatures, extraEdgeListSignature) |
| 46 | chunkSizes = append(chunkSizes, uint64(extraEdgesCount)*4) |
| 47 | } |
| 48 | |
| 49 | if err := e.encodeFileHeader(len(chunkSignatures)); err != nil { |
| 50 | return err |
| 51 | } |
| 52 | if err := e.encodeChunkHeaders(chunkSignatures, chunkSizes); err != nil { |
| 53 | return err |
| 54 | } |
| 55 | if err := e.encodeFanout(fanout); err != nil { |
| 56 | return err |
| 57 | } |
| 58 | if err := e.encodeOidLookup(hashes); err != nil { |
| 59 | return err |
| 60 | } |
| 61 | if extraEdges, err := e.encodeCommitData(hashes, hashToIndex, idx); err == nil { |
| 62 | if err = e.encodeExtraEdges(extraEdges); err != nil { |
| 63 | return err |
| 64 | } |
| 65 | } else { |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | return e.encodeChecksum() |
| 70 | } |
| 71 | |
| 72 | func (e *Encoder) prepare(idx Index, hashes []plumbing.Hash) (hashToIndex map[plumbing.Hash]uint32, fanout []uint32, extraEdgesCount uint32) { |
| 73 | // Sort the hashes and build our index |