Skip to content

Commit 1b25a13

Browse files
committed
Further revise docstrings within git.index
1 parent fc1762b commit 1b25a13

File tree

3 files changed

+99
-88
lines changed

3 files changed

+99
-88
lines changed

Diff for: git/index/base.py

+77-70
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# This module is part of GitPython and is released under the
44
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
55

6-
"""Module containing IndexFile, an Index implementation facilitating all kinds of index
7-
manipulations such as querying and merging."""
6+
"""Module containing :class:`IndexFile`, an Index implementation facilitating all kinds
7+
of index manipulations such as querying and merging."""
88

99
import contextlib
1010
import datetime
@@ -125,9 +125,9 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable):
125125
git command function calls wherever possible.
126126
127127
This provides custom merging facilities allowing to merge without actually changing
128-
your index or your working tree. This way you can perform own test-merges based on
129-
the index only without having to deal with the working copy. This is useful in case
130-
of partial working trees.
128+
your index or your working tree. This way you can perform your own test merges based
129+
on the index only without having to deal with the working copy. This is useful in
130+
case of partial working trees.
131131
132132
Entries:
133133
@@ -211,7 +211,7 @@ def _deserialize(self, stream: IO) -> "IndexFile":
211211
return self
212212

213213
def _entries_sorted(self) -> List[IndexEntry]:
214-
""":return: list of entries, in a sorted fashion, first by path, then by stage"""
214+
""":return: List of entries, in a sorted fashion, first by path, then by stage"""
215215
return sorted(self.entries.values(), key=lambda e: (e.path, e.stage))
216216

217217
def _serialize(self, stream: IO, ignore_extension_data: bool = False) -> "IndexFile":
@@ -232,17 +232,17 @@ def write(
232232
"""Write the current state to our file path or to the given one.
233233
234234
:param file_path:
235-
If None, we will write to our stored file path from which we have been
235+
If ``None``, we will write to our stored file path from which we have been
236236
initialized. Otherwise we write to the given file path. Please note that
237-
this will change the file_path of this index to the one you gave.
237+
this will change the `file_path` of this index to the one you gave.
238238
239239
:param ignore_extension_data:
240-
If True, the TREE type extension data read in the index will not be written
241-
to disk. NOTE that no extension data is actually written.
242-
Use this if you have altered the index and would like to use git-write-tree
243-
afterwards to create a tree representing your written changes.
244-
If this data is present in the written index, git-write-tree will instead
245-
write the stored/cached tree.
240+
If ``True``, the TREE type extension data read in the index will not be
241+
written to disk. NOTE that no extension data is actually written.
242+
Use this if you have altered the index and would like to use
243+
``git write-tree`` afterwards to create a tree representing your written
244+
changes. If this data is present in the written index, ``git write-tree``
245+
will instead write the stored/cached tree.
246246
Alternatively, use :meth:`write_tree` to handle this case automatically.
247247
"""
248248
# Make sure we have our entries read before getting a write lock.
@@ -479,8 +479,8 @@ def _write_path_to_stdin(
479479
stdout string
480480
481481
:param read_from_stdout:
482-
If True, proc.stdout will be read after the item was sent to stdin. In that
483-
case, it will return None.
482+
If ``True``, ``proc.stdout`` will be read after the item was sent to stdin.
483+
In that case, it will return ``None``.
484484
485485
:note:
486486
There is a bug in git-update-index that prevents it from sending reports
@@ -516,12 +516,13 @@ def iter_blobs(
516516
) -> Iterator[Tuple[StageType, Blob]]:
517517
"""
518518
:return:
519-
Iterator yielding tuples of Blob objects and stages, tuple(stage, Blob).
519+
Iterator yielding tuples of :class:`~git.objects.blob.Blob` objects and
520+
stages, tuple(stage, Blob).
520521
521522
:param predicate:
522-
Function(t) returning True if tuple(stage, Blob) should be yielded by the
523-
iterator. A default filter, the `~git.index.typ.BlobFilter`, allows you to
524-
yield blobs only if they match a given list of paths.
523+
Function(t) returning ``True`` if tuple(stage, Blob) should be yielded by
524+
the iterator. A default filter, the `~git.index.typ.BlobFilter`, allows you
525+
to yield blobs only if they match a given list of paths.
525526
"""
526527
for entry in self.entries.values():
527528
blob = entry.to_blob(self.repo)
@@ -534,8 +535,8 @@ def iter_blobs(
534535
def unmerged_blobs(self) -> Dict[PathLike, List[Tuple[StageType, Blob]]]:
535536
"""
536537
:return:
537-
Dict(path : list( tuple( stage, Blob, ...))), being a dictionary associating
538-
a path in the index with a list containing sorted stage/blob pairs.
538+
Dict(path : list(tuple(stage, Blob, ...))), being a dictionary associating a
539+
path in the index with a list containing sorted stage/blob pairs.
539540
540541
:note:
541542
Blobs that have been removed in one side simply do not exist in the given
@@ -562,8 +563,8 @@ def resolve_blobs(self, iter_blobs: Iterator[Blob]) -> "IndexFile":
562563
This will effectively remove the index entries of the respective path at all
563564
non-null stages and add the given blob as new stage null blob.
564565
565-
For each path there may only be one blob, otherwise a ValueError will be raised
566-
claiming the path is already at stage 0.
566+
For each path there may only be one blob, otherwise a :class:`ValueError` will
567+
be raised claiming the path is already at stage 0.
567568
568569
:raise ValueError:
569570
If one of the blobs already existed at stage 0.
@@ -603,7 +604,8 @@ def update(self) -> "IndexFile":
603604
This is a possibly dangerous operations as it will discard your changes to
604605
:attr:`index.entries <entries>`.
605606
606-
:return: self
607+
:return:
608+
self
607609
"""
608610
self._delete_entries_cache()
609611
# Allows to lazily reread on demand.
@@ -654,8 +656,9 @@ def _process_diff_args(
654656

655657
def _to_relative_path(self, path: PathLike) -> PathLike:
656658
"""
657-
:return: Version of path relative to our git directory or raise
658-
:class:`ValueError` if it is not within our git directory.
659+
:return:
660+
Version of path relative to our git directory or raise :class:`ValueError`
661+
if it is not within our git directory.
659662
660663
:raise ValueError:
661664
"""
@@ -693,7 +696,7 @@ def _store_path(self, filepath: PathLike, fprogress: Callable) -> BaseIndexEntry
693696
"""Store file at filepath in the database and return the base index entry.
694697
695698
:note:
696-
This needs the git_working_dir decorator active!
699+
This needs the :func:`~git.index.util.git_working_dir` decorator active!
697700
This must be ensured in the calling code.
698701
"""
699702
st = os.lstat(filepath) # Handles non-symlinks as well.
@@ -810,33 +813,36 @@ def add(
810813
The handling now very much equals the way string paths are processed,
811814
except that the mode you have set will be kept. This allows you to
812815
create symlinks by settings the mode respectively and writing the target
813-
of the symlink directly into the file. This equals a default
814-
Linux symlink which is not dereferenced automatically, except that it
815-
can be created on filesystems not supporting it as well.
816+
of the symlink directly into the file. This equals a default Linux
817+
symlink which is not dereferenced automatically, except that it can be
818+
created on filesystems not supporting it as well.
816819
817820
Please note that globs or directories are not allowed in
818-
:class:~`git.objects.blob.Blob` objects.
821+
:class:`~git.objects.blob.Blob` objects.
819822
820823
They are added at stage 0.
821824
822825
- :class:`~git.index.typ.BaseIndexEntry` or type
823826
824-
Handling equals the one of Blob objects, but the stage may be explicitly
825-
set. Please note that Index Entries require binary sha's.
827+
Handling equals the one of :class:~`git.objects.blob.Blob` objects, but
828+
the stage may be explicitly set. Please note that Index Entries require
829+
binary sha's.
826830
827831
:param force:
828832
**CURRENTLY INEFFECTIVE**
829-
If True, otherwise ignored or excluded files will be added anyway.
830-
As opposed to the ``git add`` command, we enable this flag by default as the
833+
If ``True``, otherwise ignored or excluded files will be added anyway. As
834+
opposed to the ``git add`` command, we enable this flag by default as the
831835
API user usually wants the item to be added even though they might be
832836
excluded.
833837
834838
:param fprogress:
835839
Function with signature ``f(path, done=False, item=item)`` called for each
836840
path to be added, one time once it is about to be added where ``done=False``
837841
and once after it was added where ``done=True``.
838-
``item`` is set to the actual item we handle, either a Path or a
842+
843+
``item`` is set to the actual item we handle, either a path or a
839844
:class:`~git.index.typ.BaseIndexEntry`.
845+
840846
Please note that the processed path is not guaranteed to be present in the
841847
index already as the index is currently being processed.
842848
@@ -845,24 +851,24 @@ def add(
845851
for each passed entry which is the path to be actually recorded for the
846852
object created from :attr:`entry.path <git.index.typ.BaseIndexEntry.path>`.
847853
This allows you to write an index which is not identical to the layout of
848-
the actual files on your hard-disk. If not None and `items` contain plain
849-
paths, these paths will be converted to Entries beforehand and passed to the
850-
path_rewriter. Please note that ``entry.path`` is relative to the git
854+
the actual files on your hard-disk. If not ``None`` and `items` contain
855+
plain paths, these paths will be converted to Entries beforehand and passed
856+
to the path_rewriter. Please note that ``entry.path`` is relative to the git
851857
repository.
852858
853859
:param write:
854-
If True, the index will be written once it was altered. Otherwise the
860+
If ``True``, the index will be written once it was altered. Otherwise the
855861
changes only exist in memory and are not available to git commands.
856862
857863
:param write_extension_data:
858-
If True, extension data will be written back to the index. This can lead to
859-
issues in case it is containing the 'TREE' extension, which will cause the
860-
``git commit`` command to write an old tree, instead of a new one
864+
If ``True``, extension data will be written back to the index. This can lead
865+
to issues in case it is containing the 'TREE' extension, which will cause
866+
the ``git commit`` command to write an old tree, instead of a new one
861867
representing the now changed index.
862868
863869
This doesn't matter if you use :meth:`IndexFile.commit`, which ignores the
864-
'TREE' extension altogether. You should set it to True if you intend to use
865-
:meth:`IndexFile.commit` exclusively while maintaining support for
870+
'TREE' extension altogether. You should set it to ``True`` if you intend to
871+
use :meth:`IndexFile.commit` exclusively while maintaining support for
866872
third-party extensions. Besides that, you can usually safely ignore the
867873
built-in extensions when using GitPython on repositories that are not
868874
handled manually at all.
@@ -875,7 +881,7 @@ def add(
875881
just actually added.
876882
877883
:raise OSError:
878-
If a supplied Path did not exist. Please note that
884+
If a supplied path did not exist. Please note that
879885
:class:`~git.index.typ.BaseIndexEntry` objects that do not have a null sha
880886
will be added even if their paths do not exist.
881887
"""
@@ -999,7 +1005,7 @@ def remove(
9991005
it. If absolute paths are given, they will be converted to a path
10001006
relative to the git repository directory containing the working tree
10011007
1002-
The path string may include globs, such as \*.c.
1008+
The path string may include globs, such as ``*.c``.
10031009
10041010
- :class:~`git.objects.blob.Blob` object
10051011
@@ -1010,9 +1016,9 @@ def remove(
10101016
The only relevant information here is the path. The stage is ignored.
10111017
10121018
:param working_tree:
1013-
If True, the entry will also be removed from the working tree, physically
1014-
removing the respective file. This may fail if there are uncommitted changes
1015-
in it.
1019+
If ``True``, the entry will also be removed from the working tree,
1020+
physically removing the respective file. This may fail if there are
1021+
uncommitted changes in it.
10161022
10171023
:param kwargs:
10181024
Additional keyword arguments to be passed to ``git rm``, such as ``r`` to
@@ -1061,7 +1067,7 @@ def move(
10611067
for reference.
10621068
10631069
:param skip_errors:
1064-
If True, errors such as ones resulting from missing source files will be
1070+
If ``True``, errors such as ones resulting from missing source files will be
10651071
skipped.
10661072
10671073
:param kwargs:
@@ -1214,21 +1220,21 @@ def checkout(
12141220
case you have altered the entries dictionary directly.
12151221
12161222
:param paths:
1217-
If None, all paths in the index will be checked out. Otherwise an iterable
1218-
of relative or absolute paths or a single path pointing to files or
1219-
directories in the index is expected.
1223+
If ``None``, all paths in the index will be checked out.
1224+
Otherwise an iterable of relative or absolute paths or a single path
1225+
pointing to files or directories in the index is expected.
12201226
12211227
:param force:
1222-
If True, existing files will be overwritten even if they contain local
1228+
If ``True``, existing files will be overwritten even if they contain local
12231229
modifications.
1224-
If False, these will trigger a :class:`~git.exc.CheckoutError`.
1230+
If ``False``, these will trigger a :class:`~git.exc.CheckoutError`.
12251231
12261232
:param fprogress:
12271233
See :meth:`IndexFile.add` for signature and explanation.
12281234
1229-
The provided progress information will contain None as path and item if no
1230-
explicit paths are given. Otherwise progress information will be send prior
1231-
and after a file has been checked out.
1235+
The provided progress information will contain ``None`` as path and item if
1236+
no explicit paths are given. Otherwise progress information will be send
1237+
prior and after a file has been checked out.
12321238
12331239
:param kwargs:
12341240
Additional arguments to be passed to ``git checkout-index``.
@@ -1238,10 +1244,10 @@ def checkout(
12381244
guaranteed to match the version stored in the index.
12391245
12401246
:raise git.exc.CheckoutError:
1241-
If at least one file failed to be checked out. This is a summary, hence it
1242-
will checkout as many files as it can anyway.
1243-
If one of files or directories do not exist in the index (as opposed to the
1244-
original git command, which ignores them).
1247+
* If at least one file failed to be checked out. This is a summary, hence it
1248+
will checkout as many files as it can anyway.
1249+
* If one of files or directories do not exist in the index (as opposed to
1250+
the original git command, which ignores them).
12451251
12461252
:raise git.exc.GitCommandError:
12471253
If error lines could not be parsed - this truly is an exceptional state.
@@ -1394,7 +1400,7 @@ def reset(
13941400
**kwargs: Any,
13951401
) -> "IndexFile":
13961402
"""Reset the index to reflect the tree at the given commit. This will not adjust
1397-
our ``HEAD`` reference by default, as opposed to
1403+
our HEAD reference by default, as opposed to
13981404
:meth:`HEAD.reset <git.refs.head.HEAD.reset>`.
13991405
14001406
:param commit:
@@ -1406,14 +1412,14 @@ def reset(
14061412
overwrite the default index.
14071413
14081414
:param working_tree:
1409-
If True, the files in the working tree will reflect the changed index.
1410-
If False, the working tree will not be touched.
1415+
If ``True``, the files in the working tree will reflect the changed index.
1416+
If ``False``, the working tree will not be touched.
14111417
Please note that changes to the working copy will be discarded without
14121418
warning!
14131419
14141420
:param head:
1415-
If True, the head will be set to the given commit. This is False by default,
1416-
but if True, this method behaves like
1421+
If ``True``, the head will be set to the given commit. This is ``False`` by
1422+
default, but if ``True``, this method behaves like
14171423
:meth:`HEAD.reset <git.refs.head.HEAD.reset>`.
14181424
14191425
:param paths:
@@ -1433,7 +1439,8 @@ def reset(
14331439
If you want ``git reset``-like behaviour, use
14341440
:meth:`HEAD.reset <git.refs.head.HEAD.reset>` instead.
14351441
1436-
:return: self
1442+
:return:
1443+
self
14371444
"""
14381445
# What we actually want to do is to merge the tree into our existing index,
14391446
# which is what git-read-tree does.

Diff for: git/index/fun.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ def read_header(stream: IO[bytes]) -> Tuple[int, int]:
222222
def entry_key(*entry: Union[BaseIndexEntry, PathLike, int]) -> Tuple[PathLike, int]:
223223
"""
224224
:return:
225-
Key suitable to be used for the :attr:`index.entries
226-
<git.index.base.IndexFile.entries>` dictionary.
225+
Key suitable to be used for the
226+
:attr:`index.entries <git.index.base.IndexFile.entries>` dictionary.
227227
228228
:param entry:
229229
One instance of type BaseIndexEntry or the path and the stage.

0 commit comments

Comments
 (0)