diff options
| author | Carlos Martín Nieto <[email protected]> | 2014-02-26 15:22:53 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2014-02-26 15:22:53 +0100 |
| commit | 5f4283fac3408b9e7385d775aedd110b070b4a6b (patch) | |
| tree | 87e9d6494271cc6eb2da0d98285eef7d2d97b3cd /index.go | |
| parent | 786393a380e17e1e0bc47fea97cbe18c8c0ebb22 (diff) | |
| parent | 14f902afed482faefc58aa3af005cb8f2a0b050d (diff) | |
Merge branch 'index-entries'
Diffstat (limited to 'index.go')
| -rw-r--r-- | index.go | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -6,7 +6,9 @@ package git */ import "C" import ( + "fmt" "runtime" + "time" "unsafe" ) @@ -14,6 +16,17 @@ type Index struct { ptr *C.git_index } +type IndexEntry struct { + Ctime time.Time + Mtime time.Time + Mode uint + Uid uint + Gid uint + Size uint + Id *Oid + Path string +} + func newIndexFromC(ptr *C.git_index) *Index { idx := &Index{ptr} runtime.SetFinalizer(idx, (*Index).Free) @@ -65,3 +78,28 @@ func (v *Index) Free() { runtime.SetFinalizer(v, nil) 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{ + 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.id), + 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 +} |
