Skip to content

Commit b514f06

Browse files
authored
Merge pull request #80 from tiennou/fix/diff-mnemonics
Little fixes to the diff viewer
2 parents df68065 + c309a2a commit b514f06

File tree

3 files changed

+41
-43
lines changed

3 files changed

+41
-43
lines changed

Classes/Controllers/PBWebController.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ - (NSURLRequest *)webView:(WebView *)sender
8686
if (!self.repository)
8787
return request;
8888

89-
// TODO: Change this to canInitWithRequest
90-
if ([[[[request URL] scheme] lowercaseString] isEqualToString:@"gitx"]) {
89+
if ([PBGitXProtocol canInitWithRequest:request]) {
9190
NSMutableURLRequest *newRequest = [request mutableCopy];
9291
[newRequest setRepository:self.repository];
9392
return newRequest;

Classes/git/PBGitXProtocol.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ @implementation PBGitXProtocol
1313

1414
+ (BOOL) canInitWithRequest:(NSURLRequest *)request
1515
{
16-
return [[[[request URL] scheme] lowercaseString] isEqualToString:@"gitx"];
16+
NSString *URLScheme = request.URL.scheme;
17+
if ([[URLScheme lowercaseString] isEqualToString:@"gitx"])
18+
return YES;
19+
20+
return NO;
1721
}
1822

1923
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request

Resources/html/lib/diffHighlighter.js

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -84,39 +84,27 @@ var highlightDiff = function(diff, element, callbacks) {
8484
else if (startname != endname)
8585
title = startname + " renamed to " + endname;
8686

87-
if (binary && endname == "/dev/null") { // in cases of a deleted binary file, there is no diff/file to display
88-
line1 = "";
89-
line2 = "";
90-
diffContent = "";
91-
file_index++;
92-
startname = "";
93-
endname = "";
94-
return; // so printing the filename in the file-list is enough
95-
}
96-
97-
if (diffContent != "" || binary) {
98-
finalContent += '<div class="file" id="file_index_' + (file_index - 1) + '">' +
99-
'<div id="title_' + title + '" class="expanded fileHeader"><a href="javascript:toggleDiff(\'' + title + '\');">' + title + '</a></div>';
100-
}
101-
102-
if (!binary && (diffContent != "")) {
103-
finalContent += '<div id="content_' + title + '" class="diffContent">' +
104-
'<div class="lineno">' + line1 + "</div>" +
105-
'<div class="lineno">' + line2 + "</div>" +
106-
'<div class="lines">' + postProcessDiffContents(diffContent).replace(/\t/g, " ") + "</div>" +
107-
'</div>';
108-
}
109-
else {
110-
if (binary) {
111-
if (callbacks["binaryFile"])
112-
finalContent += callbacks["binaryFile"](binaryname);
113-
else
114-
finalContent += '<div id="content_' + title + '">Binary file differs</div>';
87+
// Show file list header
88+
finalContent += '<div class="file" id="file_index_' + (file_index - 1) + '">';
89+
finalContent += '<div id="title_' + title + '" class="expanded fileHeader"><a href="javascript:toggleDiff(\'' + title + '\');">' + title + '</a></div>';
90+
91+
if (binary) {
92+
// diffContent is assumed to be empty for binary files
93+
if (callbacks["binaryFile"]) {
94+
finalContent += callbacks["binaryFile"](binaryname);
95+
} else {
96+
finalContent += '<div id="content_' + title + '">Binary file differs</div>';
11597
}
98+
} else if (diffContent != "") {
99+
finalContent += '<div id="content_' + title + '" class="diffContent">' +
100+
'<div class="lineno">' + line1 + '</div>' +
101+
'<div class="lineno">' + line2 + '</div>' +
102+
'<div class="lines">' + postProcessDiffContents(diffContent).replace(/\t/g, " ") + '</div>' +
103+
'</div>';
116104
}
117105

118-
if (diffContent != "" || binary)
119-
finalContent += '</div>' + linkToTop;
106+
// Close div.file
107+
finalContent += '</div>' + linkToTop;
120108

121109
line1 = "";
122110
line2 = "";
@@ -130,18 +118,25 @@ var highlightDiff = function(diff, element, callbacks) {
130118

131119
var firstChar = l.charAt(0);
132120

133-
if (firstChar == "d" && l.charAt(1) == "i") { // "diff", i.e. new file, we have to reset everything
134-
header = true; // diff always starts with a header
121+
if (firstChar == "d" && l.charAt(1) == "i") {
122+
// "diff", i.e. new file, we have to reset everything
135123

136-
finishContent(); // Finish last file
124+
// diff always starts with a header
125+
header = true;
126+
127+
// Finish last file
128+
finishContent();
137129

138130
binary = false;
139131
mode_change = false;
140132

141-
if(match = l.match(/^diff --git (a\/)+(.*) (b\/)+(.*)$/)) { // there are cases when we need to capture filenames from
142-
startname = match[2]; // the diff line, like with mode-changes.
143-
endname = match[4]; // this can get overwritten later if there is a diff or if
144-
} // the file is binary
133+
// there are cases when we need to capture filenames from the diff
134+
// line, like with mode-changes. this can get overridden later if
135+
// there is a diff or if the file is binary
136+
if (match = l.match(/^diff --git ([a-z]\/)+(.*) ([a-z]\/)+(.*)$/)) {
137+
startname = match[2];
138+
endname = match[4];
139+
}
145140

146141
continue;
147142
}
@@ -171,12 +166,12 @@ var highlightDiff = function(diff, element, callbacks) {
171166
continue;
172167
}
173168
if (firstChar == "-") {
174-
if (match = l.match(/^--- (a\/)?(.*)$/))
169+
if (match = l.match(/^--- ([a-z]\/)?(.*)$/))
175170
startname = match[2];
176171
continue;
177172
}
178173
if (firstChar == "+") {
179-
if (match = l.match(/^\+\+\+ (b\/)?(.*)$/))
174+
if (match = l.match(/^\+\+\+ ([a-z]\/)?(.*)$/))
180175
endname = match[2];
181176
continue;
182177
}
@@ -199,7 +194,7 @@ var highlightDiff = function(diff, element, callbacks) {
199194
// We might not have a diff from the binary file if it's new.
200195
// So, we use a regex to figure that out
201196

202-
if (match = l.match(/^Binary files (a\/)?(.*) and (b\/)?(.*) differ$/))
197+
if (match = l.match(/^Binary files ([a-z]\/)?(.*) and ([a-z]\/)?(.*) differ$/))
203198
{
204199
startname = match[2];
205200
endname = match[4];

0 commit comments

Comments
 (0)