summaryrefslogtreecommitdiff
path: root/index.go
diff options
context:
space:
mode:
authorFUJII Ryota <[email protected]>2015-12-21 18:19:03 +0900
committerFUJII Ryota <[email protected]>2015-12-21 18:19:03 +0900
commit20ab28bfeacbfd0c0b1a83e471de8de5610f9de8 (patch)
treeab0b1fbd70d429c25db5ceb01a430edba97efdd4 /index.go
parent9022ab9c195e646f9e9928b4ab3f2e83c8f04268 (diff)
Add Index.Find() and Index.FindPrefix()
Diffstat (limited to 'index.go')
-rw-r--r--index.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/index.go b/index.go
index 8417b65..16e63a1 100644
--- a/index.go
+++ b/index.go
@@ -363,6 +363,36 @@ func (v *Index) EntryByPath(path string, stage int) (*IndexEntry, error) {
return newIndexEntryFromC(centry), nil
}
+func (v *Index) Find(path string) (uint, error) {
+ cpath := C.CString(path)
+ defer C.free(unsafe.Pointer(cpath))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ var pos C.size_t
+ ret := C.git_index_find(&pos, v.ptr, cpath)
+ if ret < 0 {
+ return uint(0), MakeGitError(ret)
+ }
+ return uint(pos), nil
+}
+
+func (v *Index) FindPrefix(prefix string) (uint, error) {
+ cprefix := C.CString(prefix)
+ defer C.free(unsafe.Pointer(cprefix))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ var pos C.size_t
+ ret := C.git_index_find_prefix(&pos, v.ptr, cprefix)
+ if ret < 0 {
+ return uint(0), MakeGitError(ret)
+ }
+ return uint(pos), nil
+}
+
func (v *Index) HasConflicts() bool {
return C.git_index_has_conflicts(v.ptr) != 0
}