1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.revwalk;
12
13 import java.io.IOException;
14
15 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
16 import org.eclipse.jgit.errors.MissingObjectException;
17
18
19 class TopoNonIntermixSortGenerator extends Generator {
20 private static final int TOPO_QUEUED = RevWalk.TOPO_QUEUED;
21
22 private final FIFORevQueue pending;
23
24 private final int outputType;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 TopoNonIntermixSortGenerator(Generator s) throws MissingObjectException,
40 IncorrectObjectTypeException, IOException {
41 super(s.firstParent);
42 pending = new FIFORevQueue(firstParent);
43 outputType = s.outputType() | SORT_TOPO;
44 s.shareFreeList(pending);
45 for (;;) {
46 final RevCommit c = s.next();
47 if (c == null) {
48 break;
49 }
50 if ((c.flags & TOPO_QUEUED) == 0) {
51 for (RevCommit p : c.parents) {
52 p.inDegree++;
53
54 if (firstParent) {
55 break;
56 }
57 }
58 }
59 c.flags |= TOPO_QUEUED;
60 pending.add(c);
61 }
62 }
63
64 @Override
65 int outputType() {
66 return outputType;
67 }
68
69 @Override
70 void shareFreeList(BlockRevQueue q) {
71 q.shareFreeList(pending);
72 }
73
74 @Override
75 RevCommit next() throws MissingObjectException,
76 IncorrectObjectTypeException, IOException {
77 for (;;) {
78 final RevCommit c = pending.next();
79 if (c == null) {
80 return null;
81 }
82
83 if (c.inDegree > 0) {
84
85
86
87 continue;
88 }
89
90 if ((c.flags & TOPO_QUEUED) == 0) {
91
92
93
94 continue;
95 }
96
97 for (RevCommit p : c.parents) {
98 if (--p.inDegree == 0 && (p.flags & TOPO_QUEUED) != 0) {
99
100
101
102
103
104
105
106 pending.unpop(p);
107 }
108 if (firstParent) {
109 break;
110 }
111 }
112
113 c.flags &= ~TOPO_QUEUED;
114 return c;
115 }
116 }
117 }