~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_core.py

  • Committer: Robert Collins
  • Date: 2005-08-24 06:53:07 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050824065307-bca8ae89734a53f8
merge from mpool

Show diffs side-by-side

added added

removed removed

Lines of Context:
150
150
    from bzrlib.trace import mutter
151
151
    def entry_data(file_id, tree):
152
152
        assert hasattr(tree, "__contains__"), "%s" % tree
153
 
        if file_id not in tree:
 
153
        if not tree.has_or_had_id(file_id):
154
154
            return (None, None, "")
155
155
        entry = tree.tree.inventory[file_id]
156
156
        my_dir = tree.id2path(entry.parent_id)
176
176
        new_parent = conflict_handler.move_conflict(entry.id, this_dir,
177
177
                                                    base_dir, other_dir)
178
178
    def get_path(name, parent):
179
 
        if name is not None and parent is not None:
 
179
        if name is not None:
 
180
            if name == "":
 
181
                assert parent is None
 
182
                return './.'
180
183
            parent_dir = {this_parent: this_dir, other_parent: other_dir, 
181
184
                          base_parent: base_dir}
182
185
            directory = parent_dir[parent]
183
186
            return os.path.join(directory, name)
184
187
        else:
185
 
            assert name is None and parent is None
 
188
            assert parent is None
186
189
            return None
187
190
 
188
191
    old_path = get_path(old_name, old_parent)
194
197
    return new_entry
195
198
 
196
199
 
 
200
def get_contents(entry, tree):
 
201
    """Get a contents change element suitable for use with ReplaceContents
 
202
    """
 
203
    tree_entry = tree.tree.inventory[entry.id]
 
204
    if tree_entry.kind == "file":
 
205
        return changeset.FileCreate(tree.get_file(entry.id).read())
 
206
    else:
 
207
        assert tree_entry.kind in ("root_directory", "directory")
 
208
        return changeset.dir_create
 
209
 
 
210
 
197
211
def make_merged_contents(entry, this, base, other, conflict_handler,
198
212
                         merge_factory):
199
213
    contents = entry.contents_change
218
232
            if this_path is None or not os.path.exists(this_path):
219
233
                return contents
220
234
            else:
221
 
                this_contents = changeset.FileCreate(file(this_path, 
222
 
                                                     "rb").read())
 
235
                this_contents = get_contents(entry, this)
223
236
                if this_contents == contents.new_contents:
224
237
                    return None
225
238
                else:
342
355
    def __contains__(self, file_id):
343
356
        return file_id in self.inventory
344
357
 
 
358
    def has_or_had_id(self, file_id):
 
359
        return file_id in self
 
360
 
345
361
    def get_file(self, file_id):
346
362
        path = self.readonly_path(file_id)
347
363
        return file(path, "rb")