~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/history.py

  • Committer: Martin Albisetti
  • Date: 2008-08-06 19:12:08 UTC
  • mfrom: (201 trunk)
  • mto: This revision was merged to the branch mainline in revision 202.
  • Revision ID: argentina@gmail.com-20080806191208-3imvz0kebwsszchn
Merge from trunk + tweak

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
 
2
# Copyright (C) 2008  Canonical Ltd. 
 
3
#                     (Authored by Martin Albisetti <argentina@gmail.com>)
2
4
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
3
5
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
4
6
# Copyright (C) 2005  Jake Edge <jake@edge2.net>
91
93
    out_chunk_list = []
92
94
    for chunk in chunk_list:
93
95
        line_list = []
 
96
        wrap_char = '<wbr/>'
94
97
        delete_list, insert_list = [], []
95
98
        for line in chunk.diff:
 
99
            # Add <wbr/> every X characters so we can wrap properly
 
100
            wrap_line = re.findall(r'.{%d}|.+$' % 78, line.line)
 
101
            wrap_lines = [util.html_clean(_line) for _line in wrap_line]
 
102
            wrapped_line = wrap_char.join(wrap_lines)
 
103
 
96
104
            if line.type == 'context':
97
105
                if len(delete_list) or len(insert_list):
98
 
                    _process_side_by_side_buffers(line_list, delete_list, insert_list)
 
106
                    _process_side_by_side_buffers(line_list, delete_list, 
 
107
                                                  insert_list)
99
108
                    delete_list, insert_list = [], []
100
 
                line_list.append(util.Container(old_lineno=line.old_lineno, new_lineno=line.new_lineno,
101
 
                                                old_line=line.line, new_line=line.line,
102
 
                                                old_type=line.type, new_type=line.type))
 
109
                line_list.append(util.Container(old_lineno=line.old_lineno, 
 
110
                                                new_lineno=line.new_lineno,
 
111
                                                old_line=wrapped_line, 
 
112
                                                new_line=wrapped_line,
 
113
                                                old_type=line.type, 
 
114
                                                new_type=line.type))
103
115
            elif line.type == 'delete':
104
 
                delete_list.append((line.old_lineno, line.line, line.type))
 
116
                delete_list.append((line.old_lineno, wrapped_line, line.type))
105
117
            elif line.type == 'insert':
106
 
                insert_list.append((line.new_lineno, line.line, line.type))
 
118
                insert_list.append((line.new_lineno, wrapped_line, line.type))
107
119
        if len(delete_list) or len(insert_list):
108
120
            _process_side_by_side_buffers(line_list, delete_list, insert_list)
109
121
        out_chunk_list.append(util.Container(diff=line_list))
686
698
                old_lineno = lines[0]
687
699
                new_lineno = lines[1]
688
700
            elif line.startswith(' '):
689
 
                chunk.diff.append(util.Container(old_lineno=old_lineno, new_lineno=new_lineno,
690
 
                                                 type='context', line=util.fixed_width(line[1:])))
 
701
                chunk.diff.append(util.Container(old_lineno=old_lineno, 
 
702
                                                 new_lineno=new_lineno,
 
703
                                                 type='context', 
 
704
                                                 line=line[1:]))
691
705
                old_lineno += 1
692
706
                new_lineno += 1
693
707
            elif line.startswith('+'):
694
 
                chunk.diff.append(util.Container(old_lineno=None, new_lineno=new_lineno,
695
 
                                                 type='insert', line=util.fixed_width(line[1:])))
 
708
                chunk.diff.append(util.Container(old_lineno=None, 
 
709
                                                 new_lineno=new_lineno,
 
710
                                                 type='insert', line=line[1:]))
696
711
                new_lineno += 1
697
712
            elif line.startswith('-'):
698
 
                chunk.diff.append(util.Container(old_lineno=old_lineno, new_lineno=None,
699
 
                                                 type='delete', line=util.fixed_width(line[1:])))
 
713
                chunk.diff.append(util.Container(old_lineno=old_lineno, 
 
714
                                                 new_lineno=None,
 
715
                                                 type='delete', line=line[1:]))
700
716
                old_lineno += 1
701
717
            else:
702
 
                chunk.diff.append(util.Container(old_lineno=None, new_lineno=None,
703
 
                                                 type='unknown', line=util.fixed_width(repr(line))))
 
718
                chunk.diff.append(util.Container(old_lineno=None, 
 
719
                                                 new_lineno=None,
 
720
                                                 type='unknown', 
 
721
                                                 line=repr(line)))
704
722
        if chunk is not None:
705
723
            chunks.append(chunk)
706
724
        return chunks