Skip to content

Commit

Permalink
contest: track if branch has changes since the previous one
Browse files Browse the repository at this point in the history
Add a tiny bit of metadata to tell us the branch is identical.
This can be technically computed offline but the branches are
garbage collected quickly so for a historical view metadata
is better.

Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
kuba-moo committed Oct 9, 2024
1 parent b273092 commit 3855a91
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pw_brancher.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ def generate_deltas(config, tree, name):
subprocess.run([cidiff, name], cwd=tree.path, stdout=fp, check=True)


def get_change_from_last(tree, branch_list) -> bool:
branch_list = list(sorted(branch_list))
if len(branch_list) < 2:
return True

try:
tree.git(['diff', '--quiet', branch_list[-1], branch_list[-2]])
return False
except:
return 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 @@ -241,6 +253,8 @@ def create_new(pw, config, state, tree, tgt_remote) -> None:
extras = apply_local_patches(config, tree)
state["info"][branch_name]["extras"] = extras

state["info"][branch_name]["new-changes"] = get_change_from_last(tree, state["info"].keys())

state["branches"][branch_name] = now.isoformat()

db_insert(config, state, branch_name)
Expand Down

0 comments on commit 3855a91

Please sign in to comment.