From 18a79d8028f934f8f78da33de3b0523fc7d1df47 Mon Sep 17 00:00:00 2001 From: Joseph Hale Date: Mon, 29 Aug 2022 23:45:51 -0700 Subject: feat(blame): Support custom `rev_opts` for blame The `git blame` CLI offers a repeated `-C` option that can be used to detect lines that move within/between files. While a slower operation, it yields more accurate authorship reports. https://git-scm.com/docs/git-blame#Documentation/git-blame.txt--Cltnumgt While GitPython does enable passing custom kwargs to the command line `git` invocation, the fact that kwargs is a dictionary (i.e. no duplicate keys) means that there was no way to request the `-C` option in `git blame` more than once. This commit adds an optional `rev_opts` parameter to the `blame` method which accepts a list of strings to propagate to the CLI invocation of `git blame`. By using a `List[str]` for `rev_opts`, users of GitPython can pass now the `-C` option multiple times to get more detailed authorship reports from `git blame`. --- git/repo/base.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index a1be5ff9..c49c6118 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -950,7 +950,12 @@ class Repo(object): ) def blame( - self, rev: Union[str, HEAD], file: str, incremental: bool = False, **kwargs: Any + self, + rev: Union[str, HEAD], + file: str, + incremental: bool = False, + rev_opts: Optional[List[str]] = None, + **kwargs: Any ) -> List[List[Commit | List[str | bytes] | None]] | Iterator[BlameEntry] | None: """The blame information for the given file at the given revision. @@ -962,8 +967,8 @@ class Repo(object): of appearance.""" if incremental: return self.blame_incremental(rev, file, **kwargs) - - data: bytes = self.git.blame(rev, "--", file, p=True, stdout_as_string=False, **kwargs) + rev_opts = rev_opts or [] + data: bytes = self.git.blame(rev, *rev_opts, "--", file, p=True, stdout_as_string=False, **kwargs) commits: Dict[str, Commit] = {} blames: List[List[Commit | List[str | bytes] | None]] = [] -- cgit v1.2.1