Skip to content

Commit c309a2a

Browse files
committed
Make the diff parsing prefix-agnostic
1 parent e720387 commit c309a2a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Resources/html/lib/diffHighlighter.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,25 @@ var highlightDiff = function(diff, element, callbacks) {
118118

119119
var firstChar = l.charAt(0);
120120

121-
if (firstChar == "d" && l.charAt(1) == "i") { // "diff", i.e. new file, we have to reset everything
122-
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
123123

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

126130
binary = false;
127131
mode_change = false;
128132

129-
if(match = l.match(/^diff --git (a\/)+(.*) (b\/)+(.*)$/)) { // there are cases when we need to capture filenames from
130-
startname = match[2]; // the diff line, like with mode-changes.
131-
endname = match[4]; // this can get overwritten later if there is a diff or if
132-
} // 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+
}
133140

134141
continue;
135142
}
@@ -159,12 +166,12 @@ var highlightDiff = function(diff, element, callbacks) {
159166
continue;
160167
}
161168
if (firstChar == "-") {
162-
if (match = l.match(/^--- (a\/)?(.*)$/))
169+
if (match = l.match(/^--- ([a-z]\/)?(.*)$/))
163170
startname = match[2];
164171
continue;
165172
}
166173
if (firstChar == "+") {
167-
if (match = l.match(/^\+\+\+ (b\/)?(.*)$/))
174+
if (match = l.match(/^\+\+\+ ([a-z]\/)?(.*)$/))
168175
endname = match[2];
169176
continue;
170177
}
@@ -187,7 +194,7 @@ var highlightDiff = function(diff, element, callbacks) {
187194
// We might not have a diff from the binary file if it's new.
188195
// So, we use a regex to figure that out
189196

190-
if (match = l.match(/^Binary files (a\/)?(.*) and (b\/)?(.*) differ$/))
197+
if (match = l.match(/^Binary files ([a-z]\/)?(.*) and ([a-z]\/)?(.*) differ$/))
191198
{
192199
startname = match[2];
193200
endname = match[4];

0 commit comments

Comments
 (0)