93
101
def _sanitize_and_decode_message(utf8_message):
94
102
"""Turn a utf-8 message into a sanitized Unicode message."""
95
103
fixed_newline = _newline_variants_re.sub('\n', utf8_message)
96
return osutils.safe_unicode(fixed_newline)
104
return fixed_newline.decode('utf-8')
99
107
class CommitDialog(Gtk.Dialog):
100
108
"""Implementation of Commit."""
102
110
def __init__(self, wt, selected=None, parent=None):
103
super(CommitDialog, self).__init__(
104
title="Commit to %s" % wt.basedir, parent=parent, flags=0)
111
Gtk.Dialog.__init__(self, title="Commit to %s" % wt.basedir,
112
parent=parent, flags=0,)
105
113
self.connect('delete-event', self._on_delete_window)
106
114
self._question_dialog = question_dialog
386
389
# file_label.show()
387
390
self._files_box.pack_start(file_label, False, True, 0)
389
self._commit_all_files_radio = Gtk.RadioButton.new_with_label(
392
self._commit_all_files_radio = Gtk.RadioButton(
390
393
None, _i18n("Commit all changes"))
391
394
self._files_box.pack_start(self._commit_all_files_radio, False, True, 0)
392
395
self._commit_all_files_radio.show()
393
396
self._commit_all_files_radio.connect('toggled',
394
397
self._toggle_commit_selection)
395
self._commit_selected_radio = Gtk.RadioButton.new_with_label_from_widget(
398
self._commit_selected_radio = Gtk.RadioButton(
396
399
self._commit_all_files_radio, _i18n("Only commit selected changes"))
397
400
self._files_box.pack_start(self._commit_selected_radio, False, True, 0)
398
401
self._commit_selected_radio.show()
569
572
def _on_treeview_files_cursor_changed(self, treeview):
570
573
treeselection = treeview.get_selection()
571
if treeselection is None:
572
# The treeview was probably destroyed as the dialog closes.
574
574
(model, selection) = treeselection.get_selected()
576
576
if selection is not None:
577
577
path, display_path = model.get(selection, 1, 3)
578
578
self._diff_label.set_text(_i18n('Diff for ') + display_path)
580
580
self._diff_view.show_diff(None)
582
self._diff_view.show_diff([osutils.safe_unicode(path)])
582
self._diff_view.show_diff([path.decode('UTF-8')])
583
583
self._update_per_file_info(selection)
585
585
def _on_accel_next(self, accel_group, window, keyval, modifier):
596
596
# We have either made it to the end of the list, or nothing was
597
597
# selected. Either way, select All Files, and jump to the global
598
598
# commit message.
599
self._treeview_files.set_cursor(
600
Gtk.TreePath(path=0), "", False)
599
self._treeview_files.set_cursor((0,))
601
600
self._global_message_text_view.grab_focus()
603
602
# Set the cursor to this entry, and jump to the per-file commit
605
self._treeview_files.set_cursor(model.get_path(next), None, False)
604
self._treeview_files.set_cursor(model.get_path(next))
606
605
self._file_message_text_view.grab_focus()
608
607
def _save_current_file_message(self):
646
645
records = iter(self._files_store)
647
646
rec = records.next() # Skip the All Files record
648
assert rec[0] == "", "Are we skipping the wrong record?"
647
assert rec[0] is None, "Are we skipping the wrong record?"
651
650
for record in records:
652
651
if self._commit_all_changes or record[2]:# [2] checkbox
653
file_id = osutils.safe_utf8(record[0]) # [0] file_id
654
path = osutils.safe_utf8(record[1]) # [1] real path
652
file_id = record[0] # [0] file_id
653
path = record[1] # [1] real path
655
654
# [5] commit message
656
655
file_message = _sanitize_and_decode_message(record[5])
657
656
files.append(path.decode('UTF-8'))
793
792
rev_dict['revision_id'] = rev.revision_id
796
class SavedCommitMessagesManager:
797
"""Save glogal and per-file commit messages.
799
Saves global commit message and utf-8 file_id->message dictionary
800
of per-file commit messages on disk. Re-reads them later for re-using.
803
def __init__(self, tree=None, branch=None):
804
"""If branch is None, builds empty messages, otherwise reads them
805
from branch's disk storage. 'tree' argument is for the future."""
807
self.global_message = u''
808
self.file_messages = {}
810
config = branch.get_config()
811
self.global_message = config.get_user_option(
812
'gtk_global_commit_message')
813
if self.global_message is None:
814
self.global_message = u''
815
file_messages = config.get_user_option('gtk_file_commit_messages')
816
if file_messages: # unicode and B-encoded:
817
self.file_messages = bencode.bdecode(
818
file_messages.encode('UTF-8'))
820
self.file_messages = {}
823
return self.global_message, self.file_messages
825
def is_not_empty(self):
826
return bool(self.global_message or self.file_messages)
828
def insert(self, global_message, file_info):
829
"""Formats per-file commit messages (list of dictionaries, one per file)
830
into one utf-8 file_id->message dictionary and merges this with
831
previously existing dictionary. Merges global commit message too."""
834
file_message = fi['message']
836
file_messages[fi['file_id']] = file_message # utf-8 strings
837
for k,v in file_messages.iteritems():
839
self.file_messages[k] = v + '\n******\n' + self.file_messages[k]
841
self.file_messages[k] = v
842
if self.global_message:
843
self.global_message = global_message + '\n******\n' \
844
+ self.global_message
846
self.global_message = global_message
848
def save(self, tree, branch):
849
# We store in branch's config, which can be a problem if two gcommit
850
# are done in two checkouts of one single branch (comments overwrite
851
# each other). Ideally should be in working tree. But uncommit does
852
# not always have a working tree, though it always has a branch.
853
# 'tree' argument is for the future
854
config = branch.get_config()
855
# should it be named "gtk_" or some more neutral name ("gui_" ?) to
856
# be compatible with qbzr in the future?
857
config.set_user_option('gtk_global_commit_message', self.global_message)
858
# bencode() does not know unicode objects but set_user_option()
860
config.set_user_option(
861
'gtk_file_commit_messages',
862
bencode.bencode(self.file_messages).decode('UTF-8'))
865
def save_commit_messages(local, master, old_revno, old_revid,
866
new_revno, new_revid):
870
mgr = SavedCommitMessagesManager(None, b)
871
revid_iterator = b.repository.iter_reverse_revision_history(old_revid)
872
cur_revno = old_revno
873
new_revision_id = old_revid
874
graph = b.repository.get_graph()
875
for rev_id in revid_iterator:
876
if cur_revno == new_revno:
879
rev = b.repository.get_revision(rev_id)
880
file_info = rev.properties.get('file-info', None)
881
if file_info is None:
884
file_info = bencode.bdecode(file_info.encode('UTF-8'))
885
global_message = osutils.safe_unicode(rev.message)
886
# Concatenate comment of the uncommitted revision
887
mgr.insert(global_message, file_info)
889
parents = graph.get_parent_map([rev_id]).get(rev_id, None)