1313#import  " PBGitGrapher.h" 
1414#import  " PBGitCommit.h" 
1515#import  " PBGitLane.h" 
16+ #import  " PBGitGraphLine.h" 
1617#import  < vector> 
1718
1819using  namespace  std ; 
@@ -33,13 +34,23 @@ - (id) initWithRepository: (PBGitRepository*) repo
3334	return  self;
3435}
3536
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+ 
3644- (void ) decorateCommit :  (PBGitCommit *) commit 
3745{
3846	int  i = 0 , newPos = -1 ;
3947	std::vector<PBGitLane *> *currentLanes = new  std::vector<PBGitLane *>;
4048	std::vector<PBGitLane *> *previousLanes = (std::vector<PBGitLane *> *)pl;
4149
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+ 
4354	PBGitLane *currentLane = NULL ;
4455	BOOL  didFirst = NO ;
4556
@@ -57,26 +68,26 @@ - (void) decorateCommit: (PBGitCommit *) commit
5768					currentLanes->push_back (*it);
5869					currentLane = currentLanes->back ();
5970					newPos = currentLanes->size ();
60- 					[ lines  addObject:  [PBGitGraphLine  upperLineFrom:  i  to:   newPos  color:   (*it)->index ()]] ;
71+ 					add_line ( lines, ¤tLine,  1 , i,  newPos, (*it)->index ()) ;
6172				}
6273				else  {
63- 					[ lines  addObject:  [PBGitGraphLine  upperLineFrom:  i  to:   newPos  color:   (*it)->index ()]] ;
74+ 					add_line ( lines, ¤tLine,  1 , i,  newPos, (*it)->index ()) ;
6475					delete  *it;
6576				}
6677			}
6778			else  {
6879				//  We are not this commit.
6980				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 ()) ;
7283			}
7384			//  For existing columns, we always just continue straight down
7485			//  ^^ I don't know what that means anymore :(
7586
7687			if  (currentLane)
77- 				[ lines  addObject: [PBGitGraphLine  lowerLineFrom: newPos  to: newPos  color:  currentLane ->index ()]] ;
88+ 				add_line ( lines, ¤tLine,  0 ,  newPos, newPos,(*it) ->index ()) ;
7889			else 
79- 				[ lines  addObject: [PBGitGraphLine  lowerLineFrom: newPos  to: newPos  color:   0 ]] ;
90+ 				add_line ( lines, ¤tLine,  0 ,  newPos,  newPos,  0 ) ;
8091		}
8192	}
8293	// Add your own parents
@@ -86,7 +97,7 @@ - (void) decorateCommit: (PBGitCommit *) commit
8697		PBGitLane *newLane = new  PBGitLane ([commit.parents objectAtIndex: 0 ]);
8798		currentLanes->push_back (newLane);
8899		newPos = currentLanes->size ();
89- 		[ lines  addObject: [PBGitGraphLine  lowerLineFrom:  newPos  to:   newPos  color:   newLane->index ()]] ;
100+ 		add_line ( lines, ¤tLine,  0 ,  newPos,  newPos,  newLane->index ()) ;
90101	}
91102
92103	//  Add all other parents
@@ -102,7 +113,7 @@ - (void) decorateCommit: (PBGitCommit *) commit
102113		for  (; it < currentLanes->end (); ++it) {
103114			i++;
104115			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 ()) ;
106117				was_displayed = YES ;
107118				break ;
108119			}
@@ -117,10 +128,14 @@ - (void) decorateCommit: (PBGitCommit *) commit
117128		addedParent = YES ;
118129		PBGitLane *newLane = new  PBGitLane (parent);
119130		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 ()) ;
121132	}
122133
123134	previous = [[PBGraphCellInfo alloc ] initWithPosition: newPos andLines: lines];
135+ 	if  (currentLine > maxLines)
136+ 		NSLog (@" Number of lines: %i  vs allocated: %i " 
137+ 
138+ 	previous.nLines  = currentLine;
124139	previous.sign  = commit.sign ;
125140
126141	//  If a parent was added, we have room to not indent.
0 commit comments