Skip to content

Commit d1d18c2

Browse files
committed
Revise docstrings within git.refs
1 parent d9fb2f4 commit d1d18c2

File tree

6 files changed

+283
-186
lines changed

6 files changed

+283
-186
lines changed

Diff for: git/refs/head.py

+40-32
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def __init__(self, repo: "Repo", path: PathLike = _HEAD_NAME):
5252

5353
def orig_head(self) -> SymbolicReference:
5454
"""
55-
:return: SymbolicReference pointing at the ORIG_HEAD, which is maintained
56-
to contain the previous value of HEAD.
55+
:return:
56+
:class:`~git.refs.symbolic.SymbolicReference` pointing at the ORIG_HEAD,
57+
which is maintained to contain the previous value of HEAD.
5758
"""
5859
return SymbolicReference(self.repo, self._ORIG_HEAD_NAME)
5960

@@ -66,16 +67,16 @@ def reset(
6667
**kwargs: Any,
6768
) -> "HEAD":
6869
"""Reset our HEAD to the given commit optionally synchronizing
69-
the index and working tree. The reference we refer to will be set to
70-
commit as well.
70+
the index and working tree. The reference we refer to will be set to commit as
71+
well.
7172
7273
:param commit:
73-
Commit object, Reference Object or string identifying a revision we
74-
should reset HEAD to.
74+
:class:`~git.objects.commit.Commit`, :class:`~git.refs.reference.Reference`,
75+
or string identifying a revision we should reset HEAD to.
7576
7677
:param index:
77-
If True, the index will be set to match the given commit. Otherwise
78-
it will not be touched.
78+
If True, the index will be set to match the given commit.
79+
Otherwise it will not be touched.
7980
8081
:param working_tree:
8182
If True, the working tree will be forcefully adjusted to match the given
@@ -87,7 +88,7 @@ def reset(
8788
that are to be reset. This allows to partially reset individual files.
8889
8990
:param kwargs:
90-
Additional arguments passed to git-reset.
91+
Additional arguments passed to ``git reset``.
9192
9293
:return: self
9394
"""
@@ -123,8 +124,8 @@ def reset(
123124

124125

125126
class Head(Reference):
126-
"""A Head is a named reference to a Commit. Every Head instance contains a name
127-
and a Commit object.
127+
"""A Head is a named reference to a :class:`~git.objects.commit.Commit`. Every Head
128+
instance contains a name and a :class:`~git.objects.commit.Commit` object.
128129
129130
Examples::
130131
@@ -150,9 +151,8 @@ def delete(cls, repo: "Repo", *heads: "Union[Head, str]", force: bool = False, *
150151
"""Delete the given heads.
151152
152153
:param force:
153-
If True, the heads will be deleted even if they are not yet merged into
154-
the main development stream.
155-
Default False
154+
If True, the heads will be deleted even if they are not yet merged into the
155+
main development stream. Default False.
156156
"""
157157
flag = "-d"
158158
if force:
@@ -163,9 +163,11 @@ def set_tracking_branch(self, remote_reference: Union["RemoteReference", None])
163163
"""Configure this branch to track the given remote reference. This will
164164
alter this branch's configuration accordingly.
165165
166-
:param remote_reference: The remote reference to track or None to untrack
167-
any references.
168-
:return: self
166+
:param remote_reference:
167+
The remote reference to track or None to untrack any references.
168+
169+
:return:
170+
self
169171
"""
170172
from .remote import RemoteReference
171173

@@ -190,8 +192,10 @@ def set_tracking_branch(self, remote_reference: Union["RemoteReference", None])
190192

191193
def tracking_branch(self) -> Union["RemoteReference", None]:
192194
"""
193-
:return: The remote_reference we are tracking, or None if we are
194-
not a tracking branch."""
195+
:return:
196+
The remote reference we are tracking, or None if we are not a tracking
197+
branch.
198+
"""
195199
from .remote import RemoteReference
196200

197201
reader = self.config_reader()
@@ -211,16 +215,18 @@ def rename(self, new_path: PathLike, force: bool = False) -> "Head":
211215
"""Rename self to a new path.
212216
213217
:param new_path:
214-
Either a simple name or a path, i.e. new_name or features/new_name.
215-
The prefix refs/heads is implied.
218+
Either a simple name or a path, e.g. ``new_name`` or ``features/new_name``.
219+
The prefix ``refs/heads`` is implied.
216220
217221
:param force:
218222
If True, the rename will succeed even if a head with the target name
219223
already exists.
220224
221-
:return: self
225+
:return:
226+
self
222227
223-
:note: Respects the ref log as git commands are used.
228+
:note:
229+
Respects the ref log as git commands are used.
224230
"""
225231
flag = "-m"
226232
if force:
@@ -247,15 +253,15 @@ def checkout(self, force: bool = False, **kwargs: Any) -> Union["HEAD", "Head"]:
247253
``b="new_branch"`` to create a new branch at the given spot.
248254
249255
:return:
250-
The active branch after the checkout operation, usually self unless
251-
a new branch has been created.
256+
The active branch after the checkout operation, usually self unless a new
257+
branch has been created.
252258
If there is no active branch, as the HEAD is now detached, the HEAD
253259
reference will be returned instead.
254260
255261
:note:
256-
By default it is only allowed to checkout heads - everything else
257-
will leave the HEAD detached which is allowed and possible, but remains
258-
a special state that some tools might not be able to handle.
262+
By default it is only allowed to checkout heads - everything else will leave
263+
the HEAD detached which is allowed and possible, but remains a special state
264+
that some tools might not be able to handle.
259265
"""
260266
kwargs["f"] = force
261267
if kwargs["f"] is False:
@@ -279,15 +285,17 @@ def _config_parser(self, read_only: bool) -> SectionConstraint[GitConfigParser]:
279285

280286
def config_reader(self) -> SectionConstraint[GitConfigParser]:
281287
"""
282-
:return: A configuration parser instance constrained to only read
283-
this instance's values.
288+
:return:
289+
A configuration parser instance constrained to only read this instance's
290+
values.
284291
"""
285292
return self._config_parser(read_only=True)
286293

287294
def config_writer(self) -> SectionConstraint[GitConfigParser]:
288295
"""
289-
:return: A configuration writer instance with read-and write access
290-
to options of this head.
296+
:return:
297+
A configuration writer instance with read-and write access to options of
298+
this head.
291299
"""
292300
return self._config_parser(read_only=False)
293301

Diff for: git/refs/log.py

+71-39
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class RefLogEntry(Tuple[str, str, Actor, Tuple[int, int], str]):
4444
"""Named tuple allowing easy access to the revlog data fields."""
4545

4646
_re_hexsha_only = re.compile(r"^[0-9A-Fa-f]{40}$")
47+
4748
__slots__ = ()
4849

4950
def __repr__(self) -> str:
@@ -81,7 +82,7 @@ def actor(self) -> Actor:
8182

8283
@property
8384
def time(self) -> Tuple[int, int]:
84-
"""time as tuple:
85+
"""Time as tuple:
8586
8687
* [0] = ``int(time)``
8788
* [1] = ``int(timezone_offset)`` in :attr:`time.altzone` format
@@ -113,9 +114,11 @@ def new(
113114
def from_line(cls, line: bytes) -> "RefLogEntry":
114115
""":return: New RefLogEntry instance from the given revlog line.
115116
116-
:param line: Line bytes without trailing newline
117+
:param line:
118+
Line bytes without trailing newline
117119
118-
:raise ValueError: If `line` could not be parsed
120+
:raise ValueError:
121+
If `line` could not be parsed.
119122
"""
120123
line_str = line.decode(defenc)
121124
fields = line_str.split("\t", 1)
@@ -147,9 +150,9 @@ def from_line(cls, line: bytes) -> "RefLogEntry":
147150

148151

149152
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.
153156
154157
Reflog entries are ordered. The first added entry is first in the list. The last
155158
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":
163166

164167
def __init__(self, filepath: Union[PathLike, None] = None):
165168
"""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."""
168171
self._path = filepath
169172
if filepath is not None:
170173
self._read_from_file()
@@ -189,31 +192,40 @@ def _read_from_file(self) -> None:
189192
@classmethod
190193
def from_file(cls, filepath: PathLike) -> "RefLog":
191194
"""
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.
196204
"""
197205
return cls(filepath)
198206

199207
@classmethod
200208
def path(cls, ref: "SymbolicReference") -> str:
201209
"""
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
206216
"""
207217
return osp.join(ref.repo.git_dir, "logs", to_native_path(ref.path))
208218

209219
@classmethod
210220
def iter_entries(cls, stream: Union[str, "BytesIO", mmap]) -> Iterator[RefLogEntry]:
211221
"""
212-
:return: Iterator yielding RefLogEntry instances, one for each line read
222+
:return:
223+
Iterator yielding :class:`RefLogEntry` instances, one for each line read
213224
from the given stream.
214225
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.
217229
"""
218230
new_entry = RefLogEntry.from_line
219231
if isinstance(stream, str):
@@ -233,18 +245,23 @@ def iter_entries(cls, stream: Union[str, "BytesIO", mmap]) -> Iterator[RefLogEnt
233245
@classmethod
234246
def entry_at(cls, filepath: PathLike, index: int) -> "RefLogEntry":
235247
"""
236-
:return: RefLogEntry at the given index.
248+
:return:
249+
:class:`RefLogEntry` at the given index.
237250
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.
239253
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.
242257
243-
:raise IndexError: If the entry didn't exist.
258+
:raise IndexError:
259+
If the entry didn't exist.
244260
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.
248265
"""
249266
with open(filepath, "rb") as fp:
250267
if index < 0:
@@ -264,7 +281,8 @@ def entry_at(cls, filepath: PathLike, index: int) -> "RefLogEntry":
264281
def to_file(self, filepath: PathLike) -> None:
265282
"""Write the contents of the reflog instance to a file at the given filepath.
266283
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.
268286
"""
269287
lfd = LockedFD(filepath)
270288
assure_directory_exists(filepath, is_file=True)
@@ -290,19 +308,32 @@ def append_entry(
290308
) -> "RefLogEntry":
291309
"""Append a new log entry to the revlog at filepath.
292310
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
295314
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.
302315
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.
304334
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
306337
interfere with readers.
307338
"""
308339

@@ -340,7 +371,8 @@ def append_entry(
340371
def write(self) -> "RefLog":
341372
"""Write this instance's data to the file we are originating from.
342373
343-
:return: self
374+
:return:
375+
self
344376
"""
345377
if self._path is None:
346378
raise ValueError("Instance was not initialized with a path, use to_file(...) instead")

0 commit comments

Comments
 (0)