1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-20 02:18:59 +00:00

Fix blocking I/O in git repository pull operation (#6380)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Stefan Agner
2025-12-02 19:03:28 +01:00
committed by GitHub
parent 50d31202ae
commit abeee95eb1

View File

@@ -183,19 +183,22 @@ class GitRepo(CoreSysAttributes):
raise StoreGitError() from err raise StoreGitError() from err
try: try:
branch = self.repo.active_branch.name repo = self.repo
# Download data def _fetch_and_check() -> tuple[str, bool]:
await self.sys_run_in_executor( """Fetch from origin and check if changed."""
ft.partial( # This property access is I/O bound
self.repo.remotes.origin.fetch, branch = repo.active_branch.name
**{"update-shallow": True, "depth": 1}, # type: ignore repo.remotes.origin.fetch(
) **{"update-shallow": True, "depth": 1} # type: ignore[arg-type]
) )
changed = repo.commit(branch) != repo.commit(f"origin/{branch}")
return branch, changed
if changed := self.repo.commit(branch) != self.repo.commit( # Download data and check for changes
f"origin/{branch}" branch, changed = await self.sys_run_in_executor(_fetch_and_check)
):
if changed:
# Jump on top of that # Jump on top of that
await self.sys_run_in_executor( await self.sys_run_in_executor(
ft.partial(self.repo.git.reset, f"origin/{branch}", hard=True) ft.partial(self.repo.git.reset, f"origin/{branch}", hard=True)