@@ -101,25 +101,31 @@ - (void) showFile
101
101
102
102
NSString *fileTxt = @" " ;
103
103
if (startFile==@" fileview" ){
104
- fileTxt=[self parseHTML: [file textContents: &theError]];
104
+ fileTxt=[file textContents: &theError];
105
+ if (!theError)
106
+ fileTxt=[self parseHTML: fileTxt];
105
107
}else if (startFile==@" blame" ){
106
- fileTxt=[self parseBlame: [file blame: &theError]];
108
+ fileTxt=[file blame: &theError];
109
+ if (!theError)
110
+ fileTxt=[self parseBlame: fileTxt];
107
111
}else if (startFile==@" log" ){
108
112
fileTxt=[file log: logFormat error: &theError];
109
113
}else if (startFile==@" diff" ){
110
114
fileTxt=[file diff: diffType error: &theError];
115
+ if (!theError)
116
+ fileTxt=[self parseDiff: fileTxt];
111
117
}
112
118
113
119
id script = [view windowScriptObject ];
114
- if (theError== nil ){
120
+ if (! theError){
115
121
NSString *filePath = [file fullPath ];
116
122
[script callWebScriptMethod: @" showFile" withArguments: [NSArray arrayWithObjects: fileTxt, filePath, nil ]];
117
123
}else {
118
124
[script callWebScriptMethod: @" setMessage" withArguments: [NSArray arrayWithObjects: [theError localizedDescription ], nil ]];
119
125
}
120
126
}
121
127
122
- #if 0
128
+ #if 1
123
129
NSString *dom=[[[[view mainFrame ] DOMDocument ] documentElement ] outerHTML ];
124
130
NSString *tmpFile=@" ~/tmp/test.html" ;
125
131
[dom writeToFile: [tmpFile stringByExpandingTildeInPath ] atomically: true encoding: NSUTF8StringEncoding error: nil ];
@@ -217,6 +223,59 @@ - (NSString *) parseHTML:(NSString *)txt
217
223
return txt;
218
224
}
219
225
226
+ - (NSString *) parseDiff : (NSString *)txt
227
+ {
228
+ txt=[self parseHTML: txt];
229
+
230
+ NSArray *lines = [txt componentsSeparatedByString: @" \n " ];
231
+ NSString *line;
232
+ NSMutableString *res=[NSMutableString string ];
233
+
234
+ [res appendString: @" <table class='diff'>" ];
235
+ int i=0 ;
236
+ while (i<[lines count ]){
237
+ line=[lines objectAtIndex: i];
238
+ if ([[line substringToIndex: 2 ] isEqualToString: @" @@" ]){
239
+
240
+ int l_int,l_count,l_line;
241
+ int r_int,r_count,r_line;
242
+
243
+ NSString *header=[line substringFromIndex: 3 ];
244
+ NSRange hr = NSMakeRange (0 , [header rangeOfString: @" @@" ].location );
245
+ header=[header substringWithRange: hr];
246
+
247
+ NSArray *pos=[header componentsSeparatedByString: @" " ];
248
+ NSArray *pos_l=[[pos objectAtIndex: 0 ] componentsSeparatedByString: @" ," ];
249
+ NSArray *pos_r=[[pos objectAtIndex: 1 ] componentsSeparatedByString: @" ," ];
250
+ l_line=l_int=abs ([[pos_l objectAtIndex: 0 ]integerValue]);
251
+ l_count=[[pos_l objectAtIndex: 1 ]integerValue];
252
+ r_line=r_int=[[pos_r objectAtIndex: 0 ]integerValue];
253
+ r_count=[[pos_r objectAtIndex: 1 ]integerValue];
254
+
255
+ [res appendString: [NSString stringWithFormat: @" <tr class='header'><td colspan=3>%@ </td></tr>" ,line]];
256
+
257
+ do {
258
+ line=[lines objectAtIndex: ++i];
259
+ NSString *s=[line substringToIndex: 1 ];
260
+ line=[line substringFromIndex: 1 ];
261
+
262
+ if ([s isEqualToString: @" " ]){
263
+ [res appendString: [NSString stringWithFormat: @" <tr><td class='l'>%d </td><td class='r'>%d </td>" ,l_line++,r_line++]];
264
+ }else if ([s isEqualToString: @" -" ]){
265
+ [res appendString: [NSString stringWithFormat: @" <tr class='l'><td class='l'>%d </td><td class='r'></td>" ,l_line++]];
266
+ }else if ([s isEqualToString: @" +" ]){
267
+ [res appendString: [NSString stringWithFormat: @" <tr class='r'><td class='l'></td><td class='r'>%d </td>" ,r_line++]];
268
+ }
269
+ [res appendString: [NSString stringWithFormat: @" <td class='code'>%@ </td></tr>" ,line]];
270
+ }while (l_line<(l_int+l_count) && r_line<(r_int+r_count));
271
+
272
+ }
273
+ i++;
274
+ }
275
+ [res appendString: @" </table>" ];
276
+ return res;
277
+ }
278
+
220
279
- (NSString *) parseBlame : (NSString *)txt
221
280
{
222
281
txt=[self parseHTML: txt];
0 commit comments