From bfefd8aa0f7afccd1c385a7332387837419f80b8 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Tue, 21 Jun 2022 10:15:43 +0100 Subject: [PATCH 1/3] tools/batch-rebase: Fix tag action FIX Fix tag action that were resulting in an exception: KeyError: 'tip' --- tools/batch-rebase | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/batch-rebase b/tools/batch-rebase index 164f44ec3..70e9b28a8 100755 --- a/tools/batch-rebase +++ b/tools/batch-rebase @@ -253,11 +253,26 @@ def _do_cherry_pick(repo, conf, persistent_tags, tags_suffix): git(['tag', '-f', '--', tag_name]) return tag_name + def resolve_action(topic): + return topic.get('action', 'cherry-pick') + + def resolve_name(topic): + action = resolve_action(topic) + if action == 'tag': + return topic['name'] + elif action == 'cherry-pick': + return topic.get('name', topic['tip']) + else: + raise ValueError(f'Could not handle action={action} in topic: {topic}') + persistent_refs = set() - topics = conf['topics'] + topics = conf['topics'].copy() for topic in topics: - topic.setdefault('name', topic['tip']) + topic.update( + action=resolve_action(topic), + name=resolve_name(topic), + ) # If we are resuming after a conflict if 'conflict-topic' in conf['resume']: @@ -296,7 +311,7 @@ def _do_cherry_pick(repo, conf, persistent_tags, tags_suffix): # Cherry pick topic branches in the specified order for topic in topics: - action = topic.get('action', 'cherry-pick') + action = topic['action'] name = topic['name'] if action == 'tag': -- GitLab From 5298232a473280bb1deb18e19f077052d039ef68 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Tue, 21 Jun 2022 10:26:41 +0100 Subject: [PATCH 2/3] tools/batch-rebase: Check for unique topic names Topic names must be unique for correct operations so ensure that it is the case in practice. --- tools/batch-rebase | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/batch-rebase b/tools/batch-rebase index 70e9b28a8..d6288cb2e 100755 --- a/tools/batch-rebase +++ b/tools/batch-rebase @@ -23,6 +23,7 @@ import argparse import subprocess import sys from collections.abc import Mapping +from collections import Counter import tempfile from pathlib import Path import datetime @@ -274,6 +275,12 @@ def _do_cherry_pick(repo, conf, persistent_tags, tags_suffix): name=resolve_name(topic), ) + for key, cnt in Counter(topic['name'] for topic in topics).items(): + if cnt > 1: + raise ValueError( + f'Found {cnt} topics named "{key}", but names must be unique.' + ) + # If we are resuming after a conflict if 'conflict-topic' in conf['resume']: resume_topic = conf['resume']['conflict-topic'] -- GitLab From a66d2bf58e47600cfc4160bc4e45328c42651e45 Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Tue, 21 Jun 2022 10:30:27 +0100 Subject: [PATCH 3/3] tools/batch-rebase: Document the optional "name" topic key Document that the "name" key defaults to the value of "tip" if not provided for a cherry-pick topic. --- tools/batch-rebase | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/batch-rebase b/tools/batch-rebase index d6288cb2e..849e31814 100755 --- a/tools/batch-rebase +++ b/tools/batch-rebase @@ -522,7 +522,7 @@ def main(): topics: - - name: foo + name: foo # The name will default to the value of "tip" if not provided remote: myremote base: mybase tip: mytip -- GitLab