code.gitea.io/gitea@v1.22.3/modules/git/object_id_gogit.go (about)

     1  // Copyright 2023 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  //go:build gogit
     4  
     5  package git
     6  
     7  import (
     8  	"github.com/go-git/go-git/v5/plumbing"
     9  	"github.com/go-git/go-git/v5/plumbing/hash"
    10  )
    11  
    12  func ParseGogitHash(h plumbing.Hash) ObjectID {
    13  	switch hash.Size {
    14  	case 20:
    15  		return Sha1ObjectFormat.MustID(h[:])
    16  	case 32:
    17  		return Sha256ObjectFormat.MustID(h[:])
    18  	}
    19  
    20  	return nil
    21  }
    22  
    23  func ParseGogitHashArray(objectIDs []plumbing.Hash) []ObjectID {
    24  	ret := make([]ObjectID, len(objectIDs))
    25  	for i, h := range objectIDs {
    26  		ret[i] = ParseGogitHash(h)
    27  	}
    28  
    29  	return ret
    30  }