From 04a27531bf1d434a8da9d17298058d1f860fe019 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Sun, 10 Mar 2024 03:36:32 -0400 Subject: [PATCH] Temporarily rename Commit_ish to Old_commit_ish And Lit_commit_ish to Lit_old_commit_ish. This is temporary, and only for purposes of bookkeeping while this type is split into two types. Specifically, Old_commit_ish will go away soon, because each occurrence of it will be changed to one of: - A newly redefined Commit_ish union of types representing only git object types that are sometimes commit-ish. - A newly introduced union (using some name formerly not used in GitPython) of all four types representing git object types, the same types as the old Commit_ish, here renamed Old_commit_ish, had overbroadly covered. - Perhaps in some cases something else. For context, see #1858 (including comments), and comments in #1859. --- git/index/base.py | 4 ++-- git/objects/base.py | 12 ++++++------ git/objects/submodule/base.py | 16 ++++++++-------- git/objects/submodule/root.py | 4 ++-- git/refs/head.py | 4 ++-- git/refs/reference.py | 4 ++-- git/refs/symbolic.py | 8 ++++---- git/refs/tag.py | 4 ++-- git/remote.py | 10 +++++----- git/repo/base.py | 8 ++++---- git/repo/fun.py | 12 ++++++------ git/types.py | 8 ++++---- 12 files changed, 47 insertions(+), 47 deletions(-) diff --git a/git/index/base.py b/git/index/base.py index 704235241..668607772 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -80,7 +80,7 @@ Union, ) -from git.types import Commit_ish, Literal, PathLike +from git.types import Old_commit_ish, Literal, PathLike if TYPE_CHECKING: from subprocess import Popen @@ -1127,7 +1127,7 @@ def move( def commit( self, message: str, - parent_commits: Union[Commit_ish, None] = None, + parent_commits: Union[Old_commit_ish, None] = None, head: bool = True, author: Union[None, "Actor"] = None, committer: Union[None, "Actor"] = None, diff --git a/git/objects/base.py b/git/objects/base.py index df9b2d9f1..dec07654a 100644 --- a/git/objects/base.py +++ b/git/objects/base.py @@ -16,7 +16,7 @@ from typing import Any, TYPE_CHECKING, Union -from git.types import PathLike, Commit_ish, Lit_commit_ish +from git.types import PathLike, Old_commit_ish, Lit_old_commit_ish if TYPE_CHECKING: from git.repo import Repo @@ -53,7 +53,7 @@ class Object(LazyMixin): * "tag object": https://git-scm.com/docs/gitglossary#def_tag_object :note: - See the :class:`~git.types.Commit_ish` union type. + See the :class:`~git.types.Old_commit_ish` union type. :note: :class:`~git.objects.submodule.base.Submodule` is defined under the hierarchy @@ -77,7 +77,7 @@ class Object(LazyMixin): __slots__ = ("repo", "binsha", "size") - type: Union[Lit_commit_ish, None] = None + type: Union[Lit_old_commit_ish, None] = None """String identifying (a concrete :class:`Object` subtype for) a git object type. The subtypes that this may name correspond to the kinds of git objects that exist, @@ -90,7 +90,7 @@ class Object(LazyMixin): ``None`` in concrete leaf subclasses representing specific git object types. :note: - See also :class:`~git.types.Commit_ish`. + See also :class:`~git.types.Old_commit_ish`. """ def __init__(self, repo: "Repo", binsha: bytes): @@ -113,7 +113,7 @@ def __init__(self, repo: "Repo", binsha: bytes): ) @classmethod - def new(cls, repo: "Repo", id: Union[str, "Reference"]) -> Commit_ish: + def new(cls, repo: "Repo", id: Union[str, "Reference"]) -> Old_commit_ish: """ :return: New :class:`Object` instance of a type appropriate to the object type behind @@ -130,7 +130,7 @@ def new(cls, repo: "Repo", id: Union[str, "Reference"]) -> Commit_ish: return repo.rev_parse(str(id)) @classmethod - def new_from_sha(cls, repo: "Repo", sha1: bytes) -> Commit_ish: + def new_from_sha(cls, repo: "Repo", sha1: bytes) -> Old_commit_ish: """ :return: New object instance of a type appropriate to represent the given binary sha1 diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index a7d638c59..783990664 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -45,7 +45,7 @@ from typing import Callable, Dict, Mapping, Sequence, TYPE_CHECKING, cast from typing import Any, Iterator, Union -from git.types import Commit_ish, Literal, PathLike, TBD +from git.types import Old_commit_ish, Literal, PathLike, TBD if TYPE_CHECKING: from git.index import IndexFile @@ -112,7 +112,7 @@ def __init__( mode: Union[int, None] = None, path: Union[PathLike, None] = None, name: Union[str, None] = None, - parent_commit: Union[Commit_ish, None] = None, + parent_commit: Union[Old_commit_ish, None] = None, url: Union[str, None] = None, branch_path: Union[PathLike, None] = None, ) -> None: @@ -213,7 +213,7 @@ def __repr__(self) -> str: @classmethod def _config_parser( - cls, repo: "Repo", parent_commit: Union[Commit_ish, None], read_only: bool + cls, repo: "Repo", parent_commit: Union[Old_commit_ish, None], read_only: bool ) -> SubmoduleConfigParser: """ :return: @@ -264,7 +264,7 @@ def _clear_cache(self) -> None: # END for each name to delete @classmethod - def _sio_modules(cls, parent_commit: Commit_ish) -> BytesIO: + def _sio_modules(cls, parent_commit: Old_commit_ish) -> BytesIO: """ :return: Configuration file as :class:`~io.BytesIO` - we only access it through the @@ -277,7 +277,7 @@ def _sio_modules(cls, parent_commit: Commit_ish) -> BytesIO: def _config_parser_constrained(self, read_only: bool) -> SectionConstraint: """:return: Config parser constrained to our submodule in read or write mode""" try: - pc: Union["Commit_ish", None] = self.parent_commit + pc: Union["Old_commit_ish", None] = self.parent_commit except ValueError: pc = None # END handle empty parent repository @@ -1242,7 +1242,7 @@ def remove( return self - def set_parent_commit(self, commit: Union[Commit_ish, None], check: bool = True) -> "Submodule": + def set_parent_commit(self, commit: Union[Old_commit_ish, None], check: bool = True) -> "Submodule": """Set this instance to use the given commit whose tree is supposed to contain the ``.gitmodules`` blob. @@ -1495,7 +1495,7 @@ def url(self) -> str: return self._url @property - def parent_commit(self) -> "Commit_ish": + def parent_commit(self) -> "Old_commit_ish": """ :return: :class:`~git.objects.commit.Commit` instance with the tree containing the @@ -1557,7 +1557,7 @@ def children(self) -> IterableList["Submodule"]: def iter_items( cls, repo: "Repo", - parent_commit: Union[Commit_ish, str] = "HEAD", + parent_commit: Union[Old_commit_ish, str] = "HEAD", *Args: Any, **kwargs: Any, ) -> Iterator["Submodule"]: diff --git a/git/objects/submodule/root.py b/git/objects/submodule/root.py index d0d1818a9..8e697ee1d 100644 --- a/git/objects/submodule/root.py +++ b/git/objects/submodule/root.py @@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, Union -from git.types import Commit_ish +from git.types import Old_commit_ish if TYPE_CHECKING: from git.repo import Repo @@ -77,7 +77,7 @@ def _clear_cache(self) -> None: def update( # type: ignore[override] self, - previous_commit: Union[Commit_ish, None] = None, + previous_commit: Union[Old_commit_ish, None] = None, recursive: bool = True, force_remove: bool = False, init: bool = True, diff --git a/git/refs/head.py b/git/refs/head.py index 4da614abd..e6bef598a 100644 --- a/git/refs/head.py +++ b/git/refs/head.py @@ -17,7 +17,7 @@ from typing import Any, Sequence, Union, TYPE_CHECKING -from git.types import PathLike, Commit_ish +from git.types import PathLike, Old_commit_ish if TYPE_CHECKING: from git.repo import Repo @@ -62,7 +62,7 @@ def orig_head(self) -> SymbolicReference: def reset( self, - commit: Union[Commit_ish, SymbolicReference, str] = "HEAD", + commit: Union[Old_commit_ish, SymbolicReference, str] = "HEAD", index: bool = True, working_tree: bool = False, paths: Union[PathLike, Sequence[PathLike], None] = None, diff --git a/git/refs/reference.py b/git/refs/reference.py index 2da511ce3..99366f710 100644 --- a/git/refs/reference.py +++ b/git/refs/reference.py @@ -11,7 +11,7 @@ # typing ------------------------------------------------------------------ from typing import Any, Callable, Iterator, Type, Union, TYPE_CHECKING -from git.types import Commit_ish, PathLike, _T +from git.types import Old_commit_ish, PathLike, _T if TYPE_CHECKING: from git.repo import Repo @@ -81,7 +81,7 @@ def __str__(self) -> str: # @ReservedAssignment def set_object( self, - object: Union[Commit_ish, "SymbolicReference", str], + object: Union[Old_commit_ish, "SymbolicReference", str], logmsg: Union[str, None] = None, ) -> "Reference": """Special version which checks if the head-log needs an update as well. diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 142952e06..092824ff8 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -31,7 +31,7 @@ TYPE_CHECKING, cast, ) -from git.types import Commit_ish, PathLike +from git.types import Old_commit_ish, PathLike if TYPE_CHECKING: from git.repo import Repo @@ -278,7 +278,7 @@ def _get_ref_info(cls, repo: "Repo", ref_path: Union[PathLike, None]) -> Union[T """ return cls._get_ref_info_helper(repo, ref_path) - def _get_object(self) -> Commit_ish: + def _get_object(self) -> Old_commit_ish: """ :return: The object our ref currently refers to. Refs can be cached, they will always @@ -345,7 +345,7 @@ def set_commit( def set_object( self, - object: Union[Commit_ish, "SymbolicReference", str], + object: Union[Old_commit_ish, "SymbolicReference", str], logmsg: Union[str, None] = None, ) -> "SymbolicReference": """Set the object we point to, possibly dereference our symbolic reference @@ -404,7 +404,7 @@ def _get_reference(self) -> "SymbolicReference": def set_reference( self, - ref: Union[Commit_ish, "SymbolicReference", str], + ref: Union[Old_commit_ish, "SymbolicReference", str], logmsg: Union[str, None] = None, ) -> "SymbolicReference": """Set ourselves to the given `ref`. diff --git a/git/refs/tag.py b/git/refs/tag.py index 6a6dad09a..0cf45cf20 100644 --- a/git/refs/tag.py +++ b/git/refs/tag.py @@ -15,7 +15,7 @@ # typing ------------------------------------------------------------------ from typing import Any, Type, Union, TYPE_CHECKING -from git.types import Commit_ish, PathLike +from git.types import Old_commit_ish, PathLike if TYPE_CHECKING: from git.repo import Repo @@ -82,7 +82,7 @@ def tag(self) -> Union["TagObject", None]: # Make object read-only. It should be reasonably hard to adjust an existing tag. @property - def object(self) -> Commit_ish: # type: ignore[override] + def object(self) -> Old_commit_ish: # type: ignore[override] return Reference._get_object(self) @classmethod diff --git a/git/remote.py b/git/remote.py index 2bd674199..cebfafb7b 100644 --- a/git/remote.py +++ b/git/remote.py @@ -41,7 +41,7 @@ overload, ) -from git.types import PathLike, Literal, Commit_ish +from git.types import PathLike, Literal, Old_commit_ish if TYPE_CHECKING: from git.repo.base import Repo @@ -196,7 +196,7 @@ def __init__( self.summary = summary @property - def old_commit(self) -> Union[str, SymbolicReference, Commit_ish, None]: + def old_commit(self) -> Union[str, SymbolicReference, Old_commit_ish, None]: return self._old_commit_sha and self._remote.repo.commit(self._old_commit_sha) or None @property @@ -362,7 +362,7 @@ def __init__( ref: SymbolicReference, flags: int, note: str = "", - old_commit: Union[Commit_ish, None] = None, + old_commit: Union[Old_commit_ish, None] = None, remote_ref_path: Optional[PathLike] = None, ) -> None: """Initialize a new instance.""" @@ -381,7 +381,7 @@ def name(self) -> str: return self.ref.name @property - def commit(self) -> Commit_ish: + def commit(self) -> Old_commit_ish: """:return: Commit of our remote ref""" return self.ref.commit @@ -438,7 +438,7 @@ def _from_line(cls, repo: "Repo", line: str, fetch_line: str) -> "FetchInfo": # Parse operation string for more info. # This makes no sense for symbolic refs, but we parse it anyway. - old_commit: Union[Commit_ish, None] = None + old_commit: Union[Old_commit_ish, None] = None is_tag_operation = False if "rejected" in operation: flags |= cls.REJECTED diff --git a/git/repo/base.py b/git/repo/base.py index 9b42ec85a..62f458f68 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -55,7 +55,7 @@ TBD, PathLike, Lit_config_levels, - Commit_ish, + Old_commit_ish, CallableProgress, Tree_ish, assert_never, @@ -696,7 +696,7 @@ def config_writer(self, config_level: Lit_config_levels = "repository") -> GitCo """ return GitConfigParser(self._get_config_path(config_level), read_only=False, repo=self, merge_includes=False) - def commit(self, rev: Union[str, Commit_ish, None] = None) -> Commit: + def commit(self, rev: Union[str, Old_commit_ish, None] = None) -> Commit: """The :class:`~git.objects.commit.Commit` object for the specified revision. :param rev: @@ -772,7 +772,7 @@ def iter_commits( return Commit.iter_items(self, rev, paths, **kwargs) - def merge_base(self, *rev: TBD, **kwargs: Any) -> List[Union[Commit_ish, None]]: + def merge_base(self, *rev: TBD, **kwargs: Any) -> List[Union[Old_commit_ish, None]]: R"""Find the closest common ancestor for the given revision (:class:`~git.objects.commit.Commit`\s, :class:`~git.refs.tag.Tag`\s, :class:`~git.refs.reference.Reference`\s, etc.). @@ -797,7 +797,7 @@ def merge_base(self, *rev: TBD, **kwargs: Any) -> List[Union[Commit_ish, None]]: raise ValueError("Please specify at least two revs, got only %i" % len(rev)) # END handle input - res: List[Union[Commit_ish, None]] = [] + res: List[Union[Old_commit_ish, None]] = [] try: lines = self.git.merge_base(*rev, **kwargs).splitlines() # List[str] except GitCommandError as err: diff --git a/git/repo/fun.py b/git/repo/fun.py index e3c69c68c..6bc998bb7 100644 --- a/git/repo/fun.py +++ b/git/repo/fun.py @@ -25,7 +25,7 @@ # Typing ---------------------------------------------------------------------- from typing import Union, Optional, cast, TYPE_CHECKING -from git.types import Commit_ish +from git.types import Old_commit_ish if TYPE_CHECKING: from git.types import PathLike @@ -249,7 +249,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]: raise NotImplementedError("commit by message search (regex)") # END handle search - obj: Union[Commit_ish, "Reference", None] = None + obj: Union[Old_commit_ish, "Reference", None] = None ref = None output_type = "commit" start = 0 @@ -271,7 +271,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]: if token == "@": ref = cast("Reference", name_to_object(repo, rev[:start], return_ref=True)) else: - obj = cast(Commit_ish, name_to_object(repo, rev[:start])) + obj = cast(Old_commit_ish, name_to_object(repo, rev[:start])) # END handle token # END handle refname else: @@ -296,7 +296,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]: pass # Default. elif output_type == "tree": try: - obj = cast(Commit_ish, obj) + obj = cast(Old_commit_ish, obj) obj = to_commit(obj).tree except (AttributeError, ValueError): pass # Error raised later. @@ -369,7 +369,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]: parsed_to = start # Handle hierarchy walk. try: - obj = cast(Commit_ish, obj) + obj = cast(Old_commit_ish, obj) if token == "~": obj = to_commit(obj) for _ in range(num): @@ -398,7 +398,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]: # Still no obj? It's probably a simple name. if obj is None: - obj = cast(Commit_ish, name_to_object(repo, rev)) + obj = cast(Old_commit_ish, name_to_object(repo, rev)) parsed_to = lr # END handle simple name diff --git a/git/types.py b/git/types.py index 8f71d079a..e9ef48ace 100644 --- a/git/types.py +++ b/git/types.py @@ -61,7 +61,7 @@ commit), is not covered as part of this union type. """ -Commit_ish = Union["Commit", "TagObject", "Blob", "Tree"] +Old_commit_ish = Union["Commit", "TagObject", "Blob", "Tree"] """Union of the :class:`~git.objects.base.Object`-based types that represent git object types. This union is often usable where a commit-ish is expected, but is not actually limited to types representing commit-ish git objects. @@ -86,18 +86,18 @@ compatibility. """ -Lit_commit_ish = Literal["commit", "tag", "blob", "tree"] +Lit_old_commit_ish = Literal["commit", "tag", "blob", "tree"] """Literal strings identifying concrete :class:`~git.objects.base.Object` subtypes representing git object types. See the :class:`Object.type ` attribute. :note: - See also :class:`Commit_ish`, a union of the the :class:`~git.objects.base.Object` + See also :class:`Old_commit_ish`, a union of the the :class:`~git.objects.base.Object` subtypes associated with these literal strings. :note: - As noted in :class:`Commit_ish`, this is not limited to types of git objects that + As noted in :class:`Old_commit_ish`, this is not limited to types of git objects that are actually commit-ish. """