Skip to content

Commit

Permalink
GitIndex: explicitly tell when stuff is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
pieter committed Sep 13, 2009
1 parent 9b1fcd7 commit 029b42c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
11 changes: 10 additions & 1 deletion PBGitCommitController.m
Expand Up @@ -18,6 +18,7 @@ - (void)commitStatusUpdated:(NSNotification *)notification;
- (void)commitFinished:(NSNotification *)notification;
- (void)commitFailed:(NSNotification *)notification;
- (void)amendCommit:(NSNotification *)notification;
- (void)indexChanged:(NSNotification *)notification;
@end

@implementation PBGitCommitController
Expand All @@ -37,6 +38,7 @@ - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGit
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFinished:) name:PBGitIndexFinishedCommit object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(commitFailed:) name:PBGitIndexCommitFailed object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(amendCommit:) name:PBGitIndexAmendMessageAvailable object:index];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(indexChanged:) name:PBGitIndexIndexUpdated object:index];

return self;
}
Expand All @@ -55,6 +57,9 @@ - (void)awakeFromNib
[[NSSortDescriptor alloc] initWithKey:@"path" ascending:true], nil]];
[cachedFilesController setSortDescriptors:[NSArray arrayWithObject:
[[NSSortDescriptor alloc] initWithKey:@"path" ascending:true]]];

[cachedFilesController setAutomaticallyRearrangesObjects:NO];
[unstagedFilesController setAutomaticallyRearrangesObjects:NO];
}

- (void) removeView
Expand Down Expand Up @@ -164,5 +169,9 @@ - (void)amendCommit:(NSNotification *)notification
commitMessageView.string = message;
}


- (void)indexChanged:(NSNotification *)notification
{
[cachedFilesController rearrangeObjects];
[unstagedFilesController rearrangeObjects];
}
@end
5 changes: 5 additions & 0 deletions PBGitIndex.h
Expand Up @@ -15,11 +15,16 @@ extern NSString *PBGitIndexIndexRefreshStatus;
extern NSString *PBGitIndexIndexRefreshFailed;
extern NSString *PBGitIndexFinishedIndexRefresh;

// The "Files" array has changed
extern NSString *PBGitIndexIndexUpdated;

extern NSString *PBGitIndexCommitStatus;
extern NSString *PBGitIndexCommitFailed;
extern NSString *PBGitIndexFinishedCommit;

extern NSString *PBGitIndexAmendMessageAvailable;


// Represents a git index for a given work tree.
// As a single git repository can have multiple trees,
// the tree has to be given explicitly, even though
Expand Down
21 changes: 16 additions & 5 deletions PBGitIndex.m
Expand Up @@ -17,6 +17,8 @@
NSString *PBGitIndexIndexRefreshFailed = @"PBGitIndexIndexRefreshFailed";
NSString *PBGitIndexFinishedIndexRefresh = @"PBGitIndexFinishedIndexRefresh";

NSString *PBGitIndexIndexUpdated = @"GBGitIndexIndexUpdated";

NSString *PBGitIndexCommitStatus = @"PBGitIndexCommitStatus";
NSString *PBGitIndexCommitFailed = @"PBGitIndexCommitFailed";
NSString *PBGitIndexFinishedCommit = @"PBGitIndexFinishedCommit";
Expand Down Expand Up @@ -45,6 +47,7 @@ @interface PBGitIndex ()
- (NSString *) parentTree;
- (void)postCommitUpdate:(NSString *)update;
- (void)postCommitFailure:(NSString *)reason;
- (void)postIndexChange;
@end

@implementation PBGitIndex
Expand Down Expand Up @@ -257,13 +260,13 @@ - (BOOL)stageFiles:(NSArray *)stageFiles
return NO;
}

// TODO: Stop Tracking
for (PBChangedFile *file in stageFiles)
{
file.hasUnstagedChanges = NO;
file.hasStagedChanges = YES;
}
// TODO: Resume tracking

[self postIndexChange];
return YES;
}

Expand All @@ -288,14 +291,13 @@ - (BOOL)unstageFiles:(NSArray *)unstageFiles
return NO;
}

// TODO: stop tracking
for (PBChangedFile *file in unstageFiles)
{
file.hasUnstagedChanges = YES;
file.hasStagedChanges = NO;
}
// TODO: resume tracking

[self postIndexChange];
return YES;
}

Expand Down Expand Up @@ -353,6 +355,11 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff-files", parameter, @"--", file.path, nil]];
}

- (void)postIndexChange
{
[[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexIndexUpdated
object:self];
}

# pragma mark WebKit Accessibility

Expand Down Expand Up @@ -568,8 +575,10 @@ - (NSMutableDictionary *)dictionaryForLines:(NSArray *)lines
- (void)indexStepComplete
{
// if we're still busy, do nothing :)
if (--refreshStatus)
if (--refreshStatus) {
[self postIndexChange];
return;
}

// At this point, all index operations have finished.
// We need to find all files that don't have either
Expand All @@ -590,6 +599,8 @@ - (void)indexStepComplete

[[NSNotificationCenter defaultCenter] postNotificationName:PBGitIndexFinishedIndexRefresh
object:self];
[self postIndexChange];

}

@end
22 changes: 4 additions & 18 deletions PBGitIndexController.m
Expand Up @@ -13,11 +13,6 @@

#define FileChangesTableViewType @"GitFileChangedType"

@interface PBGitIndexController (PrivateMethods)
- (void)stopTrackingIndex;
- (void)resumeTrackingIndex;
@end

@implementation PBGitIndexController

- (void)awakeFromNib
Expand Down Expand Up @@ -67,6 +62,8 @@ - (void) ignoreFiles:(NSArray *)files
[ignoreFile writeToFile:gitIgnoreName atomically:YES encoding:enc error:&error];
if (error)
[[commitController.repository windowController] showErrorSheet:error];

// TODO: Post index change
}

# pragma mark Displaying diffs
Expand Down Expand Up @@ -97,6 +94,8 @@ - (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force

for (PBChangedFile *file in files)
file.hasUnstagedChanges = NO;

// TODO: Post index update
}

# pragma mark Context Menu methods
Expand Down Expand Up @@ -316,17 +315,4 @@ + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
return NO;
}

#pragma mark Private Methods
- (void)stopTrackingIndex
{
[stagedFilesController setAutomaticallyRearrangesObjects:NO];
[unstagedFilesController setAutomaticallyRearrangesObjects:NO];
}
- (void)resumeTrackingIndex
{
[stagedFilesController setAutomaticallyRearrangesObjects:YES];
[unstagedFilesController setAutomaticallyRearrangesObjects:YES];
[stagedFilesController rearrangeObjects];
[unstagedFilesController rearrangeObjects];
}
@end

0 comments on commit 029b42c

Please sign in to comment.