Skip to content

Commit 0090f00

Browse files
committed
Merge remote-tracking branch 'rcoup/better-tree-nav'
2 parents 33d3885 + 0bbd717 commit 0090f00

File tree

6 files changed

+347
-32
lines changed

6 files changed

+347
-32
lines changed

docs/objects.rst

+14-3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ interfaces.
157157
Return the TreeEntry object for the given *name*. Raise ``KeyError`` if
158158
there is not a tree entry with that name.
159159

160+
.. method:: Tree.__truediv__(name)
161+
162+
Return the TreeEntry object for the given *name*. Raise ``KeyError`` if
163+
there is not a tree entry with that name. This allows navigating the tree
164+
similarly to Pathlib using the slash operator via:
165+
166+
Example::
167+
168+
>>> entry = tree / 'path' / 'deeper' / 'some.file'
169+
160170
.. method:: Tree.__contains__(name)
161171

162172
Return True if there is a tree entry with the given name, False otherwise.
@@ -181,6 +191,7 @@ Tree entries
181191
.. autoattribute:: pygit2.TreeEntry.hex
182192
.. autoattribute:: pygit2.TreeEntry.filemode
183193
.. autoattribute:: pygit2.TreeEntry.type
194+
.. autoattribute:: pygit2.TreeEntry.obj
184195

185196
.. method:: TreeEntry.__cmp__(TreeEntry)
186197

@@ -202,12 +213,12 @@ Example::
202213
85a67270a49ef16cdd3d328f06a3e4b459f09b27 blob setup.py
203214
3d8985bbec338eb4d47c5b01b863ee89d044bd53 tree test
204215

205-
>>> entry = tree['pygit2.c'] # Get an entry by name
216+
>>> entry = tree / 'pygit2.c' # Get an entry by name
206217
>>> entry
207218
<pygit2.TreeEntry object at 0xcc10f0>
208219

209-
>>> blob = repo[entry.id] # Get the object the entry points to
210-
>>> blob
220+
>>> obj = entry.obj # Get the blob the entry points to
221+
>>> obj
211222
<pygit2.Blob object at 0xcc12d0>
212223

213224
Creating trees

0 commit comments

Comments
 (0)