| 114 | |
| 115 | |
| 116 | class Blame: |
| 117 | _repo: Repository |
| 118 | _blame: 'GitBlameC' |
| 119 | |
| 120 | @classmethod |
| 121 | def _from_c(cls, repo: Repository, ptr: 'GitBlameC') -> 'Blame': |
| 122 | blame = cls.__new__(cls) |
| 123 | blame._repo = repo |
| 124 | blame._blame = ptr |
| 125 | return blame |
| 126 | |
| 127 | def __del__(self) -> None: |
| 128 | C.git_blame_free(self._blame) |
| 129 | |
| 130 | def __len__(self) -> int: |
| 131 | return C.git_blame_get_hunk_count(self._blame) |
| 132 | |
| 133 | def __getitem__(self, index: int) -> BlameHunk: |
| 134 | chunk = C.git_blame_get_hunk_byindex(self._blame, index) |
| 135 | if not chunk: |
| 136 | raise IndexError |
| 137 | |
| 138 | return BlameHunk._from_c(self, chunk) |
| 139 | |
| 140 | def for_line(self, line_no: int) -> BlameHunk: |
| 141 | """ |
| 142 | Returns the <BlameHunk> object for a given line given its number in the |
| 143 | current Blame. |
| 144 | |
| 145 | Parameters: |
| 146 | |
| 147 | line_no |
| 148 | Line number, starts at 1. |
| 149 | """ |
| 150 | if line_no < 0: |
| 151 | raise IndexError |
| 152 | |
| 153 | chunk = C.git_blame_get_hunk_byline(self._blame, line_no) |
| 154 | if not chunk: |
| 155 | raise IndexError |
| 156 | |
| 157 | return BlameHunk._from_c(self, chunk) |
| 158 | |
| 159 | def __iter__(self) -> Iterator[BlameHunk]: |
| 160 | return GenericIterator(self) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…