[IMP] runbot_merge: de-randomise fw/bp uniquifier

The forward port process adds a uniquifier to the branch name as it's
possible to reuse branch names for different sets of PRs (and some
individuals do that systematically) which can cause collisions in the
fw branches.

Originally this uniquifier was random by necessity, however now that
batches are reified and forward port is performed batch-wise we don't
need the randomness we can just use the source batch's id as it's
unique per sequence of forward ports. This means it'll eventually be
possible for an external system to retrieve the source(s) of a forward
port by reading the batch object, and it's also possible to correlate
forward ports through the batch id (although not possible to find the
source set without access to the mergebot's information).

Do the same thing for backports, because why not.
This commit is contained in:
Xavier Morel 2025-01-30 09:08:35 +01:00
parent 25cfaa95a5
commit 645a10a7ca
3 changed files with 5 additions and 15 deletions

View File

@ -12,8 +12,8 @@ MESSAGE_TEMPLATE = """{message}
closes {repo}#{number}
{headers}Signed-off-by: {name} <{email}>"""
# target branch '-' source branch '-' base64 unique '-fw'
REF_PATTERN = r'{target}-{source}-[a-zA-Z0-9_-]{{4}}-fw'
# target branch '-' source branch '-' batch id '-fw'
REF_PATTERN = r'{target}-{source}-\d+-fw'
class Commit:
def __init__(self, message, *, author=None, committer=None, tree, reset=False):

View File

@ -83,11 +83,7 @@ class PullRequestBackport(models.TransientModel):
self.target.name,
)
bp_branch = "%s-%s-%s-bp" % (
self.target.name,
self.pr_id.refname,
secrets.token_urlsafe(3),
)
bp_branch = f"{self.target.name}-{self.pr_id.refname}-{self.pr_id.batch_id.id}-bp"
repo_id = self.pr_id.repository
repo = git.get_local(repo_id)

View File

@ -315,14 +315,8 @@ class Batch(models.Model):
)
return
# the base PR is the PR with the "oldest" target
base = max(all_sources, key=lambda p: (p.target.sequence, p.target.name))
# take only the branch bit
new_branch = '%s-%s-%s-fw' % (
target.name,
base.refname,
secrets.token_urlsafe(3),
)
refname = self.genealogy_ids[0].name.split(':', 1)[-1]
new_branch = f'{target.name}-{refname}-{self.id}-fw'
conflicts = {}
for pr in prs:
repo = git.get_local(pr.repository)