From 7df4ee7625cfe161c0233c9a0938d4a2d35a9038 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Tue, 11 Feb 2025 00:23:26 -0300 Subject: Handle work repos more carefully --- ganarchy/git.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'ganarchy') diff --git a/ganarchy/git.py b/ganarchy/git.py index a88a979..ccee0bf 100644 --- a/ganarchy/git.py +++ b/ganarchy/git.py @@ -358,15 +358,20 @@ class _WithWorkRepos: del work del branch + collected_branches = [] for i, repo in enumerate(self.work_repos): for branch in repo.pending_branches: fetch_head = "{}-{}".format(branch, i) # First collect the work branch into a fetch head self.cache_repo._fetch_work(repo, fetch_head, branch) # If that succeeds, delete the work branch to free up disk + # (this doesn't really free up disk unless we run git gc) repo._rm_branch(branch) - # We have all the objects in the main repo and we probably - # have enough disk, so just replace the fetch head into - # the main branch and hope nothing errors. - self.cache_repo._replace(fetch_head, branch) + # We now have all the branch's objects in the main repo, + # save it to update the refs later + collected_branches.append((fetch_head, branch)) repo._delete() + for fetch_head, branch in collected_branches: + # Once every work branch is referenced in the main repo, update + # the original refs so objects can be safely GCed + self.cache_repo._replace(fetch_head, branch) -- cgit 1.4.1