Measure chunks in projects that merge by rebase, as runs of commits sharing one commit time
This commit is contained in:
+60
-14
@@ -21,7 +21,14 @@ its table also had A, G and Goals. The chunk measures:
|
||||
such as `Answer stability round 1: 1 🔴, 2 🟡; flag a deleted test`. Unknown where a round title
|
||||
lacks the counts, or the branch has no round.
|
||||
|
||||
A project that merges without merge commits, by fast-forward or squash, has no chunk to measure.
|
||||
After the first-parent line's newest merge commit, where a project merges by rebase or squash, a
|
||||
chunk is instead a run of commits on that line sharing one commit time, as a rebase merge replays a
|
||||
pull request's commits at once; it measures against the commit before its first, whose todo.md
|
||||
holds the guesses, and its titles are its commits'. It is marked `by rebase` where a commit time
|
||||
differs from its author time, and `never replayed` where none does, since a pushed or
|
||||
fast-forwarded commit may be part of a pull request. Two pull requests merged in the same second
|
||||
read as one chunk. Rebase drops a round's commit that changed no file, so such a chunk gives its
|
||||
rounds and findings as lower bounds, `at least`, and the report ends saying all this.
|
||||
|
||||
Given L, E and I, on the levels ~/.claude/rules/todo-items.md defines, and S, it works out R from
|
||||
L, E and I, as rank_todo.py does, and lists the 5 finished items whose guesses sit closest, closest
|
||||
@@ -52,13 +59,22 @@ import sys
|
||||
from score_outcomes.anchors import anchor_lines, Anchors, ANCHORS_PATH, parse_anchors
|
||||
from git_repo import default_branch, file_at, full_history, git, top
|
||||
from failure import Failure
|
||||
from score_outcomes.outcomes import Landing, nearest, Outcome, outcomes_of, render, report, shipped
|
||||
from todo_table import LEVELS, risk, TOP_SCORE
|
||||
from markdown_text import listed
|
||||
from score_outcomes.outcomes import nearest, Outcome, outcomes_of, render, report, shipped
|
||||
from utc_stamp import utc
|
||||
|
||||
# The scores score-outcomes takes, in order.
|
||||
GIVEN = ("L", "E", "I", "S")
|
||||
# How the report reads the chunks that left no merge commit, which history bounds only by their shared commit time.
|
||||
UNMERGED = [
|
||||
"Chunks that left no merge commit:",
|
||||
"",
|
||||
"- Each is the run of commits on the default branch that share one commit time, since a rebase merge replays a pull request's commits at once. Its guesses come from the todo.md before its first commit.",
|
||||
"- Two pull requests merged in the same second read as one chunk, so a pull request that shipped nothing adds its lines, files and rounds to the chunk it shares a time with.",
|
||||
"- A run whose commits all kept their author time was never replayed: pushed or fast-forwarded as committed, it may hold only part of its pull request.",
|
||||
"- Rebase drops a round's commit that changed no file, so their rounds and findings are at least what history shows, and the medians count them as shown.",
|
||||
]
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
@@ -88,10 +104,12 @@ def report_text(outcomes: list[Outcome], anchored: Anchors | Failure, given: dic
|
||||
sections = []
|
||||
if given is not None:
|
||||
r = risk(given["L"], given["E"], given["I"])
|
||||
near = [render(outcome) for outcome in nearest(outcomes, given | {"R": r})] or ["- None: no merge commit on the default branch shipped an item from todo.md. A project that merges by squash or fast-forward has none."]
|
||||
near = [render(outcome) for outcome in nearest(outcomes, given | {"R": r})] or ["- None: no chunk on the default branch shipped an item from todo.md."]
|
||||
sections.append([f"Finished items nearest L {given['L']}, E {given['E']}, I {given['I']}, so R {r}, and S {given['S']}, closest first:", "", *near])
|
||||
sections.append([f"Anchors in {ANCHORS_PATH}, each level's shipped items:", "", *anchor_lines(anchored, outcomes)])
|
||||
sections.append(["Median outcome at each guessed score, among chunks that shipped one item:", "", *report(outcomes)])
|
||||
if any(outcome.landed != "merge" for outcome in outcomes):
|
||||
sections.append(UNMERGED)
|
||||
return "\n\n".join("\n".join(section) for section in sections)
|
||||
|
||||
|
||||
@@ -114,6 +132,7 @@ def read_anchors() -> Anchors | Failure:
|
||||
|
||||
|
||||
def read_outcomes(default: str) -> list[Outcome] | Failure:
|
||||
"""What each chunk measured: each merge commit on the default branch's first-parent line, and each run of commits after the newest that share one commit time."""
|
||||
if partial := full_history():
|
||||
return partial
|
||||
merges = git("log", "--first-parent", "--merges", "--format=%H %h %ct", default, "--", "todo.md")
|
||||
@@ -122,28 +141,55 @@ def read_outcomes(default: str) -> list[Outcome] | Failure:
|
||||
outcomes: list[Outcome] = []
|
||||
for line in merges.splitlines():
|
||||
merge, short, time = line.split()
|
||||
measured = measure(merge, short, utc(int(time)))
|
||||
measured = measure(f"{merge}^1", merge, short, utc(int(time)), f"{merge}^1..{merge}^2", "merge")
|
||||
if isinstance(measured, Failure):
|
||||
return measured
|
||||
outcomes += measured
|
||||
replays = read_replays(default)
|
||||
if isinstance(replays, Failure):
|
||||
return replays
|
||||
for first, last, committed, landed in replays:
|
||||
label = f"{first}^..{last}" if first != last else first
|
||||
measured = measure(f"{first}^1", last, label, utc(committed), f"{first}^1..{last}", landed)
|
||||
if isinstance(measured, Failure):
|
||||
return measured
|
||||
outcomes += measured
|
||||
return outcomes
|
||||
|
||||
|
||||
def measure(merge: str, short: str, merged: str) -> list[Outcome] | Failure:
|
||||
"""What one merge measured for each item it shipped."""
|
||||
before = file_at(f"{merge}^1", "todo.md")
|
||||
if isinstance(before, Failure):
|
||||
return before
|
||||
after = file_at(merge, "todo.md")
|
||||
def read_replays(default: str) -> list[tuple[str, str, int, Landing]] | Failure:
|
||||
"""Each run of commits on the default branch's first-parent line after its newest merge commit that share one commit time: its first and last commit, as short hashes, that time, and whether a rebase replayed it, which leaves a commit time apart from its author time."""
|
||||
log = git("log", "--first-parent", "--format=%h %ct %at %p", default)
|
||||
if isinstance(log, Failure):
|
||||
return log
|
||||
runs: list[tuple[str, str, int, Landing]] = []
|
||||
for line in log.splitlines():
|
||||
short, committed, authored, *parents = line.split()
|
||||
if len(parents) > 1:
|
||||
break
|
||||
replayed = committed != authored
|
||||
if runs and runs[-1][2] == int(committed):
|
||||
runs[-1] = (short, runs[-1][1], int(committed), "rebase" if replayed or runs[-1][3] == "rebase" else "push")
|
||||
else:
|
||||
runs.append((short, short, int(committed), "rebase" if replayed else "push"))
|
||||
return runs
|
||||
|
||||
|
||||
def measure(before: str, tip: str, label: str, merged: str, titled: str, landed: Landing) -> list[Outcome] | Failure:
|
||||
"""What one chunk measured for each item it shipped: its change from the commit before it to its tip, and the titles of the commits in the range titled."""
|
||||
planned = file_at(before, "todo.md")
|
||||
if isinstance(planned, Failure):
|
||||
return planned
|
||||
after = file_at(tip, "todo.md")
|
||||
if isinstance(after, Failure):
|
||||
return after
|
||||
items = shipped(before, after)
|
||||
items = shipped(planned, after)
|
||||
if not items:
|
||||
return []
|
||||
numstat = git("diff", "--numstat", f"{merge}^1", merge)
|
||||
numstat = git("diff", "--numstat", before, tip)
|
||||
if isinstance(numstat, Failure):
|
||||
return numstat
|
||||
titles = git("log", "--format=%s", f"{merge}^1..{merge}^2")
|
||||
titles = git("log", "--format=%s", titled)
|
||||
if isinstance(titles, Failure):
|
||||
return titles
|
||||
return outcomes_of(items, short, merged, numstat, titles.splitlines())
|
||||
return outcomes_of(items, label, merged, numstat, titles.splitlines(), landed)
|
||||
|
||||
Reference in New Issue
Block a user