Skip to content

Commit

Permalink
Merge pull request #2 from nanotech/f/binary-size-diffs
Browse files Browse the repository at this point in the history
Display size changes for binary files
  • Loading branch information
tiennou authored Dec 13, 2016
2 parents 21174b5 + 7b5fede commit df65378
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
32 changes: 29 additions & 3 deletions Classes/Controllers/PBWebHistoryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ - (void) changeContentToMultipleSelectionMessage {

static NSDictionary *loadCommitSummary(GTRepository *repo, GTCommit *commit, BOOL (^isCanceled)());

// A GTDiffDelta's GTDiffFile does not always set the file size. See `git_diff_get_delta`.
static NSUInteger reallyGetFileSize(GTRepository *repo, GTDiffFile *file) {
GTObjectDatabase *odb = [repo objectDatabaseWithError:nil];
if (!odb) return 0;
size_t size = 0;
git_otype otype;
if (git_odb_read_header(&size, &otype, odb.git_odb, file.OID.git_oid) != 0) {
return 0;
}
return size;
}

- (void) changeContentToCommit:(PBGitCommit *)commit
{
// The sha is the same, but refs may have changed. reload it lazy
Expand Down Expand Up @@ -196,14 +208,28 @@ - (void) changeContentToCommit:(PBGitCommit *)commit
[fullDiff appendString:patchString];
}
}
// Use the patch's delta as it may have loaded more file sizes.
delta = patch.delta;
} else {
NSLog(@"generatePatch error: %@", err);
}
GTDiffFile *oldFile = delta.oldFile;
GTDiffFile *newFile = delta.newFile;
NSUInteger oldFileSize = oldFile.size;
NSUInteger newFileSize = newFile.size;
if (oldFileSize == 0 && (oldFile.flags & GIT_DIFF_FLAG_EXISTS)) {
oldFileSize = reallyGetFileSize(repo, newFile);
}
if (newFileSize == 0 && (newFile.flags & GIT_DIFF_FLAG_EXISTS)) {
newFileSize = reallyGetFileSize(repo, newFile);
}
[fileDeltas addObject:@{
@"filename" : delta.newFile.path,
@"oldFilename" : delta.oldFile.path,
@"newFilename" : delta.newFile.path,
@"filename" : newFile.path,
@"oldFilename" : oldFile.path,
@"newFilename" : newFile.path,
@"changeType" : deltaTypeName(delta.type),
@"oldFileSize" : @(oldFileSize),
@"newFileSize" : @(newFileSize),
@"numLinesAdded" : @(numLinesAdded),
@"numLinesRemoved" : @(numLinesRemoved),
@"binary" :
Expand Down
2 changes: 0 additions & 2 deletions html/views/history/history.css
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ a {
#files .diffstat-numbers.binary {
display: inline-block;
right: 30px;
-webkit-border-radius: 12px;
background-color: #a7681f;
}

/*
Expand Down
2 changes: 2 additions & 0 deletions html/views/history/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ var loadCommitDiff = function(jsonData)
if (fileInfo.binary) {
// remove the diffstat-info element
diffstatElem.parentNode.removeChild(diffstatElem);
binaryElem.innerText =
fileInfo.oldFileSize + " \u2192 " + fileInfo.newFileSize + " bytes";
}
else {
// remove the binary element
Expand Down

0 comments on commit df65378

Please sign in to comment.