Skip to content

Commit

Permalink
brancher: pre-generate deltas when creating a branch
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kuba-moo committed Aug 28, 2024
1 parent 8bc607d commit 830e275
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions contest/cidiff
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions pw_brancher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import os
import psycopg2
import subprocess
import time
from typing import List, Tuple
import uuid
Expand All @@ -32,6 +33,7 @@
[output]
branches=branches.json
info=branches-info.json
deltas=/path/to/dir/
[db]
db=db-name
"""
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 830e275

Please sign in to comment.