Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CommitView: move index functions to separate controller

This merges functionality that was previously stored in the
combination of PBGitCommitController / PBChangedFile to a
dedicated controller, PBGitIndexController.
  • Loading branch information...
commit 0975426f2f5119335c00768006b1ede0252ac448 1 parent 874737f
@pieter authored
View
6 GitX.xcodeproj/project.pbxproj
@@ -29,6 +29,7 @@
F50FE0E30E07BE9600854FCD /* PBGitRevisionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F50FE0E20E07BE9600854FCD /* PBGitRevisionCell.m */; };
F513085B0E0740F2000C8BCD /* PBQLOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = F513085A0E0740F2000C8BCD /* PBQLOutlineView.m */; };
F5140DC90E8A8EB20091E9F3 /* RoundedRectangle.m in Sources */ = {isa = PBXBuildFile; fileRef = F5140DC80E8A8EB20091E9F3 /* RoundedRectangle.m */; };
+ F523CEB60ED3399200DDD714 /* PBGitIndexController.m in Sources */ = {isa = PBXBuildFile; fileRef = F523CEB50ED3399200DDD714 /* PBGitIndexController.m */; };
F52BCE030E84208300AA3741 /* PBGitHistoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F52BCE020E84208300AA3741 /* PBGitHistoryView.xib */; };
F52BCE070E84211300AA3741 /* PBGitHistoryController.m in Sources */ = {isa = PBXBuildFile; fileRef = F52BCE060E84211300AA3741 /* PBGitHistoryController.m */; };
F53C4DF70E97FC630022AD59 /* PBGitBinary.m in Sources */ = {isa = PBXBuildFile; fileRef = F53C4DF60E97FC630022AD59 /* PBGitBinary.m */; };
@@ -141,6 +142,8 @@
F513085A0E0740F2000C8BCD /* PBQLOutlineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBQLOutlineView.m; sourceTree = "<group>"; };
F5140DC70E8A8EB20091E9F3 /* RoundedRectangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoundedRectangle.h; sourceTree = "<group>"; };
F5140DC80E8A8EB20091E9F3 /* RoundedRectangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoundedRectangle.m; sourceTree = "<group>"; };
+ F523CEB40ED3399100DDD714 /* PBGitIndexController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitIndexController.h; sourceTree = "<group>"; };
+ F523CEB50ED3399200DDD714 /* PBGitIndexController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitIndexController.m; sourceTree = "<group>"; };
F52BCE020E84208300AA3741 /* PBGitHistoryView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PBGitHistoryView.xib; sourceTree = "<group>"; };
F52BCE050E84211300AA3741 /* PBGitHistoryController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitHistoryController.h; sourceTree = "<group>"; };
F52BCE060E84211300AA3741 /* PBGitHistoryController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitHistoryController.m; sourceTree = "<group>"; };
@@ -503,6 +506,8 @@
F59116E80E843BCB0072CCB1 /* PBGitCommitController.m */,
F5E927FA0E883F0700056E75 /* PBWebChangesController.h */,
F5E927FB0E883F0700056E75 /* PBWebChangesController.m */,
+ F523CEB40ED3399100DDD714 /* PBGitIndexController.h */,
+ F523CEB50ED3399200DDD714 /* PBGitIndexController.m */,
);
name = Commit;
sourceTree = "<group>";
@@ -671,6 +676,7 @@
F5FC41F40EBCBD4300191D80 /* PBGitXProtocol.m in Sources */,
F574A2850EAE2EAC003F2CB1 /* PBRefController.m in Sources */,
F5FC43FE0EBD08EE00191D80 /* PBRefMenuItem.m in Sources */,
+ F523CEB60ED3399200DDD714 /* PBGitIndexController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
17 PBChangedFile.h
@@ -19,21 +19,22 @@ typedef enum {
NSString *path;
BOOL hasCachedChanges;
BOOL hasUnstagedChanges;
- __weak PBGitRepository *repository;
+
+ // Index and HEAD stuff, to be used to revert changes
+ NSString *commitBlobSHA;
+ NSString *commitBlobMode;
+
PBChangedFileStatus status;
}
-@property (readonly) NSString *path;
+@property (copy) NSString *path, *commitBlobSHA, *commitBlobMode;
@property (assign) PBChangedFileStatus status;
@property (assign) BOOL hasCachedChanges;
@property (assign) BOOL hasUnstagedChanges;
-- (NSImage *)icon;
-- (NSString *)cachedChangesAmend:(BOOL)amend;
-- (NSString *)unstagedChanges;
-- (void) stageChanges;
-- (void) unstageChangesAmend:(BOOL)amend;
+- (NSImage *)icon;
+- (NSString *)indexInfo;
-- (id) initWithPath:(NSString *)p andRepository:(PBGitRepository *)r;
+- (id) initWithPath:(NSString *)p;
@end
View
73 PBChangedFile.m
@@ -11,39 +11,25 @@
@implementation PBChangedFile
-@synthesize path, status, hasCachedChanges, hasUnstagedChanges;
+@synthesize path, status, hasCachedChanges, hasUnstagedChanges, commitBlobSHA, commitBlobMode;
-- (id) initWithPath:(NSString *)p andRepository:(PBGitRepository *)r
+- (id) initWithPath:(NSString *)p
{
+ if (![super init])
+ return nil;
+
path = p;
- repository = r;
return self;
}
-- (NSString *) cachedChangesAmend:(BOOL) amend
+- (NSString *)indexInfo
{
- if (amend)
- return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--cached", @"HEAD^", @"--", path, nil]];
-
- return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--cached", @"--", path, nil]];
-}
-
-- (NSString *)unstagedChanges
-{
- if (status == NEW) {
- NSStringEncoding encoding;
- NSError *error = nil;
- NSString *contents = [NSString stringWithContentsOfFile:[[repository workingDirectory] stringByAppendingPathComponent:path] usedEncoding:&encoding error:&error];
- if (error)
- return nil;
-
- return contents;
- }
-
- return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--", path, nil]];
+ if (!self.commitBlobSHA)
+ return [NSString stringWithFormat:@"0 0000000000000000000000000000000000000000\t%@\0", self.path];
+ else
+ return [NSString stringWithFormat:@"%@ %@\t%@\0", self.commitBlobMode, self.commitBlobSHA, self.path];
}
-
- (NSImage *) icon
{
NSString *filename;
@@ -62,45 +48,6 @@ - (NSImage *) icon
return [[NSImage alloc] initByReferencingFile: p];
}
-- (void) stageChanges
-{
- if (status == DELETED)
- [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"rm", path, nil]];
- else
- [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"add", path, nil]];
-
- self.hasUnstagedChanges = NO;
- self.hasCachedChanges = YES;
-}
-
-- (void) unstageChangesAmend:(BOOL) amend
-{
- if (amend)
- [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"reset", @"HEAD^", @"--", path, nil]];
- else
- [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"reset", @"--", path, nil]];
- self.hasCachedChanges = NO;
- self.hasUnstagedChanges = YES;
-}
-
-- (void) forceRevertChanges
-{
- [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"checkout", @"--", path, nil]];
- self.hasUnstagedChanges = NO;
-}
-
-- (void) revertChanges
-{
- int ret = [[NSAlert alertWithMessageText:@"Revert changes"
- defaultButton:nil
- alternateButton:@"Cancel"
- otherButton:nil
- informativeTextWithFormat:@"Are you sure you wish to revert the changes in '%@'?\n\n You cannot undo this operation.", path] runModal];
-
- if (ret == NSAlertDefaultReturn)
- [self forceRevertChanges];
-}
-
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
{
return NO;
View
2  PBFileChangesTableView.h
@@ -10,8 +10,6 @@
@interface PBFileChangesTableView : NSTableView {
- id controller;
}
-@property (retain) id controller;
@end
View
7 PBFileChangesTableView.m
@@ -7,17 +7,14 @@
//
#import "PBFileChangesTableView.h"
-#import "PBGitCommitController.h"
@implementation PBFileChangesTableView
-@synthesize controller;
-
#pragma mark NSTableView overrides
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
{
- if (controller)
- return [(PBGitCommitController *)controller menuForTable: self];
+ if ([self delegate])
+ return [[self delegate] menuForTable: self];
return nil;
}
View
11 PBGitCommitController.h
@@ -17,21 +17,18 @@
IBOutlet NSTextView *commitMessageView;
IBOutlet NSArrayController *unstagedFilesController;
IBOutlet NSArrayController *cachedFilesController;
- NSString *status;
+ IBOutlet id indexController;
IBOutlet id webController;
+ NSString *status;
+
// We use busy as a count of active processes.
// You can increase it when your process start
// And decrease it after you have finished.
int busy;
BOOL amend;
- IBOutlet PBIconAndTextCell* unstagedButtonCell;
- IBOutlet PBIconAndTextCell* cachedButtonCell;
-
- IBOutlet NSTableView *unstagedTable;
- IBOutlet NSTableView *cachedTable;
}
@property (retain) NSMutableArray *files;
@@ -44,8 +41,6 @@
- (void) readUnstagedFiles:(NSNotification *)notification;
- (void) stageHunk: (NSString *)hunk reverse:(BOOL)reverse;
-- (NSMenu *) menuForTable:(NSTableView *)table;
-
- (IBAction) refresh:(id) sender;
- (IBAction) commit:(id) sender;
@end
View
84 PBGitCommitController.m
@@ -17,18 +17,6 @@ @implementation PBGitCommitController
- (void)awakeFromNib
{
[super awakeFromNib];
- self.busy = 0;
-
- amend = NO;
-
- [unstagedButtonCell setAction:@selector(rowClicked:)];
- [cachedButtonCell setAction:@selector(rowClicked:)];
-
- [unstagedTable setDoubleAction:@selector(tableClicked:)];
- [cachedTable setDoubleAction:@selector(tableClicked:)];
-
- [unstagedTable setController: self];
-
[self refresh:self];
[commitMessageView setTypingAttributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Monaco" size:12.0] forKey:NSFontAttributeName]];
@@ -133,7 +121,7 @@ - (void) readOtherFiles:(NSNotification *)notification;
for (NSString *line in lines) {
if ([line length] == 0)
continue;
- PBChangedFile *file =[[PBChangedFile alloc] initWithPath:line andRepository:repository];
+ PBChangedFile *file =[[PBChangedFile alloc] initWithPath:line];
file.status = NEW;
file.hasCachedChanges = NO;
file.hasUnstagedChanges = YES;
@@ -155,15 +143,22 @@ - (void) addFilesFromLines:(NSArray *)lines cached:(BOOL) cached
}
even = 0;
+ NSString *mode = [[fileStatus objectAtIndex:0] substringFromIndex:1];
+ NSString *sha = [fileStatus objectAtIndex:2];
+
BOOL isNew = YES;
// If the file is already added, we shouldn't add it again
// but rather update it to incorporate our changes
for (PBChangedFile *file in files) {
if ([file.path isEqualToString:line]) {
- if (cached)
+ if (cached) {
+ file.commitBlobSHA = sha;
+ file.commitBlobMode = mode;
file.hasCachedChanges = YES;
+ }
else
file.hasUnstagedChanges = YES;
+
isNew = NO;
break;
}
@@ -172,12 +167,17 @@ - (void) addFilesFromLines:(NSArray *)lines cached:(BOOL) cached
if (!isNew)
continue;
- PBChangedFile *file = [[PBChangedFile alloc] initWithPath:line andRepository:repository];
+ PBChangedFile *file = [[PBChangedFile alloc] initWithPath:line];
if ([[fileStatus objectAtIndex:4] isEqualToString:@"D"])
file.status = DELETED;
+ else if([[fileStatus objectAtIndex:0] isEqualToString:@":000000"])
+ file.status = NEW;
else
file.status = MODIFIED;
+ file.commitBlobSHA = sha;
+ file.commitBlobMode = mode;
+
file.hasCachedChanges = cached;
file.hasUnstagedChanges = !cached;
@@ -279,60 +279,6 @@ - (IBAction) commit:(id) sender
self.amend = NO;
}
-- (void) tableClicked:(NSTableView *) tableView
-{
- NSUInteger selectionIndex = [[tableView selectedRowIndexes] firstIndex];
- NSArrayController *controller = [tableView tag] == 0 ? unstagedFilesController : cachedFilesController;
- PBChangedFile *selectedItem = [[controller arrangedObjects] objectAtIndex:selectionIndex];
-
- if ([tableView tag] == 0)
- [selectedItem stageChanges];
- else
- [selectedItem unstageChangesAmend:amend];
-
-}
-
-- (void) rowClicked:(NSCell *)sender
-{
- NSTableView *tableView = (NSTableView *)[sender controlView];
- if([tableView numberOfSelectedRows] != 1)
- return;
- [self tableClicked: tableView];
-}
-
-- (void)tableView:(NSTableView*)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn*)tableColumn row:(int)rowIndex
-{
- [[tableColumn dataCell] setImage:[[[(([tableView tag] == 0) ? unstagedFilesController : cachedFilesController) arrangedObjects] objectAtIndex:rowIndex] icon]];
-}
-
-- (NSMenu *) menuForTable:(NSTableView *)table
-{
- NSUInteger selectionIndex = [[table selectedRowIndexes] firstIndex];
- PBChangedFile *selectedItem = [[unstagedFilesController arrangedObjects] objectAtIndex:selectionIndex];
-
- NSMenu *a = [[NSMenu alloc] init];
- NSMenuItem *stageItem = [[NSMenuItem alloc] initWithTitle:@"Stage Changes" action:@selector(stageChanges) keyEquivalent:@""];
- [stageItem setTarget:selectedItem];
- [a addItem:stageItem];
-
- // Do not add "revert" options for untracked files
- if (selectedItem.status == NEW)
- return a;
-
- NSMenuItem *revertItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes…" action:@selector(revertChanges) keyEquivalent:@""];
- [revertItem setTarget:selectedItem];
- [revertItem setAlternate:NO];
- [a addItem:revertItem];
-
- NSMenuItem *revertForceItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes" action:@selector(forceRevertChanges) keyEquivalent:@""];
- [revertForceItem setTarget:selectedItem];
- [revertForceItem setAlternate:YES];
- [revertForceItem setKeyEquivalentModifierMask:NSAlternateKeyMask];
- [a addItem:revertForceItem];
-
- return a;
-}
-
- (void) stageHunk:(NSString *)hunk reverse:(BOOL)reverse
{
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"apply", @"--cached", nil];
View
276 PBGitCommitView.xib
@@ -48,7 +48,7 @@
<int key="NSfFlags">1044</int>
</object>
<reference key="NSControlView" ref="1073221655"/>
- <object class="NSColor" key="NSBackgroundColor">
+ <object class="NSColor" key="NSBackgroundColor" id="602862277">
<int key="NSColorSpace">6</int>
<string key="NSCatalogName">System</string>
<string key="NSColorName">controlColor</string>
@@ -678,6 +678,22 @@
<double key="NSMinValue">1.600000e+01</double>
<double key="NSMaxValue">1.000000e+02</double>
</object>
+ <object class="NSTextField" id="981504079">
+ <reference key="NSNextResponder" ref="750704519"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{264, 10}, {169, 17}}</string>
+ <reference key="NSSuperview" ref="750704519"/>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="780514957">
+ <int key="NSCellFlags">68288064</int>
+ <int key="NSCellFlags2">272630784</int>
+ <string key="NSContents">Label</string>
+ <reference key="NSSupport" ref="554612341"/>
+ <reference key="NSControlView" ref="981504079"/>
+ <reference key="NSBackgroundColor" ref="602862277"/>
+ <reference key="NSTextColor" ref="132492410"/>
+ </object>
+ </object>
</object>
<string key="NSFrameSize">{852, 432}</string>
<reference key="NSSuperview"/>
@@ -706,6 +722,7 @@
<string>description</string>
<string>path</string>
<string>icon</string>
+ <string>commitBlobSHA</string>
</object>
<bool key="NSEditable">YES</bool>
<object class="_NSManagedProxy" key="_NSManagedProxy"/>
@@ -830,6 +847,9 @@
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
+ <object class="NSCustomObject" id="49450131">
+ <string key="NSClassName">PBGitIndexController</string>
+ </object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
@@ -963,38 +983,6 @@
<int key="connectionID">156</int>
</object>
<object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">delegate</string>
- <reference key="source" ref="588180404"/>
- <reference key="destination" ref="1001"/>
- </object>
- <int key="connectionID">178</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">delegate</string>
- <reference key="source" ref="638535043"/>
- <reference key="destination" ref="1001"/>
- </object>
- <int key="connectionID">179</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">cachedButtonCell</string>
- <reference key="source" ref="1001"/>
- <reference key="destination" ref="39450212"/>
- </object>
- <int key="connectionID">210</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">unstagedButtonCell</string>
- <reference key="source" ref="1001"/>
- <reference key="destination" ref="45690317"/>
- </object>
- <int key="connectionID">211</int>
- </object>
- <object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">commit:</string>
<reference key="source" ref="1001"/>
@@ -1044,22 +1032,6 @@
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
- <string key="label">unstagedTable</string>
- <reference key="source" ref="1001"/>
- <reference key="destination" ref="588180404"/>
- </object>
- <int key="connectionID">223</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">cachedTable</string>
- <reference key="source" ref="1001"/>
- <reference key="destination" ref="638535043"/>
- </object>
- <int key="connectionID">224</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
<string key="label">viewToolbar</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="570289088"/>
@@ -1090,6 +1062,126 @@
</object>
<int key="connectionID">253</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">indexController</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="49450131"/>
+ </object>
+ <int key="connectionID">256</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">commitController</string>
+ <reference key="source" ref="49450131"/>
+ <reference key="destination" ref="1001"/>
+ </object>
+ <int key="connectionID">257</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">delegate</string>
+ <reference key="source" ref="588180404"/>
+ <reference key="destination" ref="49450131"/>
+ </object>
+ <int key="connectionID">258</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">delegate</string>
+ <reference key="source" ref="638535043"/>
+ <reference key="destination" ref="49450131"/>
+ </object>
+ <int key="connectionID">259</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">unstagedFilesController</string>
+ <reference key="source" ref="49450131"/>
+ <reference key="destination" ref="128809524"/>
+ </object>
+ <int key="connectionID">260</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">stagedFilesController</string>
+ <reference key="source" ref="49450131"/>
+ <reference key="destination" ref="667905213"/>
+ </object>
+ <int key="connectionID">261</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">indexController</string>
+ <reference key="source" ref="1007648253"/>
+ <reference key="destination" ref="49450131"/>
+ </object>
+ <int key="connectionID">262</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">stagedTable</string>
+ <reference key="source" ref="49450131"/>
+ <reference key="destination" ref="638535043"/>
+ </object>
+ <int key="connectionID">263</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">unstagedTable</string>
+ <reference key="source" ref="49450131"/>
+ <reference key="destination" ref="588180404"/>
+ </object>
+ <int key="connectionID">264</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">stagedButtonCell</string>
+ <reference key="source" ref="49450131"/>
+ <reference key="destination" ref="39450212"/>
+ </object>
+ <int key="connectionID">265</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">unstagedButtonCell</string>
+ <reference key="source" ref="49450131"/>
+ <reference key="destination" ref="45690317"/>
+ </object>
+ <int key="connectionID">266</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">rowClicked:</string>
+ <reference key="source" ref="49450131"/>
+ <reference key="destination" ref="45690317"/>
+ </object>
+ <int key="connectionID">268</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">rowClicked:</string>
+ <reference key="source" ref="49450131"/>
+ <reference key="destination" ref="39450212"/>
+ </object>
+ <int key="connectionID">269</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: selection.commitBlobSHA</string>
+ <reference key="source" ref="981504079"/>
+ <reference key="destination" ref="667905213"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="981504079"/>
+ <reference key="NSDestination" ref="667905213"/>
+ <string key="NSLabel">value: selection.commitBlobSHA</string>
+ <string key="NSBinding">value</string>
+ <string key="NSKeyPath">selection.commitBlobSHA</string>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">274</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1128,6 +1220,7 @@
<reference ref="812432808"/>
<reference ref="221814497"/>
<reference ref="1073221655"/>
+ <reference ref="981504079"/>
</object>
<reference key="parent" ref="1002"/>
</object>
@@ -1410,6 +1503,25 @@
<reference key="object" ref="475684116"/>
<reference key="parent" ref="18874447"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">254</int>
+ <reference key="object" ref="49450131"/>
+ <reference key="parent" ref="1002"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">270</int>
+ <reference key="object" ref="981504079"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="780514957"/>
+ </object>
+ <reference key="parent" ref="750704519"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">271</int>
+ <reference key="object" ref="780514957"/>
+ <reference key="parent" ref="981504079"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -1444,6 +1556,9 @@
<string>240.IBPluginDependency</string>
<string>247.IBPluginDependency</string>
<string>248.IBPluginDependency</string>
+ <string>254.IBPluginDependency</string>
+ <string>270.IBPluginDependency</string>
+ <string>271.IBPluginDependency</string>
<string>42.IBPluginDependency</string>
<string>45.IBPluginDependency</string>
<string>46.IBPluginDependency</string>
@@ -1453,6 +1568,7 @@
<string>54.IBPluginDependency</string>
<string>55.IBPluginDependency</string>
<string>56.IBPluginDependency</string>
+ <string>57.CustomClassName</string>
<string>57.IBPluginDependency</string>
<string>81.IBPluginDependency</string>
<string>86.IBPluginDependency</string>
@@ -1492,11 +1608,15 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>PBFileChangesTableView</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>PBFileChangesTableView</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1523,7 +1643,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">253</int>
+ <int key="maxID">275</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1539,10 +1659,6 @@
<object class="IBPartialClassDescription">
<string key="className">PBFileChangesTableView</string>
<string key="superclassName">NSTableView</string>
- <object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">controller</string>
- <string key="NS.object.0">id</string>
- </object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">PBFileChangesTableView.h</string>
@@ -1568,30 +1684,68 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
- <string>cachedButtonCell</string>
<string>cachedFilesController</string>
- <string>cachedTable</string>
<string>commitMessageView</string>
+ <string>indexController</string>
+ <string>unstagedFilesController</string>
+ <string>webController</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSArrayController</string>
+ <string>NSTextView</string>
+ <string>id</string>
+ <string>NSArrayController</string>
+ <string>id</string>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">PBGitCommitController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">PBGitIndexController</string>
+ <string key="superclassName">NSObject</string>
+ <object class="NSMutableDictionary" key="actions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>rowClicked:</string>
+ <string>tableClicked:</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSCell</string>
+ <string>NSTableView</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="outlets">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>commitController</string>
+ <string>stagedButtonCell</string>
+ <string>stagedFilesController</string>
+ <string>stagedTable</string>
<string>unstagedButtonCell</string>
<string>unstagedFilesController</string>
<string>unstagedTable</string>
- <string>webController</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <string>PBGitCommitController</string>
<string>PBIconAndTextCell</string>
<string>NSArrayController</string>
<string>NSTableView</string>
- <string>NSTextView</string>
<string>PBIconAndTextCell</string>
<string>NSArrayController</string>
<string>NSTableView</string>
- <string>id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
- <string key="minorKey">PBGitCommitController.h</string>
+ <string key="minorKey">PBGitIndexController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
@@ -1631,12 +1785,14 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>cachedFilesController</string>
<string>controller</string>
+ <string>indexController</string>
<string>unstagedFilesController</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSArrayController</string>
<string>PBGitCommitController</string>
+ <string>id</string>
<string>NSArrayController</string>
</object>
</object>
View
32 PBGitIndexController.h
@@ -0,0 +1,32 @@
+//
+// PBGitIndexController.h
+// GitX
+//
+// Created by Pieter de Bie on 18-11-08.
+// Copyright 2008 Pieter de Bie. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import "PBGitCommitController.h"
+#import "PBChangedFile.h"
+
+@interface PBGitIndexController : NSObject {
+ IBOutlet NSArrayController *stagedFilesController, *unstagedFilesController;
+ IBOutlet PBGitCommitController *commitController;
+
+ IBOutlet PBIconAndTextCell* unstagedButtonCell;
+ IBOutlet PBIconAndTextCell* stagedButtonCell;
+
+ IBOutlet NSTableView *unstagedTable;
+ IBOutlet NSTableView *stagedTable;
+}
+
+- (void) stageFiles:(NSArray *)files;
+- (void) unstageFiles:(NSArray *)files;
+
+- (IBAction) rowClicked:(NSCell *) sender;
+- (IBAction) tableClicked:(NSTableView *)tableView;
+
+- (NSString *) stagedChangesForFile:(PBChangedFile *)file;
+- (NSString *) unstagedChangesForFile:(PBChangedFile *)file;
+@end
View
205 PBGitIndexController.m
@@ -0,0 +1,205 @@
+//
+// PBGitIndexController.m
+// GitX
+//
+// Created by Pieter de Bie on 18-11-08.
+// Copyright 2008 Pieter de Bie. All rights reserved.
+//
+
+#import "PBGitIndexController.h"
+#import "PBChangedFile.h"
+
+@implementation PBGitIndexController
+
+- (void)awakeFromNib
+{
+ [unstagedTable setDoubleAction:@selector(tableClicked:)];
+ [stagedTable setDoubleAction:@selector(tableClicked:)];
+
+ [unstagedTable setTarget:self];
+ [stagedTable setTarget:self];
+}
+
+- (void) stageFiles:(NSArray *)files
+{
+ NSMutableString *input = [NSMutableString string];
+
+ for (PBChangedFile *file in files) {
+ [input appendFormat:@"%@\0", file.path];
+ }
+
+ int ret = 1;
+ [commitController.repository outputForArguments:[NSArray arrayWithObjects:@"update-index", @"--add", @"--remove", @"-z", @"--stdin", nil]
+ inputString:input retValue:&ret];
+
+ if (ret)
+ {
+ NSLog(@"Error when updating index. Retvalue: %i", ret);
+ return;
+ }
+
+ for (PBChangedFile *file in files)
+ {
+ file.hasUnstagedChanges = NO;
+ file.hasCachedChanges = YES;
+ }
+}
+
+- (void) unstageFiles:(NSArray *)files
+{
+ NSMutableString *input = [NSMutableString string];
+
+ for (PBChangedFile *file in files) {
+ [input appendString:[file indexInfo]];
+ }
+
+ int ret = 1;
+ [commitController.repository outputForArguments:[NSArray arrayWithObjects:@"update-index", @"-z", @"--index-info", nil]
+ inputString:input retValue:&ret];
+
+ if (ret)
+ {
+ NSLog(@"Error when updating index. Retvalue: %i", ret);
+ return;
+ }
+
+ for (PBChangedFile *file in files)
+ {
+ file.hasUnstagedChanges = YES;
+ file.hasCachedChanges = NO;
+ }
+}
+
+# pragma mark Displaying diffs
+
+- (NSString *) stagedChangesForFile:(PBChangedFile *)file
+{
+ NSString *indexPath = [@":0:" stringByAppendingString:file.path];
+
+ if (file.status == NEW)
+ return [commitController.repository outputForArguments:[NSArray arrayWithObjects:@"show", indexPath, nil]];
+
+ return [commitController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", file.commitBlobSHA, indexPath, nil]];
+}
+
+- (NSString *)unstagedChangesForFile:(PBChangedFile *)file
+{
+ if (file.status == NEW) {
+ NSStringEncoding encoding;
+ NSError *error = nil;
+ NSString *contents = [NSString stringWithContentsOfFile:[[commitController.repository workingDirectory] stringByAppendingPathComponent:file.path]
+ usedEncoding:&encoding error:&error];
+ if (error)
+ return nil;
+
+ return contents;
+ }
+
+ return [commitController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--", file.path, nil]];
+}
+
+//- (void) forceRevertChanges
+//{
+// [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"checkout", @"--", file.path, nil]];
+// self.hasUnstagedChanges = NO;
+//}
+//
+//- (void) revertChanges
+//{
+// int ret = [[NSAlert alertWithMessageText:@"Revert changes"
+// defaultButton:nil
+// alternateButton:@"Cancel"
+// otherButton:nil
+// informativeTextWithFormat:@"Are you sure you wish to revert the changes in '%@'?\n\n You cannot undo this operation.", path] runModal];
+//
+// if (ret == NSAlertDefaultReturn)
+// [self forceRevertChanges];
+//}
+
+
+# pragma mark Context Menu methods
+- (NSMenu *) menuForTable:(NSTableView *)table
+{
+ NSMenu *menu = [[NSMenu alloc] init];
+
+ // Unstaged changes
+ if ([table tag] == 0) {
+ NSArray *selectedFiles = [unstagedFilesController selectedObjects];
+
+ NSMenuItem *stageItem = [[NSMenuItem alloc] initWithTitle:@"Stage Changes" action:@selector(stageFilesAction:) keyEquivalent:@""];
+ [stageItem setTarget:self];
+ [stageItem setRepresentedObject:selectedFiles];
+ [menu addItem:stageItem];
+ }
+ else if ([table tag] == 1) {
+ NSArray *selectedFiles = [stagedFilesController selectedObjects];
+
+ NSMenuItem *unstageItem = [[NSMenuItem alloc] initWithTitle:@"Unstage Changes" action:@selector(unstageFilesAction:) keyEquivalent:@""];
+ [unstageItem setTarget:self];
+ [unstageItem setRepresentedObject:selectedFiles];
+ [menu addItem:unstageItem];
+ }
+
+ // Do not add "revert" options for untracked files
+ // if (selectedItem.status == NEW)
+ // return a;
+ //
+ // NSMenuItem *revertItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes…" action:@selector(revertChanges) keyEquivalent:@""];
+ // [revertItem setTarget:selectedItem];
+ // [revertItem setAlternate:NO];
+ // [a addItem:revertItem];
+ //
+ // NSMenuItem *revertForceItem = [[NSMenuItem alloc] initWithTitle:@"Revert Changes" action:@selector(forceRevertChanges) keyEquivalent:@""];
+ // [revertForceItem setTarget:selectedItem];
+ // [revertForceItem setAlternate:YES];
+ // [revertForceItem setKeyEquivalentModifierMask:NSAlternateKeyMask];
+ // [a addItem:revertForceItem];
+
+ return menu;
+}
+
+- (void) stageFilesAction:(id) sender
+{
+ [self stageFiles:[sender representedObject]];
+}
+
+- (void) unstageFilesAction:(id) sender
+{
+ [self unstageFiles:[sender representedObject]];
+}
+
+# pragma mark TableView icon delegate
+- (void)tableView:(NSTableView*)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn*)tableColumn row:(int)rowIndex
+{
+ id controller = [tableView tag] == 0 ? unstagedFilesController : stagedFilesController;
+ [[tableColumn dataCell] setImage:[[[controller arrangedObjects] objectAtIndex:rowIndex] icon]];
+}
+
+- (void) tableClicked:(NSTableView *) tableView
+{
+ NSArrayController *controller = [tableView tag] == 0 ? unstagedFilesController : stagedFilesController;
+
+ NSIndexSet *selectionIndexes = [tableView selectedRowIndexes];
+ NSArray *files = [[controller arrangedObjects] objectsAtIndexes:selectionIndexes];
+ if ([tableView tag] == 0)
+ [self stageFiles:files];
+ else
+ [self unstageFiles:files];
+}
+
+- (void) rowClicked:(NSCell *)sender
+{
+ NSTableView *tableView = (NSTableView *)[sender controlView];
+ if([tableView numberOfSelectedRows] != 1)
+ return;
+ [self tableClicked: tableView];
+}
+
+# pragma mark WebKit Accessibility
+
++ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
+{
+ return NO;
+}
+
+@end
View
2  PBGitRepository.m
@@ -367,7 +367,7 @@ - (NSString*) outputForArguments:(NSArray *)arguments inputString:(NSString *)in
{
return [PBEasyPipe outputForCommand:[PBGitBinary path]
withArgs:arguments
- inDir: self.fileURL.path
+ inDir:[self workingDirectory]
inputString:input
retValue: ret];
}
View
2  PBWebChangesController.h
@@ -15,6 +15,7 @@
IBOutlet NSArrayController *unstagedFilesController;
IBOutlet NSArrayController *cachedFilesController;
IBOutlet PBGitCommitController *controller;
+ IBOutlet id indexController;
PBChangedFile *selectedFile;
BOOL selectedFileIsCached;
@@ -23,4 +24,5 @@
- (void) refresh;
- (void) setStateMessage:(NSString *)state;
+- (void) showMultiple:(NSArray *)files;
@end
View
1  PBWebChangesController.m
@@ -24,6 +24,7 @@ - (void) awakeFromNib
- (void) didLoad
{
+ [[self script] setValue:indexController forKey:@"IndexController"];
[self refresh];
}
View
6 html/views/commit/commit.js
@@ -2,7 +2,7 @@ var showNewFile = function(file)
{
$('title').innerHTML = "New file: " + file.path;
- var contents = file.unstagedChanges();
+ var contents = IndexController.unstagedChangesForFile_(file);
if (!contents) {
notify("Can not display changes (Binary file?)", -1);
return;
@@ -36,11 +36,11 @@ var showFileChanges = function(file, cached) {
var changes;
if (cached) {
$("title").innerHTML = "Staged changes for " + file.path;
- changes = file.cachedChangesAmend_(Controller.amend());
+ changes = IndexController.stagedChangesForFile_(file);
}
else {
$("title").innerHTML = "Unstaged changes for " + file.path;
- changes = file.unstagedChanges();
+ changes = IndexController.unstagedChangesForFile_(file);
}
if (changes == "") {
Please sign in to comment.
Something went wrong with that request. Please try again.