1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
|
/*
* Copyright (C) 2010, 2014 Christian Halstrick <christian.halstrick@sap.com> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.revplot;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalkTestCase;
import org.junit.Test;
public class PlotCommitListTest extends RevWalkTestCase {
static class CommitListAssert {
private PlotCommitList<PlotLane> pcl;
private PlotCommit<PlotLane> current;
private int nextIndex = 0;
CommitListAssert(PlotCommitList<PlotLane> pcl) {
this.pcl = pcl;
}
public CommitListAssert commit(RevCommit id) {
assertTrue("Unexpected end of list at pos#"+nextIndex, pcl.size()>nextIndex);
current = pcl.get(nextIndex++);
assertEquals("Expected commit not found at pos#" + (nextIndex - 1),
id.getId(), current.getId());
return this;
}
public CommitListAssert lanePos(int pos) {
PlotLane lane = current.getLane();
assertEquals("Position of lane of commit #" + (nextIndex - 1)
+ " not as expected.", pos, lane.getPosition());
return this;
}
public int getLanePos() {
return current.getLane().position;
}
/**
* Checks that the current position is valid and consumes this position.
*
* @param allowedPositions
* @return this
*/
public CommitListAssert lanePos(Set<Integer> allowedPositions) {
PlotLane lane = current.getLane();
@SuppressWarnings("boxing")
boolean found = allowedPositions.remove(lane.getPosition());
assertTrue("Position of lane of commit #" + (nextIndex - 1)
+ " not as expected. Expecting one of: " + allowedPositions + " Actual: "+ lane.getPosition(), found);
return this;
}
public CommitListAssert nrOfPassingLanes(int lanes) {
assertEquals("Number of passing lanes of commit #"
+ (nextIndex - 1)
+ " not as expected.", lanes, current.passingLanes.length);
return this;
}
public CommitListAssert parents(RevCommit... parents) {
assertEquals("Number of parents of commit #" + (nextIndex - 1)
+ " not as expected.", parents.length,
current.getParentCount());
for (int i = 0; i < parents.length; i++)
assertEquals("Unexpected parent of commit #" + (nextIndex - 1),
parents[i], current.getParent(i));
return this;
}
public CommitListAssert noMoreCommits() {
assertEquals("Unexpected size of list", nextIndex, pcl.size());
return this;
}
}
private static Set<Integer> asSet(int... numbers) {
Set<Integer> result = new HashSet<>();
for (int n : numbers)
result.add(Integer.valueOf(n));
return result;
}
@Test
public void testLinear() throws Exception {
final RevCommit a = commit();
final RevCommit b = commit(a);
final RevCommit c = commit(b);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(c.getId()));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
CommitListAssert test = new CommitListAssert(pcl);
test.commit(c).lanePos(0).parents(b);
test.commit(b).lanePos(0).parents(a);
test.commit(a).lanePos(0).parents();
test.noMoreCommits();
}
}
@Test
public void testMerged() throws Exception {
final RevCommit a = commit();
final RevCommit b = commit(a);
final RevCommit c = commit(a);
final RevCommit d = commit(b, c);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(d.getId()));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
CommitListAssert test = new CommitListAssert(pcl);
test.commit(d).lanePos(0).parents(b, c);
test.commit(c).lanePos(1).parents(a);
test.commit(b).lanePos(0).parents(a);
test.commit(a).lanePos(0).parents();
test.noMoreCommits();
}
}
@Test
public void testSideBranch() throws Exception {
final RevCommit a = commit();
final RevCommit b = commit(a);
final RevCommit c = commit(a);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(b.getId()));
pw.markStart(pw.lookupCommit(c.getId()));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
Set<Integer> childPositions = asSet(0, 1);
CommitListAssert test = new CommitListAssert(pcl);
test.commit(c).lanePos(childPositions).parents(a);
test.commit(b).lanePos(childPositions).parents(a);
test.commit(a).lanePos(0).parents();
test.noMoreCommits();
}
}
@Test
public void test2SideBranches() throws Exception {
final RevCommit a = commit();
final RevCommit b = commit(a);
final RevCommit c = commit(a);
final RevCommit d = commit(a);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(b.getId()));
pw.markStart(pw.lookupCommit(c.getId()));
pw.markStart(pw.lookupCommit(d.getId()));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
Set<Integer> childPositions = asSet(0, 1, 2);
CommitListAssert test = new CommitListAssert(pcl);
test.commit(d).lanePos(childPositions).parents(a);
test.commit(c).lanePos(childPositions).parents(a);
test.commit(b).lanePos(childPositions).parents(a);
test.commit(a).lanePos(0).parents();
test.noMoreCommits();
}
}
@Test
public void testBug300282_1() throws Exception {
final RevCommit a = commit();
final RevCommit b = commit(a);
final RevCommit c = commit(a);
final RevCommit d = commit(a);
final RevCommit e = commit(a);
final RevCommit f = commit(a);
final RevCommit g = commit(f);
try (PlotWalk pw = new PlotWalk(db)) {
// TODO: when we add unnecessary commit's as tips (e.g. a commit
// which is a parent of another tip) the walk will return those
// commits twice. Find out why!
// pw.markStart(pw.lookupCommit(a.getId()));
pw.markStart(pw.lookupCommit(b.getId()));
pw.markStart(pw.lookupCommit(c.getId()));
pw.markStart(pw.lookupCommit(d.getId()));
pw.markStart(pw.lookupCommit(e.getId()));
// pw.markStart(pw.lookupCommit(f.getId()));
pw.markStart(pw.lookupCommit(g.getId()));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
Set<Integer> childPositions = asSet(0, 1, 2, 3, 4);
CommitListAssert test = new CommitListAssert(pcl);
int posG = test.commit(g).lanePos(childPositions).parents(f)
.getLanePos();
test.commit(f).lanePos(posG).parents(a);
test.commit(e).lanePos(childPositions).parents(a);
test.commit(d).lanePos(childPositions).parents(a);
test.commit(c).lanePos(childPositions).parents(a);
test.commit(b).lanePos(childPositions).parents(a);
test.commit(a).lanePos(0).parents();
test.noMoreCommits();
}
}
@Test
public void testBug368927() throws Exception {
final RevCommit a = commit();
final RevCommit b = commit(a);
final RevCommit c = commit(b);
final RevCommit d = commit(b);
final RevCommit e = commit(c);
final RevCommit f = commit(e, d);
final RevCommit g = commit(a);
final RevCommit h = commit(f);
final RevCommit i = commit(h);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(i.getId()));
pw.markStart(pw.lookupCommit(g.getId()));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
Set<Integer> childPositions = asSet(0, 1);
CommitListAssert test = new CommitListAssert(pcl);
int posI = test.commit(i).lanePos(childPositions).parents(h)
.getLanePos();
test.commit(h).lanePos(posI).parents(f);
test.commit(g).lanePos(childPositions).parents(a);
test.commit(f).lanePos(posI).parents(e, d);
test.commit(e).lanePos(posI).parents(c);
test.commit(d).lanePos(2).parents(b);
test.commit(c).lanePos(posI).parents(b);
test.commit(b).lanePos(posI).parents(a);
test.commit(a).lanePos(0).parents();
}
}
// test the history of the egit project between 9fdaf3c1 and e76ad9170f
@Test
public void testEgitHistory() throws Exception {
final RevCommit merge_fix = commit();
final RevCommit add_simple = commit(merge_fix);
final RevCommit remove_unused = commit(merge_fix);
final RevCommit merge_remove = commit(add_simple, remove_unused);
final RevCommit resolve_handler = commit(merge_fix);
final RevCommit clear_repositorycache = commit(merge_remove);
final RevCommit add_Maven = commit(clear_repositorycache);
final RevCommit use_remote = commit(clear_repositorycache);
final RevCommit findToolBar_layout = commit(clear_repositorycache);
final RevCommit merge_add_Maven = commit(findToolBar_layout, add_Maven);
final RevCommit update_eclipse_iplog = commit(merge_add_Maven);
final RevCommit changeset_implementation = commit(clear_repositorycache);
final RevCommit merge_use_remote = commit(update_eclipse_iplog,
use_remote);
final RevCommit disable_source = commit(merge_use_remote);
final RevCommit update_eclipse_iplog2 = commit(merge_use_remote);
final RevCommit merge_disable_source = commit(update_eclipse_iplog2,
disable_source);
final RevCommit merge_changeset_implementation = commit(
merge_disable_source, changeset_implementation);
final RevCommit clone_operation = commit(merge_changeset_implementation);
final RevCommit update_eclipse = commit(add_Maven);
final RevCommit merge_resolve_handler = commit(clone_operation,
resolve_handler);
final RevCommit disable_comment = commit(clone_operation);
final RevCommit merge_disable_comment = commit(merge_resolve_handler,
disable_comment);
final RevCommit fix_broken = commit(merge_disable_comment);
final RevCommit add_a_clear = commit(fix_broken);
final RevCommit merge_update_eclipse = commit(add_a_clear,
update_eclipse);
final RevCommit sort_roots = commit(merge_update_eclipse);
final RevCommit fix_logged_npe = commit(merge_changeset_implementation);
final RevCommit merge_fixed_logged_npe = commit(sort_roots,
fix_logged_npe);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(merge_fixed_logged_npe.getId()));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
CommitListAssert test = new CommitListAssert(pcl);
// Note: all positions of side branches are rather arbitrary, but
// some
// may not overlap. Testing for the positions yielded by the current
// implementation, which was manually checked to not overlap.
final int mainPos = 0;
test.commit(merge_fixed_logged_npe)
.parents(sort_roots, fix_logged_npe).lanePos(mainPos);
test.commit(fix_logged_npe).parents(merge_changeset_implementation)
.lanePos(1);
test.commit(sort_roots).parents(merge_update_eclipse)
.lanePos(mainPos);
test.commit(merge_update_eclipse)
.parents(add_a_clear, update_eclipse).lanePos(mainPos);
test.commit(add_a_clear).parents(fix_broken).lanePos(mainPos);
test.commit(fix_broken).parents(merge_disable_comment)
.lanePos(mainPos);
test.commit(merge_disable_comment)
.parents(merge_resolve_handler, disable_comment)
.lanePos(mainPos);
test.commit(disable_comment).parents(clone_operation).lanePos(2);
test.commit(merge_resolve_handler)
.parents(clone_operation, resolve_handler).lanePos(mainPos);
test.commit(update_eclipse).parents(add_Maven).lanePos(3);
test.commit(clone_operation).parents(merge_changeset_implementation)
.lanePos(mainPos);
test.commit(merge_changeset_implementation)
.parents(merge_disable_source, changeset_implementation)
.lanePos(mainPos);
test.commit(merge_disable_source)
.parents(update_eclipse_iplog2, disable_source)
.lanePos(mainPos);
test.commit(update_eclipse_iplog2).parents(merge_use_remote)
.lanePos(mainPos);
test.commit(disable_source).parents(merge_use_remote).lanePos(1);
test.commit(merge_use_remote)
.parents(update_eclipse_iplog, use_remote).lanePos(mainPos);
test.commit(changeset_implementation).parents(clear_repositorycache)
.lanePos(2);
test.commit(update_eclipse_iplog).parents(merge_add_Maven)
.lanePos(mainPos);
test.commit(merge_add_Maven).parents(findToolBar_layout, add_Maven)
.lanePos(mainPos);
test.commit(findToolBar_layout).parents(clear_repositorycache)
.lanePos(mainPos);
test.commit(use_remote).parents(clear_repositorycache).lanePos(1);
test.commit(add_Maven).parents(clear_repositorycache).lanePos(3);
test.commit(clear_repositorycache).parents(merge_remove)
.lanePos(mainPos);
test.commit(resolve_handler).parents(merge_fix).lanePos(4);
test.commit(merge_remove).parents(add_simple, remove_unused)
.lanePos(mainPos);
test.commit(remove_unused).parents(merge_fix).lanePos(1);
test.commit(add_simple).parents(merge_fix).lanePos(mainPos);
test.commit(merge_fix).parents().lanePos(mainPos);
test.noMoreCommits();
}
}
// test a history where a merge commit has two time the same parent
@Test
public void testDuplicateParents() throws Exception {
final RevCommit m1 = commit();
final RevCommit m2 = commit(m1);
final RevCommit m3 = commit(m2, m2);
final RevCommit s1 = commit(m2);
final RevCommit s2 = commit(s1);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(m3));
pw.markStart(pw.lookupCommit(s2));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
CommitListAssert test = new CommitListAssert(pcl);
test.commit(s2).nrOfPassingLanes(0);
test.commit(s1).nrOfPassingLanes(0);
test.commit(m3).nrOfPassingLanes(1);
test.commit(m2).nrOfPassingLanes(0);
test.commit(m1).nrOfPassingLanes(0);
test.noMoreCommits();
}
}
/**
* The graph shows the problematic original positioning. Due to this some
* lanes are no straight lines here, but they are with the new layout code)
*
* <pre>
* a5
* | \
* | a4
* | /
* a3
* |
* | e
* | \
* | |
* | b3 |
* | | d
* | |/
* | /|
* |/ |
* a2 |
* | b2
* | \
* | c |
* | / /
* |/ b1
* a1
* </pre>
*
* @throws Exception
*/
@Test
public void testBug419359() throws Exception {
// this may not be the exact situation of bug 419359 but it shows
// similar behavior
final RevCommit a1 = commit();
final RevCommit b1 = commit();
final RevCommit c = commit(a1);
final RevCommit b2 = commit(b1);
final RevCommit a2 = commit(a1);
final RevCommit d = commit(a2);
final RevCommit b3 = commit(b2);
final RevCommit e = commit(d);
final RevCommit a3 = commit(a2);
final RevCommit a4 = commit(a3);
final RevCommit a5 = commit(a3, a4);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(b3.getId()));
pw.markStart(pw.lookupCommit(c.getId()));
pw.markStart(pw.lookupCommit(e.getId()));
pw.markStart(pw.lookupCommit(a5.getId()));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
// test that the commits b1, b2 and b3 are on the same position
int bPos = pcl.get(9).lane.position; // b1
assertEquals("b2 is an a different position", bPos,
pcl.get(7).lane.position);
assertEquals("b3 is on a different position", bPos,
pcl.get(4).lane.position);
// test that nothing blocks the connections between b1, b2 and b3
assertNotEquals("b lane is blocked by c", bPos,
pcl.get(8).lane.position);
assertNotEquals("b lane is blocked by a2", bPos,
pcl.get(6).lane.position);
assertNotEquals("b lane is blocked by d", bPos,
pcl.get(5).lane.position);
}
}
/**
* <pre>
* b3
* a4 |
* | \|
* | b2
* a3 |
* | \|
* a2 |
* | b1
* | /
* a1
* </pre>
*
* @throws Exception
*/
@Test
public void testMultipleMerges() throws Exception {
final RevCommit a1 = commit();
final RevCommit b1 = commit(a1);
final RevCommit a2 = commit(a1);
final RevCommit a3 = commit(a2, b1);
final RevCommit b2 = commit(b1);
final RevCommit a4 = commit(a3, b2);
final RevCommit b3 = commit(b2);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(a4));
pw.markStart(pw.lookupCommit(b3));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
Set<Integer> positions = asSet(0, 1);
CommitListAssert test = new CommitListAssert(pcl);
int posB = test.commit(b3).lanePos(positions).getLanePos();
int posA = test.commit(a4).lanePos(positions).getLanePos();
test.commit(b2).lanePos(posB);
test.commit(a3).lanePos(posA);
test.commit(a2).lanePos(posA);
test.commit(b1).lanePos(posB);
test.commit(a1).lanePos(posA);
test.noMoreCommits();
}
}
/**
* <pre>
* a4
* | b3
* a3 |
* | \\|
* | |\\
* | b2||
* a2 | //
* | b1
* | /
* a1
* </pre>
*
* @throws Exception
*/
@Test
public void testMergeBlockedBySelf() throws Exception {
final RevCommit a1 = commit();
final RevCommit b1 = commit(a1);
final RevCommit a2 = commit(a1);
final RevCommit b2 = commit(b1); // blocks merging arc
final RevCommit a3 = commit(a2, b1);
final RevCommit b3 = commit(b2);
final RevCommit a4 = commit(a3);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(a4));
pw.markStart(pw.lookupCommit(b3));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
Set<Integer> positions = asSet(0, 1);
CommitListAssert test = new CommitListAssert(pcl);
int posA = test.commit(a4).lanePos(positions).getLanePos();
int posB = test.commit(b3).lanePos(positions).getLanePos();
test.commit(a3).lanePos(posA);
test.commit(b2).lanePos(posB);
test.commit(a2).lanePos(posA);
// b1 is not repositioned, uses "detour lane"
// (drawn as a double arc in the ascii graph above)
test.commit(b1).lanePos(posB);
test.commit(a1).lanePos(posA);
test.noMoreCommits();
}
}
/**
* <pre>
* b2
* a4 |
* | \ |
* a3 \|
* | \ |
* | c |
* | / |
* a2 |
* | b1
* /
* | /
* a1
* </pre>
*
* @throws Exception
*/
@Test
public void testMergeBlockedByOther() throws Exception {
final RevCommit a1 = commit();
final RevCommit b1 = commit(a1);
final RevCommit a2 = commit(a1);
final RevCommit c = commit(a2);// blocks merging arc
final RevCommit a3 = commit(a2, c);
final RevCommit a4 = commit(a3, b1);
final RevCommit b2 = commit(b1);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(a4));
pw.markStart(pw.lookupCommit(b2));
pw.markStart(pw.lookupCommit(c));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
Set<Integer> positions = asSet(0, 1, 2);
CommitListAssert test = new CommitListAssert(pcl);
int posB = test.commit(b2).lanePos(positions).getLanePos();
int posA = test.commit(a4).lanePos(positions).getLanePos();
test.commit(a3).lanePos(posA);
test.commit(c).lanePos(positions);
test.commit(a2).lanePos(posA);
test.commit(b1).lanePos(posB); // repositioned to go around c
test.commit(a1).lanePos(posA);
test.noMoreCommits();
}
}
/**
* <pre>
* b1
* a3 |
* | |
* a2 |
* -- processing stops here --
* | /
* a1
* </pre>
*
* @throws Exception
*/
@Test
public void testDanglingCommitShouldContinueLane() throws Exception {
final RevCommit a1 = commit();
final RevCommit a2 = commit(a1);
final RevCommit a3 = commit(a2);
final RevCommit b1 = commit(a1);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(a3));
pw.markStart(pw.lookupCommit(b1));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(2); // don't process a1
Set<Integer> positions = asSet(0, 1);
CommitListAssert test = new CommitListAssert(pcl);
PlotLane laneB = test.commit(b1).lanePos(positions).current
.getLane();
int posA = test.commit(a3).lanePos(positions).getLanePos();
test.commit(a2).lanePos(posA);
assertArrayEquals(
"Although the parent of b1, a1, is not processed yet, the b lane should still be drawn",
new PlotLane[] { laneB }, test.current.passingLanes);
test.noMoreCommits();
}
}
@Test
public void testTwoRoots1() throws Exception {
final RevCommit a = commit();
final RevCommit b = commit();
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(a));
pw.markStart(pw.lookupCommit(b));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
CommitListAssert test = new CommitListAssert(pcl);
test.commit(b).lanePos(0);
test.commit(a).lanePos(0);
test.noMoreCommits();
}
}
@Test
public void testTwoRoots2() throws Exception {
final RevCommit a = commit();
final RevCommit b1 = commit();
final RevCommit b2 = commit(b1);
try (PlotWalk pw = new PlotWalk(db)) {
pw.markStart(pw.lookupCommit(a));
pw.markStart(pw.lookupCommit(b2));
PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
pcl.source(pw);
pcl.fillTo(Integer.MAX_VALUE);
CommitListAssert test = new CommitListAssert(pcl);
test.commit(b2).lanePos(0);
test.commit(b1).lanePos(0);
test.commit(a).lanePos(0);
test.noMoreCommits();
}
}
}
|