@@ -117,7 +117,13 @@ - (NSString*) contents
117
117
return string;
118
118
}
119
119
120
- return [repository outputOfTaskWithArguments: @[@" show" , self .refSpec] error: NULL ];
120
+ NSError *error;
121
+ NSString *output = [repository outputOfTaskWithArguments: @[@" show" , self .refSpec] error: &error];
122
+ if (!output) {
123
+ return error.userInfo [PBTaskTerminationOutputKey];
124
+ }
125
+
126
+ return output;
121
127
}
122
128
123
129
- (NSString *) blame
@@ -131,7 +137,11 @@ - (NSString *) blame
131
137
if ([self fileSize ] > 52428800 ) // ~50MB
132
138
return [NSString stringWithFormat: @" %@ is too big to be displayed (%lld bytes)" , [self fullPath ], [self fileSize ]];
133
139
134
- NSString *contents = [repository outputOfTaskWithArguments: @[@" blame" , @" -p" , sha, @" --" , self .fullPath] error: NULL ];
140
+ NSError *error = nil ;
141
+ NSString *contents = [repository outputOfTaskWithArguments: @[@" blame" , @" -p" , sha, @" --" , self .fullPath] error: &error];
142
+ if (!contents) {
143
+ return error.userInfo [PBTaskTerminationOutputKey];
144
+ }
135
145
136
146
if ([self hasBinaryHeader: contents])
137
147
return [NSString stringWithFormat: @" %@ appears to be a binary file of %lld bytes" , [self fullPath ], [self fileSize ]];
@@ -263,31 +273,56 @@ - (NSString*) tmpFileNameForContents
263
273
return localFileName;
264
274
}
265
275
266
- - (NSArray *) children
276
+ - (NSArray *) children
267
277
{
268
278
if (children != nil )
269
279
return children;
270
-
271
- NSString * ref = [self refSpec ];
272
280
273
- NSFileHandle * handle = [repository handleForArguments: [NSArray arrayWithObjects: @" show" , ref, nil ]];
274
- [handle readLine ];
275
- [handle readLine ];
276
-
277
- NSMutableArray * c = [NSMutableArray array ];
278
-
279
- NSString * p = [handle readLine ];
280
- while (p.length > 0 ) {
281
- BOOL isLeaf = ([p characterAtIndex: p.length - 1 ] != ' /' );
282
- if (!isLeaf)
283
- p = [p substringToIndex: p.length -1 ];
284
-
285
- PBGitTree* child = [PBGitTree treeForTree: self andPath: p];
286
- child.leaf = isLeaf;
281
+ GTOID *oid = [GTOID oidWithSHA: [[self refSpec ] substringToIndex: GIT_OID_HEXSZ]];
282
+ NSString *path = [[self refSpec ] substringFromIndex: GIT_OID_HEXSZ + 1 ];
283
+
284
+ NSError *error;
285
+ GTObject *object = [repository.gtRepo lookUpObjectByOID: oid error: &error];
286
+ if (!object) {
287
+ PBLogError (error);
288
+ return nil ;
289
+ }
290
+
291
+ GTTree *tree = [object objectByPeelingToType: GTObjectTypeTree error: &error];
292
+ if (!tree) {
293
+ PBLogError (error);
294
+ return nil ;
295
+ }
296
+
297
+ GTTree *actualTree = nil ;
298
+ if ([path isEqualToString: @" " ]) {
299
+ actualTree = tree;
300
+ } else {
301
+ GTTreeEntry *entry = [tree entryWithPath: path error: &error];
302
+ if (!entry) {
303
+ PBLogError (error);
304
+ return nil ;
305
+ }
306
+ actualTree = [[entry GTObject: &error] objectByPeelingToType: GTObjectTypeTree error: &error];
307
+ if (!actualTree) {
308
+ // Some types of paths can't be peeled, like submodules
309
+ return nil ;
310
+ }
311
+ }
312
+
313
+ NSMutableArray *c = [NSMutableArray array ];
314
+ BOOL success = [actualTree enumerateEntriesWithOptions: GTTreeEnumerationOptionPre error: &error block: ^BOOL (GTTreeEntry * _Nonnull entry, NSString * _Nonnull root, BOOL * _Nonnull stop) {
315
+
316
+ PBGitTree *child = [PBGitTree treeForTree: self andPath: entry.name];
317
+ child.leaf = entry.type != GTObjectTypeTree;
287
318
[c addObject: child];
288
-
289
- p = [handle readLine ];
319
+ return NO ;
320
+ }];
321
+ if (!success) {
322
+ PBLogError (error);
323
+ return nil ;
290
324
}
325
+
291
326
[c sortUsingComparator: ^NSComparisonResult (id obj1, id obj2) {
292
327
PBGitTree* tree1 = (PBGitTree*)obj1;
293
328
PBGitTree* tree2 = (PBGitTree*)obj2;
0 commit comments