From 830e27562e99b354de32412d10dcb2693947216c Mon Sep 17 00:00:00 2001 From: Jakub Kicinski Date: Wed, 28 Aug 2024 08:07:53 -0700 Subject: [PATCH] brancher: pre-generate deltas when creating a branch Instead of having to fetch the branches locally and manually run cidiff just generate the output after creating each branch. We can make UI link to it later. Signed-off-by: Jakub Kicinski --- contest/cidiff | 9 +++++++++ pw_brancher.py | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/contest/cidiff b/contest/cidiff index 2df5232..fd5e9af 100755 --- a/contest/cidiff +++ b/contest/cidiff @@ -15,6 +15,15 @@ if [ x$BRANCH1$BRANCH2 == x ]; then BRANCH1=${branches[0]} BRANCH2=${branches[1]} + echo " " $BRANCH1 + echo " " $BRANCH2 + echo +elif [ x$BRANCH2 == x ]; then + echo "Single branch specified, using that and the previous one:" + branches=( $(git branch -a | grep -B1 "$1") ) + BRANCH1=${branches[0]} + BRANCH2=${branches[1]} + echo " " $BRANCH1 echo " " $BRANCH2 echo diff --git a/pw_brancher.py b/pw_brancher.py index 0a461d2..0cb5928 100755 --- a/pw_brancher.py +++ b/pw_brancher.py @@ -6,6 +6,7 @@ import json import os import psycopg2 +import subprocess import time from typing import List, Tuple import uuid @@ -32,6 +33,7 @@ [output] branches=branches.json info=branches-info.json +deltas=/path/to/dir/ [db] db=db-name """ @@ -190,6 +192,18 @@ def db_insert(config, state, name): cur.execute("INSERT INTO branches VALUES " + arg.decode('utf-8')) +def generate_deltas(config, name): + outdir = config.get("output", "deltas", fallback=None) + if not outdir: + return + + outfile = os.path.join(outdir, name) + cidiff = os.path.join(__file__, "contest", "cidiff") + + with open(outfile, 'w') as fp: + subprocess.run([cidiff, name], stdout=fp, check=True) + + def create_new(pw, config, state, tree, tgt_remote) -> None: now = datetime.datetime.now(datetime.UTC) pfx = config.get("target", "branch_pfx") @@ -235,6 +249,10 @@ def create_new(pw, config, state, tree, tgt_remote) -> None: tree.git_push(tgt_remote, "HEAD:" + branch_name) log_end_sec() + log_open_sec("Generate deltas") + generate_deltas(config, branch_name) + log_end_sec() + def state_delete_branch(state, br): del state["branches"][br]