@@ -112,14 +112,15 @@ def close(self):
112
112
self .out .write ('</table>' )
113
113
114
114
115
- class DiffEditor (delta .Editor ):
115
+ class HtmlDiffEditor (delta .Editor ):
116
116
"""
117
- generates a unified diff of the changes for a given changeset.
117
+ generates a htmlized unified diff of the changes for a given changeset.
118
118
the output is written to stdout.
119
119
"""
120
- def __init__ (self , old_root , new_root , output ):
120
+ def __init__ (self , old_root , new_root , rev , output ):
121
121
self .old_root = old_root
122
122
self .new_root = new_root
123
+ self .rev = rev
123
124
self .output = output
124
125
125
126
def print_diff (self , old_path , new_path , pool ):
@@ -149,8 +150,33 @@ def open_file(self, path, parent_baton, base_revision, file_pool):
149
150
150
151
def apply_textdelta (self , file_baton , base_checksum ):
151
152
self .print_diff (* file_baton )
153
+
154
+ class UnifiedDiffEditor (HtmlDiffEditor ):
155
+ """
156
+ generates a unified diff of the changes for a given changeset.
157
+ the output is written to stdout.
158
+ """
159
+ def print_diff (self , old_path , new_path , pool ):
160
+ if not old_path or not new_path :
161
+ return
162
+
163
+ options = ['-u' ]
164
+ options .append ('-L' )
165
+ options .append ("%s\t (revision %d)" % (old_path , self .rev - 1 ))
166
+ options .append ('-L' )
167
+ options .append ("%s\t (revision %d)" % (new_path , self .rev ))
168
+
169
+ differ = fs .FileDiff (self .old_root , old_path ,
170
+ self .new_root , new_path , pool , options )
171
+ differ .get_files ()
172
+ pobj = differ .get_pipe ()
173
+ line = pobj .readline ()
174
+ while line :
175
+ self .output .write (line )
176
+ line = pobj .readline ()
177
+
152
178
153
- def render_diffs (fs_ptr , rev , pool ):
179
+ def render_diffs (fs_ptr , rev , pool , diff_class = HtmlDiffEditor ):
154
180
"""
155
181
generates a unified diff of the changes for a given changeset.
156
182
the output is written to stdout.
@@ -159,7 +185,9 @@ def render_diffs(fs_ptr, rev, pool):
159
185
new_root = fs .revision_root (fs_ptr , rev , pool )
160
186
161
187
output = StringIO ()
162
- editor = DiffEditor (old_root , new_root , output )
188
+
189
+ editor = diff_class (old_root , new_root , rev , output )
190
+
163
191
e_ptr , e_baton = delta .make_editor (editor , pool )
164
192
165
193
if util .SVN_VER_MAJOR == 0 and util .SVN_VER_MINOR == 37 :
@@ -230,3 +258,12 @@ def render (self):
230
258
231
259
difftext = render_diffs (self .fs_ptr , int (self .rev ), self .pool )
232
260
self .req .hdf .setValue ('changeset.diff_output' , difftext )
261
+
262
+ def display_diff (self ):
263
+ self .req .send_response (200 )
264
+ self .req .send_header ('Content-Type' , 'text/plain' )
265
+ self .req .end_headers ()
266
+ difftext = render_diffs (self .fs_ptr , int (self .rev ), self .pool , UnifiedDiffEditor )
267
+ self .req .write (difftext )
268
+
269
+
0 commit comments