| 1 | # vcs-graph |
| 2 | |
| 3 | Graph algorithms for version control systems. |
| 4 | |
| 5 | `vcs-graph` provides building blocks used by version control tools: topological |
| 6 | sorting (including merge-aware sorting that preserves branch structure), |
| 7 | parent-map manipulation, least common ancestor queries, and related |
| 8 | operations. It is the Rust core behind the [`vcsgraph`][vcsgraph-py] Python |
| 9 | package, originally extracted from the Breezy version control system. |
| 10 | |
| 11 | ## Features |
| 12 | |
| 13 | - `TopoSorter` — iterative topological sort of a parent graph. |
| 14 | - `MergeSorter` — merge-aware topological sort that assigns revision numbers |
| 15 | and tracks merge depth, suitable for rendering commit history. |
| 16 | - `ParentMap` / `ChildMap` — parent/child map types with utilities like |
| 17 | `invert_parent_map` and `collapse_linear_regions`. |
| 18 | - `ParentsProvider` trait with `DictParentsProvider` and |
| 19 | `StackedParentsProvider` implementations. |
| 20 | - Optional `pyo3` feature for exposing these types to Python. |
| 21 | |
| 22 | ## Example |
| 23 | |
| 24 | ```rust |
| 25 | use std::collections::HashMap; |
| 26 | use vcs_graph::tsort::TopoSorter; |
| 27 | |
| 28 | let graph: HashMap<&str, Vec<&str>> = HashMap::from([ |
| 29 | ("A", vec![]), |
| 30 | ("B", vec!["A"]), |
| 31 | ("C", vec!["A"]), |
| 32 | ("D", vec!["B", "C"]), |
| 33 | ]); |
| 34 | |
| 35 | let sorted = TopoSorter::new(graph.into_iter()).sorted().unwrap(); |
| 36 | // Parents always come before children. |
| 37 | ``` |
| 38 | |
| 39 | ## License |
| 40 | |
| 41 | GPL-2.0-or-later. See `COPYING.txt` in the repository root. |
| 42 | |
| 43 | [vcsgraph-py]: https://pypi.org/project/vcsgraph/ |