Skip to content

Commit 535a178

Browse files
author
Axel Wagner
committed
Implement ShortenOids
1 parent 4e0a28b commit 535a178

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

git.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ func (oid *Oid) NCmp(oid2 *Oid, n uint) int {
9696
return bytes.Compare(oid.bytes[:n], oid2.bytes[:n])
9797
}
9898

99+
func ShortenOids(ids []*Oid, minlen int) (int, error) {
100+
shorten := C.git_oid_shorten_new(C.size_t(minlen))
101+
if shorten == nil {
102+
panic("Out of memory")
103+
}
104+
defer C.git_oid_shorten_free(shorten)
105+
106+
var ret C.int
107+
for _, id := range ids {
108+
buf := make([]byte, 41)
109+
C.git_oid_fmt((*C.char)(unsafe.Pointer(&buf[0])), id.toC())
110+
buf[40] = 0
111+
ret = C.git_oid_shorten_add(shorten, (*C.char)(unsafe.Pointer(&buf[0])))
112+
if ret < 0 {
113+
return int(ret), LastError()
114+
}
115+
}
116+
return int(ret), nil
117+
}
118+
99119
type GitError struct {
100120
Message string
101121
Code int

0 commit comments

Comments
 (0)