~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to changelog_merge.py

  • Committer: Andrew Bennetts
  • Date: 2011-03-14 04:39:40 UTC
  • mto: (5724.2.1 add-changelog-merge)
  • mto: This revision was merged to the branch mainline in revision 5726.
  • Revision ID: andrew.bennetts@canonical.com-20110314043940-vqiz0r79rh5llmxz
Do a spot of code gardening.

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
    pass
96
96
 
97
97
 
98
 
def merge_entries_old(base_entries, this_entries, other_entries):
99
 
    # Determine which entries have been added by other (compared to base)
100
 
    base_entries = frozenset(base_entries)
101
 
    new_in_other = [
102
 
        entry for entry in other_entries if entry not in base_entries]
103
 
    # Prepend them to the entries in this
104
 
    result_entries = new_in_other + this_entries
105
 
    return result_entries
106
 
 
107
 
 
108
98
def default_guess_edits(new_entries, deleted_entries, entry_as_str=''.join):
109
 
    # This algorithm does O(N^2 * logN) SequenceMatcher.ratio() calls, which is
110
 
    # pretty bad, but it shouldn't be used very often.
 
99
    """Default implementation of guess_edits param of merge_entries.
 
100
 
 
101
    This algorithm does O(N^2 * logN) SequenceMatcher.ratio() calls, which is
 
102
    pretty bad, but it shouldn't be used very often.
 
103
    """
111
104
    deleted_entries_as_strs = [
112
105
        entry_as_str(entry) for entry in deleted_entries]
113
106
    new_entries_as_strs = [
142
135
    return result_new, result_deleted, result_edits
143
136
 
144
137
 
145
 
def merge_entries_new(base_entries, this_entries, other_entries,
 
138
def merge_entries(base_entries, this_entries, other_entries,
146
139
        guess_edits=default_guess_edits):
147
 
    m3 = Merge3(base_entries, this_entries, other_entries,
148
 
        allow_objects=True)
 
140
    """Merge changelog given base, this, and other versions."""
 
141
    m3 = Merge3(base_entries, this_entries, other_entries, allow_objects=True)
149
142
    result_entries = []
150
143
    at_top = True
151
144
    for group in m3.merge_groups():
197
190
            result_entries.extend(lines)
198
191
        at_top = False
199
192
    return result_entries
200
 
 
201
 
 
202
 
merge_entries = merge_entries_new