diff --git a/PBGitCommitController.h b/PBGitCommitController.h index f96e986..a8b2802 100644 --- a/PBGitCommitController.h +++ b/PBGitCommitController.h @@ -12,6 +12,8 @@ @class PBGitIndexController, PBIconAndTextCell, PBWebChangesController, PBGitIndex; @interface PBGitCommitController : PBViewController { + // This might have to transfer over to the PBGitRepository + // object sometime PBGitIndex *index; IBOutlet NSTextView *commitMessageView; diff --git a/PBGitIndexController.h b/PBGitIndexController.h index a3bc191..87b3cab 100644 --- a/PBGitIndexController.h +++ b/PBGitIndexController.h @@ -33,8 +33,5 @@ - (IBAction) rowClicked:(NSCell *) sender; - (IBAction) tableClicked:(NSTableView *)tableView; -- (NSString *) stagedChangesForFile:(PBChangedFile *)file; -- (NSString *) unstagedChangesForFile:(PBChangedFile *)file; - - (NSMenu *) menuForTable:(NSTableView *)table; @end diff --git a/PBGitIndexController.m b/PBGitIndexController.m index a03b3a2..0517a0b 100644 --- a/PBGitIndexController.m +++ b/PBGitIndexController.m @@ -129,33 +129,6 @@ # 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-index", [self contextParameter], @"--cached", [commitController.index parentTree], @"--", file.path, nil]]; -} - -- (NSString *)unstagedChangesForFile:(PBChangedFile *)file -{ - if (file.status == NEW) { - NSStringEncoding encoding; - NSError *error = nil; - NSString *path = [[commitController.repository workingDirectory] stringByAppendingPathComponent:file.path]; - NSString *contents = [NSString stringWithContentsOfFile:path - usedEncoding:&encoding - error:&error]; - if (error) - return nil; - - return contents; - } - - return [commitController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff-files", [self contextParameter], @"--", file.path, nil]]; -} - (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force { diff --git a/PBWebChangesController.m b/PBWebChangesController.m index 697307d..96b9a5c 100644 --- a/PBWebChangesController.m +++ b/PBWebChangesController.m @@ -26,7 +26,7 @@ - (void) didLoad { - [[self script] setValue:indexController forKey:@"IndexController"]; + [[self script] setValue:controller.index forKey:@"Index"]; [self refresh]; } diff --git a/html/views/commit/commit.js b/html/views/commit/commit.js index df0cb42..cdec998 100644 --- a/html/views/commit/commit.js +++ b/html/views/commit/commit.js @@ -1,11 +1,13 @@ /* Commit: Interface for selecting, staging, discarding, and unstaging hunks, individual lines, or ranges of lines. */ +var contextLines = 5; + var showNewFile = function(file) { setTitle("New file: " + file.path); - var contents = IndexController.unstagedChangesForFile_(file); + var contents = Index.diffForFile_staged_contextLines_(file, false, contextLines); if (!contents) { notify("Can not display changes (Binary file?)", -1); diff.innerHTML = ""; @@ -49,23 +51,16 @@ var showFileChanges = function(file, cached) { hideState(); $("contextSize").oninput = function(element) { - Controller.setContextSize_($("contextSize").value); + contextSize = $("contextSize").value; } if (file.status == 0) // New file? return showNewFile(file); - var changes; - if (cached) { - setTitle("Staged changes for " + file.path); - displayContext(); - changes = IndexController.stagedChangesForFile_(file); - } - else { - setTitle("Unstaged changes for " + file.path); - displayContext(); - changes = IndexController.unstagedChangesForFile_(file); - } + setTitle((cached ? "Staged": "Unstaged") + " changes for" + file.path); + displayContext(); + var changes = Index.diffForFile_staged_contextLines_(file, cached, contextLines); + if (changes == "") { notify("This file has no more changes", 1);