@@ -44,6 +44,7 @@ class RefLogEntry(Tuple[str, str, Actor, Tuple[int, int], str]):
44
44
"""Named tuple allowing easy access to the revlog data fields."""
45
45
46
46
_re_hexsha_only = re .compile (r"^[0-9A-Fa-f]{40}$" )
47
+
47
48
__slots__ = ()
48
49
49
50
def __repr__ (self ) -> str :
@@ -81,7 +82,7 @@ def actor(self) -> Actor:
81
82
82
83
@property
83
84
def time (self ) -> Tuple [int , int ]:
84
- """time as tuple:
85
+ """Time as tuple:
85
86
86
87
* [0] = ``int(time)``
87
88
* [1] = ``int(timezone_offset)`` in :attr:`time.altzone` format
@@ -113,9 +114,11 @@ def new(
113
114
def from_line (cls , line : bytes ) -> "RefLogEntry" :
114
115
""":return: New RefLogEntry instance from the given revlog line.
115
116
116
- :param line: Line bytes without trailing newline
117
+ :param line:
118
+ Line bytes without trailing newline
117
119
118
- :raise ValueError: If `line` could not be parsed
120
+ :raise ValueError:
121
+ If `line` could not be parsed.
119
122
"""
120
123
line_str = line .decode (defenc )
121
124
fields = line_str .split ("\t " , 1 )
@@ -147,9 +150,9 @@ def from_line(cls, line: bytes) -> "RefLogEntry":
147
150
148
151
149
152
class RefLog (List [RefLogEntry ], Serializable ):
150
- """A reflog contains RefLogEntrys , each of which defines a certain state
151
- of the head in question. Custom query methods allow to retrieve log entries
152
- by date or by other criteria.
153
+ R """A reflog contains :class:`RefLogEntry`\s , each of which defines a certain state
154
+ of the head in question. Custom query methods allow to retrieve log entries by date
155
+ or by other criteria.
153
156
154
157
Reflog entries are ordered. The first added entry is first in the list. The last
155
158
entry, i.e. the last change of the head or reference, is last in the list.
@@ -163,8 +166,8 @@ def __new__(cls, filepath: Union[PathLike, None] = None) -> "RefLog":
163
166
164
167
def __init__ (self , filepath : Union [PathLike , None ] = None ):
165
168
"""Initialize this instance with an optional filepath, from which we will
166
- initialize our data. The path is also used to write changes back using
167
- the write() method."""
169
+ initialize our data. The path is also used to write changes back using the
170
+ :meth:` write` method."""
168
171
self ._path = filepath
169
172
if filepath is not None :
170
173
self ._read_from_file ()
@@ -189,31 +192,40 @@ def _read_from_file(self) -> None:
189
192
@classmethod
190
193
def from_file (cls , filepath : PathLike ) -> "RefLog" :
191
194
"""
192
- :return: A new RefLog instance containing all entries from the reflog
193
- at the given filepath
194
- :param filepath: Path to reflog
195
- :raise ValueError: If the file could not be read or was corrupted in some way
195
+ :return:
196
+ A new :class:`RefLog` instance containing all entries from the reflog at the
197
+ given `filepath`.
198
+
199
+ :param filepath:
200
+ Path to reflog.
201
+
202
+ :raise ValueError:
203
+ If the file could not be read or was corrupted in some way.
196
204
"""
197
205
return cls (filepath )
198
206
199
207
@classmethod
200
208
def path (cls , ref : "SymbolicReference" ) -> str :
201
209
"""
202
- :return: String to absolute path at which the reflog of the given ref
203
- instance would be found. The path is not guaranteed to point to a valid
204
- file though.
205
- :param ref: SymbolicReference instance
210
+ :return:
211
+ String to absolute path at which the reflog of the given ref instance would
212
+ be found. The path is not guaranteed to point to a valid file though.
213
+
214
+ :param ref:
215
+ :class:`~git.refs.symbolic.SymbolicReference` instance
206
216
"""
207
217
return osp .join (ref .repo .git_dir , "logs" , to_native_path (ref .path ))
208
218
209
219
@classmethod
210
220
def iter_entries (cls , stream : Union [str , "BytesIO" , mmap ]) -> Iterator [RefLogEntry ]:
211
221
"""
212
- :return: Iterator yielding RefLogEntry instances, one for each line read
222
+ :return:
223
+ Iterator yielding :class:`RefLogEntry` instances, one for each line read
213
224
from the given stream.
214
225
215
- :param stream: File-like object containing the revlog in its native format
216
- or string instance pointing to a file to read.
226
+ :param stream:
227
+ File-like object containing the revlog in its native format or string
228
+ instance pointing to a file to read.
217
229
"""
218
230
new_entry = RefLogEntry .from_line
219
231
if isinstance (stream , str ):
@@ -233,18 +245,23 @@ def iter_entries(cls, stream: Union[str, "BytesIO", mmap]) -> Iterator[RefLogEnt
233
245
@classmethod
234
246
def entry_at (cls , filepath : PathLike , index : int ) -> "RefLogEntry" :
235
247
"""
236
- :return: RefLogEntry at the given index.
248
+ :return:
249
+ :class:`RefLogEntry` at the given index.
237
250
238
- :param filepath: Full path to the index file from which to read the entry.
251
+ :param filepath:
252
+ Full path to the index file from which to read the entry.
239
253
240
- :param index: Python list compatible index, i.e. it may be negative to
241
- specify an entry counted from the end of the list.
254
+ :param index:
255
+ Python list compatible index, i.e. it may be negative to specify an entry
256
+ counted from the end of the list.
242
257
243
- :raise IndexError: If the entry didn't exist.
258
+ :raise IndexError:
259
+ If the entry didn't exist.
244
260
245
- .. note:: This method is faster as it only parses the entry at index, skipping
246
- all other lines. Nonetheless, the whole file has to be read if
247
- the index is negative.
261
+ :note:
262
+ This method is faster as it only parses the entry at index, skipping all
263
+ other lines. Nonetheless, the whole file has to be read if the index is
264
+ negative.
248
265
"""
249
266
with open (filepath , "rb" ) as fp :
250
267
if index < 0 :
@@ -264,7 +281,8 @@ def entry_at(cls, filepath: PathLike, index: int) -> "RefLogEntry":
264
281
def to_file (self , filepath : PathLike ) -> None :
265
282
"""Write the contents of the reflog instance to a file at the given filepath.
266
283
267
- :param filepath: Path to file, parent directories are assumed to exist.
284
+ :param filepath:
285
+ Path to file. Parent directories are assumed to exist.
268
286
"""
269
287
lfd = LockedFD (filepath )
270
288
assure_directory_exists (filepath , is_file = True )
@@ -290,19 +308,32 @@ def append_entry(
290
308
) -> "RefLogEntry" :
291
309
"""Append a new log entry to the revlog at filepath.
292
310
293
- :param config_reader: Configuration reader of the repository - used to obtain
294
- user information. May also be an Actor instance identifying the committer
311
+ :param config_reader:
312
+ Configuration reader of the repository - used to obtain user information.
313
+ May also be an :class:`~git.util.Actor` instance identifying the committer
295
314
directly or None.
296
- :param filepath: Full path to the log file.
297
- :param oldbinsha: Binary sha of the previous commit.
298
- :param newbinsha: Binary sha of the current commit.
299
- :param message: Message describing the change to the reference.
300
- :param write: If True, the changes will be written right away. Otherwise the
301
- change will not be written.
302
315
303
- :return: RefLogEntry objects which was appended to the log.
316
+ :param filepath:
317
+ Full path to the log file.
318
+
319
+ :param oldbinsha:
320
+ Binary sha of the previous commit.
321
+
322
+ :param newbinsha:
323
+ Binary sha of the current commit.
324
+
325
+ :param message:
326
+ Message describing the change to the reference.
327
+
328
+ :param write:
329
+ If True, the changes will be written right away.
330
+ Otherwise the change will not be written.
331
+
332
+ :return:
333
+ :class:`RefLogEntry` objects which was appended to the log.
304
334
305
- :note: As we are append-only, concurrent access is not a problem as we do not
335
+ :note:
336
+ As we are append-only, concurrent access is not a problem as we do not
306
337
interfere with readers.
307
338
"""
308
339
@@ -340,7 +371,8 @@ def append_entry(
340
371
def write (self ) -> "RefLog" :
341
372
"""Write this instance's data to the file we are originating from.
342
373
343
- :return: self
374
+ :return:
375
+ self
344
376
"""
345
377
if self ._path is None :
346
378
raise ValueError ("Instance was not initialized with a path, use to_file(...) instead" )
0 commit comments