Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise docstrings, comments, and a few messages #1850

Merged
merged 61 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9b5531b
Fix typos and further clarify Git.refresh docstring
EliahKagan Feb 24, 2024
c0cd8a8
Clarify comment on shell case in _safer_popen_windows
EliahKagan Feb 24, 2024
afd943a
Tweak message about GIT_PYTHON_REFRESH for 80-column terminals
EliahKagan Feb 24, 2024
e08066c
Revise docstrings in git.__init__ and git.cmd
EliahKagan Feb 24, 2024
8bb882e
Fix concurrency note for stream_object_data
EliahKagan Feb 24, 2024
ba878ef
Reword partial_to_complete_sha_hex note
EliahKagan Feb 24, 2024
3958747
Update CommandError._msg documentation
EliahKagan Feb 24, 2024
f56e1ac
Tweak code formatting in Remote._set_cache_
EliahKagan Feb 24, 2024
fa471fe
Fix up Remote.push docstring
EliahKagan Feb 24, 2024
1cd73ba
Revise docstrings in second-level modules
EliahKagan Feb 25, 2024
29c63ac
Format first Git.execute overload stub like the others
EliahKagan Feb 25, 2024
cd8a312
Show full-path refresh() in failure message differently
EliahKagan Feb 25, 2024
8ec7e32
Revise docstrings within git.index
EliahKagan Feb 26, 2024
ca2ab61
Rewrite post_clear_cache note
EliahKagan Feb 26, 2024
37421e1
Further revise post_clear_cache docstring
EliahKagan Feb 26, 2024
ca32c22
Condense output_stream description in Git.execute docstring
EliahKagan Feb 26, 2024
3813bfb
Clarify Submodule.branch_path documentation
EliahKagan Feb 26, 2024
63c62ed
Revise docstrings within git.objects.submodule
EliahKagan Feb 27, 2024
115451d
Change _write to write in SubmoduleConfigParser docstring
EliahKagan Feb 27, 2024
5219489
Fix IndexObject.abspath docstring formatting
EliahKagan Feb 27, 2024
c06dfd9
Fix parameter names in TagObject.__init__
EliahKagan Feb 27, 2024
ae37a4a
Revise docstrings within git.objects
EliahKagan Feb 27, 2024
37011bf
Fix backslash formatting in git.util docstrings
EliahKagan Feb 27, 2024
d9fb2f4
Further git.util docstring revisions
EliahKagan Feb 27, 2024
d1d18c2
Revise docstrings within git.refs
EliahKagan Feb 27, 2024
4f67369
Fix backslashes in Repo.__init__ docstring
EliahKagan Feb 27, 2024
0c8ca1a
Fix Repo.iter_commits docstring about return type
EliahKagan Feb 27, 2024
b2b6f7c
Revise docstrings within git.repo
EliahKagan Feb 28, 2024
c67b2e2
Adjust spacing in colon seach mode NotImplementedError
EliahKagan Feb 28, 2024
5ee8744
Update git source link in Repo.merge_base comment
EliahKagan Feb 28, 2024
c8b6cf0
Update comment about improving expand_path overloads
EliahKagan Feb 28, 2024
bcc0c27
Fix recent inconsistency, using :raise:, not :raises:
EliahKagan Feb 28, 2024
0231b74
Further revise docstrings in git.objects.submodule.base
EliahKagan Feb 28, 2024
8344f44
Revise Repo.archive docstring
EliahKagan Feb 28, 2024
432ec72
Fix another :raises: to :raise:
EliahKagan Feb 28, 2024
5ca5844
Fully qualify non-builtin exceptions in :raise:
EliahKagan Feb 28, 2024
e6768ec
Improve Git.execute docstring formatting re: max_chunk_size
EliahKagan Feb 28, 2024
cd61eb4
Further revise docstrings in second-level modules
EliahKagan Feb 28, 2024
fc1762b
Undo a couple minor black-incompatible changes
EliahKagan Feb 28, 2024
1b25a13
Further revise docstrings within git.index
EliahKagan Feb 28, 2024
08a80aa
Further revise docstrings within git.objects.submodule
EliahKagan Feb 28, 2024
bc48d26
Further revise other docstrings within git.objects
EliahKagan Feb 28, 2024
30f7da5
Fix erroneous reference to DateTime "class"
EliahKagan Feb 28, 2024
6126997
Improve docstrings about tags
EliahKagan Feb 29, 2024
110706e
Fix param name in TagRefernece docstring and add info
EliahKagan Feb 29, 2024
b0e5bff
Undo some expansion of "reference" parameter
EliahKagan Feb 29, 2024
a5a1b2c
Add a bit of missing docstring formatting
EliahKagan Feb 29, 2024
018ebaf
Further revise docstrings within git.repo
EliahKagan Feb 29, 2024
608147e
Better explain conditional cleanup in test_base_object
EliahKagan Feb 29, 2024
5cf5b60
Revise test suite docstrings and comments
EliahKagan Feb 29, 2024
4b04d8a
Better clarify Submodule.branch_path documentation
EliahKagan Feb 29, 2024
254c82a
More docstring revisions within git.refs
EliahKagan Feb 29, 2024
679d2e8
Fix exception type in require_remote_ref_path docstring
EliahKagan Feb 29, 2024
ee0301a
More docstring revisions in second-level modules and git.__init__
EliahKagan Feb 29, 2024
231c3ef
More docstring revisions within git.repo
EliahKagan Feb 29, 2024
e166a0a
More docstring revisions within git.objects
EliahKagan Feb 29, 2024
ffeb7e7
More docstring revisions in git.objects.submodule.base
EliahKagan Feb 29, 2024
ec93955
Further refine some docstring revisions
EliahKagan Feb 29, 2024
63983c2
Remove note in GitCmdObjectDB docstring
EliahKagan Feb 29, 2024
f43292e
Somewhat improve _get_ref_info{,_helper} docstrings
EliahKagan Feb 29, 2024
37c93de
A couple more small docstring refinements
EliahKagan Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,23 @@
def refresh(path: Optional[PathLike] = None) -> None:
"""Convenience method for setting the git executable path.

:param path: Optional path to the Git executable. If not absolute, it is resolved
:param path:
Optional path to the Git executable. If not absolute, it is resolved
immediately, relative to the current directory.

:note: The *path* parameter is usually omitted and cannot be used to specify a
custom command whose location is looked up in a path search on each call. See
:meth:`Git.refresh` for details on how to achieve this.
:note:
The `path` parameter is usually omitted and cannot be used to specify a custom
command whose location is looked up in a path search on each call. See
:meth:`Git.refresh <git.cmd.Git.refresh>` for details on how to achieve this.

:note: This calls :meth:`Git.refresh` and sets other global configuration according
to the effect of doing so. As such, this function should usually be used instead
of using :meth:`Git.refresh` or :meth:`FetchInfo.refresh` directly.
:note:
This calls :meth:`Git.refresh <git.cmd.Git.refresh>` and sets other global
configuration according to the effect of doing so. As such, this function should
usually be used instead of using :meth:`Git.refresh <git.cmd.Git.refresh>` or
:meth:`FetchInfo.refresh <git.remote.FetchInfo.refresh>` directly.

:note: This function is called automatically, with no arguments, at import time.
:note:
This function is called automatically, with no arguments, at import time.
"""
global GIT_OK
GIT_OK = False
Expand Down
353 changes: 204 additions & 149 deletions git/cmd.py

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions git/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
:attr:`sys.platform` checks explicitly, especially in cases where it matters which is
used.

:note: ``is_win`` is ``False`` on Cygwin, but is often wrongly assumed ``True``. To
detect Cygwin, use ``sys.platform == "cygwin"``.
:note:
``is_win`` is ``False`` on Cygwin, but is often wrongly assumed ``True``. To detect
Cygwin, use ``sys.platform == "cygwin"``.
"""

is_posix = os.name == "posix"
Expand All @@ -46,9 +47,10 @@
:attr:`sys.platform` checks explicitly, especially in cases where it matters which is
used.

:note: For POSIX systems, more detailed information is available in
:attr:`sys.platform`, while :attr:`os.name` is always ``"posix"`` on such systems,
including macOS (Darwin).
:note:
For POSIX systems, more detailed information is available in :attr:`sys.platform`,
while :attr:`os.name` is always ``"posix"`` on such systems, including macOS
(Darwin).
"""

is_darwin = sys.platform == "darwin"
Expand All @@ -57,7 +59,8 @@
This is deprecated because it clearer to write out :attr:`os.name` or
:attr:`sys.platform` checks explicitly.

:note: For macOS (Darwin), ``os.name == "posix"`` as in other Unix-like systems, while
:note:
For macOS (Darwin), ``os.name == "posix"`` as in other Unix-like systems, while
``sys.platform == "darwin"`.
"""

Expand Down
182 changes: 111 additions & 71 deletions git/config.py

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions git/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class GitCmdObjectDB(LooseObjectDB):
objects, pack files and an alternates file.

It will create objects only in the loose object database.

:note: For now, we use the git command to do all the lookup, just until we
have packs and the other implementations.
"""

def __init__(self, root_path: PathLike, git: "Git") -> None:
Expand All @@ -53,13 +50,16 @@ def stream(self, binsha: bytes) -> OStream:

def partial_to_complete_sha_hex(self, partial_hexsha: str) -> bytes:
"""
:return: Full binary 20 byte sha from the given partial hexsha
:return:
Full binary 20 byte sha from the given partial hexsha

:raise gitdb.exc.AmbiguousObjectName:

:raise AmbiguousObjectName:
:raise BadObject:
:raise gitdb.exc.BadObject:

:note: Currently we only raise :class:`BadObject` as git does not communicate
AmbiguousObjects separately.
:note:
Currently we only raise :class:`~gitdb.exc.BadObject` as git does not
communicate ambiguous objects separately.
"""
try:
hexsha, _typename, _size = self._git.get_object_header(partial_hexsha)
Expand Down
98 changes: 58 additions & 40 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ class Diffable:
compatible type.

:note:
Subclasses require a repo member as it is the case for Object instances, for
practical reasons we do not derive from Object.
Subclasses require a repo member as it is the case for
:class:`~git.objects.base.Object` instances, for practical reasons we do not
derive from :class:`~git.objects.base.Object`.
"""

__slots__ = ()
Expand All @@ -111,37 +112,38 @@ def diff(
create_patch: bool = False,
**kwargs: Any,
) -> "DiffIndex":
"""Create diffs between two items being trees, trees and index or an
index and the working tree. Detects renames automatically.
"""Create diffs between two items being trees, trees and index or an index and
the working tree. Detects renames automatically.

:param other:
This the item to compare us with.

* If None, we will be compared to the working tree.
* If ``None``, we will be compared to the working tree.
* If :class:`~git.index.base.Treeish`, it will be compared against the
respective tree.
* If :class:`~Diffable.Index`, it will be compared against the index.
* If :class:`Diffable.Index`, it will be compared against the index.
* If :attr:`git.NULL_TREE`, it will compare against the empty tree.
* It defaults to :class:`~Diffable.Index` so that the method will not by
* It defaults to :class:`Diffable.Index` so that the method will not by
default fail on bare repositories.

:param paths:
This a list of paths or a single path to limit the diff to. It will only
include at least one of the given path or paths.

:param create_patch:
If True, the returned :class:`Diff` contains a detailed patch that if
If ``True``, the returned :class:`Diff` contains a detailed patch that if
applied makes the self to other. Patches are somewhat costly as blobs have
to be read and diffed.

:param kwargs:
Additional arguments passed to git-diff, such as ``R=True`` to swap both
Additional arguments passed to ``git diff``, such as ``R=True`` to swap both
sides of the diff.

:return: git.DiffIndex
:return:
:class:`DiffIndex`

:note:
On a bare repository, 'other' needs to be provided as
On a bare repository, `other` needs to be provided as
:class:`~Diffable.Index`, or as :class:`~git.objects.tree.Tree` or
:class:`~git.objects.commit.Commit`, or a git command error will occur.
"""
Expand Down Expand Up @@ -183,7 +185,7 @@ def diff(

args.insert(0, self)

# paths is list here, or None.
# paths is a list here, or None.
if paths:
args.append("--")
args.extend(paths)
Expand All @@ -203,7 +205,7 @@ def diff(


class DiffIndex(List[T_Diff]):
"""An Index for diffs, allowing a list of Diffs to be queried by the diff
R"""An Index for diffs, allowing a list of :class:`Diff`\s to be queried by the diff
properties.

The class improves the diff handling convenience.
Expand Down Expand Up @@ -255,34 +257,34 @@ def iter_change_type(self, change_type: Lit_change_type) -> Iterator[T_Diff]:
class Diff:
"""A Diff contains diff information between two Trees.

It contains two sides a and b of the diff, members are prefixed with
"a" and "b" respectively to indicate that.
It contains two sides a and b of the diff. Members are prefixed with "a" and "b"
respectively to indicate that.

Diffs keep information about the changed blob objects, the file mode, renames,
deletions and new files.

There are a few cases where None has to be expected as member variable value:
There are a few cases where ``None`` has to be expected as member variable value:

``New File``::
New File::

a_mode is None
a_blob is None
a_path is None

``Deleted File``::
Deleted File::

b_mode is None
b_blob is None
b_path is None

``Working Tree Blobs``
Working Tree Blobs:

When comparing to working trees, the working tree blob will have a null hexsha
as a corresponding object does not yet exist. The mode will be null as well.
The path will be available, though.
as a corresponding object does not yet exist. The mode will be null as well. The
path will be available, though.

If it is listed in a diff, the working tree version of the file must
differ from the version in the index or tree, and hence has been modified.
If it is listed in a diff, the working tree version of the file must differ from
the version in the index or tree, and hence has been modified.
"""

# Precompiled regex.
Expand Down Expand Up @@ -466,17 +468,20 @@ def rename_to(self) -> Optional[str]:

@property
def renamed(self) -> bool:
"""
:return: True if the blob of our diff has been renamed
"""Deprecated, use :attr:`renamed_file` instead.

:return:
``True`` if the blob of our diff has been renamed

:note: This property is deprecated.
:note:
This property is deprecated.
Please use the :attr:`renamed_file` property instead.
"""
return self.renamed_file

@property
def renamed_file(self) -> bool:
""":return: True if the blob of our diff has been renamed"""
""":return: ``True`` if the blob of our diff has been renamed"""
return self.rename_from != self.rename_to

@classmethod
Expand All @@ -494,11 +499,18 @@ def _pick_best_path(cls, path_match: bytes, rename_match: bytes, path_fallback_m

@classmethod
def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoInterrupt"]) -> DiffIndex:
"""Create a new DiffIndex from the given process output which must be in patch format.
"""Create a new :class:`DiffIndex` from the given process output which must be
in patch format.

:param repo:
The repository we are operating on.

:param repo: The repository we are operating on
:param proc: ``git diff`` process to read from (supports :class:`Git.AutoInterrupt` wrapper)
:return: git.DiffIndex
:param proc:
``git diff`` process to read from
(supports :class:`Git.AutoInterrupt <git.cmd.Git.AutoInterrupt>` wrapper).

:return:
:class:`DiffIndex`
"""

# FIXME: Here SLURPING raw, need to re-phrase header-regexes linewise.
Expand Down Expand Up @@ -539,14 +551,14 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn
a_path = cls._pick_best_path(a_path, rename_from, a_path_fallback)
b_path = cls._pick_best_path(b_path, rename_to, b_path_fallback)

# Our only means to find the actual text is to see what has not been matched by our regex,
# and then retro-actively assign it to our index.
# Our only means to find the actual text is to see what has not been matched
# by our regex, and then retro-actively assign it to our index.
if previous_header is not None:
index[-1].diff = text[previous_header.end() : _header.start()]
# END assign actual diff

# Make sure the mode is set if the path is set. Otherwise the resulting blob is invalid.
# We just use the one mode we should have parsed.
# Make sure the mode is set if the path is set. Otherwise the resulting blob
# is invalid. We just use the one mode we should have parsed.
a_mode = old_mode or deleted_file_mode or (a_path and (b_mode or new_mode or new_file_mode))
b_mode = b_mode or new_mode or new_file_mode or (b_path and a_mode)
index.append(
Expand Down Expand Up @@ -610,7 +622,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> Non
rename_from = None
rename_to = None

# NOTE: We cannot conclude from the existence of a blob to change type
# NOTE: We cannot conclude from the existence of a blob to change type,
# as diffs with the working do not have blobs yet.
if change_type == "D":
b_blob_id = None # Optional[str]
Expand Down Expand Up @@ -654,11 +666,17 @@ def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> Non

@classmethod
def _index_from_raw_format(cls, repo: "Repo", proc: "Popen") -> "DiffIndex":
"""Create a new DiffIndex from the given process output which must be in raw format.
"""Create a new :class:`DiffIndex` from the given process output which must be
in raw format.

:param repo:
The repository we are operating on.

:param repo: The repository we are operating on
:param proc: Process to read output from
:return: git.DiffIndex
:param proc:
Process to read output from.

:return:
:class:`DiffIndex`
"""
# handles
# :100644 100644 687099101... 37c5e30c8... M .gitignore
Expand Down
18 changes: 11 additions & 7 deletions git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,20 @@ class UnsafeOptionError(GitError):


class CommandError(GitError):
"""Base class for exceptions thrown at every stage of `Popen()` execution.
"""Base class for exceptions thrown at every stage of :class:`~subprocess.Popen`
execution.

:param command:
A non-empty list of argv comprising the command-line.
"""

#: A unicode print-format with 2 `%s for `<cmdline>` and the rest,
#: e.g.
#: "'%s' failed%s"
_msg = "Cmd('%s') failed%s"
"""Format string with 2 ``%s`` for ``<cmdline>`` and the rest.

For example: ``"'%s' failed%s"``

Subclasses may override this attribute, provided it is still in this form.
"""

def __init__(
self,
Expand Down Expand Up @@ -132,8 +136,8 @@ def __str__(self) -> str:


class GitCommandNotFound(CommandError):
"""Thrown if we cannot find the `git` executable in the PATH or at the path given by
the GIT_PYTHON_GIT_EXECUTABLE environment variable."""
"""Thrown if we cannot find the ``git`` executable in the :envvar:`PATH` or at the
path given by the :envvar:`GIT_PYTHON_GIT_EXECUTABLE` environment variable."""

def __init__(self, command: Union[List[str], Tuple[str], str], cause: Union[str, Exception]) -> None:
super().__init__(command, cause)
Expand Down Expand Up @@ -184,7 +188,7 @@ def __str__(self) -> str:


class CacheError(GitError):
"""Base for all errors related to the git index, which is called cache
"""Base for all errors related to the git index, which is called "cache"
internally."""


Expand Down
Loading
Loading