37
37
38
38
39
39
class Object (LazyMixin ):
40
- """An Object which may be Blobs, Trees, Commits and Tags."""
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`."""
41
43
42
44
NULL_HEX_SHA = "0" * 40
43
45
NULL_BIN_SHA = b"\0 " * 20
@@ -55,11 +57,14 @@ class Object(LazyMixin):
55
57
56
58
def __init__ (self , repo : "Repo" , binsha : bytes ):
57
59
"""Initialize an object by identifying it by its binary sha.
60
+
58
61
All keyword arguments will be set on demand if None.
59
62
60
- :param repo: repository this object is located in
63
+ :param repo:
64
+ Repository this object is located in.
61
65
62
- :param binsha: 20 byte SHA1
66
+ :param binsha:
67
+ 20 byte SHA1
63
68
"""
64
69
super ().__init__ ()
65
70
self .repo = repo
@@ -72,24 +77,28 @@ def __init__(self, repo: "Repo", binsha: bytes):
72
77
@classmethod
73
78
def new (cls , repo : "Repo" , id : Union [str , "Reference" ]) -> Commit_ish :
74
79
"""
75
- :return: New :class:`Object`` instance of a type appropriate to the object type
76
- behind `id`. The id of the newly created object will be a binsha even though
77
- the input id may have been a Reference or Rev-Spec.
80
+ :return:
81
+ New :class:`Object` instance of a type appropriate to the object type behind
82
+ `id`. The id of the newly created object will be a binsha even though the
83
+ input id may have been a `~git.refs.reference.Reference` or rev-spec.
78
84
79
- :param id: reference, rev-spec, or hexsha
85
+ :param id:
86
+ :class:`~git.refs.reference.Reference`, rev-spec, or hexsha
80
87
81
- :note: This cannot be a ``__new__`` method as it would always call
82
- :meth:`__init__` with the input id which is not necessarily a binsha.
88
+ :note:
89
+ This cannot be a ``__new__`` method as it would always call :meth:`__init__`
90
+ with the input id which is not necessarily a binsha.
83
91
"""
84
92
return repo .rev_parse (str (id ))
85
93
86
94
@classmethod
87
95
def new_from_sha (cls , repo : "Repo" , sha1 : bytes ) -> Commit_ish :
88
96
"""
89
- :return: new object instance of a type appropriate to represent the given
90
- binary sha1
97
+ :return:
98
+ New object instance of a type appropriate to represent the given binary sha1
91
99
92
- :param sha1: 20 byte binary sha1
100
+ :param sha1:
101
+ 20 byte binary sha1
93
102
"""
94
103
if sha1 == cls .NULL_BIN_SHA :
95
104
# The NULL binsha is always the root commit.
@@ -126,11 +135,11 @@ def __hash__(self) -> int:
126
135
return hash (self .binsha )
127
136
128
137
def __str__ (self ) -> str :
129
- """:return: string of our SHA1 as understood by all git commands"""
138
+ """:return: String of our SHA1 as understood by all git commands"""
130
139
return self .hexsha
131
140
132
141
def __repr__ (self ) -> str :
133
- """:return: string with pythonic representation of our object"""
142
+ """:return: String with pythonic representation of our object"""
134
143
return '<git.%s "%s">' % (self .__class__ .__name__ , self .hexsha )
135
144
136
145
@property
@@ -142,26 +151,32 @@ def hexsha(self) -> str:
142
151
@property
143
152
def data_stream (self ) -> "OStream" :
144
153
"""
145
- :return: File Object compatible stream to the uncompressed raw data of the object
154
+ :return:
155
+ File-object compatible stream to the uncompressed raw data of the object
146
156
147
- :note: Returned streams must be read in order.
157
+ :note:
158
+ Returned streams must be read in order.
148
159
"""
149
160
return self .repo .odb .stream (self .binsha )
150
161
151
162
def stream_data (self , ostream : "OStream" ) -> "Object" :
152
163
"""Write our data directly to the given output stream.
153
164
154
- :param ostream: File object compatible stream object.
155
- :return: self
165
+ :param ostream:
166
+ File-object compatible stream object.
167
+
168
+ :return:
169
+ self
156
170
"""
157
171
istream = self .repo .odb .stream (self .binsha )
158
172
stream_copy (istream , ostream )
159
173
return self
160
174
161
175
162
176
class IndexObject (Object ):
163
- """Base for all objects that can be part of the index file, namely Tree, Blob and
164
- SubModule objects."""
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."""
165
180
166
181
__slots__ = ("path" , "mode" )
167
182
@@ -175,16 +190,22 @@ def __init__(
175
190
mode : Union [None , int ] = None ,
176
191
path : Union [None , PathLike ] = None ,
177
192
) -> None :
178
- """Initialize a newly instanced IndexObject.
193
+ """Initialize a newly instanced :class:`IndexObject`.
194
+
195
+ :param repo:
196
+ The :class:`~git.repo.base.Repo` we are located in.
197
+
198
+ :param binsha:
199
+ 20 byte sha1.
179
200
180
- :param repo: The :class:`~git.repo.base.Repo` we are located in.
181
- :param binsha: 20 byte sha1.
182
201
:param mode:
183
202
The stat compatible file mode as int, use the :mod:`stat` module to evaluate
184
203
the information.
204
+
185
205
:param path:
186
206
The path to the file in the file system, relative to the git repository
187
207
root, like ``file.ext`` or ``folder/other.ext``.
208
+
188
209
:note:
189
210
Path may not be set if the index object has been created directly, as it
190
211
cannot be retrieved without knowing the parent tree.
@@ -198,8 +219,8 @@ def __init__(
198
219
def __hash__ (self ) -> int :
199
220
"""
200
221
:return:
201
- Hash of our path as index items are uniquely identifiable by path, not
202
- by their data!
222
+ Hash of our path as index items are uniquely identifiable by path, not by
223
+ their data!
203
224
"""
204
225
return hash (self .path )
205
226
0 commit comments