5 // Created by Pieter de Bie on 17-06-08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
9 #import "PBGitGrapher.h"
10 #import "PBGitCommit.h"
12 @implementation PBGitGrapher
15 - (void) parseCommits: (NSArray *) commits
17 cellsInfo = [NSMutableArray arrayWithCapacity: [commits count]];
20 PBGraphCellInfo* previous;
21 NSMutableArray* previousLanes = [NSMutableArray array];
23 for (PBGitCommit* commit in commits) {
24 int i = 0, newPos = -1;
25 NSMutableArray* currentLanes = [NSMutableArray array];
26 NSMutableArray* lines = [NSMutableArray array];
29 // First, iterate over earlier columns and pass through any that don't want this commit
30 if (previous != nil) {
32 // We can't count until numColumns here, as it's only used for the width of the cell.
33 for (NSString* lane in previousLanes) {
35 // This is our commit! We should do a "merge": move the line from
36 // our upperMapping to their lowerMapping
37 if ([lane isEqualToString:commit.sha]) {
40 [currentLanes addObject: [commit.parents objectAtIndex:0]];
41 newPos = [currentLanes count];
43 [lines addObject: [PBLine upperLineFrom: i to: newPos]];
46 // We are not this commit.
47 // Try to find an earlier column for this commit.
50 for (NSString* column in currentLanes) {
55 if ([column isEqualToString: lane]) {
56 // We already have a column for this commit. use it instead
57 [lines addObject: [PBLine upperLineFrom: i to: j]];
63 // We need a new column for this.
66 // This was used as a hack to stop large lanes from drawing
67 //if (previous->columns[i].color == 10)
70 [currentLanes addObject: lane];
71 [lines addObject: [PBLine upperLineFrom: [currentLanes count] to: [currentLanes count]]];
72 [lines addObject: [PBLine lowerLineFrom: [currentLanes count] to: [currentLanes count]]];
75 // For existing columns, we always just continue straight down
76 // ^^ I don't know what that means anymore :(
77 [lines addObject:[PBLine lowerLineFrom:newPos to:newPos]];
81 //Add your own parents
83 // If we already did the first parent, don't do so again
85 [currentLanes addObject: [commit.parents objectAtIndex:0]];
86 newPos = [currentLanes count];
87 [lines addObject:[PBLine lowerLineFrom: newPos to: newPos]];
90 // Add all other parents
92 // If we add at least one parent, we can go back a single column.
93 // This boolean will tell us if that happened
94 BOOL addedParent = NO;
96 for (NSString* parent in [commit.parents subarrayWithRange:NSMakeRange(1, [commit.parents count] -1)]) {
98 BOOL was_displayed = NO;
99 for (NSString* column in currentLanes) {
101 if ([column isEqualToString: parent]) {
102 [lines addObject:[PBLine lowerLineFrom: i to: newPos]];
110 // Really add this parent
112 [currentLanes addObject:parent];
113 [lines addObject:[PBLine lowerLineFrom: [currentLanes count] to: newPos]];
117 previous = [[PBGraphCellInfo alloc] initWithPosition:newPos andLines:lines];
119 // If a parent was added, we have room to not indent.
121 previous.numColumns = [currentLanes count] - 1;
123 previous.numColumns = [currentLanes count];
124 previousLanes = currentLanes;
125 [cellsInfo addObject: previous];
129 - (PBGraphCellInfo*) cellInfoForRow: (int) row
131 return [cellsInfo objectAtIndex: row];