Language breakdown bar for a repository
The cost is not the classification — extension-to-language is a lookup table — but that byte counts per file require reading the tree, and 0001 §2 means every file goes through a `zit cat` subprocess. For sqlite that is 2,219 spawns.
Two things make it affordable:
- `zit ls` already reports sizes, so the bar can be built from extension plus size WITHOUT reading any file contents. That is one subprocess, not thousands. It misclassifies files whose extension lies, which for a language bar is an acceptable error. - The result is a pure function of a resolved check-in, exactly like an archive, so it caches under the same rule and never needs invalidating.
Recommend the `zit ls` route: one call, cacheable forever per check-in, and no new dependency. Show it as the strip forgejo uses but with the legend inline rather than on hover, so it is readable on touch.
Design, now that the About panel (#765689a7ac) gives this a home:
Classification is by file extension over the tip's tree listing — which is already fetched and memoized per tip, so the raw material is free. Extension → language table for the common few dozen; files that match nothing fall into no bucket rather than "Other" lying about precision. Sizes come from the long listing, so the bar is weighted by BYTES like GitHub's, not file count.
Where it computes: a memo keyed on the tip hash (the leaves memo pattern) — the answer is immutable per tip, so it is computed once per push, not per render. No index schema change, no fold work: this is a pure derivation over the listing.
Vendored noise: GitHub uses .gitattributes linguist overrides; our
analogue is a "languages": {"exclude": ["vendor/", "fixtures/"]} key
in .quarry/repo.json — same file, same read path as everything else.
Defaults to no exclusions; a wrong bar is visible and fixable by
commit.
Display: one stacked bar + the top 6 with percentages, exactly the GitHub shape. Colors from a fixed language→hue table, falling back to branchHue(name) so unknown languages get a stable color for free.