Merge 179b69ce21
into 786393a380
This commit is contained in:
commit
f9bb10d4c4
40
index.go
40
index.go
|
@ -6,7 +6,9 @@ package git
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,6 +16,18 @@ type Index struct {
|
||||||
ptr *C.git_index
|
ptr *C.git_index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IndexEntry struct {
|
||||||
|
ptr *C.git_index_entry
|
||||||
|
Ctime time.Time
|
||||||
|
Mtime time.Time
|
||||||
|
Mode uint
|
||||||
|
Uid uint
|
||||||
|
Gid uint
|
||||||
|
Size uint
|
||||||
|
Oid *Oid
|
||||||
|
Path string
|
||||||
|
}
|
||||||
|
|
||||||
func newIndexFromC(ptr *C.git_index) *Index {
|
func newIndexFromC(ptr *C.git_index) *Index {
|
||||||
idx := &Index{ptr}
|
idx := &Index{ptr}
|
||||||
runtime.SetFinalizer(idx, (*Index).Free)
|
runtime.SetFinalizer(idx, (*Index).Free)
|
||||||
|
@ -65,3 +79,29 @@ func (v *Index) Free() {
|
||||||
runtime.SetFinalizer(v, nil)
|
runtime.SetFinalizer(v, nil)
|
||||||
C.git_index_free(v.ptr)
|
C.git_index_free(v.ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *Index) EntryCount() uint {
|
||||||
|
return uint(C.git_index_entrycount(v.ptr))
|
||||||
|
}
|
||||||
|
|
||||||
|
func newIndexEntryFromC(entry *C.git_index_entry) *IndexEntry {
|
||||||
|
return &IndexEntry{
|
||||||
|
entry,
|
||||||
|
time.Unix(int64(entry.ctime.seconds), int64(entry.ctime.nanoseconds)),
|
||||||
|
time.Unix(int64(entry.mtime.seconds), int64(entry.mtime.nanoseconds)),
|
||||||
|
uint(entry.mode),
|
||||||
|
uint(entry.uid),
|
||||||
|
uint(entry.gid),
|
||||||
|
uint(entry.file_size),
|
||||||
|
newOidFromC(&entry.oid),
|
||||||
|
C.GoString(entry.path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *Index) EntryByIndex(index uint) (*IndexEntry, error) {
|
||||||
|
centry := C.git_index_get_byindex(v.ptr, C.size_t(index))
|
||||||
|
if centry == nil {
|
||||||
|
return nil, fmt.Errorf("Index out of Bounds")
|
||||||
|
}
|
||||||
|
return newIndexEntryFromC(centry), nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue