summaryrefslogtreecommitdiff
path: root/index.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2016-03-07 11:17:10 +0100
committerCarlos Martín Nieto <[email protected]>2016-03-07 11:22:53 +0100
commit2ae7d13ba1037c7fa579fc52263ea280b37244ea (patch)
treef2509df04ec4e6187943aad83ea672e660102a8b /index.go
parentfa644d2fc9efa3baee93b525212d76dfa17a5db5 (diff)
parente095c85fd06b5820d2f0098ff3e66b266553dbd5 (diff)
Merge branch 'next'
Diffstat (limited to 'index.go')
-rw-r--r--index.go68
1 files changed, 65 insertions, 3 deletions
diff --git a/index.go b/index.go
index 1eb5e9d..ae94864 100644
--- a/index.go
+++ b/index.go
@@ -26,6 +26,24 @@ const (
IndexAddCheckPathspec IndexAddOpts = C.GIT_INDEX_ADD_CHECK_PATHSPEC
)
+type IndexStageOpts int
+
+const (
+ // IndexStageAny matches any index stage.
+ //
+ // Some index APIs take a stage to match; pass this value to match
+ // any entry matching the path regardless of stage.
+ IndexStageAny IndexStageOpts = C.GIT_INDEX_STAGE_ANY
+ // IndexStageNormal is a normal staged file in the index.
+ IndexStageNormal IndexStageOpts = C.GIT_INDEX_STAGE_NORMAL
+ // IndexStageAncestor is the ancestor side of a conflict.
+ IndexStageAncestor IndexStageOpts = C.GIT_INDEX_STAGE_ANCESTOR
+ // IndexStageOurs is the "ours" side of a conflict.
+ IndexStageOurs IndexStageOpts = C.GIT_INDEX_STAGE_OURS
+ // IndexStageTheirs is the "theirs" side of a conflict.
+ IndexStageTheirs IndexStageOpts = C.GIT_INDEX_STAGE_THEIRS
+)
+
type Index struct {
ptr *C.git_index
}
@@ -51,8 +69,8 @@ func newIndexEntryFromC(entry *C.git_index_entry) *IndexEntry {
return nil
}
return &IndexEntry{
- IndexTime { int32(entry.ctime.seconds), uint32(entry.ctime.nanoseconds) },
- IndexTime { int32(entry.mtime.seconds), uint32(entry.mtime.nanoseconds) },
+ IndexTime{int32(entry.ctime.seconds), uint32(entry.ctime.nanoseconds)},
+ IndexTime{int32(entry.mtime.seconds), uint32(entry.mtime.nanoseconds)},
Filemode(entry.mode),
uint32(entry.uid),
uint32(entry.gid),
@@ -280,7 +298,7 @@ func (v *Index) ReadTree(tree *Tree) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
- ret := C.git_index_read_tree(v.ptr, tree.cast_ptr);
+ ret := C.git_index_read_tree(v.ptr, tree.cast_ptr)
if ret < 0 {
return MakeGitError(ret)
}
@@ -331,6 +349,50 @@ func (v *Index) EntryByIndex(index uint) (*IndexEntry, error) {
return newIndexEntryFromC(centry), nil
}
+func (v *Index) EntryByPath(path string, stage int) (*IndexEntry, error) {
+ cpath := C.CString(path)
+ defer C.free(unsafe.Pointer(cpath))
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ centry := C.git_index_get_bypath(v.ptr, cpath, C.int(stage))
+ if centry == nil {
+ return nil, MakeGitError(C.GIT_ENOTFOUND)
+ }
+ 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
}