Skip to content

Commit f3b9a69

Browse files
committed
Expand docs of classes representing Git objects
This expands the docstrings of the Object base class, as well as the four leaf subclasses that represent git objects (Blob, Commit, TagObject, and Tree) to clarify those classes' relationship to git objects in general and specific types of git objects, to each other, and where applicable to types defined in git.types. This includes links to specific sections of the gitglossary(7) manpage (as hosted online), where directly applicable.
1 parent 3bd8177 commit f3b9a69

File tree

5 files changed

+65
-10
lines changed

5 files changed

+65
-10
lines changed

git/objects/base.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,33 @@
3737

3838

3939
class Object(LazyMixin):
40-
"""An Object which may be :class:`~git.objects.blob.Blob`,
41-
:class:`~git.objects.tree.Tree`, :class:`~git.objects.commit.Commit` or
42-
`~git.objects.tag.TagObject`."""
40+
"""Base class for classes representing kinds of git objects.
41+
42+
The following leaf classes represent specific kinds of git objects:
43+
44+
* :class:`Blob <git.objects.blob.Blob>`
45+
* :class:`Tree <git.objects.tree.Tree>`
46+
* :class:`Commit <git.objects.commit.Commit>`
47+
* :class:`TagObject <git.objects.tag.TagObject>`
48+
49+
See gitglossary(7) on:
50+
51+
* "object": https://git-scm.com/docs/gitglossary#def_object
52+
* "object type": https://git-scm.com/docs/gitglossary#def_object_type
53+
* "blob": https://git-scm.com/docs/gitglossary#def_blob_object
54+
* "tree object": https://git-scm.com/docs/gitglossary#def_tree_object
55+
* "commit object": https://git-scm.com/docs/gitglossary#def_commit_object
56+
* "tag object": https://git-scm.com/docs/gitglossary#def_tag_object
57+
58+
:note:
59+
See the :class:`git.types.Commit_ish` union type.
60+
61+
:note:
62+
:class:`~git.objects.submodule.base.Submodule` is defined under the hierarchy
63+
rooted at this :class:`Object` class, even though submodules are not really a
64+
kind of git object.
65+
66+
"""
4367

4468
NULL_HEX_SHA = "0" * 40
4569
NULL_BIN_SHA = b"\0" * 20
@@ -54,6 +78,20 @@ class Object(LazyMixin):
5478
__slots__ = ("repo", "binsha", "size")
5579

5680
type: Union[Lit_commit_ish, None] = None
81+
"""String identifying (a concrete :class:`Object` subtype for) a kind of git object.
82+
83+
The subtypes that this may name correspond to the kinds of git objects that exist,
84+
i.e., the objects that may be present in a git repository.
85+
86+
:note:
87+
Most subclasses represent specific types of git objects and override this class
88+
attribute accordingly. This attribute is ``None`` in the :class:`Object` base
89+
class, as well as the :class:`IndexObject` intermediate subclass, but never
90+
``None`` in concrete leaf subclasses representing specific kinds of git objects.
91+
92+
:note:
93+
See also :class:`~git.types.Commit_ish`.
94+
"""
5795

5896
def __init__(self, repo: "Repo", binsha: bytes):
5997
"""Initialize an object by identifying it by its binary sha.
@@ -174,9 +212,12 @@ def stream_data(self, ostream: "OStream") -> "Object":
174212

175213

176214
class IndexObject(Object):
177-
"""Base for all objects that can be part of the index file, namely
178-
:class:`~git.objects.tree.Tree`, :class:`~git.objects.blob.Blob` and
179-
:class:`~git.objects.submodule.base.Submodule` objects."""
215+
"""Base for all objects that can be part of the index file.
216+
217+
The classes representing kinds of git objects that can be part of the index file are
218+
:class:`~git.objects.tree.Tree and :class:`~git.objects.blob.Blob`. In addition,
219+
:class:`~git.objects.submodule.base.Submodule` is also a subclass.
220+
"""
180221

181222
__slots__ = ("path", "mode")
182223

git/objects/blob.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313

1414
class Blob(base.IndexObject):
15-
"""A Blob encapsulates a git blob object."""
15+
"""A Blob encapsulates a git blob object.
16+
17+
See gitglossary(7) on "blob": https://git-scm.com/docs/gitglossary#def_blob_object
18+
"""
1619

1720
DEFAULT_MIME_TYPE = "text/plain"
1821
type: Literal["blob"] = "blob"

git/objects/commit.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@
6060
class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
6161
"""Wraps a git commit object.
6262
63-
This class will act lazily on some of its attributes and will query the value on
64-
demand only if it involves calling the git binary.
63+
See gitglossary(7) on "commit object":
64+
https://git-scm.com/docs/gitglossary#def_commit_object
65+
66+
:note:
67+
This class will act lazily on some of its attributes and will query the value on
68+
demand only if it involves calling the git binary.
6569
"""
6670

6771
# ENVIRONMENT VARIABLES

git/objects/tag.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030

3131
class TagObject(base.Object):
3232
"""Annotated (i.e. non-lightweight) tag carrying additional information about an
33-
object we are pointing to."""
33+
object we are pointing to.
34+
35+
See gitglossary(7) on "tag object":
36+
https://git-scm.com/docs/gitglossary#def_tag_object
37+
"""
3438

3539
type: Literal["tag"] = "tag"
3640

git/objects/tree.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable):
164164
R"""Tree objects represent an ordered list of :class:`~git.objects.blob.Blob`\s and
165165
other :class:`Tree`\s.
166166
167+
See gitglossary(7) on "tree object":
168+
https://git-scm.com/docs/gitglossary#def_tree_object
169+
167170
Subscripting is supported, as with a list or dict:
168171
169172
* Access a specific blob using the ``tree["filename"]`` notation.

0 commit comments

Comments
 (0)