diff options
author | Yobmod <yobmod@gmail.com> | 2021-08-02 23:04:43 +0100 |
---|---|---|
committer | Yobmod <yobmod@gmail.com> | 2021-08-02 23:04:43 +0100 |
commit | ecb1f79cdb5198a10e099c2b7cd27aff69105ea9 (patch) | |
tree | db70322e08e7b42bd8c891ee0180f8f185969c91 /git/repo/base.py | |
parent | ad417ba77c98a39c2d5b3b3a74eb0a1ca17f0ccc (diff) | |
download | gitpython-ecb1f79cdb5198a10e099c2b7cd27aff69105ea9.tar.gz |
Choose TypedDict!
Diffstat (limited to 'git/repo/base.py')
-rw-r--r-- | git/repo/base.py | 69 |
1 files changed, 32 insertions, 37 deletions
diff --git a/git/repo/base.py b/git/repo/base.py index 54409b6a..e06e4eac 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -7,7 +7,6 @@ from __future__ import annotations import logging import os import re -from dataclasses import dataclass import shlex import warnings from gitdb.db.loose import LooseObjectDB @@ -890,7 +889,7 @@ class Repo(object): commits: Dict[str, Commit] = {} blames: List[List[Commit | List[str | bytes] | None]] = [] - class InfoTC(TypedDict, total=False): + class InfoTD(TypedDict, total=False): sha: str id: str filename: str @@ -902,21 +901,7 @@ class Repo(object): committer_email: str committer_date: int - @dataclass - class InfoDC(Dict[str, Union[str, int]]): - sha: str = '' - id: str = '' - filename: str = '' - summary: str = '' - author: str = '' - author_email: str = '' - author_date: int = 0 - committer: str = '' - committer_email: str = '' - committer_date: int = 0 - - # info: InfoTD = {} - info = InfoDC() + info: InfoTD = {} keepends = True for line_bytes in data.splitlines(keepends): @@ -924,7 +909,7 @@ class Repo(object): line_str = line_bytes.rstrip().decode(defenc) except UnicodeDecodeError: firstpart = '' - parts = [''] + parts = [] is_binary = True else: # As we don't have an idea when the binary data ends, as it could contain multiple newlines @@ -943,10 +928,10 @@ class Repo(object): # another line of blame with the same data digits = parts[-1].split(" ") if len(digits) == 3: - info.id = firstpart + info = {'id': firstpart} blames.append([None, []]) - elif info.id != firstpart: - info.id = firstpart + elif info['id'] != firstpart: + info = {'id': firstpart} blames.append([commits.get(firstpart), []]) # END blame data initialization else: @@ -962,12 +947,20 @@ class Repo(object): # committer-time 1192271832 # committer-tz -0700 - IGNORED BY US role = m.group(0) - if firstpart.endswith('-mail'): - info[f"{role}_email"] = parts[-1] - elif firstpart.endswith('-time'): - info[f"{role}_date"] = int(parts[-1]) - elif role == firstpart: - info[role] = parts[-1] + if role == 'author': + if firstpart.endswith('-mail'): + info["author_email"] = parts[-1] + elif firstpart.endswith('-time'): + info["author_date"] = int(parts[-1]) + elif role == firstpart: + info["author"] = parts[-1] + elif role == 'committer': + if firstpart.endswith('-mail'): + info["committer_email"] = parts[-1] + elif firstpart.endswith('-time'): + info["committer_date"] = int(parts[-1]) + elif role == firstpart: + info["committer"] = parts[-1] # END distinguish mail,time,name else: # handle @@ -980,32 +973,34 @@ class Repo(object): info['summary'] = parts[-1] elif firstpart == '': if info: - sha = info.id + sha = info['id'] c = commits.get(sha) if c is None: c = Commit(self, hex_to_bin(sha), - author=Actor._from_string(f"{info.author} {info.author_email}"), - authored_date=info.author_date, - committer=Actor._from_string(f"{info.committer} {info.committer_email}"), - committed_date=info.committer_date) + author=Actor._from_string(f"{info['author']} {info['author_email']}"), + authored_date=info['author_date'], + committer=Actor._from_string( + f"{info['committer']} {info['committer_email']}"), + committed_date=info['committer_date']) commits[sha] = c blames[-1][0] = c # END if commit objects needs initial creation + if blames[-1][1] is not None: + line: str | bytes if not is_binary: if line_str and line_str[0] == '\t': line_str = line_str[1:] - - blames[-1][1].append(line_str) + line = line_str else: + line = line_bytes # NOTE: We are actually parsing lines out of binary data, which can lead to the # binary being split up along the newline separator. We will append this to the # blame we are currently looking at, even though it should be concatenated with # the last line we have seen. - blames[-1][1].append(line_bytes) - # end handle line contents + blames[-1][1].append(line) - info.id = sha + info = {'id': sha} # END if we collected commit info # END distinguish filename,summary,rest # END distinguish author|committer vs filename,summary,rest |