@@ -84,39 +84,27 @@ var highlightDiff = function(diff, element, callbacks) {
84
84
else if ( startname != endname )
85
85
title = startname + " renamed to " + endname ;
86
86
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>' ;
115
97
}
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>' ;
116
104
}
117
105
118
- if ( diffContent != "" || binary )
119
- finalContent += '</div>' + linkToTop ;
106
+ // Close div.file
107
+ finalContent += '</div>' + linkToTop ;
120
108
121
109
line1 = "" ;
122
110
line2 = "" ;
@@ -130,18 +118,25 @@ var highlightDiff = function(diff, element, callbacks) {
130
118
131
119
var firstChar = l . charAt ( 0 ) ;
132
120
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
135
123
136
- finishContent ( ) ; // Finish last file
124
+ // diff always starts with a header
125
+ header = true ;
126
+
127
+ // Finish last file
128
+ finishContent ( ) ;
137
129
138
130
binary = false ;
139
131
mode_change = false ;
140
132
141
- if ( match = l . match ( / ^ d i f f - - g i t ( 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 ( / ^ d i f f - - g i t ( [ a - z ] \/ ) + ( .* ) ( [ a - z ] \/ ) + ( .* ) $ / ) ) {
137
+ startname = match [ 2 ] ;
138
+ endname = match [ 4 ] ;
139
+ }
145
140
146
141
continue ;
147
142
}
@@ -171,12 +166,12 @@ var highlightDiff = function(diff, element, callbacks) {
171
166
continue ;
172
167
}
173
168
if ( firstChar == "-" ) {
174
- if ( match = l . match ( / ^ - - - ( a \/ ) ? ( .* ) $ / ) )
169
+ if ( match = l . match ( / ^ - - - ( [ a - z ] \/ ) ? ( .* ) $ / ) )
175
170
startname = match [ 2 ] ;
176
171
continue ;
177
172
}
178
173
if ( firstChar == "+" ) {
179
- if ( match = l . match ( / ^ \+ \+ \+ ( b \/ ) ? ( .* ) $ / ) )
174
+ if ( match = l . match ( / ^ \+ \+ \+ ( [ a - z ] \/ ) ? ( .* ) $ / ) )
180
175
endname = match [ 2 ] ;
181
176
continue ;
182
177
}
@@ -199,7 +194,7 @@ var highlightDiff = function(diff, element, callbacks) {
199
194
// We might not have a diff from the binary file if it's new.
200
195
// So, we use a regex to figure that out
201
196
202
- if ( match = l . match ( / ^ B i n a r y f i l e s ( a \/ ) ? ( .* ) a n d ( b \/ ) ? ( .* ) d i f f e r $ / ) )
197
+ if ( match = l . match ( / ^ B i n a r y f i l e s ( [ a - z ] \/ ) ? ( .* ) a n d ( [ a - z ] \/ ) ? ( .* ) d i f f e r $ / ) )
203
198
{
204
199
startname = match [ 2 ] ;
205
200
endname = match [ 4 ] ;
0 commit comments