/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

  • Committer: Curtis Hovey
  • Date: 2011-08-12 20:25:28 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110812202528-4xf4a2t23urx50d2
Updated gst to gtk3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from gi.repository import GObject
22
22
from gi.repository import Pango
23
23
 
24
 
try:
25
 
    from bzrlib import bencode
26
 
except ImportError:
27
 
    from bzrlib.util import bencode
28
 
 
29
24
from bzrlib import (
30
25
    errors,
 
26
    osutils,
31
27
    trace,
32
28
    )
 
29
try:
 
30
    from bzrlib import bencode
 
31
except ImportError:
 
32
    from bzrlib.util import bencode
 
33
 
33
34
from bzrlib.plugins.gtk.dialog import question_dialog
34
35
from bzrlib.plugins.gtk.errors import show_bzr_error
35
36
from bzrlib.plugins.gtk.i18n import _i18n
36
 
from bzrlib.plugins.gtk.commitmsgs import SavedCommitMessagesManager
37
37
 
38
38
try:
39
39
    import dbus
62
62
    last_revision = parents[0]
63
63
 
64
64
    if last_revision is not None:
65
 
        graph = branch.repository.get_graph()
66
 
        ignore = set([r for r,ps in graph.iter_ancestry([last_revision])])
 
65
        try:
 
66
            ignore = set(branch.repository.get_ancestry(last_revision,
 
67
                                                        topo_sorted=False))
 
68
        except errors.NoSuchRevision:
 
69
            # the last revision is a ghost : assume everything is new
 
70
            # except for it
 
71
            ignore = set([None, last_revision])
67
72
    else:
68
 
        ignore = set([])
 
73
        ignore = set([None])
69
74
 
70
75
    pm = []
71
76
    for merge in pending:
103
108
    """Implementation of Commit."""
104
109
 
105
110
    def __init__(self, wt, selected=None, parent=None):
106
 
        super(CommitDialog, self).__init__(
107
 
            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,)
108
113
        self.connect('delete-event', self._on_delete_window)
109
114
        self._question_dialog = question_dialog
110
115
 
128
133
        """Setup the member variables for state."""
129
134
        self._basis_tree = self._wt.basis_tree()
130
135
        self._delta = None
131
 
        self._wt.lock_read()
132
 
        try:
133
 
            self._pending = pending_revisions(self._wt)
134
 
        finally:
135
 
            self._wt.unlock()
 
136
        self._pending = pending_revisions(self._wt)
136
137
 
137
138
        self._is_checkout = (self._wt.branch.get_bound_location() is not None)
138
139
 
227
228
        # This sets the cursor, which causes the expander to close, which
228
229
        # causes the _file_message_text_view to never get realized. So we have
229
230
        # to give it a little kick, or it warns when we try to grab the focus
230
 
        self._treeview_files.set_cursor(initial_cursor, None, False)
 
231
        self._treeview_files.set_cursor(initial_cursor, None, None)
231
232
 
232
233
        def _realize_file_message_tree_view(*args):
233
234
            self._file_message_text_view.realize()
388
389
        # file_label.show()
389
390
        self._files_box.pack_start(file_label, False, True, 0)
390
391
 
391
 
        self._commit_all_files_radio = Gtk.RadioButton.new_with_label(
 
392
        self._commit_all_files_radio = Gtk.RadioButton(
392
393
            None, _i18n("Commit all changes"))
393
394
        self._files_box.pack_start(self._commit_all_files_radio, False, True, 0)
394
395
        self._commit_all_files_radio.show()
395
396
        self._commit_all_files_radio.connect('toggled',
396
397
            self._toggle_commit_selection)
397
 
        self._commit_selected_radio = Gtk.RadioButton.new_with_label_from_widget(
 
398
        self._commit_selected_radio = Gtk.RadioButton(
398
399
            self._commit_all_files_radio, _i18n("Only commit selected changes"))
399
400
        self._files_box.pack_start(self._commit_selected_radio, False, True, 0)
400
401
        self._commit_selected_radio.show()
463
464
                checked_col.set_visible(False)
464
465
            else:
465
466
                checked_col.set_visible(True)
466
 
            renderer = checked_col.get_cells()[0]
 
467
            renderer = checked_col.get_cell_renderers()[0]
467
468
            renderer.set_property('activatable', not all_files)
468
469
 
469
470
    def _construct_pending_list(self):
595
596
            # We have either made it to the end of the list, or nothing was
596
597
            # selected. Either way, select All Files, and jump to the global
597
598
            # commit message.
598
 
            self._treeview_files.set_cursor(
599
 
                Gtk.TreePath(path=0), None, False)
 
599
            self._treeview_files.set_cursor((0,))
600
600
            self._global_message_text_view.grab_focus()
601
601
        else:
602
602
            # Set the cursor to this entry, and jump to the per-file commit
603
603
            # message
604
 
            self._treeview_files.set_cursor(model.get_path(next), None, False)
 
604
            self._treeview_files.set_cursor(model.get_path(next))
605
605
            self._file_message_text_view.grab_focus()
606
606
 
607
607
    def _save_current_file_message(self):
792
792
        rev_dict['revision_id'] = rev.revision_id
793
793
        return rev_dict
794
794
 
 
795
 
 
796
class SavedCommitMessagesManager:
 
797
    """Save glogal and per-file commit messages.
 
798
 
 
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.
 
801
    """
 
802
 
 
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."""
 
806
        if branch is None:
 
807
            self.global_message = u''
 
808
            self.file_messages = {}
 
809
        else:
 
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'))
 
819
            else:
 
820
                self.file_messages = {}
 
821
 
 
822
    def get(self):
 
823
        return self.global_message, self.file_messages
 
824
 
 
825
    def is_not_empty(self):
 
826
        return bool(self.global_message or self.file_messages)
 
827
 
 
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."""
 
832
        file_messages = {}
 
833
        for fi in file_info:
 
834
            file_message = fi['message']
 
835
            if file_message:
 
836
                file_messages[fi['file_id']] = file_message # utf-8 strings
 
837
        for k,v in file_messages.iteritems():
 
838
            try:
 
839
                self.file_messages[k] = v + '\n******\n' + self.file_messages[k]
 
840
            except KeyError:
 
841
                self.file_messages[k] = v
 
842
        if self.global_message:
 
843
            self.global_message = global_message + '\n******\n' \
 
844
                + self.global_message
 
845
        else:
 
846
            self.global_message = global_message
 
847
 
 
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()
 
859
        # requires one:
 
860
        config.set_user_option(
 
861
            'gtk_file_commit_messages',
 
862
            bencode.bencode(self.file_messages).decode('UTF-8'))
 
863
 
 
864
 
 
865
def save_commit_messages(local, master, old_revno, old_revid,
 
866
                         new_revno, new_revid):
 
867
    b = local
 
868
    if b is None:
 
869
        b = master
 
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:
 
877
            break
 
878
        cur_revno -= 1
 
879
        rev = b.repository.get_revision(rev_id)
 
880
        file_info = rev.properties.get('file-info', None)
 
881
        if file_info is None:
 
882
            file_info = {}
 
883
        else:
 
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)
 
888
 
 
889
        parents = graph.get_parent_map([rev_id]).get(rev_id, None)
 
890
        if not parents:
 
891
            continue
 
892
    mgr.save(None, b)