summaryrefslogtreecommitdiff
path: root/tree.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-07-29 01:53:10 +0200
committerCarlos Martín Nieto <[email protected]>2015-07-29 01:53:10 +0200
commita2e4e9259be7fcd4019e85accc7f25f130c27d3c (patch)
treeada7d9570cccdeee8bc64cab435ab77b9094a6b7 /tree.go
parentb4ba35d85c4d2967c7e70350c98cb944de96d51d (diff)
parent64c160f6f2300fc675453761471dc8d4726756e0 (diff)
Merge pull request #230 from clns/tree-entry-by-id
Find tree entry by id
Diffstat (limited to 'tree.go')
-rw-r--r--tree.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/tree.go b/tree.go
index aad2c8d..f543c11 100644
--- a/tree.go
+++ b/tree.go
@@ -55,6 +55,24 @@ func (t Tree) EntryByName(filename string) *TreeEntry {
return newTreeEntry(entry)
}
+// EntryById performs a lookup for a tree entry with the given SHA value.
+//
+// It returns a *TreeEntry that is owned by the Tree. You don't have to
+// free it, but you must not use it after the Tree is freed.
+//
+// Warning: this must examine every entry in the tree, so it is not fast.
+func (t Tree) EntryById(id *Oid) *TreeEntry {
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ entry := C.git_tree_entry_byid(t.cast_ptr, id.toC())
+ if entry == nil {
+ return nil
+ }
+
+ return newTreeEntry(entry)
+}
+
// EntryByPath looks up an entry by its full path, recursing into
// deeper trees if necessary (i.e. if there are slashes in the path)
func (t Tree) EntryByPath(path string) (*TreeEntry, error) {