mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-22 04:33:42 +09:00
fix(migrations): preserve SHA-256 pull request commit IDs (#39343)
* Fixes #39339 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -6,16 +6,9 @@ package git
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"regexp"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// sha1Pattern can be used to determine if a string is a valid sha
|
||||
var sha1Pattern = regexp.MustCompile(`^[0-9a-f]{4,40}$`)
|
||||
|
||||
// sha256Pattern can be used to determine if a string is a valid sha
|
||||
var sha256Pattern = regexp.MustCompile(`^[0-9a-f]{4,64}$`)
|
||||
|
||||
type ObjectFormat interface {
|
||||
// Name returns the name of the object format
|
||||
Name() string
|
||||
@@ -25,8 +18,6 @@ type ObjectFormat interface {
|
||||
EmptyTree() ObjectID
|
||||
// FullLength is the length of the hash's hex string
|
||||
FullLength() int
|
||||
// IsValid returns true if the input is a valid hash
|
||||
IsValid(input string) bool
|
||||
// MustID creates a new ObjectID from a byte slice
|
||||
MustID(b []byte) ObjectID
|
||||
// ComputeHash compute the hash for a given ObjectType and content
|
||||
@@ -41,19 +32,10 @@ var (
|
||||
emptySha1Tree = &Sha1Hash{0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04}
|
||||
)
|
||||
|
||||
func (Sha1ObjectFormatImpl) Name() string { return "sha1" }
|
||||
func (Sha1ObjectFormatImpl) EmptyObjectID() ObjectID {
|
||||
return emptySha1ObjectID
|
||||
}
|
||||
|
||||
func (Sha1ObjectFormatImpl) EmptyTree() ObjectID {
|
||||
return emptySha1Tree
|
||||
}
|
||||
func (Sha1ObjectFormatImpl) FullLength() int { return 40 }
|
||||
func (Sha1ObjectFormatImpl) IsValid(input string) bool {
|
||||
return sha1Pattern.MatchString(input)
|
||||
}
|
||||
|
||||
func (Sha1ObjectFormatImpl) Name() string { return "sha1" }
|
||||
func (Sha1ObjectFormatImpl) EmptyObjectID() ObjectID { return emptySha1ObjectID }
|
||||
func (Sha1ObjectFormatImpl) EmptyTree() ObjectID { return emptySha1Tree }
|
||||
func (Sha1ObjectFormatImpl) FullLength() int { return 40 }
|
||||
func (Sha1ObjectFormatImpl) MustID(b []byte) ObjectID {
|
||||
var id Sha1Hash
|
||||
copy(id[0:20], b)
|
||||
@@ -83,19 +65,10 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func (Sha256ObjectFormatImpl) Name() string { return "sha256" }
|
||||
func (Sha256ObjectFormatImpl) EmptyObjectID() ObjectID {
|
||||
return emptySha256ObjectID
|
||||
}
|
||||
|
||||
func (Sha256ObjectFormatImpl) EmptyTree() ObjectID {
|
||||
return emptySha256Tree
|
||||
}
|
||||
func (Sha256ObjectFormatImpl) FullLength() int { return 64 }
|
||||
func (Sha256ObjectFormatImpl) IsValid(input string) bool {
|
||||
return sha256Pattern.MatchString(input)
|
||||
}
|
||||
|
||||
func (Sha256ObjectFormatImpl) Name() string { return "sha256" }
|
||||
func (Sha256ObjectFormatImpl) EmptyObjectID() ObjectID { return emptySha256ObjectID }
|
||||
func (Sha256ObjectFormatImpl) EmptyTree() ObjectID { return emptySha256Tree }
|
||||
func (Sha256ObjectFormatImpl) FullLength() int { return 64 }
|
||||
func (Sha256ObjectFormatImpl) MustID(b []byte) ObjectID {
|
||||
var id Sha256Hash
|
||||
copy(id[0:32], b)
|
||||
@@ -115,34 +88,13 @@ func (h Sha256ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) Object
|
||||
|
||||
type invalidObjectFormatImpl struct{}
|
||||
|
||||
var emptyInvalidObjectID = &Sha1Hash{}
|
||||
|
||||
func (h invalidObjectFormatImpl) Name() string {
|
||||
return "invalid-object-format"
|
||||
}
|
||||
|
||||
func (h invalidObjectFormatImpl) EmptyObjectID() ObjectID {
|
||||
return emptyInvalidObjectID
|
||||
}
|
||||
|
||||
func (h invalidObjectFormatImpl) EmptyTree() ObjectID {
|
||||
return emptyInvalidObjectID
|
||||
}
|
||||
|
||||
func (h invalidObjectFormatImpl) FullLength() int {
|
||||
return len(emptyInvalidObjectID) * 2
|
||||
}
|
||||
|
||||
func (h invalidObjectFormatImpl) IsValid(input string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (h invalidObjectFormatImpl) MustID(b []byte) ObjectID {
|
||||
return emptyInvalidObjectID
|
||||
}
|
||||
|
||||
func (h invalidObjectFormatImpl) Name() string { return "invalid-object-format" }
|
||||
func (h invalidObjectFormatImpl) EmptyObjectID() ObjectID { return &Sha1Hash{} }
|
||||
func (h invalidObjectFormatImpl) EmptyTree() ObjectID { return h.EmptyObjectID() }
|
||||
func (h invalidObjectFormatImpl) FullLength() int { return len(h.EmptyObjectID().RawValue()) * 2 }
|
||||
func (h invalidObjectFormatImpl) MustID(b []byte) ObjectID { return h.EmptyObjectID() }
|
||||
func (h invalidObjectFormatImpl) ComputeHash(t ObjectType, content []byte) ObjectID {
|
||||
return emptyInvalidObjectID
|
||||
return h.EmptyObjectID()
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user