~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/history.py

  • Committer: Robey Pointer
  • Date: 2006-12-12 00:47:38 UTC
  • Revision ID: robey@lag.net-20061212004738-fyhww4fadma2v3jm
okay, redo the changes-list screen

Show diffs side-by-side

added added

removed removed

Lines of Context:
187
187
            'revno': self.get_revno(parent_revid),
188
188
        } for parent_revid in rev.parent_ids]
189
189
 
 
190
        if len(parents) == 0:
 
191
            left_parent = None
 
192
        else:
 
193
            left_parent = rev.parent_ids[-1]
 
194
            
190
195
        entry = {
191
196
            'revid': revid,
192
197
            'revno': self.get_revno(revid),
195
200
            'age': util.timespan(now - commit_time) + ' ago',
196
201
            'short_comment': short_comment,
197
202
            'comment': rev.message,
 
203
            'comment_clean': util.html_clean(rev.message),
198
204
            'parents': [util.Container(p) for p in parents],
 
205
            'changes': self.diff_revisions(revid, left_parent, get_diffs=False),
199
206
        }
200
207
        return util.Container(entry)
201
208
    
226
233
        else:
227
234
            yield ('>', None, None)
228
235
    
229
 
    def diff_revisions(self, revid, otherrevid):
 
236
    def diff_revisions(self, revid, otherrevid, get_diffs=True):
230
237
        """
231
238
        Return a nested data structure containing the changes between two
232
239
        revisions::
245
252
                    ),
246
253
                ),
247
254
            )
 
255
        
 
256
        if C{get_diffs} is false, the C{chunks} will be omitted.
248
257
        """
249
258
 
250
259
        new_tree = self._branch.repository.revision_tree(revid)
269
278
            tree_file = bzrlib.textfile.text_file(tree.get_file(fid))
270
279
            return tree_file.readlines()
271
280
        
272
 
        def fix_line(s):
273
 
            # to avoid using <pre>, we need to turn spaces into nbsp, and kid
274
 
            # doesn't notice u'\xa0', so we have to do it by hand, and escape
275
 
            # html also.  oh well.
276
 
            s = cgi.escape(s)
277
 
            return s.replace(' ', '&nbsp;')
278
 
        
279
281
        def process_diff(diff):
280
282
            chunks = []
281
283
            chunk = None
282
284
            for line in diff.splitlines():
283
 
                if len(line) == 1:
284
 
                    # i think this happens because bazaar gets too aggressive about removing trailing whitespace
285
 
                    line = line + ' '
 
285
                if len(line) == 0:
 
286
                    continue
286
287
                if line.startswith('+++ ') or line.startswith('--- '):
287
288
                    continue
288
289
                if line.startswith('@@ '):
296
297
                    new_lineno = lines[1]
297
298
                elif line.startswith('  '):
298
299
                    chunk.diff.append(util.Container(old_lineno=old_lineno, new_lineno=new_lineno,
299
 
                                                     type='context', line=fix_line(line[2:])))
 
300
                                                     type='context', line=util.html_clean(line[2:])))
300
301
                    old_lineno += 1
301
302
                    new_lineno += 1
302
303
                elif line.startswith('+ '):
303
304
                    chunk.diff.append(util.Container(old_lineno=None, new_lineno=new_lineno,
304
 
                                                     type='insert', line=fix_line(line[2:])))
 
305
                                                     type='insert', line=util.html_clean(line[2:])))
305
306
                    new_lineno += 1
306
307
                elif line.startswith('- '):
307
308
                    chunk.diff.append(util.Container(old_lineno=old_lineno, new_lineno=None,
308
 
                                                     type='delete', line=fix_line(line[2:])))
 
309
                                                     type='delete', line=util.html_clean(line[2:])))
 
310
                    old_lineno += 1
 
311
                elif line.startswith(' '):
 
312
                    # why does this happen?
 
313
                    chunk.diff.append(util.Container(old_lineno=old_lineno, new_lineno=new_lineno,
 
314
                                                     type='context', line=util.html_clean(line[1:])))
 
315
                    old_lineno += 1
 
316
                    new_lineno += 1
 
317
                elif line.startswith('+'):
 
318
                    # why does this happen?
 
319
                    chunk.diff.append(util.Container(old_lineno=None, new_lineno=new_lineno,
 
320
                                                     type='insert', line=util.html_clean(line[1:])))
 
321
                    new_lineno += 1
 
322
                elif line.startswith('-'):
 
323
                    # why does this happen?
 
324
                    chunk.diff.append(util.Container(old_lineno=old_lineno, new_lineno=None,
 
325
                                                     type='delete', line=util.html_clean(line[1:])))
309
326
                    old_lineno += 1
310
327
                else:
311
 
                    chunk.diff.append(util.Container(type='unknown', line=fix_line(repr(line))))
 
328
                    chunk.diff.append(util.Container(old_lineno=None, new_lineno=None,
 
329
                                                     type='unknown', line=util.html_clean(repr(line))))
 
330
            if chunk is not None:
 
331
                chunks.append(chunk)
312
332
            return chunks
313
333
                    
314
334
        def handle_modify(old_path, new_path, fid, kind):
 
335
            if not get_diffs:
 
336
                modified.append(util.Container(filename=rich_filename(new_path, kind)))
 
337
                return
315
338
            old_lines = tree_lines(old_tree, fid)
316
339
            new_lines = tree_lines(new_tree, fid)
317
340
            buffer = StringIO()