mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 06:47:41 +03:00
44dc946468
Summary: There's a bug here, so let's add a test exposing it. A future diff will fix the bug and update the test. Reviewed By: jordanwebster Differential Revision: D37771384 fbshipit-source-id: f482cf6d07ba4f16d833b9337a61b9dd7a85d7ac
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2.
|
|
|
|
# pyre-strict
|
|
from __future__ import annotations
|
|
|
|
from typing import List, TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from .repo import Repo
|
|
from .types import PathLike
|
|
|
|
|
|
from .errors import MissingCommitError
|
|
from .file import ScmFile
|
|
from .status import Status
|
|
|
|
|
|
class Commit:
|
|
hash: str
|
|
repo: Repo
|
|
|
|
def __init__(self, repo: Repo, hash: str) -> None:
|
|
self.hash = hash
|
|
self.repo = repo
|
|
|
|
def __repr__(self) -> str:
|
|
return "Commit-%s" % self.hash
|
|
|
|
def __eq__(self, other: Commit) -> bool:
|
|
if isinstance(other, Commit):
|
|
return self.hash == other.hash
|
|
return super().__eq__(other)
|
|
|
|
def __hash__(self) -> int:
|
|
return hash(self.hash)
|
|
|
|
def ancestor(self, idx: int) -> Commit:
|
|
try:
|
|
return self.repo.commit(f"ancestors({self.hash}, {idx}, {idx})")
|
|
except MissingCommitError:
|
|
raise MissingCommitError(f"ancestor with depth {idx} does not exist")
|
|
|
|
def status(self) -> Status:
|
|
return Status(
|
|
self.repo.hg.status(change=self.hash, copies=True, template="json").stdout
|
|
)
|
|
|
|
def parents(self) -> List[Commit]:
|
|
return self.repo.commits(f"parents({self.hash})", allowempty=True)
|
|
|
|
def __getitem__(self, path: PathLike) -> ScmFile:
|
|
return ScmFile(self, path)
|