summaryrefslogtreecommitdiff
path: root/index.go
diff options
context:
space:
mode:
authorCalin Seciu <[email protected]>2016-02-20 14:52:57 +0200
committerCalin Seciu <[email protected]>2016-02-20 14:52:57 +0200
commitc6f394e407a8f119eea191e1321f61828921f164 (patch)
tree6b4ab4bbd263388f0384b029b2a770189782b9d0 /index.go
parentdc4409793db0205ce7c0783a10363d7d67aee674 (diff)
parent251d89e1d41037185df0ea89e9aab208efc40d4e (diff)
Merge branch 'next' into stash-support
Diffstat (limited to 'index.go')
-rw-r--r--index.go66
1 files changed, 64 insertions, 2 deletions
diff --git a/index.go b/index.go
index f4c0c1e..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
}
@@ -97,7 +115,7 @@ func NewIndex() (*Index, error) {
return nil, MakeGitError(err)
}
- return &Index{ptr: ptr}, nil
+ return newIndexFromC(ptr), nil
}
// OpenIndex creates a new index at the given path. If the file does
@@ -115,7 +133,7 @@ func OpenIndex(path string) (*Index, error) {
return nil, MakeGitError(err)
}
- return &Index{ptr: ptr}, nil
+ return newIndexFromC(ptr), nil
}
// Path returns the index' path on disk or an empty string if it
@@ -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
}