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 def landed_since_release(default: str) -> bool | Failure: """Whether the default branch holds a commit after its newest `v*` tag, or any commit when it has none.""" # Sorts v1.0.0-rc.1 below v1.0.0. tags = git("-c", "versionsort.suffix=-", "tag", "--list", "v*", "--merged", default, "--sort=-v:refname") if isinstance(tags, Failure): return tags newest = tags.split()[:1] count = git("rev-list", "--count", f"{newest[0]}..{default}" if newest else default) return count if isinstance(count, Failure) else int(count) > 0