summaryrefslogtreecommitdiff
path: root/git/repo
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2022-05-18 08:01:38 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2022-05-18 08:01:38 +0800
commite530544546b2a4e5f00e8d9458bf1b895573ec41 (patch)
tree9b957bd812fe98664d3f1f75615dda8242663097 /git/repo
parentf78fc42b90711c81e06699d1ebdbe69e6648b949 (diff)
downloadgitpython-e530544546b2a4e5f00e8d9458bf1b895573ec41.tar.gz
reformat according to 'black' configuration file.
Diffstat (limited to 'git/repo')
-rw-r--r--git/repo/base.py85
-rw-r--r--git/repo/fun.py35
2 files changed, 30 insertions, 90 deletions
diff --git a/git/repo/base.py b/git/repo/base.py
index 356a8f2f..111a350e 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -115,9 +115,7 @@ class Repo(object):
DAEMON_EXPORT_FILE = "git-daemon-export-ok"
- git = cast(
- "Git", None
- ) # Must exist, or __del__ will fail in case we raise on `__init__()`
+ git = cast("Git", None) # Must exist, or __del__ will fail in case we raise on `__init__()`
working_dir: Optional[PathLike] = None
_working_tree_dir: Optional[PathLike] = None
git_dir: PathLike = ""
@@ -251,9 +249,7 @@ class Repo(object):
pass
try:
- common_dir = (
- open(osp.join(self.git_dir, "commondir"), "rt").readlines()[0].strip()
- )
+ common_dir = open(osp.join(self.git_dir, "commondir"), "rt").readlines()[0].strip()
self._common_dir = osp.join(self.git_dir, common_dir)
except OSError:
self._common_dir = ""
@@ -325,9 +321,7 @@ class Repo(object):
with open(filename, "wb") as fp:
fp.write((descr + "\n").encode(defenc))
- description = property(
- _get_description, _set_description, doc="the project's description"
- )
+ description = property(_get_description, _set_description, doc="the project's description")
del _get_description
del _set_description
@@ -522,9 +516,7 @@ class Repo(object):
if config_level == "system":
return "/etc/gitconfig"
elif config_level == "user":
- config_home = os.environ.get("XDG_CONFIG_HOME") or osp.join(
- os.environ.get("HOME", "~"), ".config"
- )
+ config_home = os.environ.get("XDG_CONFIG_HOME") or osp.join(os.environ.get("HOME", "~"), ".config")
return osp.normpath(osp.expanduser(osp.join(config_home, "git", "config")))
elif config_level == "global":
return osp.normpath(osp.expanduser("~/.gitconfig"))
@@ -569,9 +561,7 @@ class Repo(object):
files = [self._get_config_path(config_level)]
return GitConfigParser(files, read_only=True, repo=self)
- def config_writer(
- self, config_level: Lit_config_levels = "repository"
- ) -> GitConfigParser:
+ def config_writer(self, config_level: Lit_config_levels = "repository") -> GitConfigParser:
"""
:return:
GitConfigParser allowing to write values of the specified configuration file level.
@@ -584,9 +574,7 @@ class Repo(object):
system = system wide configuration file
global = user level configuration file
repository = configuration file for this repository only"""
- return GitConfigParser(
- self._get_config_path(config_level), read_only=False, repo=self
- )
+ return GitConfigParser(self._get_config_path(config_level), read_only=False, repo=self)
def commit(self, rev: Union[str, Commit_ish, None] = None) -> Commit:
"""The Commit object for the specified revision
@@ -801,9 +789,7 @@ class Repo(object):
default_args.extend(["--", str(path)])
if index:
# diff index against HEAD
- if osp.isfile(self.index.path) and len(
- self.git.diff("--cached", *default_args)
- ):
+ if osp.isfile(self.index.path) and len(self.git.diff("--cached", *default_args)):
return True
# END index handling
if working_tree:
@@ -835,9 +821,7 @@ class Repo(object):
def _get_untracked_files(self, *args: Any, **kwargs: Any) -> List[str]:
# make sure we get all files, not only untracked directories
- proc = self.git.status(
- *args, porcelain=True, untracked_files=True, as_process=True, **kwargs
- )
+ proc = self.git.status(*args, porcelain=True, untracked_files=True, as_process=True, **kwargs)
# Untracked files prefix in porcelain mode
prefix = "?? "
untracked_files = []
@@ -850,12 +834,7 @@ class Repo(object):
if filename[0] == filename[-1] == '"':
filename = filename[1:-1]
# WHATEVER ... it's a mess, but works for me
- filename = (
- filename.encode("ascii")
- .decode("unicode_escape")
- .encode("latin1")
- .decode(defenc)
- )
+ filename = filename.encode("ascii").decode("unicode_escape").encode("latin1").decode(defenc)
untracked_files.append(filename)
finalize_process(proc)
return untracked_files
@@ -880,9 +859,7 @@ class Repo(object):
# reveal_type(self.head.reference) # => Reference
return self.head.reference
- def blame_incremental(
- self, rev: str | HEAD, file: str, **kwargs: Any
- ) -> Iterator["BlameEntry"]:
+ def blame_incremental(self, rev: str | HEAD, file: str, **kwargs: Any) -> Iterator["BlameEntry"]:
"""Iterator for blame information for the given file at the given revision.
Unlike .blame(), this does not return the actual file's contents, only
@@ -897,17 +874,13 @@ class Repo(object):
should get a continuous range spanning all line numbers in the file.
"""
- data: bytes = self.git.blame(
- rev, "--", file, p=True, incremental=True, stdout_as_string=False, **kwargs
- )
+ data: bytes = self.git.blame(rev, "--", file, p=True, incremental=True, stdout_as_string=False, **kwargs)
commits: Dict[bytes, Commit] = {}
stream = (line for line in data.split(b"\n") if line)
while True:
try:
- line = next(
- stream
- ) # when exhausted, causes a StopIteration, terminating this function
+ line = next(stream) # when exhausted, causes a StopIteration, terminating this function
except StopIteration:
return
split_line = line.split()
@@ -956,9 +929,7 @@ class Repo(object):
# guaranteed to be the last line
while True:
try:
- line = next(
- stream
- ) # will fail if we reach the EOF unexpectedly
+ line = next(stream) # will fail if we reach the EOF unexpectedly
except StopIteration:
return
tag, value = line.split(b" ", 1)
@@ -987,9 +958,7 @@ class Repo(object):
if incremental:
return self.blame_incremental(rev, file, **kwargs)
- data: bytes = self.git.blame(
- rev, "--", file, p=True, stdout_as_string=False, **kwargs
- )
+ data: bytes = self.git.blame(rev, "--", file, p=True, stdout_as_string=False, **kwargs)
commits: Dict[str, Commit] = {}
blames: List[List[Commit | List[str | bytes] | None]] = []
@@ -1083,13 +1052,9 @@ class Repo(object):
c = Commit(
self,
hex_to_bin(sha),
- author=Actor._from_string(
- f"{info['author']} {info['author_email']}"
- ),
+ 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']}"
- ),
+ committer=Actor._from_string(f"{info['committer']} {info['committer_email']}"),
committed_date=info["committer_date"],
)
commits[sha] = c
@@ -1169,9 +1134,7 @@ class Repo(object):
url: PathLike,
path: PathLike,
odb_default_type: Type[GitCmdObjectDB],
- progress: Union[
- "RemoteProgress", "UpdateProgress", Callable[..., "RemoteProgress"], None
- ] = None,
+ progress: Union["RemoteProgress", "UpdateProgress", Callable[..., "RemoteProgress"], None] = None,
multi_options: Optional[List[str]] = None,
**kwargs: Any,
) -> "Repo":
@@ -1187,9 +1150,7 @@ class Repo(object):
# becomes::
# git clone --bare /cygwin/d/foo.git /cygwin/d/C:\\Work
#
- clone_path = (
- Git.polish_url(path) if Git.is_cygwin() and "bare" in kwargs else path
- )
+ clone_path = Git.polish_url(path) if Git.is_cygwin() and "bare" in kwargs else path
sep_dir = kwargs.get("separate_git_dir")
if sep_dir:
kwargs["separate_git_dir"] = Git.polish_url(sep_dir)
@@ -1225,11 +1186,7 @@ class Repo(object):
# our git command could have a different working dir than our actual
# environment, hence we prepend its working dir if required
if not osp.isabs(path):
- path = (
- osp.join(git._working_dir, path)
- if git._working_dir is not None
- else path
- )
+ path = osp.join(git._working_dir, path) if git._working_dir is not None else path
repo = cls(path, odbt=odbt)
@@ -1305,9 +1262,7 @@ class Repo(object):
git = cls.GitCommandWrapperType(os.getcwd())
if env is not None:
git.update_environment(**env)
- return cls._clone(
- git, url, to_path, GitCmdObjectDB, progress, multi_options, **kwargs
- )
+ return cls._clone(git, url, to_path, GitCmdObjectDB, progress, multi_options, **kwargs)
def archive(
self,
diff --git a/git/repo/fun.py b/git/repo/fun.py
index 03f9cabb..8a07c2ab 100644
--- a/git/repo/fun.py
+++ b/git/repo/fun.py
@@ -59,13 +59,11 @@ def is_git_dir(d: "PathLike") -> bool:
There is the unlikely danger to throw if we see directories which just look like a worktree dir,
but are none."""
if osp.isdir(d):
- if (
- osp.isdir(osp.join(d, "objects")) or "GIT_OBJECT_DIRECTORY" in os.environ
- ) and osp.isdir(osp.join(d, "refs")):
+ if (osp.isdir(osp.join(d, "objects")) or "GIT_OBJECT_DIRECTORY" in os.environ) and osp.isdir(
+ osp.join(d, "refs")
+ ):
headref = osp.join(d, "HEAD")
- return osp.isfile(headref) or (
- osp.islink(headref) and os.readlink(headref).startswith("refs")
- )
+ return osp.isfile(headref) or (osp.islink(headref) and os.readlink(headref).startswith("refs"))
elif (
osp.isfile(osp.join(d, "gitdir"))
and osp.isfile(osp.join(d, "commondir"))
@@ -244,9 +242,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]:
ref = repo.head.ref
else:
if token == "@":
- ref = cast(
- "Reference", name_to_object(repo, rev[:start], return_ref=True)
- )
+ ref = cast("Reference", name_to_object(repo, rev[:start], return_ref=True))
else:
obj = cast(Commit_ish, name_to_object(repo, rev[:start]))
# END handle token
@@ -296,9 +292,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]:
except ValueError as e:
# TODO: Try to parse the other date options, using parse_date
# maybe
- raise NotImplementedError(
- "Support for additional @{...} modes not implemented"
- ) from e
+ raise NotImplementedError("Support for additional @{...} modes not implemented") from e
# END handle revlog index
try:
@@ -312,17 +306,12 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]:
# make it pass the following checks
output_type = ""
else:
- raise ValueError(
- "Invalid output type: %s ( in %s )" % (output_type, rev)
- )
+ raise ValueError("Invalid output type: %s ( in %s )" % (output_type, rev))
# END handle output type
# empty output types don't require any specific type, its just about dereferencing tags
if output_type and obj and obj.type != output_type:
- raise ValueError(
- "Could not accommodate requested object type %r, got %s"
- % (output_type, obj.type)
- )
+ raise ValueError("Could not accommodate requested object type %r, got %s" % (output_type, obj.type))
# END verify output type
start = end + 1 # skip brace
@@ -376,8 +365,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]:
# END end handle tag
except (IndexError, AttributeError) as e:
raise BadName(
- f"Invalid revision spec '{rev}' - not enough "
- f"parent commits to reach '{token}{int(num)}'"
+ f"Invalid revision spec '{rev}' - not enough " f"parent commits to reach '{token}{int(num)}'"
) from e
# END exception handling
# END parse loop
@@ -392,9 +380,6 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]:
raise ValueError("Revision specifier could not be parsed: %s" % rev)
if parsed_to != lr:
- raise ValueError(
- "Didn't consume complete rev spec %s, consumed part: %s"
- % (rev, rev[:parsed_to])
- )
+ raise ValueError("Didn't consume complete rev spec %s, consumed part: %s" % (rev, rev[:parsed_to]))
return obj