/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: Jelmer Vernooij
  • Date: 2011-11-06 00:49:02 UTC
  • Revision ID: jelmer@samba.org-20111106004902-rchmxi3vfy6zj8tn
Fix typo in setup.py.

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
 
24
29
from bzrlib import (
25
 
    bencode,
26
30
    errors,
27
 
    osutils,
28
 
    revision as _mod_revision,
29
31
    trace,
30
 
    tsort,
31
32
    )
32
33
from bzrlib.plugins.gtk.dialog import question_dialog
33
34
from bzrlib.plugins.gtk.errors import show_bzr_error
42
43
    have_dbus = False
43
44
 
44
45
 
45
 
def _get_sorted_revisions(tip_revision, revision_ids, parent_map):
46
 
    """Get an iterator which will return the revisions in merge sorted order.
47
 
 
48
 
    This will build up a list of all nodes, such that only nodes in the list
49
 
    are referenced. It then uses MergeSorter to return them in 'merge-sorted'
50
 
    order.
51
 
 
52
 
    :param revision_ids: A set of revision_ids
53
 
    :param parent_map: The parent information for each node. Revisions which
54
 
        are considered ghosts should not be present in the map.
55
 
    :return: iterator from MergeSorter.iter_topo_order()
56
 
    """
57
 
    # MergeSorter requires that all nodes be present in the graph, so get rid
58
 
    # of any references pointing outside of this graph.
59
 
    parent_graph = {}
60
 
    for revision_id in revision_ids:
61
 
        if revision_id not in parent_map: # ghost
62
 
            parent_graph[revision_id] = []
63
 
        else:
64
 
            # Only include parents which are in this sub-graph
65
 
            parent_graph[revision_id] = [p for p in parent_map[revision_id]
66
 
                                            if p in revision_ids]
67
 
    sorter = tsort.MergeSorter(parent_graph, tip_revision)
68
 
    return sorter.iter_topo_order()
69
 
 
70
 
 
71
46
def pending_revisions(wt):
72
47
    """Return a list of pending merges or None if there are none of them.
73
48
 
78
53
    """
79
54
    parents = wt.get_parent_ids()
80
55
    if len(parents) < 2:
81
 
        return
 
56
        return None
82
57
 
83
58
    # The basic pending merge algorithm uses the same algorithm as
84
59
    # bzrlib.status.show_pending_merges
86
61
    branch = wt.branch
87
62
    last_revision = parents[0]
88
63
 
89
 
    graph = branch.repository.get_graph()
90
 
    other_revisions = [last_revision]
 
64
    if last_revision is not None:
 
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])
 
72
    else:
 
73
        ignore = set([None])
91
74
 
92
75
    pm = []
93
76
    for merge in pending:
94
 
        try:
95
 
            merge_rev = branch.repository.get_revision(merge)
96
 
        except errors.NoSuchRevision:
97
 
            # If we are missing a revision, just print out the revision id
98
 
            trace.mutter("ghost: %r", merge)
99
 
            other_revisions.append(merge)
100
 
            continue
101
 
 
102
 
        # Find all of the revisions in the merge source, which are not in the
103
 
        # last committed revision.
104
 
        merge_extra = graph.find_unique_ancestors(merge, other_revisions)
105
 
        other_revisions.append(merge)
106
 
        merge_extra.discard(_mod_revision.NULL_REVISION)
107
 
 
108
 
        # Get a handle to all of the revisions we will need
109
 
        try:
110
 
            revisions = dict((rev.revision_id, rev) for rev in
111
 
                             branch.repository.get_revisions(merge_extra))
112
 
        except errors.NoSuchRevision:
113
 
            # One of the sub nodes is a ghost, check each one
114
 
            revisions = {}
115
 
            for revision_id in merge_extra:
116
 
                try:
117
 
                    rev = branch.repository.get_revisions([revision_id])[0]
118
 
                except errors.NoSuchRevision:
119
 
                    revisions[revision_id] = None
120
 
                else:
121
 
                    revisions[revision_id] = rev
122
 
 
123
 
         # Display the revisions brought in by this merge.
124
 
        rev_id_iterator = _get_sorted_revisions(merge, merge_extra,
125
 
                            branch.repository.get_parent_map(merge_extra))
126
 
        # Skip the first node
127
 
        num, first, depth, eom = rev_id_iterator.next()
128
 
        if first != merge:
129
 
            raise AssertionError('Somehow we misunderstood how'
130
 
                ' iter_topo_order works %s != %s' % (first, merge))
131
 
        children = []
132
 
        for num, sub_merge, depth, eom in rev_id_iterator:
133
 
            rev = revisions[sub_merge]
134
 
            if rev is None:
135
 
                trace.warning("ghost: %r", sub_merge)
136
 
                continue
137
 
            children.append(rev)
138
 
        yield (merge_rev, children)
 
77
        ignore.add(merge)
 
78
        try:
 
79
            rev = branch.repository.get_revision(merge)
 
80
            children = []
 
81
            pm.append((rev, children))
 
82
 
 
83
            # This does need to be topo sorted, so we search backwards
 
84
            inner_merges = branch.repository.get_ancestry(merge)
 
85
            assert inner_merges[0] is None
 
86
            inner_merges.pop(0)
 
87
            for mmerge in reversed(inner_merges):
 
88
                if mmerge in ignore:
 
89
                    continue
 
90
                rev = branch.repository.get_revision(mmerge)
 
91
                children.append(rev)
 
92
 
 
93
                ignore.add(mmerge)
 
94
        except errors.NoSuchRevision:
 
95
            print "DEBUG: NoSuchRevision:", merge
 
96
 
 
97
    return pm
139
98
 
140
99
 
141
100
_newline_variants_re = re.compile(r'\r\n?')
142
101
def _sanitize_and_decode_message(utf8_message):
143
102
    """Turn a utf-8 message into a sanitized Unicode message."""
144
103
    fixed_newline = _newline_variants_re.sub('\n', utf8_message)
145
 
    return osutils.safe_unicode(fixed_newline)
 
104
    return fixed_newline.decode('utf-8')
146
105
 
147
106
 
148
107
class CommitDialog(Gtk.Dialog):
163
122
        self._enable_per_file_commits = True
164
123
        self._commit_all_changes = True
165
124
        self.committed_revision_id = None # Nothing has been committed yet
166
 
        self._last_selected_file = None
167
125
        self._saved_commit_messages_manager = SavedCommitMessagesManager(
168
126
            self._wt, self._wt.branch)
169
127
 
175
133
        """Setup the member variables for state."""
176
134
        self._basis_tree = self._wt.basis_tree()
177
135
        self._delta = None
178
 
        self._wt.lock_read()
179
 
        try:
180
 
            self._pending = list(pending_revisions(self._wt))
181
 
        finally:
182
 
            self._wt.unlock()
 
136
        self._pending = pending_revisions(self._wt)
183
137
 
184
138
        self._is_checkout = (self._wt.branch.get_bound_location() is not None)
185
139
 
237
191
 
238
192
        all_enabled = (self._selected is None)
239
193
        # The first entry is always the 'whole tree'
240
 
        all_iter = store.append(["", "", all_enabled, 'All Files', '', ''])
 
194
        all_iter = store.append([None, None, all_enabled, 'All Files', '', ''])
241
195
        initial_cursor = store.get_path(all_iter)
242
196
        # should we pass specific_files?
243
197
        self._wt.lock_read()
288
242
            self._check_local.hide()
289
243
            return
290
244
        if have_dbus:
291
 
            try:
292
 
                bus = dbus.SystemBus()
293
 
            except dbus.DBusException:
294
 
                trace.mutter("DBus system bus not available")
295
 
                self._check_local.show()
296
 
                return
 
245
            bus = dbus.SystemBus()
297
246
            try:
298
247
                proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
299
248
                                           '/org/freedesktop/NetworkManager')
301
250
                trace.mutter("networkmanager not available.")
302
251
                self._check_local.show()
303
252
                return
304
 
 
 
253
            
305
254
            dbus_iface = dbus.Interface(proxy_obj,
306
255
                                        'org.freedesktop.NetworkManager')
307
256
            try:
333
282
        """Build up the dialog widgets."""
334
283
        # The primary pane which splits it into left and right (adjustable)
335
284
        # sections.
336
 
        self._hpane = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
 
285
        self._hpane = Gtk.HPaned()
337
286
 
338
287
        self._construct_left_pane()
339
288
        self._construct_right_pane()
499
448
                                     self._on_treeview_files_cursor_changed)
500
449
 
501
450
    def _toggle_commit(self, cell, path, model):
502
 
        if model[path][0] == "": # No file_id means 'All Files'
 
451
        if model[path][0] is None: # No file_id means 'All Files'
503
452
            new_val = not model[path][2]
504
453
            for node in model:
505
454
                node[2] = new_val
622
571
 
623
572
    def _on_treeview_files_cursor_changed(self, treeview):
624
573
        treeselection = treeview.get_selection()
625
 
        if treeselection is None:
626
 
            # The treeview was probably destroyed as the dialog closes.
627
 
            return
628
574
        (model, selection) = treeselection.get_selected()
629
575
 
630
576
        if selection is not None:
631
577
            path, display_path = model.get(selection, 1, 3)
632
578
            self._diff_label.set_text(_i18n('Diff for ') + display_path)
633
 
            if path == "":
 
579
            if path is None:
634
580
                self._diff_view.show_diff(None)
635
581
            else:
636
 
                self._diff_view.show_diff([osutils.safe_unicode(path)])
 
582
                self._diff_view.show_diff([path.decode('UTF-8')])
637
583
            self._update_per_file_info(selection)
638
584
 
639
585
    def _on_accel_next(self, accel_group, window, keyval, modifier):
651
597
            # selected. Either way, select All Files, and jump to the global
652
598
            # commit message.
653
599
            self._treeview_files.set_cursor(
654
 
                Gtk.TreePath(path=0), "", False)
 
600
                Gtk.TreePath(path=0), None, False)
655
601
            self._global_message_text_view.grab_focus()
656
602
        else:
657
603
            # Set the cursor to this entry, and jump to the per-file commit
676
622
        self._save_current_file_message()
677
623
        text_buffer = self._file_message_text_view.get_buffer()
678
624
        file_id, display_path, message = self._files_store.get(selection, 0, 3, 5)
679
 
        if file_id == "": # Whole tree
 
625
        if file_id is None: # Whole tree
680
626
            self._file_message_expander.set_label(_i18n('File commit message'))
681
627
            self._file_message_expander.set_expanded(False)
682
628
            self._file_message_expander.set_sensitive(False)
699
645
        files = []
700
646
        records = iter(self._files_store)
701
647
        rec = records.next() # Skip the All Files record
702
 
        assert rec[0] == "", "Are we skipping the wrong record?"
 
648
        assert rec[0] is None, "Are we skipping the wrong record?"
703
649
 
704
650
        file_info = []
705
651
        for record in records:
706
652
            if self._commit_all_changes or record[2]:# [2] checkbox
707
 
                file_id = osutils.safe_utf8(record[0]) # [0] file_id
708
 
                path = osutils.safe_utf8(record[1])    # [1] real path
 
653
                file_id = record[0] # [0] file_id
 
654
                path = record[1]    # [1] real path
709
655
                # [5] commit message
710
656
                file_message = _sanitize_and_decode_message(record[5])
711
657
                files.append(path.decode('UTF-8'))