Skip to content

Commit d2d6374

Browse files
committed
Update docs
1 parent 1edfec4 commit d2d6374

File tree

7 files changed

+122
-91
lines changed

7 files changed

+122
-91
lines changed

CHANGELOG.rst

+23-2
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,48 @@
77
- Add Python 3.8 support
88
`#918 <https://github.com/libgit2/pygit2/issues/918>`_
99

10+
- New ``Repository.odb`` returns new ``Odb`` type instance. And new
11+
``OdbBackend`` type.
12+
`#940 <https://github.com/libgit2/pygit2/pull/940>`_
13+
`#942 <https://github.com/libgit2/pygit2/pull/942>`_
14+
1015
- New support for ``/`` operator to traverse trees
1116
`#903 <https://github.com/libgit2/pygit2/pull/903>`_
17+
`#924 <https://github.com/libgit2/pygit2/issues/924>`_
1218

1319
- New ``Index.remove_all()``
1420
`#920 <https://github.com/libgit2/pygit2/pull/920>`_
1521

1622
- New ``Repository.lookup_reference_dwim(..)`` and ``Repository.resolve_refish(..)``
17-
`#922 <https://github.com/libgit2/pygit2/pull/922>`_
23+
`#922 <https://github.com/libgit2/pygit2/issues/922>`_
24+
`#923 <https://github.com/libgit2/pygit2/pull/923>`_
1825

1926
- New ``Remote.ls_remotes(..)``
27+
`#935 <https://github.com/libgit2/pygit2/pull/935>`_
28+
`#936 <https://github.com/libgit2/pygit2/issues/936>`_
2029

2130
- Fix spurious exception in config
2231
`#916 <https://github.com/libgit2/pygit2/issues/916>`_
2332
`#917 <https://github.com/libgit2/pygit2/pull/917>`_
2433

25-
- Minor fixes
34+
- Minor documentation and cosmetic changes
2635
`#919 <https://github.com/libgit2/pygit2/pull/919>`_
2736
`#921 <https://github.com/libgit2/pygit2/pull/921>`_
37+
`#946 <https://github.com/libgit2/pygit2/pull/946>`_
38+
`#950 <https://github.com/libgit2/pygit2/pull/950>`_
2839

2940
Breaking changes:
3041

42+
- Now the Repository has a new attribue ``odb`` for object database::
43+
44+
# Before
45+
repository.read(...)
46+
repository.write(...)
47+
48+
# Now
49+
repository.odb.read(...)
50+
repository.odb.write(...)
51+
3152
- Now ``Tree[x]`` returns a ``Object`` instance instead of a ``TreeEntry``;
3253
``Object.type`` returns an integer while ``TreeEntry.type`` returned a
3354
string::

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
build:
44
python setup.py build_ext --inplace
5+
6+
html:
7+
cd docs && find . -name "*rst" | entr make html

docs/install.rst

+31-24
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ To install the source package:
2727
2828
$ pip install pygit2 --no-binary
2929
30-
It's preferable to install the source package, if it works for you. But the
31-
binary package will often be easier to install.
32-
3330
3431
Requirements
3532
============
@@ -43,9 +40,8 @@ Python requirements (these are specified in ``setup.py``):
4340

4441
- cffi 1.0+
4542

46-
Libgit2 **v0.28.x** (see the version numbering section below for details).
47-
Binary wheels already include libgit2, so you only need to worry about this if
48-
you install the source package
43+
Libgit2 **v0.28.x**; binary wheels already include libgit2, so you only need to
44+
worry about this if you install the source package
4945

5046
Optional libgit2 dependecies to support ssh and https:
5147

@@ -60,31 +56,42 @@ To run the tests:
6056
Version numbers
6157
===============
6258

63-
.. warning::
59+
The version number of pygit2 is composed of three numbers separated by dots
60+
|lq| *major.minor.micro* |rq|:
6461

65-
One common mistake users do is to choose incompatible versions of libgit2
66-
and pygit2. Double check the versions do match before filing a bug report.
67-
Though you don't need to worry about this if you install a binary wheel.
62+
- *major* will always be 1 (until we release 2.0 in a far undefined future)
63+
- *minor* will increase whenever we make breaking changes, or add new features, or
64+
upgrade to new versions of libgit2.
65+
- *micro* will increase for bug fixes.
6866

69-
The version number of pygit2 is composed of three numbers separated by dots
70-
|lq| *major.minor.micro* |rq|, where the first two numbers
71-
|lq| *major.minor* |rq| match the first two numbers of the libgit2 version,
72-
while the last number |lq| *.micro* |rq| auto-increments independently.
67+
The table below summarizes the latest pygit2 versions with the supported versions
68+
of Python and the required libgit2 version.
7369

74-
It is recommended to use the latest version in each series. Example of
75-
compatible releases:
70+
+-----------+----------------+---------+
71+
| pygit2 | Python | libgit2 |
72+
+-----------+----------------+---------+
73+
| 1.0.x | 3.5 - 3.8 | 0.28.x |
74+
+-----------+----------------+---------+
75+
| 0.28.2 | 2.7, 3.4 - 3.7 | 0.28.x |
76+
+-----------+----------------+---------+
7677

77-
+-----------+--------+--------+--------+--------+--------+
78-
|**libgit2**| 0.28.2 | 0.27.8 | 0.26.8 | 0.25.1 | 0.24.6 |
79-
+-----------+--------+--------+--------+--------+--------+
80-
|**pygit2** | 0.28.2 | 0.27.4 | 0.26.4 | 0.25.1 | 0.24.2 |
81-
+-----------+--------+--------+--------+--------+--------+
78+
.. warning::
79+
80+
It is recommended to use the latest 1.x.y release. Because only the latest
81+
is supported.
8282

8383
.. warning::
8484

85-
Backwards compatibility is not guaranteed even between micro releases.
86-
Please check the release notes for incompatible changes before upgrading to
87-
a new release.
85+
Backwards compatibility is not guaranteed in minor releases. Please check
86+
the release notes for incompatible changes before upgrading to a new
87+
release.
88+
89+
History: the 0.x series
90+
-----------------------
91+
92+
The development of pygit2 started in October 2010, the release of 1.0.0
93+
happened in November 2019. In the 0.x series the version numbering was
94+
lockstep with libgit2, e.g. pygit2 0.28.x worked with libgit2 0.28.x
8895

8996

9097
Advanced

docs/objects.rst

+33-35
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ New objects are created using an specific API we will see later.
7979
This is the common interface for all Git objects:
8080

8181
.. autoclass:: pygit2.Object
82-
:members: id, type, short_id, read_raw, peel, name, filemode, __eq__, __ne__, __hash__
82+
:members: id, type, type_str, short_id, read_raw, peel, name, filemode
83+
84+
.. automethod:: __eq__(other)
85+
.. automethod:: __ne__(other)
86+
.. automethod:: __hash__()
87+
8388

8489
Blobs
8590
=================
@@ -141,64 +146,61 @@ creating the blob object:
141146
Trees
142147
=================
143148

144-
A tree is a sorted collection of tree entries. It is similar to a folder or
145-
directory in a file system. Each entry points to another tree or a blob. A
146-
tree can be iterated, and partially implements the sequence and mapping
149+
At the low level (libgit2) a tree is a sorted collection of tree entries. In
150+
pygit2 accessing an entry directly returns the object.
151+
152+
A tree can be iterated, and partially implements the sequence and mapping
147153
interfaces.
148154

149155
.. method:: Tree.__getitem__(name)
150156

151-
Return the TreeEntry object for the given *name*. Raise ``KeyError`` if
152-
there is not a tree entry with that name.
157+
``Tree[name]``
158+
159+
Return the Object subclass instance for the given *name*. Raise ``KeyError``
160+
if there is not a tree entry with that name.
153161

154162
.. method:: Tree.__truediv__(name)
155163

156-
Return the TreeEntry object for the given *name*. Raise ``KeyError`` if
157-
there is not a tree entry with that name. This allows navigating the tree
158-
similarly to Pathlib using the slash operator via:
164+
``Tree / name``
159165

160-
Example::
166+
Return the Object subclass instance for the given *name*. Raise ``KeyError``
167+
if there is not a tree entry with that name. This allows navigating the tree
168+
similarly to Pathlib using the slash operator via.
169+
170+
Example::
161171

162-
>>> entry = tree / 'path' / 'deeper' / 'some.file'
172+
>>> entry = tree / 'path' / 'deeper' / 'some.file'
163173

164174
.. method:: Tree.__contains__(name)
165175

176+
``name in Tree``
177+
166178
Return True if there is a tree entry with the given name, False otherwise.
167179

168180
.. method:: Tree.__len__()
169181

170-
Return the number of entries in the tree.
182+
``len(Tree)``
183+
184+
Return the number of objects in the tree.
171185

172186
.. method:: Tree.__iter__()
173187

174-
Return an iterator over the entries of the tree.
188+
``for object in Tree``
189+
190+
Return an iterator over the objects in the tree.
175191

176192
.. automethod:: pygit2.Tree.diff_to_tree
177193
.. automethod:: pygit2.Tree.diff_to_workdir
178194
.. automethod:: pygit2.Tree.diff_to_index
179195

180-
Tree entries
181-
------------
182-
183-
.. autoattribute:: pygit2.TreeEntry.name
184-
.. autoattribute:: pygit2.TreeEntry.id
185-
.. autoattribute:: pygit2.TreeEntry.hex
186-
.. autoattribute:: pygit2.TreeEntry.filemode
187-
.. autoattribute:: pygit2.TreeEntry.type
188-
.. autoattribute:: pygit2.TreeEntry.obj
189-
190-
.. method:: TreeEntry.__cmp__(TreeEntry)
191-
192-
Rich comparison between tree entries.
193-
194196
Example::
195197

196198
>>> tree = commit.tree
197199
>>> len(tree) # Number of entries
198200
6
199201

200-
>>> for entry in tree: # Iteration
201-
... print(entry.id, entry.type, entry.name)
202+
>>> for obj in tree: # Iteration
203+
... print(obj.id, obj.type_str, obj.name)
202204
...
203205
7151ca7cd3e59f3eab19c485cfbf3cb30928d7fa blob .gitignore
204206
c36f4cf1e38ec1bb9d9ad146ed572b89ecfc9f18 blob COPYING
@@ -207,13 +209,9 @@ Example::
207209
85a67270a49ef16cdd3d328f06a3e4b459f09b27 blob setup.py
208210
3d8985bbec338eb4d47c5b01b863ee89d044bd53 tree test
209211

210-
>>> entry = tree / 'pygit2.c' # Get an entry by name
211-
>>> entry
212-
<pygit2.TreeEntry object at 0xcc10f0>
213-
214-
>>> obj = entry.obj # Get the blob the entry points to
212+
>>> obj = tree / 'pygit2.c' # Get an object by name
215213
>>> obj
216-
<pygit2.Blob object at 0xcc12d0>
214+
<_pygit2.Blob at 0x7f08a70acc10>
217215

218216
Creating trees
219217
--------------------

docs/repository.rst

+21-25
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,24 @@ Functions
3939
>>> repository_path = discover_repository(current_working_directory)
4040
>>> repo = Repository(repository_path)
4141

42+
.. autofunction:: pygit2.tree_entry_cmp(object, other)
43+
4244

4345
The Repository class
4446
===================================
4547

46-
.. py:class:: pygit2.Repository(path)
48+
The API of the Repository class is quite large. Since this documentation is
49+
organized by features, the related bits are explained in the related chapters,
50+
for instance the :py:meth:`pygit2.Repository.checkout` method is explained in
51+
the Checkout section.
52+
53+
Below there are some general attributes and methods:
54+
55+
.. autoclass:: pygit2.Repository
56+
:members: ahead_behind, apply, create_reference, default_signature,
57+
descendant_of, describe, free, is_bare, is_empty, odb, path,
58+
path_is_ignored, reset, revert_commit, state_cleanup, workdir,
59+
write_archive
4760

4861
The Repository constructor only takes one argument, the path of the
4962
repository to open.
@@ -53,29 +66,12 @@ The Repository class
5366
>>> from pygit2 import Repository
5467
>>> repo = Repository('pygit2/.git')
5568

56-
The API of the Repository class is quite large. Since this documentation is
57-
organized by features, the related bits are explained in the related chapters,
58-
for instance the :py:meth:`pygit2.Repository.checkout` method is explained in
59-
the Checkout section.
6069

61-
Below there are some general attributes and methods:
70+
The Odb class
71+
===================================
72+
73+
.. autoclass:: pygit2.Odb
74+
:members:
6275

63-
.. autoattribute:: pygit2.Repository.path
64-
.. autoattribute:: pygit2.Repository.workdir
65-
.. autoattribute:: pygit2.Repository.is_bare
66-
.. autoattribute:: pygit2.Repository.is_empty
67-
.. autoattribute:: pygit2.Repository.default_signature
68-
69-
.. automethod:: pygit2.Repository.apply
70-
.. automethod:: pygit2.Repository.ahead_behind
71-
.. automethod:: pygit2.Repository.create_reference
72-
.. automethod:: pygit2.Repository.descendant_of
73-
.. automethod:: pygit2.Repository.describe
74-
.. automethod:: pygit2.Repository.free
75-
.. automethod:: pygit2.Repository.path_is_ignored
76-
.. automethod:: pygit2.Repository.read
77-
.. automethod:: pygit2.Repository.reset
78-
.. automethod:: pygit2.Repository.revert_commit
79-
.. automethod:: pygit2.Repository.state_cleanup
80-
.. automethod:: pygit2.Repository.write
81-
.. automethod:: pygit2.Repository.write_archive
76+
.. autoclass:: pygit2.OdbBackend
77+
:members:

pygit2/remote.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def _credentials_cb(cred_out, url, username, allowed, data):
304304
try:
305305
ccred = get_credentials(credentials, url, username, allowed)
306306
cred_out[0] = ccred[0]
307-
except Passthrough as e:
307+
except Passthrough:
308308
return C.GIT_PASSTHROUGH
309309
except Exception as e:
310310
self._stored_exception = e
@@ -331,7 +331,7 @@ def _certificate_cb(cert_i, valid, host, data):
331331
val = certificate_check(None, bool(valid), ffi.string(host))
332332
if not val:
333333
return C.GIT_ECERTIFICATE
334-
except Passthrough as e:
334+
except Passthrough:
335335
if is_ssh:
336336
return 0
337337
elif valid:
@@ -427,7 +427,10 @@ def fetch(self, refspecs=None, message=None, callbacks=None, prune=C.GIT_FETCH_P
427427
return TransferProgress(C.git_remote_stats(self._remote))
428428

429429
def ls_remotes(self, callbacks=None):
430-
"""Return a list of dicts that maps to `git_remote_head` from a `ls_remotes` call."""
430+
"""
431+
Return a list of dicts that maps to `git_remote_head` from a
432+
`ls_remotes` call.
433+
"""
431434

432435
self.connect(callbacks=callbacks)
433436

src/pygit2.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,12 @@ reference_is_valid_name(PyObject *self, PyObject *py_refname)
213213
PyDoc_STRVAR(tree_entry_cmp__doc__,
214214
"tree_entry_obj(a, b) -> int\n"
215215
"\n"
216+
"Rich comparison for objects, only available when the objects have been\n"
217+
"obtained through a tree. The sort criteria is the one Git uses to sort\n"
218+
"tree entries in a tree object. This function wraps git_tree_entry_cmp.\n"
219+
"\n"
216220
"Returns < 0 if a is before b, > 0 if a is after b, and 0 if a and b are\n"
217-
"the same. The sort criteria is the one Git uses to sort tree entries in\n"
218-
"a tree object. This function wraps git_tree_entry_cmp.");
221+
"the same.");
219222

220223
PyObject *
221224
tree_entry_cmp(PyObject *self, PyObject *args)

0 commit comments

Comments
 (0)