13
13
#import " PBGitGrapher.h"
14
14
#import " PBGitCommit.h"
15
15
#import " PBGitLane.h"
16
+ #import " PBGitGraphLine.h"
16
17
#import < vector>
17
18
18
19
using namespace std ;
@@ -33,13 +34,23 @@ - (id) initWithRepository: (PBGitRepository*) repo
33
34
return self;
34
35
}
35
36
37
+ void add_line (struct PBGitGraphLine *lines, int *nLines, int upper, int from, int to, int index)
38
+ {
39
+ // TODO: put in one thing
40
+ struct PBGitGraphLine a = { upper, from, to, index };
41
+ lines[(*nLines)++] = a;
42
+ }
43
+
36
44
- (void ) decorateCommit : (PBGitCommit *) commit
37
45
{
38
46
int i = 0 , newPos = -1 ;
39
47
std::vector<PBGitLane *> *currentLanes = new std::vector<PBGitLane *>;
40
48
std::vector<PBGitLane *> *previousLanes = (std::vector<PBGitLane *> *)pl;
41
49
42
- NSMutableArray * lines = [NSMutableArray array ];
50
+ int maxLines = (previousLanes->size () + [commit.parents count ] + 2 ) * 3 ;
51
+ struct PBGitGraphLine *lines = (struct PBGitGraphLine *)malloc (sizeof (struct PBGitGraphLine ) * maxLines);
52
+ int currentLine = 0 ;
53
+
43
54
PBGitLane *currentLane = NULL ;
44
55
BOOL didFirst = NO ;
45
56
@@ -57,26 +68,26 @@ - (void) decorateCommit: (PBGitCommit *) commit
57
68
currentLanes->push_back (*it);
58
69
currentLane = currentLanes->back ();
59
70
newPos = currentLanes->size ();
60
- [ lines addObject: [PBGitGraphLine upperLineFrom: i to: newPos color: (*it)->index ()]] ;
71
+ add_line ( lines, ¤tLine, 1 , i, newPos, (*it)->index ()) ;
61
72
}
62
73
else {
63
- [ lines addObject: [PBGitGraphLine upperLineFrom: i to: newPos color: (*it)->index ()]] ;
74
+ add_line ( lines, ¤tLine, 1 , i, newPos, (*it)->index ()) ;
64
75
delete *it;
65
76
}
66
77
}
67
78
else {
68
79
// We are not this commit.
69
80
currentLanes->push_back (*it);
70
- [ lines addObject: [PBGitGraphLine upperLineFrom: i to: currentLanes->size () color: (*it)->index ()]] ;
71
- [ lines addObject: [PBGitGraphLine lowerLineFrom: currentLanes->size () to: currentLanes->size () color: (*it)->index ()]] ;
81
+ add_line ( lines, ¤tLine, 1 , i, currentLanes->size (), (*it)->index ()) ;
82
+ add_line ( lines, ¤tLine, 0 , currentLanes->size (), currentLanes->size (), (*it)->index ()) ;
72
83
}
73
84
// For existing columns, we always just continue straight down
74
85
// ^^ I don't know what that means anymore :(
75
86
76
87
if (currentLane)
77
- [ lines addObject: [PBGitGraphLine lowerLineFrom: newPos to: newPos color: currentLane ->index ()]] ;
88
+ add_line ( lines, ¤tLine, 0 , newPos, newPos,(*it) ->index ()) ;
78
89
else
79
- [ lines addObject: [PBGitGraphLine lowerLineFrom: newPos to: newPos color: 0 ]] ;
90
+ add_line ( lines, ¤tLine, 0 , newPos, newPos, 0 ) ;
80
91
}
81
92
}
82
93
// Add your own parents
@@ -86,7 +97,7 @@ - (void) decorateCommit: (PBGitCommit *) commit
86
97
PBGitLane *newLane = new PBGitLane ([commit.parents objectAtIndex: 0 ]);
87
98
currentLanes->push_back (newLane);
88
99
newPos = currentLanes->size ();
89
- [ lines addObject: [PBGitGraphLine lowerLineFrom: newPos to: newPos color: newLane->index ()]] ;
100
+ add_line ( lines, ¤tLine, 0 , newPos, newPos, newLane->index ()) ;
90
101
}
91
102
92
103
// Add all other parents
@@ -102,7 +113,7 @@ - (void) decorateCommit: (PBGitCommit *) commit
102
113
for (; it < currentLanes->end (); ++it) {
103
114
i++;
104
115
if ((*it)->isCommit (parent)) {
105
- [ lines addObject: [PBGitGraphLine lowerLineFrom: i to: newPos color: (*it)->index ()]] ;
116
+ add_line ( lines, ¤tLine, 0 , i, newPos, (*it)->index ()) ;
106
117
was_displayed = YES ;
107
118
break ;
108
119
}
@@ -117,10 +128,14 @@ - (void) decorateCommit: (PBGitCommit *) commit
117
128
addedParent = YES ;
118
129
PBGitLane *newLane = new PBGitLane (parent);
119
130
currentLanes->push_back (newLane);
120
- [ lines addObject: [PBGitGraphLine lowerLineFrom: currentLanes->size () to: newPos color: newLane->index ()]] ;
131
+ add_line ( lines, ¤tLine, 0 , currentLanes->size (), newPos, newLane->index ()) ;
121
132
}
122
133
123
134
previous = [[PBGraphCellInfo alloc ] initWithPosition: newPos andLines: lines];
135
+ if (currentLine > maxLines)
136
+ NSLog (@" Number of lines: %i vs allocated: %i " , currentLine, maxLines);
137
+
138
+ previous.nLines = currentLine;
124
139
previous.sign = commit.sign ;
125
140
126
141
// If a parent was added, we have room to not indent.
0 commit comments