~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from bzrlib import bzrdir, errors
22
22
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
23
23
                           ReusingTransform, NotVersionedError, CantMoveRoot,
24
 
                           ExistingLimbo, ImmortalLimbo)
 
24
                           ExistingLimbo, ImmortalLimbo, NoFinalPath)
25
25
from bzrlib.inventory import InventoryEntry
26
26
from bzrlib.osutils import (file_kind, supports_executable, pathjoin, lexists,
27
27
                            delete_any)
73
73
     * set_executability
74
74
    """
75
75
    def __init__(self, tree, pb=DummyProgress()):
76
 
        """Note: a write lock is taken on the tree.
 
76
        """Note: a tree_write lock is taken on the tree.
77
77
        
78
78
        Use TreeTransform.finalize() to release the lock
79
79
        """
80
80
        object.__init__(self)
81
81
        self._tree = tree
82
 
        self._tree.lock_write()
 
82
        self._tree.lock_tree_write()
83
83
        try:
84
84
            control_files = self._tree._control_files
85
85
            self._limbodir = urlutils.local_path_from_url(
292
292
        except KeyError:
293
293
            return
294
294
        try:
295
 
            mode = os.stat(old_path).st_mode
 
295
            mode = os.stat(self._tree.abspath(old_path)).st_mode
296
296
        except OSError, e:
297
297
            if e.errno == errno.ENOENT:
298
298
                return
457
457
        try:
458
458
            return self._new_name[trans_id]
459
459
        except KeyError:
460
 
            return os.path.basename(self._tree_id_paths[trans_id])
 
460
            try:
 
461
                return os.path.basename(self._tree_id_paths[trans_id])
 
462
            except KeyError:
 
463
                raise NoFinalPath(trans_id, self)
461
464
 
462
465
    def by_parent(self):
463
466
        """Return a map of parent: children for known parents.
570
573
            parent_id = trans_id
571
574
            while parent_id is not ROOT_PARENT:
572
575
                seen.add(parent_id)
573
 
                parent_id = self.final_parent(parent_id)
 
576
                try:
 
577
                    parent_id = self.final_parent(parent_id)
 
578
                except KeyError:
 
579
                    break
574
580
                if parent_id == trans_id:
575
581
                    conflicts.append(('parent loop', trans_id))
576
582
                if parent_id in seen:
958
964
    file_trans_id = {}
959
965
    top_pb = bzrlib.ui.ui_factory.nested_progress_bar()
960
966
    pp = ProgressPhase("Build phase", 2, top_pb)
 
967
    if tree.inventory.root is not None:
 
968
        wt.set_root_id(tree.inventory.root.file_id)
961
969
    tt = TreeTransform(wt)
962
970
    divert = set()
963
971
    try:
1086
1094
def create_by_entry(tt, entry, tree, trans_id, lines=None, mode_id=None):
1087
1095
    """Create new file contents according to an inventory entry."""
1088
1096
    if entry.kind == "file":
1089
 
        if lines == None:
 
1097
        if lines is None:
1090
1098
            lines = tree.get_file(entry.file_id).readlines()
1091
1099
        tt.create_file(lines, trans_id, mode_id=mode_id)
1092
1100
    elif entry.kind == "symlink":
1229
1237
        pp.next_phase()
1230
1238
        wt_interesting = [i for i in working_tree.inventory if interesting(i)]
1231
1239
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
1240
        basis_tree = None
1232
1241
        try:
1233
1242
            for id_num, file_id in enumerate(wt_interesting):
 
1243
                if (working_tree.inventory.is_root(file_id) and 
 
1244
                    len(target_tree.inventory) == 0):
 
1245
                    continue
1234
1246
                child_pb.update("New file check", id_num+1, 
1235
1247
                                len(sorted_interesting))
1236
1248
                if file_id not in target_tree:
1240
1252
                        file_kind = working_tree.kind(file_id)
1241
1253
                    except NoSuchFile:
1242
1254
                        file_kind = None
 
1255
                    delete_merge_modified = (file_id in merge_modified)
1243
1256
                    if file_kind != 'file' and file_kind is not None:
1244
1257
                        keep_contents = False
1245
 
                        delete_merge_modified = False
1246
1258
                    else:
 
1259
                        if basis_tree is None:
 
1260
                            basis_tree = working_tree.basis_tree()
 
1261
                        wt_sha1 = working_tree.get_file_sha1(file_id)
1247
1262
                        if (file_id in merge_modified and 
1248
 
                            merge_modified[file_id] == 
1249
 
                            working_tree.get_file_sha1(file_id)):
1250
 
                            keep_contents = False
1251
 
                            delete_merge_modified = True
 
1263
                            merge_modified[file_id] == wt_sha1):
 
1264
                            keep_contents = False
 
1265
                        elif (file_id in basis_tree and 
 
1266
                            basis_tree.get_file_sha1(file_id) == wt_sha1):
 
1267
                            keep_contents = False
1252
1268
                        else:
1253
1269
                            keep_contents = True
1254
 
                            delete_merge_modified = False
1255
1270
                    if not keep_contents:
1256
1271
                        tt.delete_contents(trans_id)
1257
1272
                    if delete_merge_modified: