Skip to content

Commit 664b5d9

Browse files
committed
Make SHA1 type alias for plumbing.Hash in go-git.
Signed-off-by: Filip Navara <[email protected]>
1 parent e7274c8 commit 664b5d9

File tree

4 files changed

+6
-35
lines changed

4 files changed

+6
-35
lines changed

modules/git/commit_info.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (tes Entries) GetCommitsInfo(commit *Commit, treePath string, cache LastCom
3232
commitsInfo := make([][]interface{}, len(tes))
3333
for i, entry := range tes {
3434
commit := &Commit{
35-
ID: SHA1(revs[i].Hash),
35+
ID: revs[i].Hash,
3636
CommitMessage: revs[i].Message,
3737
Committer: &Signature{
3838
When: revs[i].Committer.When,
@@ -55,18 +55,13 @@ func convertCommit(c *object.Commit) *Commit {
5555
}
5656
}
5757

58-
parents := make([]SHA1, len(c.ParentHashes))
59-
for i, parentHash := range c.ParentHashes {
60-
parents[i] = SHA1(parentHash)
61-
}
62-
6358
return &Commit{
64-
ID: SHA1(c.Hash),
59+
ID: c.Hash,
6560
CommitMessage: c.Message,
6661
Committer: &commiter,
6762
Author: &author,
6863
Signature: pgpSignaure,
69-
parents: parents,
64+
parents: c.ParentHashes,
7065
}
7166
}
7267

modules/git/repo_commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
5858
commit.repo = repo
5959

6060
if tree, err := gogitCommit.Tree(); err != nil {
61-
commit.Tree.ID = SHA1(tree.Hash)
61+
commit.Tree.ID = tree.Hash
6262
commit.Tree.gogitTree = tree
6363
}
6464

modules/git/sha1.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package git
66

77
import (
8-
"bytes"
98
"encoding/hex"
109
"fmt"
1110
"strings"
@@ -17,30 +16,7 @@ import (
1716
const EmptySHA = "0000000000000000000000000000000000000000"
1817

1918
// SHA1 a git commit name
20-
type SHA1 plumbing.Hash
21-
22-
// Equal returns true if s has the same SHA1 as caller.
23-
// Support 40-length-string, []byte, SHA1.
24-
func (id SHA1) Equal(s2 interface{}) bool {
25-
switch v := s2.(type) {
26-
case string:
27-
if len(v) != 40 {
28-
return false
29-
}
30-
return v == id.String()
31-
case []byte:
32-
return bytes.Equal(v, id[:])
33-
case SHA1:
34-
return v == id
35-
default:
36-
return false
37-
}
38-
}
39-
40-
// String returns string (hex) representation of the Oid.
41-
func (id SHA1) String() string {
42-
return hex.EncodeToString(id[:])
43-
}
19+
type SHA1 = plumbing.Hash
4420

4521
// MustID always creates a new SHA1 from a [20]byte array with no validation of input.
4622
func MustID(b []byte) SHA1 {

modules/git/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (t *Tree) ListEntries() (Entries, error) {
7474
entries := make([]*TreeEntry, len(t.gogitTree.Entries))
7575
for i, entry := range t.gogitTree.Entries {
7676
entries[i] = &TreeEntry{
77-
ID: SHA1(entry.Hash),
77+
ID: entry.Hash,
7878
gogitTreeEntry: &t.gogitTree.Entries[i],
7979
ptree: t,
8080
}

0 commit comments

Comments
 (0)