mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Grapher: add first part of displaying refs
This adds the "hasRef" boolean member in PBGitCellInfo which is set to true if the specific commit has symbolic refs. This is the first part in supporting labels just like gitk has. For now, commits with refs are just displayed with a red circle. Things that need to be done to support all refs: * Make the NSDictionary in PBGitRepository contain arrays of refs, not a single string * Make PBGitGrapher store all refs of a commit in the PBGitCellInfo * Figure out a nice way to display the labels in PBGitRevisionCell
This commit is contained in:
@@ -21,8 +21,10 @@ struct PBGitGraphColumn {
|
||||
|
||||
@interface PBGitGrapher : NSObject {
|
||||
NSMutableArray* cellsInfo;
|
||||
PBGitRepository* repository;
|
||||
}
|
||||
|
||||
- (id) initWithRepository: (PBGitRepository*) repo;
|
||||
- (void) parseCommits: (NSArray *) array;
|
||||
- (PBGraphCellInfo*) cellInfoForRow: (int) row;
|
||||
@end
|
||||
|
||||
+13
-1
@@ -12,12 +12,21 @@
|
||||
|
||||
@implementation PBGitGrapher
|
||||
|
||||
- (id) initWithRepository: (PBGitRepository*) repo
|
||||
{
|
||||
repository = repo;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) parseCommits: (NSArray *) commits
|
||||
{
|
||||
cellsInfo = [NSMutableArray arrayWithCapacity: [commits count]];
|
||||
int row = 0;
|
||||
|
||||
NSDictionary* refs = nil;
|
||||
if (repository)
|
||||
refs = repository.refs;
|
||||
|
||||
PBGraphCellInfo* previous;
|
||||
NSMutableArray* previousLanes = [NSMutableArray array];
|
||||
|
||||
@@ -120,7 +129,10 @@
|
||||
|
||||
++row;
|
||||
previous = [[PBGraphCellInfo alloc] initWithPosition:newPos andLines:lines];
|
||||
|
||||
|
||||
if (refs && [refs objectForKey:commit.sha])
|
||||
previous.hasRef = TRUE;
|
||||
|
||||
// If a parent was added, we have room to not indent.
|
||||
if (addedParent)
|
||||
previous.numColumns = [currentLanes count] - 1;
|
||||
|
||||
+3
-2
@@ -15,6 +15,7 @@ extern NSString* PBGitRepositoryErrorDomain;
|
||||
PBGitRevList* revisionList;
|
||||
NSArray* branches;
|
||||
NSString* currentBranch;
|
||||
NSDictionary* refs;
|
||||
}
|
||||
|
||||
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
|
||||
@@ -22,7 +23,7 @@ extern NSString* PBGitRepositoryErrorDomain;
|
||||
- (NSString*) outputForCommand:(NSString*) cmd;
|
||||
- (NSString*) outputForArguments:(NSArray*) args;
|
||||
|
||||
- (void) readBranches;
|
||||
- (void) readRefs;
|
||||
- (void) readCurrentBranch;
|
||||
|
||||
- (NSString*) parseSymbolicReference:(NSString*) ref;
|
||||
@@ -34,5 +35,5 @@ extern NSString* PBGitRepositoryErrorDomain;
|
||||
@property (readonly) PBGitRevList* revisionList;
|
||||
@property (assign) NSArray* branches;
|
||||
@property (assign) NSString* currentBranch;
|
||||
|
||||
@property (assign) NSDictionary* refs;
|
||||
@end
|
||||
|
||||
+11
-9
@@ -17,7 +17,7 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
|
||||
|
||||
@implementation PBGitRepository
|
||||
|
||||
@synthesize revisionList, branches, currentBranch;
|
||||
@synthesize revisionList, branches, currentBranch, refs;
|
||||
static NSString* gitPath;
|
||||
|
||||
+ (void) initialize
|
||||
@@ -112,7 +112,7 @@ static NSString* gitPath;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
[self readBranches];
|
||||
[self readRefs];
|
||||
[self readCurrentBranch];
|
||||
revisionList = [[PBGitRevList alloc] initWithRepository:self andRevListParameters:[NSArray array]];
|
||||
}
|
||||
@@ -139,21 +139,23 @@ static NSString* gitPath;
|
||||
[controller release];
|
||||
}
|
||||
|
||||
- (void) readBranches
|
||||
- (void) readRefs
|
||||
{
|
||||
NSString* output = [PBEasyPipe outputForCommand:gitPath withArgs:[NSArray arrayWithObjects:@"for-each-ref", @"refs/heads", nil] inDir: self.fileURL.path];
|
||||
NSString* output = [PBEasyPipe outputForCommand:gitPath withArgs:[NSArray arrayWithObjects:@"for-each-ref", @"refs", nil] inDir: self.fileURL.path];
|
||||
NSArray* lines = [output componentsSeparatedByString:@"\n"];
|
||||
NSMutableDictionary* newRefs = [NSMutableDictionary dictionary];
|
||||
NSMutableArray* newBranches = [NSMutableArray array];
|
||||
for (NSString* line in lines) {
|
||||
NSString* substr = [line substringWithRange: NSMakeRange(40,19)];
|
||||
if (![substr isEqualToString:@" commit\trefs/heads/"]) {
|
||||
NSLog(@"Cannot parse branch %@. (%@)", line, substr);
|
||||
continue;
|
||||
if ([substr isEqualToString:@" commit\trefs/heads/"]) {
|
||||
NSString* branch = [line substringFromIndex:59];
|
||||
[newBranches addObject: branch];
|
||||
}
|
||||
NSString* branch = [line substringFromIndex:59];
|
||||
[newBranches addObject: branch];
|
||||
NSArray* components = [line componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" \t"]];
|
||||
[newRefs setObject:[components objectAtIndex:2] forKey:[components objectAtIndex:0]];
|
||||
}
|
||||
self.branches = newBranches;
|
||||
self.refs = newRefs;
|
||||
}
|
||||
|
||||
- (void) readCurrentBranch
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
}
|
||||
|
||||
- initWithRepository:(id)repo andRevListParameters:(NSArray*) params;
|
||||
- readCommits;
|
||||
- (void) readCommits;
|
||||
|
||||
@property(retain) NSArray* commits;
|
||||
@property(retain) id grapher;
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@
|
||||
|
||||
[self performSelectorOnMainThread:@selector(setCommits:) withObject:newArray waitUntilDone:YES];
|
||||
|
||||
PBGitGrapher* g = [[PBGitGrapher alloc] init];
|
||||
PBGitGrapher* g = [[PBGitGrapher alloc] initWithRepository: repository];
|
||||
[g parseCommits: self.commits];
|
||||
[self performSelectorOnMainThread:@selector(setGrapher:) withObject:g waitUntilDone:YES];
|
||||
[self performSelectorOnMainThread:@selector(setCommits:) withObject:newArray waitUntilDone:YES];
|
||||
|
||||
+5
-1
@@ -63,7 +63,11 @@
|
||||
|
||||
- (void) drawCircleForColumn: (int) c inRect: (NSRect) r
|
||||
{
|
||||
[[NSColor blackColor] set];
|
||||
if (!cellInfo.hasRef)
|
||||
[[NSColor blackColor] set];
|
||||
else
|
||||
[[NSColor redColor] set];
|
||||
|
||||
int columnWidth = 10;
|
||||
NSPoint origin = r.origin;
|
||||
NSPoint columnOrigin = { origin.x + columnWidth * c, origin.y};
|
||||
|
||||
@@ -14,9 +14,11 @@
|
||||
int position;
|
||||
NSArray* lines;
|
||||
int numColumns;
|
||||
BOOL hasRef;
|
||||
}
|
||||
@property(readonly) NSArray* lines;
|
||||
@property(assign) int position, numColumns;
|
||||
@property(assign) BOOL hasRef;
|
||||
|
||||
- (id)initWithPosition: (int) p andLines: (NSArray*) l;
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
|
||||
|
||||
@implementation PBGraphCellInfo
|
||||
@synthesize lines, position, numColumns;
|
||||
@synthesize lines, position, numColumns, hasRef;
|
||||
- (id)initWithPosition: (int) p andLines: (NSArray*) l
|
||||
{
|
||||
position = p;
|
||||
|
||||
Reference in New Issue
Block a user