@@ -52,14 +52,6 @@ export class CommitGraph {
52
52
}
53
53
54
54
computePositions ( repo : RepoState ) {
55
- function mergeSets ( sets : Set < number > [ ] ) {
56
- return new Set < number > ( function * ( ) {
57
- for ( let set of sets ) {
58
- yield * set ;
59
- }
60
- } ( ) ) ;
61
- }
62
-
63
55
function insertCommit ( commitSha : string , j : number , forbiddenIndices : Set < number > ) {
64
56
// Try to insert as close as possible to i
65
57
// replace i by j
@@ -83,18 +75,14 @@ export class CommitGraph {
83
75
const headSha = repo . headCommit ? repo . headCommit . sha ( ) : null ;
84
76
let i = 1 ;
85
77
const branches : ( string | null ) [ ] = [ 'index' ] ;
86
- const activeNodes = new Map < string , Set < number > > ( ) ;
87
- const activeNodesQueue = new FastPriorityQueue < [ number , string ] > ( ( lhs , rhs ) => lhs [ 0 ] < rhs [ 0 ] ) ;
88
- activeNodes . set ( 'index' , new Set < number > ( ) ) ;
89
- if ( headSha ) {
90
- activeNodesQueue . add ( [ repo . shaToIndex . get ( headSha ) ! , 'index' ] ) ;
91
- }
78
+ const edges = new IntervalTree < number > ( ) ;
92
79
for ( let commit of repo . commits ) {
93
80
let j = - 1 ;
94
81
const commitSha = commit . sha ( ) ;
95
82
const children = repo . children . get ( commit . sha ( ) ) ! ;
96
83
// Compute forbidden indices
97
- const forbiddenIndices = mergeSets ( children . filter ( ( childSha ) => repo . parents . get ( childSha ) ! [ 0 ] !== commitSha ) . map ( ( childSha ) => activeNodes . get ( childSha ) ! ) ) ;
84
+ const iMin = Math . min ( ...children . filter ( ( childSha ) => repo . parents . get ( childSha ) ! [ 0 ] !== commitSha ) . map ( ( childSha ) => this . positions . get ( childSha ) ! [ 0 ] ) ! , i ) ;
85
+ const forbiddenIndices = new Set < number > ( edges . search ( iMin , i ) ) ;
98
86
// Find a commit to replace
99
87
let commitToReplace : string | null = null ;
100
88
let jCommitToReplace = Infinity ;
@@ -127,25 +115,21 @@ export class CommitGraph {
127
115
j = insertCommit ( commitSha , 0 , new Set ( ) ) ;
128
116
}
129
117
}
130
- // Remove useless active nodes
131
- while ( ! activeNodesQueue . isEmpty ( ) && activeNodesQueue . peek ( ) [ 0 ] < i ) {
132
- const sha = activeNodesQueue . poll ( ) [ 1 ] ;
133
- activeNodes . delete ( sha ) ;
134
- }
135
- // Upddate the active nodes
136
- const jToAdd = [ j , ...children . filter ( ( childSha ) => repo . parents . get ( childSha ) ! [ 0 ] === commitSha ) . map ( ( childSha ) => this . positions . get ( childSha ) ! [ 1 ] ) ] ;
137
- for ( let activeNode of activeNodes . values ( ) ) {
138
- jToAdd . forEach ( ( j ) => activeNode . add ( j ) ) ;
139
- }
140
- activeNodes . set ( commitSha , new Set < number > ( ) ) ;
141
- const iRemove = Math . max ( ...repo . parents . get ( commitSha ) ! . map ( ( parentSha ) => repo . shaToIndex . get ( parentSha ) ! ) ) ;
142
- activeNodesQueue . add ( [ iRemove , commitSha ] ) ;
143
118
// Remove children from active branches
144
119
for ( let childSha of children ) {
145
120
if ( childSha != commitToReplace && repo . parents . get ( childSha ) ! [ 0 ] === commitSha ) {
146
121
branches [ branches . indexOf ( childSha ) ] = null ; // Use positions
147
122
}
148
123
}
124
+ // Add edges
125
+ for ( let childSha of children ) {
126
+ const [ iChild , jChild ] = this . positions . get ( childSha ) ! ;
127
+ if ( repo . parents . get ( childSha ) ! [ 0 ] === commitSha ) {
128
+ edges . insert ( iChild , i - 1 , jChild ) ;
129
+ } else {
130
+ edges . insert ( iChild , i - 1 , j ) ;
131
+ }
132
+ }
149
133
// Finally set the position
150
134
this . positions . set ( commitSha , [ i , j , repo . stashes . has ( commitSha ) ? NodeType . Stash : NodeType . Commit ] ) ;
151
135
++ i ;
0 commit comments