diff options
| author | Carlos Martín Nieto <[email protected]> | 2013-09-12 08:56:47 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2013-09-12 10:16:49 +0200 |
| commit | ef5fc378703bb4a0da2f9558237f1652b68431ec (patch) | |
| tree | 9326ac27a3fa95e7a4530949db93df8533b4eb0b | |
| parent | 008e1efb35b07b4a91dba69369b8217862f11abd (diff) | |
Tree: add EntryByPath
The more powerful version of EntryByName.
| -rw-r--r-- | tree.go | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -54,6 +54,21 @@ func (t Tree) EntryByName(filename string) *TreeEntry { 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) { + cpath := C.CString(path) + defer C.free(unsafe.Pointer(cpath)) + var entry *C.git_tree_entry + + ret := C.git_tree_entry_bypath(&entry, t.ptr, cpath) + if ret < 0 { + return nil, LastError() + } + + return newTreeEntry(entry), nil +} + func (t Tree) EntryByIndex(index uint64) *TreeEntry { entry := C.git_tree_entry_byindex(t.ptr, C.size_t(index)) if entry == nil { |
