Skip to content

Commit f1848e4

Browse files
author
Axel Wagner
committed
Implement most of the oid_-functions as Methods
1 parent 9822cc9 commit f1848e4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

git.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package git
77
*/
88
import "C"
99
import (
10+
"bytes"
1011
"unsafe"
1112
)
1213

@@ -67,6 +68,33 @@ func (oid *Oid) Bytes() []byte {
6768
return oid.bytes[0:]
6869
}
6970

71+
func (oid *Oid) Cmp(oid2 *Oid) int {
72+
return bytes.Compare(oid.bytes[:], oid2.bytes[:])
73+
}
74+
75+
func (oid *Oid) Copy() *Oid {
76+
ret := new(Oid)
77+
copy(ret.bytes[:], oid.bytes[:])
78+
return ret
79+
}
80+
81+
func (oid *Oid) Equal(oid2 *Oid) bool {
82+
return bytes.Equal(oid.bytes[:], oid2.bytes[:])
83+
}
84+
85+
func (oid *Oid) IsZero() bool {
86+
for _, a := range(oid.bytes) {
87+
if a != '0' {
88+
return false
89+
}
90+
}
91+
return true
92+
}
93+
94+
func (oid *Oid) NCmp(oid2 *Oid, n uint) int {
95+
return bytes.Compare(oid.bytes[:n], oid2.bytes[:n])
96+
}
97+
7098
type GitError struct {
7199
Message string
72100
Code int

0 commit comments

Comments
 (0)