Skip to content

Commit

Permalink
use sha1 Compare method (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 17, 2023
1 parent 08618e8 commit 557e647
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func isIndexDifferentFromTree(index *store.Index, tree *object.Tree) (bool, erro
if string(gotEntries[i].Path) != string(index.Entries[i].Path) {
return true, nil
}
if gotEntries[i].Hash.String() != index.Entries[i].Hash.String() {
if !gotEntries[i].Hash.Compare(index.Entries[i].Hash) {
return true, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/object/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestNewTree(t *testing.T) {
for i := 0; i < len(got.Children); i++ {
gotChild := got.Children[i]
wantChild := tt.want.Children[i]
if gotChild.Hash.String() != wantChild.Hash.String() {
if !gotChild.Hash.Compare(wantChild.Hash) {
t.Errorf("got = %v, want = %v", gotChild.Hash.String(), wantChild.Hash.String())
}
if gotChild.Name != wantChild.Name {
Expand Down
2 changes: 1 addition & 1 deletion internal/store/reflog.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r *Reflog) load(rootGoitPath string, head *Head, refs *Refs) error {
record.hash = hash

// references
if head.Commit.Hash.String() == sp1[1] {
if head.Commit.Hash.Compare(hash) {
record.isHead = true
}
branches := refs.getBranchesByHash(hash)
Expand Down
2 changes: 1 addition & 1 deletion internal/store/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (r *Refs) getBranchPos(branchName string) int {
func (r *Refs) getBranchesByHash(hash sha.SHA1) []*branch {
var branches []*branch
for _, branch := range r.Heads {
if branch.hash.String() == hash.String() {
if branch.hash.Compare(hash) {
branches = append(branches, branch)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/store/refs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestLoadHash(t *testing.T) {
if err := b.loadHash(goitDir); !errors.Is(err, tt.wantErr) {
t.Errorf("got = %v, want = %v", err, tt.wantErr)
}
if b.hash.String() != tt.want.String() {
if !b.hash.Compare(tt.want) {
t.Errorf("got = %s, want = %s", b.hash, tt.want)
}
})
Expand Down

0 comments on commit 557e647

Please sign in to comment.