45
def _get_sorted_revisions(tip_revision, revision_ids, parent_map):
46
"""Get an iterator which will return the revisions in merge sorted order.
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'
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()
57
# MergeSorter requires that all nodes be present in the graph, so get rid
58
# of any references pointing outside of this graph.
60
for revision_id in revision_ids:
61
if revision_id not in parent_map: # ghost
62
parent_graph[revision_id] = []
64
# Only include parents which are in this sub-graph
65
parent_graph[revision_id] = [p for p in parent_map[revision_id]
67
sorter = tsort.MergeSorter(parent_graph, tip_revision)
68
return sorter.iter_topo_order()
71
46
def pending_revisions(wt):
72
47
"""Return a list of pending merges or None if there are none of them.
87
62
last_revision = parents[0]
89
graph = branch.repository.get_graph()
90
other_revisions = [last_revision]
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])])
93
71
for merge in pending:
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)
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)
108
# Get a handle to all of the revisions we will need
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
115
for revision_id in merge_extra:
117
rev = branch.repository.get_revisions([revision_id])[0]
118
except errors.NoSuchRevision:
119
revisions[revision_id] = None
121
revisions[revision_id] = rev
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()
129
raise AssertionError('Somehow we misunderstood how'
130
' iter_topo_order works %s != %s' % (first, merge))
132
for num, sub_merge, depth, eom in rev_id_iterator:
133
rev = revisions[sub_merge]
135
trace.warning("ghost: %r", sub_merge)
138
yield (merge_rev, children)
74
rev = branch.repository.get_revision(merge)
76
pm.append((rev, children))
78
# This does need to be topo sorted, so we search backwards
79
inner_merges = branch.repository.get_ancestry(merge)
80
assert inner_merges[0] is None
82
for mmerge in reversed(inner_merges):
85
rev = branch.repository.get_revision(mmerge)
89
except errors.NoSuchRevision:
90
print "DEBUG: NoSuchRevision:", merge
141
95
_newline_variants_re = re.compile(r'\r\n?')
142
96
def _sanitize_and_decode_message(utf8_message):
143
97
"""Turn a utf-8 message into a sanitized Unicode message."""
144
98
fixed_newline = _newline_variants_re.sub('\n', utf8_message)
145
return osutils.safe_unicode(fixed_newline)
99
return fixed_newline.decode('utf-8')
148
102
class CommitDialog(Gtk.Dialog):
238
191
all_enabled = (self._selected is None)
239
192
# The first entry is always the 'whole tree'
240
all_iter = store.append(["", "", all_enabled, 'All Files', '', ''])
193
all_iter = store.append([None, None, all_enabled, 'All Files', '', ''])
241
194
initial_cursor = store.get_path(all_iter)
242
195
# should we pass specific_files?
243
196
self._wt.lock_read()
623
571
def _on_treeview_files_cursor_changed(self, treeview):
624
572
treeselection = treeview.get_selection()
625
if treeselection is None:
626
# The treeview was probably destroyed as the dialog closes.
628
573
(model, selection) = treeselection.get_selected()
630
575
if selection is not None:
631
576
path, display_path = model.get(selection, 1, 3)
632
577
self._diff_label.set_text(_i18n('Diff for ') + display_path)
634
579
self._diff_view.show_diff(None)
636
self._diff_view.show_diff([osutils.safe_unicode(path)])
581
self._diff_view.show_diff([path.decode('UTF-8')])
637
582
self._update_per_file_info(selection)
639
584
def _on_accel_next(self, accel_group, window, keyval, modifier):
651
596
# selected. Either way, select All Files, and jump to the global
652
597
# commit message.
653
598
self._treeview_files.set_cursor(
654
Gtk.TreePath(path=0), "", False)
599
Gtk.TreePath(path=0), None, False)
655
600
self._global_message_text_view.grab_focus()
657
602
# Set the cursor to this entry, and jump to the per-file commit
676
621
self._save_current_file_message()
677
622
text_buffer = self._file_message_text_view.get_buffer()
678
623
file_id, display_path, message = self._files_store.get(selection, 0, 3, 5)
679
if file_id == "": # Whole tree
624
if file_id is None: # Whole tree
680
625
self._file_message_expander.set_label(_i18n('File commit message'))
681
626
self._file_message_expander.set_expanded(False)
682
627
self._file_message_expander.set_sensitive(False)
700
645
records = iter(self._files_store)
701
646
rec = records.next() # Skip the All Files record
702
assert rec[0] == "", "Are we skipping the wrong record?"
647
assert rec[0] is None, "Are we skipping the wrong record?"
705
650
for record in records:
706
651
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
652
file_id = record[0] # [0] file_id
653
path = record[1] # [1] real path
709
654
# [5] commit message
710
655
file_message = _sanitize_and_decode_message(record[5])
711
656
files.append(path.decode('UTF-8'))