From 0b1e33da7ceaeb3dcd2703a48355603e9a2f3947 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 1 Mar 2021 12:38:23 +0100 Subject: [PATCH] [IMP] forwardport: mitigate cat-file not finding commit on updates Fix #457 hopefully: I didn't manage to repro / create a test for. It looks like in some cases during the update process the PR ref lags behind the branch itself. This means `forwardport.updates` creates a new commit, pushes it, then on the next iteration updates the local cache, tries to find the commit we just pushed... and that fails. I can only assume this is because when there's enough load on the github side the update to the `info/refs` pseudo-file can fall behind (it's now 4MB and holding nearly 65k refs). So cheat: take the commit we just pushed to the dev remote and... immediately push it to the local cache under a dummy branch, which we delete. Since we only gc "1 day ago" this should not vacuum. --- forwardport/models/forwardport.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/forwardport/models/forwardport.py b/forwardport/models/forwardport.py index e19e3a81..be81981d 100644 --- a/forwardport/models/forwardport.py +++ b/forwardport/models/forwardport.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import logging +import uuid from contextlib import ExitStack from datetime import datetime @@ -128,6 +129,16 @@ class UpdateQueue(models.Model, Queue): 'squash': commits_count == 1, }) working_copy.push('-f', 'target', child.refname) + + # also push to local cache: looks like in some cases github + # doesn't propagate revisions (?) or at least does so too slowly + # so on the next loop we try to fetch the revision we just + # pushed through PR and... we can't find it + dummy_branch = str(uuid.uuid4()) + ref = previous._get_local_directory() + working_copy.push(ref._directory, f'{new_head}:refs/heads/{dummy_branch}') + ref.branch('--delete', '--force', dummy_branch) + # committing here means github could technically trigger its # webhook before sending a response, but committing before # would mean we can update the PR in database but fail to