Skip to content

Commit 6a4f5bd

Browse files
committed
better error control
1 parent e343cba commit 6a4f5bd

File tree

5 files changed

+103
-101
lines changed

5 files changed

+103
-101
lines changed

GLFileView.m

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ - (void) awakeFromNib
7373
@"h", ITEM_IDENTIFIER,
7474
@"HEAD", ITEM_NAME,
7575
nil],
76-
[NSDictionary dictionaryWithObjectsAndKeys:
77-
@"p", ITEM_IDENTIFIER,
78-
@"Previous", ITEM_NAME,
79-
nil],
8076
nil];
8177
[self.groups addObject:[NSDictionary dictionaryWithObjectsAndKeys:
8278
[NSNumber numberWithBool:NO], GROUP_SEPARATOR,
@@ -93,29 +89,34 @@ - (void) awakeFromNib
9389

9490
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
9591
{
96-
//NSLog(@"keyPath=%@ change=%@ context=%@ object=%@ \n %@",keyPath,change,context,object,[historyController.treeController selectedObjects]);
9792
[self showFile];
9893
}
9994

10095
- (void) showFile
10196
{
97+
NSError *theError = nil;
10298
NSArray *files=[historyController.treeController selectedObjects];
10399
if ([files count]>0) {
104100
PBGitTree *file=[files objectAtIndex:0];
105-
101+
106102
NSString *fileTxt = @"";
107-
if(startFile==@"fileview")
108-
fileTxt=[self parseHTML:[file textContents]];
109-
else if(startFile==@"blame")
110-
fileTxt=[self parseBlame:[file blame]];
111-
else if(startFile==@"log")
112-
fileTxt=[file log:logFormat];
113-
else if(startFile==@"diff")
114-
fileTxt=[file diff:diffType];
103+
if(startFile==@"fileview"){
104+
fileTxt=[self parseHTML:[file textContents:&theError]];
105+
}else if(startFile==@"blame"){
106+
fileTxt=[self parseBlame:[file blame:&theError]];
107+
}else if(startFile==@"log"){
108+
fileTxt=[file log:logFormat error:&theError];
109+
}else if(startFile==@"diff"){
110+
fileTxt=[file diff:diffType error:&theError];
111+
}
115112

116113
id script = [view windowScriptObject];
117-
NSString *filePath = [file fullPath];
118-
[script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]];
114+
if(theError==nil){
115+
NSString *filePath = [file fullPath];
116+
[script callWebScriptMethod:@"showFile" withArguments:[NSArray arrayWithObjects:fileTxt, filePath, nil]];
117+
}else{
118+
[script callWebScriptMethod:@"setMessage" withArguments:[NSArray arrayWithObjects:[theError localizedDescription], nil]];
119+
}
119120
}
120121

121122
#if 0
@@ -174,7 +175,8 @@ - (MGScopeBarGroupSelectionMode)scopeBar:(MGScopeBar *)theScopeBar selectionMode
174175

175176
- (void)scopeBar:(MGScopeBar *)theScopeBar selectedStateChanged:(BOOL)selected forItem:(NSString *)identifier inGroup:(int)groupNumber
176177
{
177-
if(groupNumber==0){
178+
NSLog(@"startFile=%@ identifier=%@ groupNumber=%d",startFile,identifier,groupNumber);
179+
if((groupNumber==0) && (startFile!=identifier)){
178180
NSString *path = [NSString stringWithFormat:@"html/views/%@", identifier];
179181
NSString *html = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:path];
180182
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:html]];

PBGitHistoryController.m

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -228,46 +228,31 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
228228
{
229229
if ([(NSString *)context isEqualToString: @"commitChange"]) {
230230
[self updateKeys];
231-
[self restoreFileBrowserSelection];
232-
return;
233-
}
234-
235-
if ([(NSString *)context isEqualToString: @"treeChange"]) {
231+
//[self restoreFileBrowserSelection];
232+
}else if ([(NSString *)context isEqualToString: @"treeChange"]) {
236233
[self updateQuicklookForce: NO];
237234
[self saveFileBrowserSelection];
238-
return;
239-
}
240-
241-
if([(NSString *)context isEqualToString:@"branchChange"]) {
235+
}else if([(NSString *)context isEqualToString:@"branchChange"]) {
242236
// Reset the sorting
243237
if ([[commitController sortDescriptors] count])
244238
[commitController setSortDescriptors:[NSArray array]];
245239
[self updateBranchFilterMatrix];
246-
return;
247-
}
248-
249-
if([(NSString *)context isEqualToString:@"updateRefs"]) {
240+
}else if([(NSString *)context isEqualToString:@"updateRefs"]) {
250241
[commitController rearrangeObjects];
251-
return;
252-
}
253-
254-
if ([(NSString *)context isEqualToString:@"branchFilterChange"]) {
242+
}else if ([(NSString *)context isEqualToString:@"branchFilterChange"]) {
255243
[PBGitDefaults setBranchFilter:repository.currentBranchFilter];
256244
[self updateBranchFilterMatrix];
257-
return;
258-
}
259-
260-
if([(NSString *)context isEqualToString:@"updateCommitCount"] || [(NSString *)context isEqualToString:@"revisionListUpdating"]) {
245+
}else if([(NSString *)context isEqualToString:@"updateCommitCount"] || [(NSString *)context isEqualToString:@"revisionListUpdating"]) {
261246
[self updateStatus];
262247

263248
if ([repository.currentBranch isSimpleRef])
264249
[self selectCommit:[repository shaForRef:[repository.currentBranch ref]]];
265250
else
266251
[self selectCommit:[[self firstCommit] sha]];
267-
return;
252+
}else{
253+
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
268254
}
269255

270-
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
271256
}
272257

273258
- (IBAction) openSelectedFile:(id)sender

PBGitTree.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
+ (PBGitTree*) rootForCommit: (id) commit;
2727
+ (PBGitTree*) treeForTree: (PBGitTree*) tree andPath: (NSString*) path;
2828
- (void) saveToFolder: (NSString *) directory;
29-
- (NSString *)textContents;
30-
- (NSString *)blame;
31-
- (NSString *) log:(NSString *)format;
32-
- (NSString *) diff:(NSString *)format;
29+
30+
- (NSString *) textContents:(NSError **)anError;
31+
- (NSString *) blame:(NSError **)anError;
32+
- (NSString *) log:(NSString *)format error:(NSError **)anError;
33+
- (NSString *) diff:(NSString *)format error:(NSError **)anError;
3334

3435
- (NSString*) tmpFileNameForContents;
3536
- (long long)fileSize;

PBGitTree.m

Lines changed: 65 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -115,73 +115,100 @@ - (NSString*) contents
115115
return [repository outputForArguments:[NSArray arrayWithObjects:@"show", [self refSpec], nil]];
116116
}
117117

118-
- (NSString *) blame
118+
- (NSString *) blame:(NSError **)anError
119119
{
120+
NSString *error=nil;
121+
NSString *res=nil;
120122
if (!leaf)
121-
return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
123+
error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
122124

123125
if ([self hasBinaryAttributes])
124-
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
126+
error=[NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
125127

126128
if ([self fileSize] > 52428800) // ~50MB
127-
return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
129+
error=[NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
128130

129-
NSString *contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"blame", @"-p", sha, @"--", [self fullPath], nil]];
131+
if(error==nil){
132+
res=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"blame", @"-p", sha, @"--", [self fullPath], nil]];
133+
}else{
134+
*anError = [NSError errorWithDomain:@"blame" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]];
135+
}
130136

131-
if ([self hasBinaryHeader:contents])
132-
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
137+
return res;
138+
}
139+
140+
- (NSString *) log:(NSString *)format error:(NSError **)anError
141+
{
142+
NSString *error=nil;
143+
NSString *res=nil;
144+
if (!leaf)
145+
error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
133146

147+
if(error==nil){
148+
res=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"log", [NSString stringWithFormat:@"--pretty=format:%@",format], @"--", [self fullPath], nil]];
149+
}else{
150+
*anError = [NSError errorWithDomain:@"log" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]];
151+
}
134152

135-
return contents;
153+
return res;
136154
}
137155

138-
- (NSString *) log:(NSString *)format
156+
- (NSString *) diff:(NSString *)format error:(NSError **)anError
139157
{
158+
NSString *error=nil;
159+
NSString *res=nil;
140160
if (!leaf)
141-
return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
161+
error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
142162

143163
if ([self hasBinaryAttributes])
144-
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
164+
error=[NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
145165

146166
if ([self fileSize] > 52428800) // ~50MB
147-
return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
167+
error=[NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
148168

149-
NSString *contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"log", [NSString stringWithFormat:@"--pretty=format:%@",format], @"--", [self fullPath], nil]];
150-
151-
if ([self hasBinaryHeader:contents])
152-
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
153-
154-
155-
return contents;
169+
if(error==nil){
170+
NSString *des=@"";
171+
if(format==@"p") {
172+
des=[NSString stringWithFormat:@"%@^",sha];
173+
}else if(format==@"h") {
174+
des=@"HEAD";
175+
}else{
176+
des=@"--";
177+
}
178+
res=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, des,[self fullPath], nil]];
179+
if ([res length]==0) {
180+
NSLog(@"--%d",[res length]);
181+
*anError = [NSError errorWithDomain:@"diff" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"No Diff",NSLocalizedDescriptionKey,nil]];
182+
}else{
183+
NSLog(@"--%@",[res substringToIndex:80]);
184+
}
185+
}else{
186+
*anError = [NSError errorWithDomain:@"diff" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]];
187+
}
188+
189+
return res;
156190
}
157191

158-
- (NSString *) diff:(NSString *)format
192+
- (NSString *)textContents:(NSError **)anError
159193
{
194+
NSString *error=nil;
195+
NSString *res=nil;
160196
if (!leaf)
161-
return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
197+
error=[NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
162198

163199
if ([self hasBinaryAttributes])
164-
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
200+
error=[NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
165201

166202
if ([self fileSize] > 52428800) // ~50MB
167-
return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
203+
error=[NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
168204

169-
NSString *contents=@"";
170-
if(format==@"p") {
171-
contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, [NSString stringWithFormat:@"%@^",sha],[self fullPath], nil]];
172-
}else if(format==@"h") {
173-
contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, @"HEAD",[self fullPath], nil]];
174-
}else if(format==@"l") {
175-
contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, @"--",[self fullPath], nil]];
205+
if(error==nil){
206+
res = [self contents];
207+
}else{
208+
*anError = [NSError errorWithDomain:@"show" code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,NSLocalizedDescriptionKey,nil]];
176209
}
177-
178-
179-
180-
if ([self hasBinaryHeader:contents])
181-
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
182-
183-
184-
return contents;
210+
211+
return res;
185212
}
186213

187214
- (long long)fileSize
@@ -200,25 +227,6 @@ - (long long)fileSize
200227
return _fileSize;
201228
}
202229

203-
- (NSString *)textContents
204-
{
205-
if (!leaf)
206-
return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
207-
208-
if ([self hasBinaryAttributes])
209-
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
210-
211-
if ([self fileSize] > 52428800) // ~50MB
212-
return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
213-
214-
NSString* contents = [self contents];
215-
216-
if ([self hasBinaryHeader:contents])
217-
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
218-
219-
return contents;
220-
}
221-
222230
- (void) saveToFolder: (NSString *) dir
223231
{
224232
NSString* newName = [dir stringByAppendingPathComponent:path];

html/views/diff/diffWindow.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ var setMessage = function(message) {
66
$("diff").style.display = "none";
77
}
88

9+
var hideMessage = function() {
10+
$("message").style.display = "none";
11+
$("diff").style.display = "";
12+
}
13+
914
var showDiff = function(diff) {
15+
hideMessage();
1016
highlightDiff(diff, $("diff"));
1117
}
1218

0 commit comments

Comments
 (0)