Skip to content

Commit d44f7aa

Browse files
committed
docs: a little more
1 parent 7b7bd5e commit d44f7aa

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

docs/objects.rst

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,48 @@ creating the blob object:
134134
.. autofunction:: pygit2.hashfile
135135

136136

137-
138-
139-
140137
Trees
141138
=================
142139

143140
A tree is a sorted collection of tree entries. It is similar to a folder or
144141
directory in a file system. Each entry points to another tree or a blob. A
145142
tree can be iterated, and partially implements the sequence and mapping
146-
interfaces::
143+
interfaces.
144+
145+
.. method:: Tree[name]
146+
147+
Return the TreeEntry object for the given *name*. Raise ``KeyError`` if
148+
there is not a tree entry with that name.
149+
150+
.. method:: name in Tree
151+
152+
Return True if there is a tree entry with the given name, False otherwise.
153+
154+
.. method:: len(Tree)
155+
156+
Return the number of entries in the tree.
157+
158+
.. method:: iter(Tree)
159+
160+
Return an iterator over the entries of the tree.
161+
162+
.. automethod:: pygit2.Tree.diff
163+
164+
Tree entries
165+
------------
166+
167+
.. autoattribute:: pygit2.TreeEntry.name
168+
.. autoattribute:: pygit2.TreeEntry.oid
169+
.. autoattribute:: pygit2.TreeEntry.hex
170+
.. autoattribute:: pygit2.TreeEntry.filemode
171+
172+
Example::
147173

148-
>>> # Number of entries
149174
>>> tree = commit.tree
150-
>>> len(tree)
175+
>>> len(tree) # Number of entries
151176
6
152177

153-
>>> # Iteration
154-
>>> for entry in tree:
178+
>>> for entry in tree: # Iteration
155179
... print(entry.hex, entry.name)
156180
...
157181
7151ca7cd3e59f3eab19c485cfbf3cb30928d7fa .gitignore
@@ -161,24 +185,14 @@ interfaces::
161185
85a67270a49ef16cdd3d328f06a3e4b459f09b27 setup.py
162186
3d8985bbec338eb4d47c5b01b863ee89d044bd53 test
163187

164-
>>> # Get an entry by name
165-
>>> entry = tree['pygit2.c']
188+
>>> entry = tree['pygit2.c'] # Get an entry by name
166189
>>> entry
167190
<pygit2.TreeEntry object at 0xcc10f0>
168191

169-
>>> # Get the object the entry points to
170-
>>> blob = repo[entry.oid]
192+
>>> blob = repo[entry.oid] # Get the object the entry points to
171193
>>> blob
172194
<pygit2.Blob object at 0xcc12d0>
173195

174-
.. automethod:: pygit2.Tree.diff
175-
176-
.. autoattribute:: pygit2.TreeEntry.name
177-
.. autoattribute:: pygit2.TreeEntry.oid
178-
.. autoattribute:: pygit2.TreeEntry.hex
179-
.. autoattribute:: pygit2.TreeEntry.filemode
180-
181-
182196
Creating trees
183197
--------------------
184198

src/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ Index_read_tree(Index *self, PyObject *value)
372372

373373

374374
PyDoc_STRVAR(Index_write_tree__doc__,
375-
"write_tree() -> str\n"
375+
"write_tree() -> Oid\n"
376376
"\n"
377377
"Create a tree object from the index file, return its oid.");
378378

src/repository.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ Repository_config__get__(Repository *self)
505505
}
506506

507507
PyDoc_STRVAR(Repository_merge_base__doc__,
508-
"merge_base(oid, oid) -> commit\n"
508+
"merge_base(oid, oid) -> Oid\n"
509509
"\n"
510510
"Find as good common ancestors as possible for a merge.");
511511

@@ -665,9 +665,9 @@ Repository_create_blob_fromdisk(Repository *self, PyObject *args)
665665

666666

667667
PyDoc_STRVAR(Repository_create_commit__doc__,
668-
"create_commit(reference, author, committer, message, tree, parents[, encoding]) -> bytes\n"
668+
"create_commit(reference, author, committer, message, tree, parents[, encoding]) -> Oid\n"
669669
"\n"
670-
"Create a new commit object, return its SHA.");
670+
"Create a new commit object, return its oid.");
671671

672672
PyObject *
673673
Repository_create_commit(Repository *self, PyObject *args)
@@ -749,9 +749,9 @@ Repository_create_commit(Repository *self, PyObject *args)
749749

750750

751751
PyDoc_STRVAR(Repository_create_tag__doc__,
752-
"create_tag(name, oid, type, tagger, message) -> bytes\n"
752+
"create_tag(name, oid, type, tagger, message) -> Oid\n"
753753
"\n"
754-
"Create a new tag object, return its SHA.");
754+
"Create a new tag object, return its oid.");
755755

756756
PyObject *
757757
Repository_create_tag(Repository *self, PyObject *args)
@@ -1209,12 +1209,11 @@ Repository_notes(Repository *self, PyObject *args)
12091209
}
12101210

12111211
return Error_set(err);
1212-
12131212
}
12141213

12151214

12161215
PyDoc_STRVAR(Repository_create_note__doc__,
1217-
"create_note(message, author, committer, annotated_id [,ref, force]) -> ID\n"
1216+
"create_note(message, author, committer, annotated_id [,ref, force]) -> Oid\n"
12181217
"\n"
12191218
"Create a new note for an object, return its SHA-ID."
12201219
"If no ref is given 'refs/notes/commits' will be used.");

src/treebuilder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ TreeBuilder_insert(TreeBuilder *self, PyObject *args)
7474

7575

7676
PyDoc_STRVAR(TreeBuilder_write__doc__,
77-
"write() -> bytes\n"
77+
"write() -> Oid\n"
7878
"\n"
7979
"Write the tree to the given repository.");
8080

0 commit comments

Comments
 (0)