Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use an instance of VCS when isn't needed #6548

Merged
merged 3 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def vcs_url(self):
if self.slug == STABLE:
slug_url = self.ref
elif self.slug == LATEST:
slug_url = self.project.default_branch or self.project.vcs_repo().fallback_branch
slug_url = self.project.get_default_branch()
else:
slug_url = self.slug

Expand Down Expand Up @@ -250,9 +250,7 @@ def commit_name(self):
# LATEST is special as it is usually a branch but does not contain the
# name in verbose_name.
if self.slug == LATEST:
if self.project.default_branch:
return self.project.default_branch
return self.project.vcs_repo().fallback_branch
return self.project.get_default_branch()

if self.slug == STABLE:
if self.type == BRANCH:
Expand Down
14 changes: 11 additions & 3 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def save(self, *args, **kwargs): # pylint: disable=arguments-differ
except Exception:
log.exception('failed to update static metadata')
try:
branch = self.default_branch or self.vcs_repo().fallback_branch
branch = self.get_default_branch()
if not self.versions.filter(slug=LATEST).exists():
self.versions.create_latest(identifier=branch)
except Exception:
Expand Down Expand Up @@ -840,7 +840,7 @@ def vcs_repo(
# ``version.slug`` instead of a ``Version`` instance (I prefer an
# instance here)

backend = backend_cls.get(self.repo_type)
backend = self.vcs_class()
if not backend:
repo = None
else:
Expand All @@ -850,6 +850,14 @@ def vcs_repo(
)
return repo

def vcs_class(self):
"""
Get the class used for VCS operations.

This is useful when doing operations that don't need to have the repository on disk.
"""
return backend_cls.get(self.repo_type)

def git_service_class(self):
"""Get the service class for project. e.g: GitHubService, GitLabService."""
from readthedocs.oauth.services import registry
Expand Down Expand Up @@ -1080,7 +1088,7 @@ def get_default_branch(self):
"""Get the version representing 'latest'."""
if self.default_branch:
return self.default_branch
return self.vcs_repo().fallback_branch
return self.vcs_class().fallback_branch

def add_subproject(self, child, alias=None):
subproject, __ = ProjectRelationship.objects.get_or_create(
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def sync_repo(self, environment):
if not os.path.exists(self.project.doc_path):
os.makedirs(self.project.doc_path)

if not self.project.vcs_repo():
if not self.project.vcs_class():
raise RepositoryError(
_('Repository type "{repo_type}" unknown').format(
repo_type=self.project.repo_type,
Expand Down