/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to commit.py

Merge sanitize commit message patch from John.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
    return pm
98
98
 
99
99
 
 
100
_newline_variants_re = re.compile(r'\r\n?')
 
101
def _sanitize_and_decode_message(utf8_message):
 
102
    """Turn a utf-8 message into a sanitized Unicode message."""
 
103
    fixed_newline = _newline_variants_re.sub('\n', utf8_message)
 
104
    return fixed_newline.decode('utf-8')
 
105
 
 
106
 
100
107
class CommitDialog(gtk.Dialog):
101
108
    """Implementation of Commit."""
102
109
 
631
638
            if self._commit_all_changes or record[2]:# [2] checkbox
632
639
                file_id = record[0] # [0] file_id
633
640
                path = record[1]    # [1] real path
634
 
                file_message = record[5] # [5] commit message
 
641
                # [5] commit message
 
642
                file_message = _sanitize_and_decode_message(record[5])
635
643
                files.append(path.decode('UTF-8'))
636
644
                if self._enable_per_file_commits and file_message:
637
645
                    # All of this needs to be utf-8 information
 
646
                    file_message = file_message.encode('UTF-8')
638
647
                    file_info.append({'path':path, 'file_id':file_id,
639
648
                                     'message':file_message})
640
649
        file_info.sort(key=lambda x:(x['path'], x['file_id']))
712
721
    def _get_global_commit_message(self):
713
722
        buf = self._global_message_text_view.get_buffer()
714
723
        start, end = buf.get_bounds()
715
 
        return buf.get_text(start, end).decode('utf-8')
 
724
        text = buf.get_text(start, end)
 
725
        return _sanitize_and_decode_message(text)
716
726
 
717
727
    def _set_global_commit_message(self, message):
718
728
        """Just a helper for the test suite."""