Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Branches and Tags pages, each file's last commit, and the branch menu on files | 1 | /** |
| 2 | * A repository's branches as its pages show them: each one's head commit, | |
| 3 | * how far it has moved from the default branch, the pull request open on | |
| 4 | * it with its checks, and its preview. The overview shows the newest few; | |
| 5 | * the Branches page shows them all. | |
| 6 | */ | |
| Merge project overview: one branch_drift call, spliced histories, cached tags, 6 repos calls instead of 25 | 7 | import type { Branch, BranchDrifts, Pull, RepoPath, Viewer } from "@g1t/contracts"; |
| Branches and Tags pages, each file's last commit, and the branch menu on files | 8 | |
| 9 | import type { ActiveBranch } from "../components/branches"; | |
| Merge project overview: one branch_drift call, spliced histories, cached tags, 6 repos calls instead of 25 | 10 | import { activeBranches, branchesToRead, summary } from "./branches"; |
| Branches and Tags pages, each file's last commit, and the branch menu on files | 11 | import { repos } from "./services.server"; |
| 12 | ||
| 13 | type Preview = { branch?: string | null; number?: number | null; url: string }; | |
| Usage, Billing settings and prepaid AI credit; fixes from the UX audit | 14 | |
| Branches and Tags pages, each file's last commit, and the branch menu on files | 15 | /** |
| 16 | * The branches other than the default, at most `read` of them read (those | |
| Merge project overview: one branch_drift call, spliced histories, cached tags, 6 repos calls instead of 25 | 17 | * with an open pull request first), newest commit first, and the default |
| 18 | * branch's head commit with its first line. | |
| 19 | * | |
| 20 | * One call to repos (`branch_drift`, services/repos/src/drift.rs) measures | |
| 21 | * every branch. It keeps each answer by the pair of head commits, so only | |
| 22 | * branches that moved, or every branch once the default branch moved, cost | |
| 23 | * a walk, and that walk reads the default branch's history once for all of | |
| 24 | * them. Before 2026-10-08 this was a `log` call per branch per depth from | |
| 25 | * here, up to twenty on an overview. | |
| Branches and Tags pages, each file's last commit, and the branch menu on files | 26 | */ |
| 27 | export async function readBranches( | |
| 28 | path: RepoPath, | |
| 29 | viewer: Viewer, | |
| 30 | input: { defaultBranch: string; branches: Branch[]; pulls: Pull[]; previews: Preview[] }, | |
| 31 | read: number, | |
| 32 | ): Promise<{ main: string; total: number; shown: ActiveBranch[]; head: ActiveBranch["commit"] }> { | |
| Merge project overview: one branch_drift call, spliced histories, cached tags, 6 repos calls instead of 25 | 33 | const { reading, total, mainHead } = branchesToRead(input, read); |
| 34 | const measured: BranchDrifts | null = mainHead | |
| 35 | ? await repos | |
| 36 | .branchDrift(path, viewer, mainHead, reading.map((branch) => branch.hash).filter(Boolean)) | |
| 37 | .then((found) => (found.ok ? found.value : null)) | |
| 38 | .catch(() => null) | |
| 39 | : null; | |
| 40 | return { main: input.defaultBranch, total, shown: activeBranches(reading, measured, input), head: summary(measured?.base) }; | |
| Branches and Tags pages, each file's last commit, and the branch menu on files | 41 | } |
This file's history is long; its oldest lines are credited to the oldest commit read.