Optimize annotating files with the last commit in the repository tree view
In the repository tree view, GitLab shows for each file which commit last touched it: ![image](/uploads/19840b95e3279d1a4d9c1b993c1f71e1/image.png){width=50%} Gitaly executes `git log -1 <filename>` for each file separately. This is inefficient and we aim to extend Git so it can return this information for multiple files at once. ## Business Case `ListLastCommitsForTree()` is executed basically every time a user navigates to a certain repository because its output is listed on its landing page. In addition, this commit is very expensive and the number of processes it needs to spawn correlates with the number of entries in the top-level tree of the current commit. This is especially problematic in large monorepos, where this RPC creates significant load on deployments. Implementing `git-blame-tree(1)` should make this scale significantly better. While the underlying operation is still expensive due to the data model of Git, we expect that this should reduce the load by quite a margin. ## Implementation steps ### git-blame-tree(1) Some time ago efforts have been made trying to upstream the `git-blame-tree(1)` subcommand. This command would fit our needs to solve the issue at hand. ### `ListLastCommitsForTreeResponse` RPC Gitaly should start using `git-blame-tree(1)` in the `ListLastCommitsForTreeResponse` handler. ## Exit criteria Gitaly no longer does `N+1` Git calls to annotate the last commit for each file in `ListLastCommitsForTree`. ### Status <!-- STATUS NOTE START --> ## Status 2026-02-03 Work around this epic is wrapping up. All the in-flight patches related to git-last-modified(1) are merged or about to be merged. And the feature is fully active on production for a week now. We still need to work on removing the feature flag and old code, but that has to happen during the course of a few GitLab releases. :clock1: **total hours spent this week by all contributors**: 16 :tada: **achievements**: - All UI, bug fix, and documentation changes related to git-last-modified(1) (about to be) merged in upstream Git. - Roll-out of using git-last-modified(1) is without issues for more than a week. :issue-blocked: **blockers**: - :arrow_forward: **next**: - Remove feature flag and old implementation (but has to wait for another GitLab release) _Copied from https://gitlab.com/groups/gitlab-org/-/epics/17844#note_3053397527_ <!-- STATUS NOTE END -->
epic