8000 Start fixing annotations that used the old Commit_ish · gitpython-developers/GitPython@7328a00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7328a00

Browse files
committed
Start fixing annotations that used the old Commit_ish
1 parent 1fe4dc8 commit 7328a00

File tree

5 files changed

+63
-60
lines changed
  • refs
  • repo
  • 5 files changed

    +63
    -60
    lines changed

    git/objects/base.py

    Lines changed: 10 additions & 8 deletions
    Original file line numberDiff line numberDiff line change
    @@ -3,28 +3,30 @@
    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-
    from git.exc import WorkTreeRepositoryUnsupported
    7-
    from git.util import LazyMixin, join_path_native, stream_copy, bin_to_hex
    8-
    96
    import gitdb.typ as dbtyp
    107
    import os.path as osp
    118

    9+
    from git.exc import WorkTreeRepositoryUnsupported
    10+
    from git.util import LazyMixin, join_path_native, stream_copy, bin_to_hex
    11+
    1212
    from .util import get_object_type_by_name
    1313

    1414

    1515
    # typing ------------------------------------------------------------------
    1616

    1717
    from typing import Any, TYPE_CHECKING, Union
    1818

    19-
    from git.types import GitObjectTypeString, Old_commit_ish, PathLike
    19+
    from git.types import AnyGitObject, GitObjectTypeString, PathLike
    2020

    2121
    if TYPE_CHECKING:
    22-
    from git.repo import Repo
    2322
    from gitdb.base import OStream
    23+
    24+
    from git.refs.reference import Reference
    25+
    from git.repo import Repo
    26+
    2427
    from .tree import Tree
    2528
    from .blob import Blob
    2629
    from .submodule.base import Submodule
    27-
    from git.refs.reference import Reference
    2830

    2931
    IndexObjUnion = Union["Tree", "Blob", "Submodule"]
    3032

    @@ -115,7 +117,7 @@ def __init__(self, repo: "Repo", binsha: bytes):
    115117
    )
    116118

    117119
    @classmethod
    118-
    def new(cls, repo: "Repo", id: Union[str, "Reference"]) -> Old_commit_ish:
    120+
    def new(cls, repo: "Repo", id: Union[str, "Reference"]) -> AnyGitObject:
    119121
    """
    120122
    :return:
    121123
    New :class:`Object` instance of a type appropriate to the object type behind
    @@ -132,7 +134,7 @@ def new(cls, repo: "Repo", id: Union[str, "Reference"]) -> Old_commit_ish:
    132134
    return repo.rev_parse(str(id))
    133135

    134136
    @classmethod
    135-
    def new_from_sha(cls, repo: "Repo", sha1: bytes) -> Old_commit_ish:
    137+
    def new_from_sha(cls, repo: "Repo", sha1: bytes) -> AnyGitObject:
    136138
    """
    137139
    :return:
    138140
    New object instance of a type appropriate to represent the given binary sha1

    git/refs/symbolic.py

    Lines changed: 26 additions & 24 deletions
    Original file line numberDiff line numberDiff line change
    @@ -6,39 +6,38 @@
    66
    from git.compat import defenc
    77
    from git.objects import Object
    88
    from git.objects.commit import Commit
    9+
    from git.refs.log import RefLog
    910
    from git.util import (
    11+
    LockedFD,
    12+
    assure_directory_exists,
    13+
    hex_to_bin,
    1014
    join_path,
    1115
    join_path_native,
    1216
    to_native_path_linux,
    13-
    assure_directory_exists,
    14-
    hex_to_bin,
    15-
    LockedFD,
    1617
    )
    17-
    from gitdb.exc import BadObject, BadName
    18-
    19-
    from .log import RefLog
    18+
    from gitdb.exc import BadName, BadObject
    2019

    2120
    # typing ------------------------------------------------------------------
    2221

    2322
    from typing import (
    2423
    Any,
    2524
    Iterator,
    2625
    List,
    26+
    TYPE_CHECKING,
    2727
    Tuple,
    2828
    Type,
    2929
    TypeVar,
    3030
    Union,
    31-
    TYPE_CHECKING,
    3231
    cast,
    3332
    )
    34-
    from git.types import Old_commit_ish, PathLike
    33+
    from git.types import AnyGitObject, PathLike
    3534

    3635
    if TYPE_CHECKING:
    37-
    from git.repo import Repo
    38-
    from git.refs import Head, TagReference, RemoteReference, Reference
    39-
    from .log import RefLogEntry
    4036
    from git.config import GitConfigParser
    4137
    from git.objects.commit import Actor
    38+
    from git.refs import Head, TagReference, RemoteReference, Reference
    39+
    from git.refs.log import RefLogEntry
    40+
    from git.repo import Repo
    4241

    4342

    4443
    T_References = TypeVar("T_References", bound="SymbolicReference")
    @@ -278,7 +277,7 @@ def _get_ref_info(cls, repo: "Repo", ref_path: Union[PathLike, None]) -> Union[T
    278277
    """
    279278
    return cls._get_ref_info_helper(repo, ref_path)
    280279

    281-
    def _get_object(self) -> Old_commit_ish:
    280+
    def _get_object(self) -> AnyGitObject:
    282281
    """
    283282
    :return:
    284283
    The object our ref currently refers to. Refs can be cached, they will always
    @@ -345,17 +344,20 @@ def set_commit(
    345344

    346345
    def set_object(
    347346
    self,
    348-
    object: Union[Old_commit_ish, "SymbolicReference", str],
    347+
    object: Union[AnyGitObject, "SymbolicReference", str],
    349348
    logmsg: Union[str, None] = None,
    350349
    ) -> "SymbolicReference":
    351350
    """Set the object we point to, possibly dereference our symbolic reference
    352351
    first. If the reference does not exist, it will be created.
    353352
    354353
    :param object:
    355354
    A refspec, a :class:`SymbolicReference` or an
    356-
    :class:`~git.objects.base.Object` instance. :class:`SymbolicReference`
    357-
    instances will be dereferenced beforehand to obtain the object they point
    358-
    to.
    355+
    :class:`~git.objects.base.Object` instance.
    356+
    357+
    * :class:`SymbolicReference` instances will be dereferenced beforehand to
    358+
    obtain the git object they point to.
    359+
    * :class:`~git.objects.base.Object` instances must represent git objects
    360+
    (:class:`~git.types.AnyGitObject`).
    359361
    360362
    :param logmsg:
    361363
    If not ``None``, the message will be used in the reflog entry to be written.
    @@ -404,22 +406,22 @@ def _get_reference(self) -> "SymbolicReference":
    404406

    405407
    def set_reference(
    406408
    self,
    407-
    ref: Union[Old_commit_ish, "SymbolicReference", str],
    409+
    ref: Union[AnyGitObject, "SymbolicReference", str],
    408410
    logmsg: Union[str, None] = None,
    409411
    ) -> "SymbolicReference":
    410412
    """Set ourselves to the given `ref`.
    411413
    412-
    It will stay a symbol if the ref is a :class:`~git.refs.reference.Reference`.
    414+
    It will stay a symbol if the `ref` is a :class:`~git.refs.reference.Reference`.
    413415
    414-
    Otherwise an Object, given as :class:`~git.objects.base.Object` instance or
    415-
    refspec, is assumed and if valid, will be set which effectively detaches the
    416-
    reference if it was a purely symbolic one.
    416+
    Otherwise a git object, specified as a :class:`~git.objects.base.Object`
    417+
    instance or refspec, is assumed. If it is valid, this reference will be set to
    418+
    it, which effectively detaches the reference if it was a purely symbolic one.
    417419
    418420
    :param ref:
    419421
    A :class:`SymbolicReference` instance, an :class:`~git.objects.base.Object`
    420-
    instance, or a refspec string. Only if the ref is a
    421-
    :class:`SymbolicReference` instance, we will point to it. Everything else is
    422-
    dereferenced to obtain the actual object.
    422+
    instance (specifically an :class:`~git.types.AnyGitObject`), or a refspec
    423+
    string. Only if the ref is a :class:`SymbolicReference` instance, we will
    424+
    point to it. Everything else is dereferenced to obtain the actual object.
    423425
    424426
    :param logmsg:
    425427
    If set to a string, the message will be used in the reflog.

    git/refs/tag.py

    Lines changed: 5 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -14,14 +14,15 @@
    1414

    1515
    # typing ------------------------------------------------------------------
    1616

    17-
    from typing import Any, Type, Union, TYPE_CHECKING
    18-
    from git.types import Old_commit_ish, PathLike
    17+
    from typing import Any, TYPE_CHECKING, Type, Union
    18+
    19+
    from git.types import AnyGitObject, PathLike
    1920

    2021
    if TYPE_CHECKING:
    21-
    from git.repo import Repo
    2222
    from git.objects import Commit
    2323
    from git.objects import TagObject
    2424
    from git.refs import SymbolicReference
    25+
    from git.repo import Repo
    2526

    2627

    2728
    # ------------------------------------------------------------------------------
    @@ -82,7 +83,7 @@ def tag(self) -> Union["TagObject", None]:
    8283

    8384
    # Make object read-only. It should be reasonably hard to adjust an existing tag.
    8485
    @property
    85-
    def object(self) -> Old_commit_ish: # type: ignore[override]
    86+
    def object(self) -> AnyGitObject: # type: ignore[override]
    8687
    return Reference._get_object(self)
    8788

    8889
    @classmethod

    git/remote.py

    Lines changed: 3 additions & 5 deletions
    Original file line numberDiff line numberDiff line change
    @@ -44,11 +44,9 @@
    4444
    from git.types import PathLike, Literal, Old_commit_ish
    4545

    4646
    if TYPE_CHECKING:
    47-
    from git.repo.base import Repo
    47+
    from git.objects.commit import Commit
    4848
    from git.objects.submodule.base import UpdateProgress
    49-
    50-
    # from git.objects.commit import Commit
    51-
    # from git.objects import Blob, Tree, TagObject
    49+
    from git.repo.base import Repo
    5250

    5351
    flagKeyLiteral = Literal[" ", "!", "+", "-", "*", "=", "t", "?"]
    5452

    @@ -381,7 +379,7 @@ def name(self) -> str:
    381379
    return self.ref.name
    382380

    383381
    @property
    384-
    def commit(self) -> Old_commit_ish:
    382+
    def commit(self) -> "Commit":
    385383
    """:return: Commit of our remote ref"""
    386384
    return self.ref.commit
    387385

    git/repo/base.py

    Lines changed: 19 additions & 19 deletions
    Original file line numberDiff line numberDiff line change
    @@ -34,29 +34,29 @@
    3434
    from git.remote import Remote, add_progress, to_progress_instance
    3535
    from git.util import (
    3636
    Actor,
    37-
    finalize_process,
    3837
    cygpath,
    39-
    hex_to_bin,
    4038
    expand_path,
    39+
    finalize_process,
    40+
    hex_to_bin,
    4141
    remove_password_if_present,
    4242
    )
    4343

    4444
    from .fun import (
    45-
    rev_parse,
    46-
    is_git_dir,
    4745
    find_submodule_git_dir,
    48-
    touch,
    4946
    find_worktree_git_dir,
    47+
    is_git_dir,
    48+
    rev_parse,
    49+
    touch,
    5050
    )
    5151

    5252
    # typing ------------------------------------------------------
    5353

    5454
    from git.types import (
    55-
    TBD,
    56-
    PathLike,
    57-
    Lit_config_levels,
    58-
    Old_commit_ish,
    5955
    CallableProgress,
    56+
    Commit_ish,
    57+
    Lit_config_levels,
    58+
    PathLike,
    59+
    TBD,
    6060
    Tree_ish,
    6161
    assert_never,
    6262
    )
    @@ -68,25 +68,25 @@
    6868
    Iterator,
    6969
    List,
    7070
    Mapping,
    71+
    NamedTuple,
    7172
    Optional,
    7273
    Sequence,
    74+
    TYPE_CHECKING,
    7375
    TextIO,
    7476
    Tuple,
    7577
    Type,
    7678
    Union,
    77-
    NamedTuple,
    7879
    cast,
    79-
    TYPE_CHECKING,
    8080
    )
    8181

    8282
    from git.types import ConfigLevels_Tup, TypedDict
    8383

    8484
    if TYPE_CHECKING:
    85-
    from git.util import IterableList
    86-
    from git.refs.symbolic import SymbolicReference
    8785
    from git.objects import Tree
    8886
    from git.objects.submodule.base import UpdateProgress
    87+
    from git.refs.symbolic import SymbolicReference
    8988
    from git.remote import RemoteProgress
    89+
    from git.util import IterableList
    9090

    9191
    # -----------------------------------------------------------
    9292

    @@ -96,7 +96,7 @@
    9696

    9797

    9898
    class BlameEntry(NamedTuple):
    99-
    commit: Dict[str, "Commit"]
    99+
    commit: Dict[str, Commit]
    100100
    linenos: range
    101101
    orig_path: Optional[str]
    102102
    orig_linenos: range
    @@ -696,7 +696,7 @@ def config_writer(self, config_level: Lit_config_levels = "repository") -> GitCo
    696696
    """
    697697
    return GitConfigParser(self._get_config_path(config_level), read_only=False, repo=self, merge_includes=False)
    698698

    699-
    def commit(self, rev: Union[str, Old_commit_ish, None] = None) -> Commit:
    699+
    def commit(self, rev: Union[str, Commit_ish, None] = None) -> Commit:
    700700
    """The :class:`~git.objects.commit.Commit` object for the specified revision.
    701701
    702702
    :param rev:
    @@ -772,7 +772,7 @@ def iter_commits(
    772772

    773773
    return Commit.iter_items(self, rev, paths, **kwargs)
    774774

    775-
    def merge_base(self, *rev: TBD, **kwargs: Any) -> List[Union[Old_commit_ish, None]]:
    775+
    def merge_base(self, *rev: TBD, **kwargs: Any) -> List[Commit]:
    776776
    R"""Find the closest common ancestor for the given revision
    777777
    (:class:`~git.objects.commit.Commit`\s, :class:`~git.refs.tag.Tag`\s,
    778778
    :class:`~git.refs.reference.Reference`\s, etc.).
    @@ -797,9 +797,9 @@ def merge_base(self, *rev: TBD, **kwargs: Any) -> List[Union[Old_commit_ish, Non
    797797
    raise ValueError("Please specify at least two revs, got only %i" % len(rev))
    798798
    # END handle input
    799799

    800-
    res: List[Union[Old_commit_ish, None]] = []
    800+
    res: List[Commit] = []
    801801
    try:
    802-
    lines = self.git.merge_base(*rev, **kwargs).splitlines() # List[str]
    802+
    lines: List[str] = self.git.merge_base(*rev, **kwargs).splitlines()
    803803
    except GitCommandError as err:
    804804
    if err.status == 128:
    805805
    raise
    @@ -815,7 +815,7 @@ def merge_base(self, *rev: TBD, **kwargs: Any) -> List[Union[Old_commit_ish, Non
    815815

    816816
    return res
    817817

    818-
    def is_ancestor(self, ancestor_rev: "Commit", rev: "Commit") -> bool:
    818+
    def is_ancestor(self, ancestor_rev: Commit, rev: Commit) -> bool:
    819819
    """Check if a commit is an ancestor of another.
    820820
    821821
    :param ancestor_rev:

    0 commit comments

    Comments
     (0)
    0