/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 trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
import os.path
 
18
import re
 
19
 
17
20
try:
18
21
    import pygtk
19
22
    pygtk.require("2.0")
24
27
import gobject
25
28
import pango
26
29
 
27
 
import os.path
28
 
import re
29
 
 
30
30
from bzrlib import errors, osutils
31
31
from bzrlib.trace import mutter
32
32
from bzrlib.util import bencode
33
33
 
34
34
from bzrlib.plugins.gtk import _i18n
35
 
from dialog import error_dialog, question_dialog
36
 
from errors import show_bzr_error
 
35
from bzrlib.plugins.gtk.dialog import question_dialog
 
36
from bzrlib.plugins.gtk.errors import show_bzr_error
37
37
 
38
38
try:
39
39
    import dbus
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
 
103
110
    def __init__(self, wt, selected=None, parent=None):
104
 
        gtk.Dialog.__init__(self, title="Commit - Olive",
 
111
        gtk.Dialog.__init__(self, title="Commit to %s" % wt.basedir,
105
112
                                  parent=parent,
106
113
                                  flags=0,
107
 
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
 
114
                                  buttons=(gtk.STOCK_CANCEL,
 
115
                                           gtk.RESPONSE_CANCEL))
108
116
        self._question_dialog = question_dialog
109
117
 
110
118
        self._wt = wt
630
638
            if self._commit_all_changes or record[2]:# [2] checkbox
631
639
                file_id = record[0] # [0] file_id
632
640
                path = record[1]    # [1] real path
633
 
                file_message = record[5] # [5] commit message
 
641
                # [5] commit message
 
642
                file_message = _sanitize_and_decode_message(record[5])
634
643
                files.append(path.decode('UTF-8'))
635
644
                if self._enable_per_file_commits and file_message:
636
645
                    # All of this needs to be utf-8 information
 
646
                    file_message = file_message.encode('UTF-8')
637
647
                    file_info.append({'path':path, 'file_id':file_id,
638
648
                                     'message':file_message})
639
649
        file_info.sort(key=lambda x:(x['path'], x['file_id']))
653
663
        if message == '':
654
664
            response = self._question_dialog(
655
665
                _i18n('Commit with an empty message?'),
656
 
                _i18n('You can describe your commit intent in the message.'))
 
666
                _i18n('You can describe your commit intent in the message.'),
 
667
                parent=self)
657
668
            if response == gtk.RESPONSE_NO:
658
669
                # Kindly give focus to message area
659
670
                self._global_message_text_view.grab_focus()
673
684
        for path in self._wt.unknowns():
674
685
            response = self._question_dialog(
675
686
                _i18n("Commit with unknowns?"),
676
 
                _i18n("Unknown files exist in the working tree. Commit anyway?"))
 
687
                _i18n("Unknown files exist in the working tree. Commit anyway?"),
 
688
                parent=self)
 
689
                # Doesn't set a parent for the dialog..
677
690
            if response == gtk.RESPONSE_NO:
678
691
                return
679
692
            break
693
706
            response = self._question_dialog(
694
707
                _i18n('Commit with no changes?'),
695
708
                _i18n('There are no changes in the working tree.'
696
 
                      ' Do you want to commit anyway?'))
 
709
                      ' Do you want to commit anyway?'),
 
710
                parent=self)
697
711
            if response == gtk.RESPONSE_YES:
698
712
                rev_id = self._wt.commit(message,
699
713
                               allow_pointless=True,
707
721
    def _get_global_commit_message(self):
708
722
        buf = self._global_message_text_view.get_buffer()
709
723
        start, end = buf.get_bounds()
710
 
        return buf.get_text(start, end).decode('utf-8')
 
724
        text = buf.get_text(start, end)
 
725
        return _sanitize_and_decode_message(text)
711
726
 
712
727
    def _set_global_commit_message(self, message):
713
728
        """Just a helper for the test suite."""