diff --git a/PBChangedFile.h b/PBChangedFile.h
index 0c68e81..73ee3f0 100644
--- a/PBChangedFile.h
+++ b/PBChangedFile.h
@@ -17,7 +17,8 @@ typedef enum {
@interface PBChangedFile : NSObject {
NSString *path;
- BOOL cached;
+ BOOL hasCachedChanges;
+ BOOL hasUnstagedChanges;
__weak PBGitRepository *repository;
PBChangedFileStatus status;
}
@@ -25,7 +26,8 @@ typedef enum {
@property (readonly) NSString *path;
@property (assign) PBChangedFileStatus status;
-@property (assign) BOOL cached;
+@property (assign) BOOL hasCachedChanges;
+@property (assign) BOOL hasUnstagedChanges;
- (NSImage *)icon;
- (NSString *)changes;
- (void) stageChanges;
diff --git a/PBChangedFile.m b/PBChangedFile.m
index 518ca64..3bb0ae7 100644
--- a/PBChangedFile.m
+++ b/PBChangedFile.m
@@ -11,7 +11,7 @@
@implementation PBChangedFile
-@synthesize path, status, cached;
+@synthesize path, status, hasCachedChanges, hasUnstagedChanges;
- (id) initWithPath:(NSString *)p andRepository:(PBGitRepository *)r
{
@@ -20,18 +20,20 @@
return self;
}
-- (NSString *) changes
+- (NSString *) cachedChanges
+{
+ return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--cached", @"--", path, nil]];
+}
+
+- (NSString *)unstagedChanges
{
if (status == NEW)
return [PBEasyPipe outputForCommand:@"/bin/cat" withArgs:[NSArray arrayWithObject:path] inDir:[repository workingDirectory]];
- else {
- if (cached == YES)
- return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--cached", @"--", path, nil]];
- else
- return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--", path, nil]];
- }
+
+ return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--", path, nil]];
}
+
- (NSImage *) icon
{
NSString *filename;
@@ -57,12 +59,15 @@
else
[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"add", path, nil]];
- self.cached = YES;
+ self.hasUnstagedChanges = NO;
+ self.hasCachedChanges = YES;
}
+
- (void) unstageChanges
{
[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"reset", @"--", path, nil]];
- self.cached = NO;
+ self.hasCachedChanges = NO;
+ self.hasUnstagedChanges = YES;
}
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
diff --git a/PBGitCommitController.m b/PBGitCommitController.m
index 502ce7e..b6d5e2a 100644
--- a/PBGitCommitController.m
+++ b/PBGitCommitController.m
@@ -29,8 +29,8 @@
[commitMessageView setTypingAttributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Monaco" size:12.0] forKey:NSFontAttributeName]];
- [unstagedFilesController setFilterPredicate:[NSPredicate predicateWithFormat:@"cached == 0"]];
- [cachedFilesController setFilterPredicate:[NSPredicate predicateWithFormat:@"cached == 1"]];
+ [unstagedFilesController setFilterPredicate:[NSPredicate predicateWithFormat:@"hasUnstagedChanges == 1"]];
+ [cachedFilesController setFilterPredicate:[NSPredicate predicateWithFormat:@"hasCachedChanges == 1"]];
[unstagedFilesController setSortDescriptors:[NSArray arrayWithObjects:
[[NSSortDescriptor alloc] initWithKey:@"status" ascending:false],
@@ -110,6 +110,8 @@
{
if (!--self.busy)
self.status = @"Ready";
+ [unstagedFilesController didChangeArrangementCriteria];
+ [cachedFilesController didChangeArrangementCriteria];
}
- (void) readOtherFiles:(NSNotification *)notification;
@@ -120,15 +122,16 @@
continue;
PBChangedFile *file =[[PBChangedFile alloc] initWithPath:line andRepository:repository];
file.status = NEW;
- file.cached = NO;
- [unstagedFilesController addObject:file];
+ file.hasCachedChanges = NO;
+ file.hasUnstagedChanges = YES;
+
+ [files addObject: file];
}
[self doneProcessingIndex];
}
-- (void) readUnstagedFiles:(NSNotification *)notification
+- (void) addFilesFromLines:(NSArray *)lines cached:(BOOL) cached
{
- NSArray *lines = [self linesFromNotification:notification];
NSArray *fileStatus;
int even = 0;
for (NSString *line in lines) {
@@ -138,54 +141,44 @@
continue;
}
even = 0;
-
+
+ // If the file is already added, we shouldn't add it again
+ // but rather update it to incorporate our changes
+ NSArray *existingFiles = [files filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"path == '%@'", line]];
+ if ([existingFiles count] != 0) {
+ PBChangedFile *file = [existingFiles objectAtIndex:0];
+ if (cached)
+ file.hasCachedChanges = YES;
+ else
+ file.hasUnstagedChanges = YES;
+ return;
+ }
+
PBChangedFile *file = [[PBChangedFile alloc] initWithPath:line andRepository:repository];
if ([[fileStatus objectAtIndex:4] isEqualToString:@"D"])
file.status = DELETED;
else
file.status = MODIFIED;
- file.cached = NO;
+ file.hasCachedChanges = cached;
+ file.hasUnstagedChanges = !cached;
- // FIXME: If you are in a merge and have conflicts, a file is displayed twice, with different
- // index values. For now, we don't handle this gracefully.
- BOOL fileExists = NO;
- for (PBChangedFile *object in [unstagedFilesController arrangedObjects]) {
- if ([[object path] isEqualToString:[file path]]) {
- fileExists = YES;
- break;
- }
- }
- if (!fileExists)
- [unstagedFilesController addObject: file];
+ [files addObject: file];
}
+
+}
+
+- (void) readUnstagedFiles:(NSNotification *)notification
+{
+ NSArray *lines = [self linesFromNotification:notification];
+ [self addFilesFromLines:lines cached:NO];
[self doneProcessingIndex];
}
- (void) readCachedFiles:(NSNotification *)notification
{
NSArray *lines = [self linesFromNotification:notification];
- NSLog(@"Reading cached files!");
- NSArray *fileStatus;
- int even = 0;
- for (NSString *line in lines) {
- if (!even) {
- even = 1;
- fileStatus = [line componentsSeparatedByString:@" "];
- continue;
- }
- even = 0;
-
- PBChangedFile *file = [[PBChangedFile alloc] initWithPath:line andRepository:repository];
- if ([[fileStatus objectAtIndex:4] isEqualToString:@"D"])
- file.status = DELETED;
- else
- file.status = MODIFIED;
-
- file.cached = YES;
- [cachedFilesController addObject: file];
- }
- self.files = files;
+ [self addFilesFromLines:lines cached:YES];
[self doneProcessingIndex];
}
@@ -284,7 +277,7 @@
PBChangedFile *selectedItem = [[controller arrangedObjects] objectAtIndex:selectionIndex];
[controller removeObject:selectedItem];
- if (selectedItem.cached == NO)
+ if ([tableView tag] == 0)
[selectedItem stageChanges];
else
[selectedItem unstageChanges];
diff --git a/PBWebChangesController.h b/PBWebChangesController.h
index e3b2ac5..de934cc 100644
--- a/PBWebChangesController.h
+++ b/PBWebChangesController.h
@@ -19,5 +19,5 @@
id previousFile;
}
-- (void) showDiff:(PBChangedFile *)file;
+- (void) showDiff:(PBChangedFile *)file cached:(BOOL)cached;
@end
diff --git a/PBWebChangesController.m b/PBWebChangesController.m
index ca7ae8b..12dd72f 100644
--- a/PBWebChangesController.m
+++ b/PBWebChangesController.m
@@ -24,7 +24,7 @@ static PBChangedFile *lastFileSelected = nil;
- (void) didLoad
{
if (lastFileSelected)
- [self showDiff: lastFileSelected];
+ [self showDiff: lastFileSelected cached:NO];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
@@ -35,6 +35,7 @@ static PBChangedFile *lastFileSelected = nil;
if ([[object selectedObjects] count] == 0)
return;
+ // TODO: Move this to commitcontroller
if (object == unstagedFilesController)
[cachedFilesController setSelectionIndexes:[NSIndexSet indexSet]];
else
@@ -42,10 +43,10 @@ static PBChangedFile *lastFileSelected = nil;
PBChangedFile *file = [[object selectedObjects] objectAtIndex:0];
- [self showDiff: file];
+ [self showDiff: file cached: object == cachedFilesController];
}
-- (void) showDiff:(PBChangedFile *)file
+- (void) showDiff:(PBChangedFile *)file cached:(BOOL) cached
{
if (!finishedLoading) {
lastFileSelected = file;
@@ -59,6 +60,7 @@ static PBChangedFile *lastFileSelected = nil;
previousFile = file;
id script = [view windowScriptObject];
- [script callWebScriptMethod:@"showFileChanges" withArguments:[NSArray arrayWithObject:file]];
+ NSLog(@"Showing diff..");
+ [script callWebScriptMethod:@"showFileChanges" withArguments:[NSArray arrayWithObjects:file, [NSNumber numberWithBool:cached], nil]];
}
@end
diff --git a/html/diff.html b/html/diff.html
index f346578..47ceb5a 100644
--- a/html/diff.html
+++ b/html/diff.html
@@ -7,11 +7,11 @@