Fast Computation of Lowest Common Ancestor in Version Control Commit Graph
Stepan Polokhin, Ruslan Savchenko, Yuriy Chernyshov
Key points
From the paper's conclusion- We present an algorithm running in time $O(\delta_Gm_c + n_s\log^2 n_s + m_s\log n_s)$ and requiring $O(d)$ preprocessed data per vertex, where $\delta_G$ is the maximum out-degree of a vertex in $G$, $n_c$ and $m_c$ are the maximum numbers of vertices and edges in a connected component formed after removing the supporting branches, $n_s$ is the number of supporting branches, $m_s$ is the number o
Abstract
The problem of finding the lowest common ancestor in the commit graph arises when a user wants to merge two (or more) development branches: for example, to add their own development into a common branch. At that moment, the version control system must determine the merge base - the common ancestor of the latest commits of the branches, in order to show the mutual difference between the branches. The problem is complicated by the fact that the commit graph is not a tree but an arbitrary acyclic graph. Moreover, if there is no common ancestor, searching for one may require traversing the entire graph. Traversing a graph with several million vertices takes tens of seconds, which becomes noticeable to users. We show that the commit graph has additional structure - supporting branches - and that this can be used to speed up the algorithm. By extracting supporting branches, the graph can be preprocessed and the search for the lowest common ancestor can be significantly accelerated. Moreover, if removing the supporting branches decomposes the graph into connected components of bounded size, the lowest common ancestor query can be answered in time comparable to searching for a common ancestor within a single component only. We present an algorithm running in time $O(\delta_Gm_c + n_s\log^2 n_s + m_s\log n_s)$ and requiring $O(d)$ preprocessed data per vertex, where $\delta_G$ is the maximum out-degree of a vertex in $G$, $n_c$ and $m_c$ are the maximum numbers of vertices and edges in a connected component formed after removing the supporting branches, $n_s$ is the number of supporting branches, $m_s$ is the number of edges in the reachability graph between the supporting branches, and $d$ is the maximum number of supporting branches adjacent to any single component.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Counting and Sampling Git GraphsarXiv · 2026
- Global Least Common Ancestor (LCA) NetworksAnnals of Combinatorics · 2026
- avaCGs: Version-Aware Call Graphs for Efficient Version-Range QueriesProceedings of the ACM on Software Engineering · 2026
- Accelerating String Comparison in RLZ Compressed Sequences via LCE JumpsbioRxiv · 2026
- Look Back Before You Bisect: A Risk-Aware Approach for Efficient BisectionACM Transactions on Software Engineering and Methodology · 2026
- Learning Spectral Representations of Code through Latent Graph Learning for Generalizable Cross-Language Code Clone DetectionarXiv · 2026