2 Description: history graph computation
4 Author: Marco Costalba (C) 2005-2007
6 Copyright: See COPYING file that comes with this distribution
12 #define IS_NODE(x) (x == NODE || x == NODE_R || x == NODE_L)
15 void Lanes::init(const CGitHash
& expectedSha
) {
20 add(BRANCH
, expectedSha
, activeLane
);
29 void Lanes::setBoundary(bool b
) {
30 // changes the state so must be called as first one
32 NODE
= b
? BOUNDARY_C
: MERGE_FORK
;
33 NODE_R
= b
? BOUNDARY_R
: MERGE_FORK_R
;
34 NODE_L
= b
? BOUNDARY_L
: MERGE_FORK_L
;
38 typeVec
[activeLane
] = BOUNDARY
;
41 bool Lanes::isFork(const CGitHash
& sha
, bool& isDiscontinuity
) {
43 int pos
= findNextSha(sha
, 0);
44 isDiscontinuity
= (activeLane
!= pos
);
45 if (pos
== -1) // new branch case
48 return (findNextSha(sha
, pos
+ 1) != -1);
53 pos = findNextSha(sha, pos + 1);
54 // if (isDiscontinuity)
55 // isDiscontinuity = (activeLane != pos);
61 void Lanes::setFork(const CGitHash
& sha
) {
63 int rangeStart
, rangeEnd
, idx
;
64 rangeStart
= rangeEnd
= idx
= findNextSha(sha
, 0);
69 idx
= findNextSha(sha
, idx
+ 1);
71 typeVec
[activeLane
] = NODE
;
73 int& startT
= typeVec
[rangeStart
];
74 int& endT
= typeVec
[rangeEnd
];
88 for (int i
= rangeStart
+ 1; i
< rangeEnd
; ++i
) {
100 void Lanes::setMerge(const CGitHashList
& parents
) {
101 // setFork() must be called before setMerge()
104 return; // handle as a simple active line
106 int& t
= typeVec
[activeLane
];
107 bool wasFork
= (t
== NODE
);
108 bool wasFork_L
= (t
== NODE_L
);
109 bool wasFork_R
= (t
== NODE_R
);
110 bool startJoinWasACross
= false, endJoinWasACross
= false;
114 int rangeStart
= activeLane
, rangeEnd
= activeLane
;
115 CGitHashList::const_iterator
it(parents
.begin());
116 for (++it
; it
!= parents
.end(); ++it
) { // skip first parent
118 int idx
= findNextSha(*it
, 0);
121 if (idx
> rangeEnd
) {
124 endJoinWasACross
= typeVec
[idx
] == CROSS
;
127 if (idx
< rangeStart
) {
130 startJoinWasACross
= typeVec
[idx
] == CROSS
;
136 rangeEnd
= add(HEAD
, *it
, rangeEnd
+ 1);
138 int& startT
= typeVec
[rangeStart
];
139 int& endT
= typeVec
[rangeEnd
];
141 if (startT
== NODE
&& !wasFork
&& !wasFork_R
)
144 if (endT
== NODE
&& !wasFork
&& !wasFork_L
)
147 if (startT
== JOIN
&& !startJoinWasACross
)
150 if (endT
== JOIN
&& !endJoinWasACross
)
159 for (int i
= rangeStart
+ 1; i
< rangeEnd
; ++i
) {
169 else if (t
== TAIL_R
|| t
== TAIL_L
)
174 void Lanes::setInitial() {
176 int& t
= typeVec
[activeLane
];
177 if (!IS_NODE(t
) && t
!= APPLIED
)
178 t
= (boundary
? BOUNDARY
: INITIAL
);
181 void Lanes::setApplied() {
183 // applied patches are not merges, nor forks
184 typeVec
[activeLane
] = APPLIED
; // TODO test with boundaries
187 void Lanes::changeActiveLane(const CGitHash
& sha
) {
189 int& t
= typeVec
[activeLane
];
190 if (t
== INITIAL
|| isBoundary(t
))
195 int idx
= findNextSha(sha
, 0); // find first sha
197 typeVec
[idx
] = ACTIVE
; // called before setBoundary()
199 idx
= add(BRANCH
, sha
, activeLane
); // new branch
204 void Lanes::afterMerge() {
207 return; // will be reset by changeActiveLane()
209 for (unsigned int i
= 0; i
< typeVec
.size(); ++i
) {
213 if (isHead(t
) || isJoin(t
) || t
== CROSS
)
216 else if (t
== CROSS_EMPTY
)
224 void Lanes::afterFork() {
226 for (unsigned int i
= 0; i
< typeVec
.size(); ++i
) {
233 else if (isTail(t
) || t
== CROSS_EMPTY
)
236 if (!boundary
&& IS_NODE(t
))
237 t
= ACTIVE
; // boundary will be reset by changeActiveLane()
239 while (typeVec
.back() == EMPTY
) {
241 nextShaVec
.pop_back();
245 bool Lanes::isBranch() {
247 return (typeVec
[activeLane
] == BRANCH
);
250 void Lanes::afterBranch() {
252 typeVec
[activeLane
] = ACTIVE
; // TODO test with boundaries
255 void Lanes::afterApplied() {
257 typeVec
[activeLane
] = ACTIVE
; // TODO test with boundaries
260 void Lanes::nextParent(const CGitHash
& sha
) {
263 nextShaVec
[activeLane
].Empty();
265 nextShaVec
[activeLane
] = sha
;
268 int Lanes::findNextSha(const CGitHash
& next
, int pos
) {
270 for (unsigned int i
= pos
; i
< nextShaVec
.size(); ++i
)
271 if (nextShaVec
[i
] == next
)
276 int Lanes::findType(int type
, int pos
) {
278 for (unsigned int i
= pos
; i
< typeVec
.size(); ++i
)
279 if (typeVec
[i
] == type
)
284 int Lanes::add(int type
, const CGitHash
& next
, int pos
) {
286 // first check empty lanes starting from pos
287 if (pos
< (int)typeVec
.size()) {
288 pos
= findType(EMPTY
, pos
);
291 nextShaVec
[pos
] = next
;
295 // if all lanes are occupied add a new lane
296 typeVec
.push_back(type
);
297 nextShaVec
.push_back(next
);
298 return (int)typeVec
.size() - 1;