Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  HistoryView: Don't show the 'loading commit' thing until after 500 ms.
  HistoryView: Remove raw view
  HistoryView: don't load in commit information in a separate thread anymore
  Fix UTF-8 bug in NSString_RegEx
  CommitView: Don't keep rearranging when iterating over files
  IndexController: de-privatize the index-stopping stuff
  • Loading branch information
pieter committed Sep 17, 2009
2 parents 4476892 + 5972bd4 commit 1a5a211
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 387 deletions.
4 changes: 3 additions & 1 deletion NSString_RegEx.m
Expand Up @@ -57,7 +57,9 @@ - (NSArray *) substringsMatchingRegularExpression:(NSString *)pattern count:(int
break;

NSRange range = NSMakeRange(pmatch[i].rm_so, pmatch[i].rm_eo - pmatch[i].rm_so);
NSString * substring = [self substringWithRange:range];
NSString * substring = [[[NSString alloc] initWithBytes:[self UTF8String] + range.location
length:range.length
encoding:NSUTF8StringEncoding] autorelease];
[outMatches addObject:substring];

if (ranges)
Expand Down
14 changes: 2 additions & 12 deletions PBGitCommit.m
Expand Up @@ -66,20 +66,10 @@ - (NSString *)realSha
return str;
}

// NOTE: This method should remain threadsafe, as we load it in async
// from the web view.
// FIXME: Remove this method once it's unused.
- (NSString*) details
{
if (details != nil)
return details;

NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", @"--no-color", [self realSha], nil];
if (![PBGitDefaults showWhitespaceDifferences])
[arguments insertObject:@"-w" atIndex:1];

details = [self.repository outputForArguments:arguments];

return details;
return @"";
}

- (NSString *) patch
Expand Down
4 changes: 3 additions & 1 deletion PBGitCommitController.m
Expand Up @@ -11,7 +11,7 @@
#import "PBChangedFile.h"
#import "PBWebChangesController.h"
#import "NSString_RegEx.h"

#import "PBGitIndexController.h"

@interface PBGitCommitController (PrivateMethods)
- (NSArray *) linesFromNotification:(NSNotification *)notification;
Expand Down Expand Up @@ -240,6 +240,7 @@ - (NSMutableDictionary *)dictionaryForLines:(NSArray *)lines
- (void) addFilesFromDictionary:(NSMutableDictionary *)dictionary staged:(BOOL)staged tracked:(BOOL)tracked
{
// Iterate over all existing files
[indexController stopTrackingIndex];
for (PBChangedFile *file in files) {
NSArray *fileStatus = [dictionary objectForKey:file.path];
// Object found, this is still a cached / uncached thing
Expand Down Expand Up @@ -270,6 +271,7 @@ - (void) addFilesFromDictionary:(NSMutableDictionary *)dictionary staged:(BOOL)s
file.hasUnstagedChanges = NO;
}
}
[indexController resumeTrackingIndex];

// Do new files
if (![[dictionary allKeys] count])
Expand Down
3 changes: 1 addition & 2 deletions PBGitHistoryController.m
Expand Up @@ -66,8 +66,7 @@ - (void) updateKeys

switch (self.selectedTab) {
case 0: self.webCommit = realCommit; break;
case 1: self.rawCommit = realCommit; break;
case 2: self.gitTree = realCommit.tree; break;
case 1: self.gitTree = realCommit.tree; break;
}
}

Expand Down
506 changes: 148 additions & 358 deletions PBGitHistoryView.xib

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions PBGitIndexController.h
Expand Up @@ -36,5 +36,8 @@
- (NSString *) stagedChangesForFile:(PBChangedFile *)file;
- (NSString *) unstagedChangesForFile:(PBChangedFile *)file;

- (void)stopTrackingIndex;
- (void)resumeTrackingIndex;

- (NSMenu *) menuForTable:(NSTableView *)table;
@end
5 changes: 0 additions & 5 deletions PBGitIndexController.m
Expand Up @@ -12,11 +12,6 @@

#define FileChangesTableViewType @"GitFileChangedType"

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

@implementation PBGitIndexController

@synthesize contextSize;
Expand Down
32 changes: 32 additions & 0 deletions PBWebHistoryController.m
Expand Up @@ -7,6 +7,7 @@
//

#import "PBWebHistoryController.h"
#import "PBGitDefaults.h"

@implementation PBWebHistoryController

Expand Down Expand Up @@ -49,6 +50,37 @@ - (void) changeContentTo: (PBGitCommit *) content

NSArray *arguments = [NSArray arrayWithObjects:content, [[[historyController repository] headRef] simpleRef], nil];
[[self script] callWebScriptMethod:@"loadCommit" withArguments: arguments];

// Now we load the extended details. We used to do this in a separate thread,
// but this caused some funny behaviour because NSTask's and NSThread's don't really
// like each other. Instead, just do it async.

NSMutableArray *taskArguments = [NSMutableArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", @"--no-color", currentSha, nil];
if (![PBGitDefaults showWhitespaceDifferences])
[taskArguments insertObject:@"-w" atIndex:1];

NSFileHandle *handle = [repository handleForArguments:taskArguments];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
// Remove notification, in case we have another one running
[nc removeObserver:self];
[nc addObserver:self selector:@selector(commitDetailsLoaded:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
[handle readToEndOfFileInBackgroundAndNotify];
}

- (void)commitDetailsLoaded:(NSNotification *)notification
{
NSData *data = [[notification userInfo] valueForKey:NSFileHandleNotificationDataItem];
if (!data)
return;

NSString *details = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (!details)
details = [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];

if (!details)
return;

[[view windowScriptObject] callWebScriptMethod:@"loadCommitDetails" withArguments:[NSArray arrayWithObject:details]];
}

- (void) selectCommit: (NSString*) sha
Expand Down
40 changes: 32 additions & 8 deletions html/views/history/history.js
@@ -1,4 +1,7 @@
var commit;

// Create a new Commit object
// obj: PBGitCommit object
var Commit = function(obj) {
this.object = obj;

Expand All @@ -7,12 +10,14 @@ var Commit = function(obj) {
this.sha = obj.realSha();
this.parents = obj.parents;
this.subject = obj.subject;
this.notificationID = null;

// TODO:
// this.author_date instant

// This all needs to be async
this.loadedRaw = function(details) {
// This can be called later with the output of
// 'git show' to fill in missing commit details (such as a diff)
this.parseDetails = function(details) {
this.raw = details;

var diffStart = this.raw.indexOf("\ndiff ");
Expand Down Expand Up @@ -138,6 +143,7 @@ var selectCommit = function(a) {
Controller.selectCommit_(a);
}

// Relead only refs
var reload = function() {
$("notification").style.display = "none";
commit.reloadRefs();
Expand All @@ -159,14 +165,16 @@ var showRefs = function() {

var loadCommit = function(commitObject, currentRef) {
// These are only the things we can do instantly.
// Other information will be loaded later by loadExtendedCommit
// Other information will be loaded later by loadCommitDetails,
// Which will be called from the controller once
// the commit details are in.

if (commit && commit.notificationID)
clearTimeout(commit.notificationID);

commit = new Commit(commitObject);
Controller.callSelector_onObject_callBack_("details", commitObject,
function(data) { commit.loadedRaw(data); loadExtendedCommit(commit); });
commit.currentRef = currentRef;

notify("Loading commit…", 0);

$("commitID").innerHTML = commit.sha;
$("authorID").innerHTML = commit.author_name;
$("subjectID").innerHTML = commit.subject.escapeHTML();
Expand Down Expand Up @@ -196,9 +204,18 @@ var loadCommit = function(commitObject, currentRef) {
"<a href='' onclick='selectCommit(this.innerHTML); return false;'>" +
commit.parents[i] + "</a></td>";
}

commit.notificationID = setTimeout(function() {
if (!commit.fullyLoaded)
notify("Loading commit…", 0);
commit.notificationID = null;
}, 500);

}

var showDiff = function() {

// Callback for the diff highlighter. Used to generate a filelist
var newfile = function(name1, name2, id, mode_change, old_mode, new_mode) {
var button = document.createElement("div");
var p = document.createElement("p");
Expand Down Expand Up @@ -270,8 +287,15 @@ var enableFeatures = function()
enableFeature("gravatar", $("gravatar"))
}

var loadExtendedCommit = function(commit)
var loadCommitDetails = function(data)
{
commit.parseDetails(data);

if (commit.notificationID)
clearTimeout(commit.notificationID)
else
$("notification").style.display = "none";

var formatEmail = function(name, email) {
return email ? name + " &lt;<a href='mailto:" + email + "'>" + email + "</a>&gt;" : name;
}
Expand Down

0 comments on commit 1a5a211

Please sign in to comment.