Skip to content

FileDiff

🛈 DocStrings

The changes of one file.

Source code in src/acptui/protocol/diff.py
@dataclass
class FileDiff:
    """The changes of one file."""

    old_path: str | None
    new_path: str | None
    hunks: list[Hunk] = field(default_factory=list)
    binary: bool = False

    @property
    def path(self) -> str:
        """The path to show (the new one, or the old one for deletions)."""
        return self.new_path or self.old_path or "?"

    @property
    def added(self) -> int:
        """Number of added lines."""
        return sum(1 for hunk in self.hunks for line in hunk.lines if line.kind == "add")

    @property
    def removed(self) -> int:
        """Number of removed lines."""
        return sum(1 for hunk in self.hunks for line in hunk.lines if line.kind == "remove")

added property

added: int

Number of added lines.

path property

path: str

The path to show (the new one, or the old one for deletions).

removed property

removed: int

Number of removed lines.

:fa-brands-github: Show source on GitHub