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

feat: cleanup git repository before doing project backup #13715

Merged
merged 1 commit into from
Jan 31, 2025
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: 6 additions & 0 deletions weblate/trans/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@
# Store VCS repo in case it is present
if component.is_repo_link:
return

# Compact the repository
with component.repository.lock:
component.repository.compact()

# Actually perform the backup
self.backup_dir(
backupzip,
component.full_path,
Expand Down Expand Up @@ -316,7 +322,7 @@
for component in project.component_set.iterator():
self.backup_component(backupzip, component)

os.rename(part_name, self.filename)

Check failure on line 325 in weblate/trans/backups.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 2 to "rename" has incompatible type "str | None"; expected "str | bytes | PathLike[str] | PathLike[bytes]"

def list_components(self, zipfile):
return [
Expand Down Expand Up @@ -349,7 +355,7 @@
data = json.load(handle)
validate_schema(data, "weblate-component.schema.json")
if skip_linked and data["component"]["repo"].startswith("weblate:"):
return False

Check failure on line 358 in weblate/trans/backups.py

View workflow job for this annotation

GitHub Actions / mypy

No return value expected
if data["component"]["vcs"] not in VCS_REGISTRY:
msg = f"Component {data['component']['name']} uses unsupported VCS: {data['component']['vcs']}"
raise ValueError(msg)
Expand All @@ -366,12 +372,12 @@

if callback is not None:
callback(zipfile, data)
return True

Check failure on line 375 in weblate/trans/backups.py

View workflow job for this annotation

GitHub Actions / mypy

No return value expected

def load_components(self, zipfile, callback: Callable | None = None) -> None:
pending: list[str] = []
for component in self.list_components(zipfile):
processed = self.load_component(

Check failure on line 380 in weblate/trans/backups.py

View workflow job for this annotation

GitHub Actions / mypy

"load_component" of "ProjectBackup" does not return a value (it only ever returns None)
zipfile, component, callback, skip_linked=True
)
if not processed:
Expand Down
3 changes: 3 additions & 0 deletions weblate/vcs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"""Ensure the configuration is periodically checked."""
if self._config_updated:
return
cache_key = f"sp-config-check-{self.component.pk}"

Check failure on line 141 in weblate/vcs/base.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "Component | None" has no attribute "pk"
if cache.get(cache_key) is None:
self.check_config()
cache.set(cache_key, True, 86400)
Expand Down Expand Up @@ -217,7 +217,7 @@
except subprocess.TimeoutExpired as error:
raise RepositoryError(
0,
f"Subprocess didn't complete before {error.timeout} seconds\n{error.stdout}{error.stderr or ''}",

Check failure on line 220 in weblate/vcs/base.py

View workflow job for this annotation

GitHub Actions / mypy

If x = b'abc' then f"{x}" or "{}".format(x) produces "b'abc'", not "abc". If this is desired behavior, use f"{x!r}" or "{!r}".format(x). Otherwise, decode the bytes
) from error
cls.add_breadcrumb(
text_cmd,
Expand Down Expand Up @@ -562,3 +562,6 @@

def list_remote_branches(self):
return []

def compact(self) -> None:
return

Check warning on line 567 in weblate/vcs/base.py

View check run for this annotation

Codecov / codecov/patch

weblate/vcs/base.py#L567

Added line #L567 was not covered by tests
3 changes: 3 additions & 0 deletions weblate/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@

return "\n".join(result)

def compact(self) -> None:
self.execute(["gc"])


class GitWithGerritRepository(GitRepository):
name = "Gerrit"
Expand Down Expand Up @@ -820,7 +823,7 @@
self, repo: str | None = None
) -> tuple[str | None, str | None, str | None, str, str, str]:
if repo is None:
repo = self.component.push or self.component.repo

Check failure on line 826 in weblate/vcs/git.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "Component | None" has no attribute "push"

Check failure on line 826 in weblate/vcs/git.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "Component | None" has no attribute "repo"
parsed = urllib.parse.urlparse(repo)
host = parsed.hostname
scheme: str | None = parsed.scheme
Expand Down Expand Up @@ -1062,7 +1065,7 @@

def get_merge_message(self):
lines = render_template(
self.component.pull_message.strip(), component=self.component

Check failure on line 1068 in weblate/vcs/git.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "Component | None" has no attribute "pull_message"
).splitlines()
return lines[0], "\n".join(lines[1:]).strip()

Expand Down Expand Up @@ -1276,7 +1279,7 @@
self, repo: str | None = None
) -> tuple[str | None, str | None, str | None, str, str, str]:
if repo is None:
repo = self.component.repo

Check failure on line 1282 in weblate/vcs/git.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "Component | None" has no attribute "repo"

scheme_regex = r"^[a-z]+:\/\/.*" # matches for example ssh://* and https://*

Expand Down
Loading