~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_core.py

Merge in format-5 work - release bzr 0.1rc1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os.path
 
2
 
1
3
import changeset
2
4
from changeset import Inventory, apply_changeset, invert_dict
3
 
import os.path
4
 
from osutils import backup_file
5
 
from merge3 import Merge3
 
5
from bzrlib.osutils import backup_file, rename
 
6
from bzrlib.merge3 import Merge3
 
7
import bzrlib
6
8
 
7
9
class ApplyMerge3:
8
10
    """Contents-change wrapper around merge3.Merge3"""
51
53
        output_file.close()
52
54
        if not new_conflicts:
53
55
            os.chmod(new_file, os.stat(filename).st_mode)
54
 
            os.rename(new_file, filename)
 
56
            rename(new_file, filename)
55
57
            return
56
58
        else:
57
59
            conflict_handler.merge_conflict(new_file, filename, base_lines,
198
200
 
199
201
 
200
202
def get_contents(entry, tree):
 
203
    return get_id_contents(entry.id, tree)
 
204
 
 
205
def get_id_contents(file_id, tree):
201
206
    """Get a contents change element suitable for use with ReplaceContents
202
207
    """
203
 
    tree_entry = tree.tree.inventory[entry.id]
 
208
    tree_entry = tree.tree.inventory[file_id]
204
209
    if tree_entry.kind == "file":
205
 
        return changeset.FileCreate(tree.get_file(entry.id).read())
 
210
        return changeset.FileCreate(tree.get_file(file_id).read())
 
211
    elif tree_entry.kind == "symlink":
 
212
        return changeset.SymlinkCreate(tree.get_symlink_target(file_id))
206
213
    else:
207
214
        assert tree_entry.kind in ("root_directory", "directory")
208
215
        return changeset.dir_create
224
231
        if contents.old_contents is None and contents.new_contents is None:
225
232
            return None
226
233
        if contents.new_contents is None:
227
 
            if this_path is not None and os.path.exists(this_path):
 
234
            this_contents = get_contents(entry, this)
 
235
            if this_path is not None and bzrlib.osutils.lexists(this_path):
 
236
                if this_contents != contents.old_contents:
 
237
                    return conflict_handler.rem_contents_conflict(this_path, 
 
238
                        this_contents, contents.old_contents)
228
239
                return contents
229
240
            else:
230
241
                return None
231
242
        elif contents.old_contents is None:
232
 
            if this_path is None or not os.path.exists(this_path):
 
243
            if this_path is None or not bzrlib.osutils.lexists(this_path):
233
244
                return contents
234
245
            else:
235
246
                this_contents = get_contents(entry, this)
246
257
            raise Exception("Unhandled merge scenario")
247
258
 
248
259
def make_merged_metadata(entry, base, other):
249
 
    if entry.metadata_change is not None:
250
 
        base_path = base.readonly_path(entry.id)
251
 
        other_path = other.readonly_path(entry.id)    
252
 
        return PermissionsMerge(base_path, other_path)
 
260
    metadata = entry.metadata_change
 
261
    if metadata is None:
 
262
        return None
 
263
    if isinstance(metadata, changeset.ChangeUnixPermissions):
 
264
        if metadata.new_mode is None:
 
265
            return None
 
266
        elif metadata.old_mode is None:
 
267
            return metadata
 
268
        else:
 
269
            base_path = base.readonly_path(entry.id)
 
270
            other_path = other.readonly_path(entry.id)    
 
271
            return PermissionsMerge(base_path, other_path)
253
272
    
254
273
 
255
274
class PermissionsMerge(object):