mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 15:00:32 +00:00 
			
		
		
		
	Abstract hash function usage (#28138)
Refactor Hash interfaces and centralize hash function. This will allow easier introduction of different hash function later on. This forms the "no-op" part of the SHA256 enablement patch.
This commit is contained in:
		| @@ -21,13 +21,13 @@ import ( | ||||
| // Commit represents a git commit. | ||||
| type Commit struct { | ||||
| 	Tree | ||||
| 	ID            SHA1 // The ID of this commit object | ||||
| 	ID            ObjectID // The ID of this commit object | ||||
| 	Author        *Signature | ||||
| 	Committer     *Signature | ||||
| 	CommitMessage string | ||||
| 	Signature     *CommitGPGSignature | ||||
|  | ||||
| 	Parents        []SHA1 // SHA1 strings | ||||
| 	Parents        []ObjectID // ID strings | ||||
| 	submoduleCache *ObjectCache | ||||
| } | ||||
|  | ||||
| @@ -50,9 +50,9 @@ func (c *Commit) Summary() string { | ||||
|  | ||||
| // ParentID returns oid of n-th parent (0-based index). | ||||
| // It returns nil if no such parent exists. | ||||
| func (c *Commit) ParentID(n int) (SHA1, error) { | ||||
| func (c *Commit) ParentID(n int) (ObjectID, error) { | ||||
| 	if n >= len(c.Parents) { | ||||
| 		return SHA1{}, ErrNotExist{"", ""} | ||||
| 		return nil, ErrNotExist{"", ""} | ||||
| 	} | ||||
| 	return c.Parents[n], nil | ||||
| } | ||||
| @@ -209,9 +209,9 @@ func (c *Commit) CommitsBefore() ([]*Commit, error) { | ||||
| } | ||||
|  | ||||
| // HasPreviousCommit returns true if a given commitHash is contained in commit's parents | ||||
| func (c *Commit) HasPreviousCommit(commitHash SHA1) (bool, error) { | ||||
| func (c *Commit) HasPreviousCommit(objectID ObjectID) (bool, error) { | ||||
| 	this := c.ID.String() | ||||
| 	that := commitHash.String() | ||||
| 	that := objectID.String() | ||||
|  | ||||
| 	if this == that { | ||||
| 		return false, nil | ||||
| @@ -232,9 +232,14 @@ func (c *Commit) HasPreviousCommit(commitHash SHA1) (bool, error) { | ||||
|  | ||||
| // IsForcePush returns true if a push from oldCommitHash to this is a force push | ||||
| func (c *Commit) IsForcePush(oldCommitID string) (bool, error) { | ||||
| 	if oldCommitID == EmptySHA { | ||||
| 	objectFormat, err := c.repo.GetObjectFormat() | ||||
| 	if err != nil { | ||||
| 		return false, err | ||||
| 	} | ||||
| 	if oldCommitID == objectFormat.Empty().String() { | ||||
| 		return false, nil | ||||
| 	} | ||||
|  | ||||
| 	oldCommit, err := c.repo.GetCommit(oldCommitID) | ||||
| 	if err != nil { | ||||
| 		return false, err | ||||
|   | ||||
		Reference in New Issue
	
	Block a user