Skip to content

Commit ebf6289

Browse files
committed
Cleanup
1 parent 51e96e3 commit ebf6289

4 files changed

Lines changed: 26 additions & 15 deletions

File tree

dfetch/project/gitsubproject.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def __init__(self, project: ProjectEntry):
2424
"""Create a Git subproject."""
2525
super().__init__(project)
2626
self._remote_repo = GitRemote(self.remote)
27-
self._local_repo = GitLocalRepo(self.local_path)
2827

2928
def check(self) -> bool:
3029
"""Check if is GIT."""
@@ -70,15 +69,16 @@ def _fetch_impl(self, version: Version) -> Version:
7069
f"/{name.upper()}" for name in self.LICENSE_GLOBS
7170
]
7271

73-
fetched_sha = self._local_repo.checkout_version(
72+
local_repo = GitLocalRepo(self.local_path)
73+
fetched_sha = local_repo.checkout_version(
7474
remote=self.remote,
7575
version=rev_or_branch_or_tag,
7676
src=self.source,
7777
must_keeps=license_globs,
7878
ignore=self.ignore,
7979
)
8080

81-
safe_rmtree(os.path.join(self.local_path, self._local_repo.METADATA_DIR))
81+
safe_rmtree(os.path.join(self.local_path, local_repo.METADATA_DIR))
8282

8383
return self._determine_fetched_version(version, fetched_sha)
8484

dfetch/project/gitsuperproject.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from collections.abc import Sequence
1212

1313
from dfetch.log import get_logger
14+
from dfetch.manifest.manifest import Manifest
1415
from dfetch.manifest.project import ProjectEntry
1516
from dfetch.project.gitsubproject import GitSubProject
1617
from dfetch.project.subproject import SubProject
@@ -25,6 +26,11 @@
2526
class GitSuperProject(SuperProject):
2627
"""A git specific superproject."""
2728

29+
def __init__(self, manifest: Manifest, root_directory: pathlib.Path) -> None:
30+
"""Create a Git Super project."""
31+
super().__init__(manifest, root_directory)
32+
self._repo = GitLocalRepo(root_directory)
33+
2834
@staticmethod
2935
def check(path: str | pathlib.Path) -> bool:
3036
"""Check if this path is of the matching VCS."""
@@ -51,7 +57,7 @@ def has_local_changes_in_dir(self, path: str) -> bool:
5157

5258
def get_username(self) -> str:
5359
"""Get the username of the superproject VCS."""
54-
username = GitLocalRepo(self.root_directory).get_username()
60+
username = self._repo.get_username()
5561

5662
if username:
5763
return username
@@ -60,15 +66,15 @@ def get_username(self) -> str:
6066

6167
def get_useremail(self) -> str:
6268
"""Get the user email of the superproject VCS."""
63-
email = GitLocalRepo(self.root_directory).get_useremail()
69+
email = self._repo.get_useremail()
6470

6571
if email:
6672
return email
6773
return self._get_useremail_fallback()
6874

6975
def get_file_revision(self, path: str | pathlib.Path) -> str:
7076
"""Get the revision of the given file."""
71-
return str(GitLocalRepo(self.root_directory).get_last_file_hash(str(path)))
77+
return str(self._repo.get_last_file_hash(str(path)))
7278

7379
@staticmethod
7480
def import_projects() -> Sequence[ProjectEntry]:
@@ -131,7 +137,7 @@ def diff(
131137
if diff_since_revision:
132138
combined_diff += [diff_since_revision]
133139

134-
untracked_files_patch = str(local_repo.untracked_files_patch(ignore))
140+
untracked_files_patch = local_repo.untracked_files_patch(ignore)
135141
if untracked_files_patch:
136142
if reverse:
137143
reversed_patch = reverse_patch(untracked_files_patch.encode("utf-8"))

dfetch/project/svnsubproject.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def __init__(self, project: ProjectEntry):
2828
"""Create a Svn subproject."""
2929
super().__init__(project)
3030
self._remote_repo = SvnRemote(self.remote)
31-
self._repo = SvnRepo(self.local_path)
3231

3332
def check(self) -> bool:
3433
"""Check if is SVN."""
@@ -41,7 +40,7 @@ def revision_is_enough() -> bool:
4140

4241
def _latest_revision_on_branch(self, branch: str) -> str:
4342
"""Get the latest revision on a branch."""
44-
if branch not in (self._repo.DEFAULT_BRANCH, "", " "):
43+
if branch not in (SvnRepo.DEFAULT_BRANCH, "", " "):
4544
branch = f"branches/{branch}"
4645
return self._get_revision(branch)
4746

@@ -86,11 +85,11 @@ def _determine_what_to_fetch(self, version: Version) -> tuple[str, str, str]:
8685
branch_path = ""
8786
branch = " "
8887
else:
89-
branch = version.branch or self._repo.DEFAULT_BRANCH
88+
branch = version.branch or SvnRepo.DEFAULT_BRANCH
9089
branch_path = (
9190
f"branches/{branch}"
92-
if branch != self._repo.DEFAULT_BRANCH
93-
else self._repo.DEFAULT_BRANCH
91+
if branch != SvnRepo.DEFAULT_BRANCH
92+
else SvnRepo.DEFAULT_BRANCH
9493
)
9594

9695
branch_path = urllib.parse.quote(branch_path)
@@ -180,7 +179,7 @@ def _get_revision(self, branch: str) -> str:
180179

181180
def get_default_branch(self) -> str:
182181
"""Get the default branch of this repository."""
183-
return self._repo.DEFAULT_BRANCH
182+
return SvnRepo.DEFAULT_BRANCH
184183

185184
def create_formatted_patch_header(self, patch_info: PatchInfo) -> str:
186185
"""Create a formatted patch header for the given patch info."""

dfetch/project/svnsuperproject.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from collections.abc import Sequence
1212

1313
from dfetch.log import get_logger
14+
from dfetch.manifest.manifest import Manifest
1415
from dfetch.manifest.project import ProjectEntry
1516
from dfetch.project.subproject import SubProject
1617
from dfetch.project.superproject import RevisionRange, SuperProject
@@ -32,6 +33,11 @@
3233
class SvnSuperProject(SuperProject):
3334
"""A SVN specific superproject."""
3435

36+
def __init__(self, manifest: Manifest, root_directory: pathlib.Path) -> None:
37+
"""Create a Svn Super project."""
38+
super().__init__(manifest, root_directory)
39+
self._repo = SvnRepo(root_directory)
40+
3541
@staticmethod
3642
def check(path: str | pathlib.Path) -> bool:
3743
"""Check if this path is of the matching VCS."""
@@ -58,7 +64,7 @@ def has_local_changes_in_dir(self, path: str) -> bool:
5864

5965
def get_username(self) -> str:
6066
"""Get the username of the superproject VCS."""
61-
username = SvnRepo(self.root_directory).get_username()
67+
username = self._repo.get_username()
6268

6369
if username:
6470
return username
@@ -71,7 +77,7 @@ def get_useremail(self) -> str:
7177

7278
def get_file_revision(self, path: str | pathlib.Path) -> str:
7379
"""Get the revision of the given file."""
74-
return str(SvnRepo(self.root_directory).get_last_changed_revision(str(path)))
80+
return str(self._repo.get_last_changed_revision(str(path)))
7581

7682
@staticmethod
7783
def import_projects() -> Sequence[ProjectEntry]:

0 commit comments

Comments
 (0)