mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-27 00:23:41 +09:00 
			
		
		
		
	Only use SHA256 feature when git >= 2.42 (#28466)
And fix some comments
This commit is contained in:
		| @@ -33,8 +33,8 @@ var ( | ||||
| 	// DefaultContext is the default context to run git commands in, must be initialized by git.InitXxx | ||||
| 	DefaultContext context.Context | ||||
|  | ||||
| 	// SupportProcReceive version >= 2.29.0 | ||||
| 	SupportProcReceive bool | ||||
| 	SupportProcReceive bool // >= 2.29 | ||||
| 	SupportHashSha256  bool // >= 2.42, SHA-256 repositories no longer an ‘experimental curiosity’ | ||||
|  | ||||
| 	gitVersion *version.Version | ||||
| ) | ||||
| @@ -189,7 +189,7 @@ func InitFull(ctx context.Context) (err error) { | ||||
| 		globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=") | ||||
| 	} | ||||
| 	SupportProcReceive = CheckGitVersionAtLeast("2.29") == nil | ||||
|  | ||||
| 	SupportHashSha256 = CheckGitVersionAtLeast("2.42") == nil | ||||
| 	if setting.LFS.StartServer { | ||||
| 		if CheckGitVersionAtLeast("2.1.2") != nil { | ||||
| 			return errors.New("LFS server support requires Git >= 2.1.2") | ||||
|   | ||||
| @@ -40,7 +40,6 @@ type ObjectFormat interface { | ||||
| 	NewHasher() HasherInterface | ||||
| } | ||||
|  | ||||
| /* SHA1 Type */ | ||||
| type Sha1ObjectFormat struct{} | ||||
|  | ||||
| func (*Sha1ObjectFormat) ID() ObjectFormatID { return Sha1 } | ||||
| @@ -83,7 +82,6 @@ func (h *Sha1ObjectFormat) NewHasher() HasherInterface { | ||||
| 	return &Sha1Hasher{sha1.New()} | ||||
| } | ||||
|  | ||||
| // utils | ||||
| func ObjectFormatFromID(id ObjectFormatID) ObjectFormat { | ||||
| 	switch id { | ||||
| 	case Sha1: | ||||
|   | ||||
| @@ -20,7 +20,6 @@ type ObjectID interface { | ||||
| 	Type() ObjectFormat | ||||
| } | ||||
|  | ||||
| /* SHA1 */ | ||||
| type Sha1Hash [20]byte | ||||
|  | ||||
| func (h *Sha1Hash) String() string { | ||||
| @@ -38,7 +37,7 @@ func NewSha1() *Sha1Hash { | ||||
| 	return &Sha1Hash{} | ||||
| } | ||||
|  | ||||
| // generic implementations | ||||
| // NewHash is for generic implementations | ||||
| func NewHash(hash string) (ObjectID, error) { | ||||
| 	hash = strings.ToLower(hash) | ||||
| 	switch hash { | ||||
| @@ -73,7 +72,6 @@ func genericIDFromString(h ObjectFormat, s string) (ObjectID, error) { | ||||
| 	return h.NewID(b) | ||||
| } | ||||
|  | ||||
| // utils | ||||
| func IDFromString(hexHash string) (ObjectID, error) { | ||||
| 	switch len(hexHash) { | ||||
| 	case 40: | ||||
| @@ -101,7 +99,7 @@ func IsEmptyCommitID(commitID string) bool { | ||||
| 	return id.IsZero() | ||||
| } | ||||
|  | ||||
| // HashInterface is a struct that will generate a Hash | ||||
| // HasherInterface is a struct that will generate a Hash | ||||
| type HasherInterface interface { | ||||
| 	hash.Hash | ||||
|  | ||||
| @@ -127,7 +125,7 @@ func ComputeHash(hashType ObjectFormat, t ObjectType, content []byte) ObjectID { | ||||
| 	return h.HashSum() | ||||
| } | ||||
|  | ||||
| // Sum generates a SHA1 for the provided hash | ||||
| // HashSum generates a SHA1 for the provided hash | ||||
| func (h *Sha1Hasher) HashSum() ObjectID { | ||||
| 	var sha1 Sha1Hash | ||||
| 	copy(sha1[:], h.Hash.Sum(nil)) | ||||
|   | ||||
| @@ -63,7 +63,7 @@ func IsRepoURLAccessible(ctx context.Context, url string) bool { | ||||
| 	return err == nil | ||||
| } | ||||
|  | ||||
| // GetObjectFormatOfRepo returns the hash type of a repository at a given path | ||||
| // GetObjectFormatOfRepo returns the hash type of repository at a given path | ||||
| func GetObjectFormatOfRepo(ctx context.Context, repoPath string) (ObjectFormat, error) { | ||||
| 	var stdout, stderr strings.Builder | ||||
|  | ||||
| @@ -96,7 +96,10 @@ func InitRepository(ctx context.Context, repoPath string, bare bool, objectForma | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	cmd := NewCommand(ctx, "init", "--object-format").AddDynamicArguments(objectFormat.String()) | ||||
| 	cmd := NewCommand(ctx, "init") | ||||
| 	if SupportHashSha256 { | ||||
| 		cmd.AddOptionValues("--object-format", objectFormat.String()) | ||||
| 	} | ||||
| 	if bare { | ||||
| 		cmd.AddArguments("--bare") | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user