Skip to content

Commit 8c6789a

Browse files
committed
Read full diffs with ObjectiveGit
1 parent 54f907e commit 8c6789a

File tree

2 files changed

+22
-57
lines changed

2 files changed

+22
-57
lines changed

Classes/Controllers/PBWebHistoryController.m

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ - (void) changeContentToCommit:(PBGitCommit *)commit
165165
}
166166
if (isCanceled()) return nil;
167167
NSMutableArray *fileDeltas = [NSMutableArray array];
168+
NSMutableString *fullDiff = [NSMutableString string];
168169
[d enumerateDeltasUsingBlock:^(GTDiffDelta *_Nonnull delta, BOOL *_Nonnull stop) {
169170
if (isCanceled()) {
170171
*stop = YES;
@@ -181,6 +182,20 @@ - (void) changeContentToCommit:(PBGitCommit *)commit
181182
if (patch) {
182183
numLinesAdded = patch.addedLinesCount;
183184
numLinesRemoved = patch.deletedLinesCount;
185+
NSData *patchData = patch.patchData;
186+
if (patchData) {
187+
NSString *patchString =
188+
[[NSString alloc] initWithData:patchData
189+
encoding:NSUTF8StringEncoding];
190+
if (!patchString) {
191+
patchString =
192+
[[NSString alloc] initWithData:patchData
193+
encoding:NSISOLatin1StringEncoding];
194+
}
195+
if (patchString) {
196+
[fullDiff appendString:patchString];
197+
}
198+
}
184199
} else {
185200
NSLog(@"generatePatch error: %@", err);
186201
}
@@ -198,6 +213,7 @@ - (void) changeContentToCommit:(PBGitCommit *)commit
198213
if (isCanceled()) return nil;
199214
return @{
200215
@"filesInfo" : fileDeltas,
216+
@"fullDiff" : fullDiff,
201217
};
202218
}
203219

@@ -208,38 +224,7 @@ - (void)commitSummaryLoaded:(NSString *)summaryJSON forOID:(GTOID *)summaryOID
208224
return;
209225
}
210226

211-
[self.view.windowScriptObject callWebScriptMethod:@"loadCommitSummary" withArguments:@[summaryJSON]];
212-
213-
// Now load the full diff
214-
NSMutableArray *taskArguments = [NSMutableArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", @"--no-color", currentOID.SHA, nil];
215-
216-
if (![PBGitDefaults showWhitespaceDifferences])
217-
[taskArguments insertObject:@"-w" atIndex:1];
218-
219-
NSFileHandle *handle = [repository handleForArguments:taskArguments];
220-
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
221-
// Remove notification, in case we have another one running
222-
[nc removeObserver:self name:NSFileHandleReadToEndOfFileCompletionNotification object:nil];
223-
[nc addObserver:self selector:@selector(commitFullDiffLoaded:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle];
224-
[handle readToEndOfFileInBackgroundAndNotify];
225-
}
226-
227-
- (void)commitFullDiffLoaded:(NSNotification *)notification
228-
{
229-
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleReadToEndOfFileCompletionNotification object:nil];
230-
231-
NSData *data = [[notification userInfo] valueForKey:NSFileHandleNotificationDataItem];
232-
if (!data)
233-
return;
234-
235-
NSString *fullDiff = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
236-
if (!fullDiff)
237-
fullDiff = [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
238-
239-
if (!fullDiff)
240-
return;
241-
242-
[self.view.windowScriptObject callWebScriptMethod:@"loadCommitFullDiff" withArguments:[NSArray arrayWithObject:fullDiff]];
227+
[self.view.windowScriptObject callWebScriptMethod:@"loadCommitDiff" withArguments:@[summaryJSON]];
243228
}
244229

245230
- (void)selectCommit:(NSString *)sha

html/views/history/history.js

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,6 @@ var Commit = function(obj) {
1919
this.message = obj.message();
2020
this.notificationID = null;
2121

22-
this.parseSummary = function(summary) {
23-
this.filesInfo = summary.filesInfo;
24-
}
25-
26-
// This can be called later with the output of
27-
// 'git show' to get the full diff
28-
this.parseFullDiff = function(fullDiff) {
29-
this.fullDiffRaw = fullDiff;
30-
31-
var diffStart = this.fullDiffRaw.indexOf("\ndiff ");
32-
if (diffStart > 0) {
33-
this.diff = this.fullDiffRaw.substring(diffStart);
34-
} else {
35-
this.diff = "";
36-
}
37-
}
38-
3922
this.reloadRefs = function() {
4023
this.refs = this.object.refs();
4124
}
@@ -310,10 +293,12 @@ var enableFeatures = function()
310293
enableFeature("gravatar", $("committer_gravatar").parentNode)
311294
}
312295

313-
var loadCommitSummary = function(summaryJSON)
296+
var loadCommitDiff = function(jsonData)
314297
{
315-
commit.parseSummary(JSON.parse(summaryJSON));
316-
298+
var diffData = JSON.parse(jsonData)
299+
commit.filesInfo = diffData.filesInfo;
300+
commit.diff = diffData.fullDiff;
301+
317302
if (commit.notificationID)
318303
clearTimeout(commit.notificationID)
319304
else
@@ -411,11 +396,6 @@ var loadCommitSummary = function(summaryJSON)
411396
}
412397
$("files").style.display = "";
413398
}
414-
}
415-
416-
var loadCommitFullDiff = function(data)
417-
{
418-
commit.parseFullDiff(data);
419399

420400
if (commit.diff.length < 200000)
421401
showDiff();

0 commit comments

Comments
 (0)