summaryrefslogtreecommitdiff
path: root/object.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-08-31 19:58:29 +0200
committerCarlos Martín Nieto <[email protected]>2015-08-31 19:58:29 +0200
commit6d3a3499f1639a6272e334f9f74b1e0cf6b0bb49 (patch)
tree04b27dfdf1faadcaff6ca40fa27d8edd690045d1 /object.go
parent157593f38da780c4f6cb6dc61275b9b36a3327bf (diff)
parent4090c401c8bf3f062e898f75bde01e2ef27b3911 (diff)
Merge branch 'master-v23'
Diffstat (limited to 'object.go')
-rw-r--r--object.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/object.go b/object.go
index 20cee85..6ecebf8 100644
--- a/object.go
+++ b/object.go
@@ -22,6 +22,7 @@ type Object interface {
Id() *Oid
Type() ObjectType
Owner() *Repository
+ Peel(t ObjectType) (Object, error)
}
type gitObject struct {
@@ -69,6 +70,31 @@ func (o *gitObject) Free() {
C.git_object_free(o.ptr)
}
+// Peel recursively peels an object until an object of the specified type is met.
+//
+// If the query cannot be satisfied due to the object model, ErrInvalidSpec
+// will be returned (e.g. trying to peel a blob to a tree).
+//
+// If you pass ObjectAny as the target type, then the object will be peeled
+// until the type changes. A tag will be peeled until the referenced object
+// is no longer a tag, and a commit will be peeled to a tree. Any other object
+// type will return ErrInvalidSpec.
+//
+// If peeling a tag we discover an object which cannot be peeled to the target
+// type due to the object model, an error will be returned.
+func (o *gitObject) Peel(t ObjectType) (Object, error) {
+ var cobj *C.git_object
+
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ if err := C.git_object_peel(&cobj, o.ptr, C.git_otype(t)); err < 0 {
+ return nil, MakeGitError(err)
+ }
+
+ return allocObject(cobj, o.repo), nil
+}
+
func allocObject(cobj *C.git_object, repo *Repository) Object {
obj := gitObject{
ptr: cobj,