from failure import Failure from git_repo import file_at, full_history, git from comprehension_history import HISTORY, HistoryChange def history_changes(default: str) -> list[HistoryChange] | Failure: """Each merged change on the default branch that touched the history, newest first; a merge commit counts as one change against its first parent.""" if partial := full_history(): return partial commits = git("log", "--first-parent", "--format=%H", default, "--", HISTORY) if isinstance(commits, Failure): return commits changes = [] for commit in commits.split(): before = file_at(f"{commit}^1", HISTORY) if isinstance(before, Failure): return before after = file_at(commit, HISTORY) if isinstance(after, Failure): return after changes.append(HistoryChange(commit, before, after)) return changes