mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
better error control
This commit is contained in:
+19
-17
@@ -73,10 +73,6 @@
|
||||
@"h", ITEM_IDENTIFIER,
|
||||
@"HEAD", ITEM_NAME,
|
||||
nil],
|
||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"p", ITEM_IDENTIFIER,
|
||||
@"Previous", ITEM_NAME,
|
||||
nil],
|
||||
nil];
|
||||
[self.groups addObject:[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithBool:NO], GROUP_SEPARATOR,
|
||||
@@ -93,29 +89,34 @@
|
||||
|
||||
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||
{
|
||||
//NSLog(@"keyPath=%@ change=%@ context=%@ object=%@ \n %@",keyPath,change,context,object,[historyController.treeController selectedObjects]);
|
||||
[self showFile];
|
||||
}
|
||||
|
||||
- (void) showFile
|
||||
{
|
||||
NSError *theError = nil;
|
||||
NSArray *files=[historyController.treeController selectedObjects];
|
||||
if ([files count]>0) {
|
||||
PBGitTree *file=[files objectAtIndex:0];
|
||||
|
||||
|
||||
NSString *fileTxt = @"";
|
||||
if(startFile==@"fileview")
|
||||
fileTxt=[self parseHTML:[file textContents]];
|
||||
else if(startFile==@"blame")
|
||||
fileTxt=[self parseBlame:[file blame]];
|
||||
else if(startFile==@"log")
|
||||
fileTxt=[file log:logFormat];
|
||||
else if(startFile==@"diff")
|
||||
fileTxt=[file diff:diffType];
|
||||
if(startFile==@"fileview"){
|
||||
fileTxt=[self parseHTML:[file textContents:&theError]];
|
||||
}else if(startFile==@"blame"){
|
||||
fileTxt=[self parseBlame:[file blame:&theError]];
|
||||
}else if(startFile==@"log"){
|
||||
fileTxt=[file log:logFormat error:&theError];
|
||||
}else if(startFile==@"diff"){
|
||||
fileTxt=[file diff:diffType error:&theError];
|
||||
}
|
||||
|
||||
id script = [view windowScriptObject];
|
||||
NSString *filePath = [file fullPath];
|
||||
[script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]];
|
||||
if(theError==nil){
|
||||
NSString *filePath = [file fullPath];
|
||||
[script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]];
|
||||
}else{
|
||||
[script callWebScriptMethod:@"setMessage" withArguments:[NSArray arrayWithObjects:[theError localizedDescription], nil]];
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -174,7 +175,8 @@
|
||||
|
||||
- (void)scopeBar:(MGScopeBar *)theScopeBar selectedStateChanged:(BOOL)selected forItem:(NSString *)identifier inGroup:(int)groupNumber
|
||||
{
|
||||
if(groupNumber==0){
|
||||
NSLog(@"startFile=%@ identifier=%@ groupNumber=%d",startFile,identifier,groupNumber);
|
||||
if((groupNumber==0) && (startFile!=identifier)){
|
||||
NSString *path = [NSString stringWithFormat:@"html/views/%@", identifier];
|
||||
NSString *html = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:path];
|
||||
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:html]];
|
||||
|
||||
@@ -228,46 +228,31 @@
|
||||
{
|
||||
if ([(NSString *)context isEqualToString: @"commitChange"]) {
|
||||
[self updateKeys];
|
||||
[self restoreFileBrowserSelection];
|
||||
return;
|
||||
}
|
||||
|
||||
if ([(NSString *)context isEqualToString: @"treeChange"]) {
|
||||
//[self restoreFileBrowserSelection];
|
||||
}else if ([(NSString *)context isEqualToString: @"treeChange"]) {
|
||||
[self updateQuicklookForce: NO];
|
||||
[self saveFileBrowserSelection];
|
||||
return;
|
||||
}
|
||||
|
||||
if([(NSString *)context isEqualToString:@"branchChange"]) {
|
||||
}else if([(NSString *)context isEqualToString:@"branchChange"]) {
|
||||
// Reset the sorting
|
||||
if ([[commitController sortDescriptors] count])
|
||||
[commitController setSortDescriptors:[NSArray array]];
|
||||
[self updateBranchFilterMatrix];
|
||||
return;
|
||||
}
|
||||
|
||||
if([(NSString *)context isEqualToString:@"updateRefs"]) {
|
||||
}else if([(NSString *)context isEqualToString:@"updateRefs"]) {
|
||||
[commitController rearrangeObjects];
|
||||
return;
|
||||
}
|
||||
|
||||
if ([(NSString *)context isEqualToString:@"branchFilterChange"]) {
|
||||
}else if ([(NSString *)context isEqualToString:@"branchFilterChange"]) {
|
||||
[PBGitDefaults setBranchFilter:repository.currentBranchFilter];
|
||||
[self updateBranchFilterMatrix];
|
||||
return;
|
||||
}
|
||||
|
||||
if([(NSString *)context isEqualToString:@"updateCommitCount"] || [(NSString *)context isEqualToString:@"revisionListUpdating"]) {
|
||||
}else if([(NSString *)context isEqualToString:@"updateCommitCount"] || [(NSString *)context isEqualToString:@"revisionListUpdating"]) {
|
||||
[self updateStatus];
|
||||
|
||||
if ([repository.currentBranch isSimpleRef])
|
||||
[self selectCommit:[repository shaForRef:[repository.currentBranch ref]]];
|
||||
else
|
||||
[self selectCommit:[[self firstCommit] sha]];
|
||||
return;
|
||||
}else{
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
|
||||
- (IBAction) openSelectedFile:(id)sender
|
||||
|
||||
+5
-4
@@ -26,10 +26,11 @@
|
||||
+ (PBGitTree*) rootForCommit: (id) commit;
|
||||
+ (PBGitTree*) treeForTree: (PBGitTree*) tree andPath: (NSString*) path;
|
||||
- (void) saveToFolder: (NSString *) directory;
|
||||
- (NSString *)textContents;
|
||||
- (NSString *)blame;
|
||||
- (NSString *) log:(NSString *)format;
|
||||
- (NSString *) diff:(NSString *)format;
|
||||
|
||||
- (NSString *) textContents:(NSError **)anError;
|
||||
- (NSString *) blame:(NSError **)anError;
|
||||
- (NSString *) log:(NSString *)format error:(NSError **)anError;
|
||||
- (NSString *) diff:(NSString *)format error:(NSError **)anError;
|
||||
|
||||
- (NSString*) tmpFileNameForContents;
|
||||
- (long long)fileSize;
|
||||
|
||||
+83
-75
@@ -115,73 +115,100 @@
|
||||
return [repository outputForArguments:[NSArray arrayWithObjects:@"show", [self refSpec], nil]];
|
||||
}
|
||||
|
||||
- (NSString *) blame
|
||||
- (NSString *) blame:(NSError **)anError
|
||||
{
|
||||
NSString *error=nil;
|
||||
NSString *res=nil;
|
||||
if (!leaf)
|
||||
return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
|
||||
error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
|
||||
|
||||
if ([self hasBinaryAttributes])
|
||||
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
error=[NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
|
||||
if ([self fileSize] > 52428800) // ~50MB
|
||||
return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
|
||||
error=[NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
|
||||
|
||||
NSString *contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"blame", @"-p", sha, @"--", [self fullPath], nil]];
|
||||
|
||||
if ([self hasBinaryHeader:contents])
|
||||
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
- (NSString *) log:(NSString *)format
|
||||
{
|
||||
if (!leaf)
|
||||
return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
|
||||
|
||||
if ([self hasBinaryAttributes])
|
||||
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
|
||||
if ([self fileSize] > 52428800) // ~50MB
|
||||
return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
|
||||
|
||||
NSString *contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"log", [NSString stringWithFormat:@"--pretty=format:%@",format], @"--", [self fullPath], nil]];
|
||||
|
||||
if ([self hasBinaryHeader:contents])
|
||||
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
- (NSString *) diff:(NSString *)format
|
||||
{
|
||||
if (!leaf)
|
||||
return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
|
||||
|
||||
if ([self hasBinaryAttributes])
|
||||
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
|
||||
if ([self fileSize] > 52428800) // ~50MB
|
||||
return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
|
||||
|
||||
NSString *contents=@"";
|
||||
if(format==@"p") {
|
||||
contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, [NSString stringWithFormat:@"%@^",sha],[self fullPath], nil]];
|
||||
}else if(format==@"h") {
|
||||
contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, @"HEAD",[self fullPath], nil]];
|
||||
}else if(format==@"l") {
|
||||
contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, @"--",[self fullPath], nil]];
|
||||
if(error==nil){
|
||||
res=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"blame", @"-p", sha, @"--", [self fullPath], nil]];
|
||||
}else{
|
||||
*anError = [NSError errorWithDomain:@"blame" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]];
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ([self hasBinaryHeader:contents])
|
||||
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
return res;
|
||||
}
|
||||
|
||||
- (NSString *) log:(NSString *)format error:(NSError **)anError
|
||||
{
|
||||
NSString *error=nil;
|
||||
NSString *res=nil;
|
||||
if (!leaf)
|
||||
error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
|
||||
|
||||
if(error==nil){
|
||||
res=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"log", [NSString stringWithFormat:@"--pretty=format:%@",format], @"--", [self fullPath], nil]];
|
||||
}else{
|
||||
*anError = [NSError errorWithDomain:@"log" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]];
|
||||
}
|
||||
|
||||
return contents;
|
||||
return res;
|
||||
}
|
||||
|
||||
- (NSString *) diff:(NSString *)format error:(NSError **)anError
|
||||
{
|
||||
NSString *error=nil;
|
||||
NSString *res=nil;
|
||||
if (!leaf)
|
||||
error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
|
||||
|
||||
if ([self hasBinaryAttributes])
|
||||
error=[NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
|
||||
if ([self fileSize] > 52428800) // ~50MB
|
||||
error=[NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
|
||||
|
||||
if(error==nil){
|
||||
NSString *des=@"";
|
||||
if(format==@"p") {
|
||||
des=[NSString stringWithFormat:@"%@^",sha];
|
||||
}else if(format==@"h") {
|
||||
des=@"HEAD";
|
||||
}else{
|
||||
des=@"--";
|
||||
}
|
||||
res=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, des,[self fullPath], nil]];
|
||||
if ([res length]==0) {
|
||||
NSLog(@"--%d",[res length]);
|
||||
*anError = [NSError errorWithDomain:@"diff" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"No Diff",NSLocalizedDescriptionKey,nil]];
|
||||
}else{
|
||||
NSLog(@"--%@",[res substringToIndex:80]);
|
||||
}
|
||||
}else{
|
||||
*anError = [NSError errorWithDomain:@"diff" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]];
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
- (NSString *)textContents:(NSError **)anError
|
||||
{
|
||||
NSString *error=nil;
|
||||
NSString *res=nil;
|
||||
if (!leaf)
|
||||
error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
|
||||
|
||||
if ([self hasBinaryAttributes])
|
||||
error=[NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
|
||||
if ([self fileSize] > 52428800) // ~50MB
|
||||
error=[NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
|
||||
|
||||
if(error==nil){
|
||||
res = [self contents];
|
||||
}else{
|
||||
*anError = [NSError errorWithDomain:@"show" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]];
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
- (long long)fileSize
|
||||
@@ -200,25 +227,6 @@
|
||||
return _fileSize;
|
||||
}
|
||||
|
||||
- (NSString *)textContents
|
||||
{
|
||||
if (!leaf)
|
||||
return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
|
||||
|
||||
if ([self hasBinaryAttributes])
|
||||
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
|
||||
if ([self fileSize] > 52428800) // ~50MB
|
||||
return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
|
||||
|
||||
NSString* contents = [self contents];
|
||||
|
||||
if ([self hasBinaryHeader:contents])
|
||||
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
- (void) saveToFolder: (NSString *) dir
|
||||
{
|
||||
NSString* newName = [dir stringByAppendingPathComponent:path];
|
||||
|
||||
@@ -6,7 +6,13 @@ var setMessage = function(message) {
|
||||
$("diff").style.display = "none";
|
||||
}
|
||||
|
||||
var hideMessage = function() {
|
||||
$("message").style.display = "none";
|
||||
$("diff").style.display = "";
|
||||
}
|
||||
|
||||
var showDiff = function(diff) {
|
||||
hideMessage();
|
||||
highlightDiff(diff, $("diff"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user