diff options
| author | 2026-03-26 04:39:38 +0000 | |
|---|---|---|
| committer | 2026-03-26 04:39:38 +0000 | |
| commit | 27c7fdd5a67eb082d3f44747e589be48c1b1011f (patch) | |
| tree | 08af30268b56f9d6caac2f8cbfa6b96a2c5b3610 /object/id/algorithms.go | |
| parent | README: Add alternatives (diff) | |
| signature | No signature | |
object/id: Empty tree v0.1.115
Diffstat (limited to 'object/id/algorithms.go')
| -rw-r--r-- | object/id/algorithms.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/object/id/algorithms.go b/object/id/algorithms.go index 404d3bbf..f3540c42 100644 --- a/object/id/algorithms.go +++ b/object/id/algorithms.go @@ -24,6 +24,7 @@ type algorithmDetails struct { packHashID uint32 sum func([]byte) ObjectID new func() hash.Hash + emptyTree ObjectID } //nolint:gochecknoglobals @@ -69,12 +70,15 @@ var ( ) func init() { //nolint:gochecknoinits + emptyTreeInput := []byte("tree 0\x00") + for algo := Algorithm(0); int(algo) < len(algorithmTable); algo++ { - info := algorithmTable[algo] + info := &algorithmTable[algo] if info.name == "" { continue } + info.emptyTree = info.sum(emptyTreeInput) algorithmByName[info.name] = algo supportedAlgorithms = append(supportedAlgorithms, algo) } @@ -135,6 +139,12 @@ func (algo Algorithm) New() (hash.Hash, error) { return newFn(), nil } +// EmptyTree returns the object ID of an empty tree ("tree 0\x00") for this +// algorithm. +func (algo Algorithm) EmptyTree() ObjectID { + return algo.info().emptyTree +} + func (algo Algorithm) info() algorithmDetails { return algorithmTable[algo] } |
