MCPcopy Create free account
hub / github.com/libgit2/pygit2 / Blame

Class Blame

pygit2/blame.py:116–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114
115
116class 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)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…