Debian Codegraph @

README.md

raw symbols SCIP
1 # vcsgraph
2
3 A Python library providing graph algorithms optimized for version control systems.
4
5 ## Overview
6
7 `vcsgraph` is a high-performance graph algorithms library specifically designed for working with version control system (VCS) data structures. It provides efficient implementations of common graph operations needed by VCS tools, with both pure Python and Rust-accelerated implementations for performance-critical operations.
8
9 ## Features
10
11 - **Topological Sorting**: Multiple algorithms for sorting commits/revisions in topological order
12 - **Graph Traversal**: Efficient algorithms for traversing revision graphs and finding common ancestors
13 - **Multi-parent Support**: Handle complex merge scenarios with multiple parent revisions
14 - **Known Graph Operations**: Optimized operations on graphs where the full structure is known in advance
15 - **Rust Acceleration**: Performance-critical algorithms implemented in Rust with Python bindings via PyO3
16
17 ## Installation
18
19 ```bash
20 pip install vcsgraph
21 ```
22
23 ## Key Components
24
25 ### Graph Operations
26
27 The `Graph` class provides fundamental graph operations:
28 - Finding least common ancestors (LCA)
29 - Finding unique ancestors
30 - Computing differences between revision sets
31 - Finding merge bases between branches
32
33 ### Topological Sorting
34
35 Multiple sorting implementations optimized for different use cases:
36 - `topo_sort()`: Fast sorting when the complete result is needed
37 - `TopoSorter`: Iterator-based sorting for processing partial results
38 - `MergeSorter`: Specialized sorting that preserves merge history
39
40 ### Multi-parent Diffs
41
42 The `MultiParent` class handles complex diff scenarios with multiple parent revisions, essential for three-way merges and conflict resolution.
43
44 ### Known Graph
45
46 The `KnownGraph` class provides optimized operations when the complete graph structure is known, enabling faster ancestor calculations and traversals.
47
48 ## Usage Examples
49
50 ### Basic Topological Sort
51
52 ```python
53 from vcsgraph import topo_sort
54
55 # Define a graph as a list of (node, parents) tuples
56 graph = [
57 (b'rev1', []),
58 (b'rev2', [b'rev1']),
59 (b'rev3', [b'rev1']),
60 (b'rev4', [b'rev2', b'rev3']),
61 ]
62
63 # Sort nodes topologically (parents before children)
64 sorted_nodes = topo_sort(graph)
65 ```
66
67 ### Using Graph for Ancestry Operations
68
69 ```python
70 from vcsgraph import Graph, DictParentsProvider
71
72 # Create a parents provider from a dictionary
73 ancestry = {
74 b'rev1': (b'null:',),
75 b'rev2a': (b'rev1',),
76 b'rev2b': (b'rev1',),
77 b'rev3': (b'rev2a',),
78 b'rev4': (b'rev3', b'rev2b'),
79 }
80 parents_provider = DictParentsProvider(ancestry)
81
82 # Create a graph and find merge bases
83 graph = Graph(parents_provider)
84 merge_base = graph.find_merge_base(b'rev2a', b'rev2b')
85 ```
86
87 ### Working with Known Graphs
88
89 ```python
90 from vcsgraph import KnownGraph
91
92 # Create a known graph from parent relationships
93 parent_map = {
94 b'rev1': (b'null:',),
95 b'rev2': (b'rev1',),
96 b'rev3': (b'rev2',),
97 }
98 kg = KnownGraph(parent_map)
99
100 # Get heads (revisions with no children)
101 heads = kg.heads([b'rev1', b'rev2', b'rev3'])
102 ```
103
104 ## Performance
105
106 The library uses Rust for performance-critical operations while maintaining a Python interface. Key optimizations include:
107 - Memory-efficient graph representations
108 - Optimized ancestor searching algorithms
109 - Lazy evaluation where possible
110 - Caching of frequently accessed data
111
112 ## License
113
114 This project is licensed under the GNU General Public License v2 or later. See the COPYING.txt file for details.
115
116 ## Origins
117
118 This library was originally part of the Breezy version control system and has been extracted as a standalone package for use in other VCS-related projects.