diff options
| author | 2026-03-05 21:05:56 +0800 | |
|---|---|---|
| committer | 2026-03-05 21:05:56 +0800 | |
| commit | f4ce6b4ee7c629b100c071e179af1bf22db73d70 (patch) | |
| tree | 3b251327c6a600a30d0befb69ee1701c2cbb28c4 /objectid | |
| parent | *: Fix lints (diff) | |
| signature | No signature | |
objectid, format/pack/ingest: Pack hash ID in algo
Diffstat (limited to 'objectid')
| -rw-r--r-- | objectid/algorithms.go | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/objectid/algorithms.go b/objectid/algorithms.go index 0a8d4517..a07edf7b 100644 --- a/objectid/algorithms.go +++ b/objectid/algorithms.go @@ -19,17 +19,19 @@ const ( ) type algorithmDetails struct { - name string - size int - sum func([]byte) ObjectID - new func() hash.Hash + name string + size int + packHashID uint32 + sum func([]byte) ObjectID + new func() hash.Hash } var algorithmTable = [...]algorithmDetails{ AlgorithmUnknown: {}, AlgorithmSHA1: { - name: "sha1", - size: sha1.Size, + name: "sha1", + size: sha1.Size, + packHashID: 1, sum: func(data []byte) ObjectID { sum := sha1.Sum(data) //#nosec G401 @@ -42,8 +44,9 @@ var algorithmTable = [...]algorithmDetails{ new: sha1.New, }, AlgorithmSHA256: { - name: "sha256", - size: sha256.Size, + name: "sha256", + size: sha256.Size, + packHashID: 2, sum: func(data []byte) ObjectID { sum := sha256.Sum256(data) @@ -107,6 +110,13 @@ func (algo Algorithm) HexLen() int { return algo.Size() * 2 } +// PackHashID returns the Git pack/rev hash-id encoding for this algorithm. +// +// Unknown algorithms return 0. +func (algo Algorithm) PackHashID() uint32 { + return algo.info().packHashID +} + // Sum computes an object ID from raw data using the selected algorithm. func (algo Algorithm) Sum(data []byte) ObjectID { return algo.info().sum(data) |
