~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

(lifeless) Changes some tests that compare paths to use a fancier method
 than just string comparison, fixing them on Windows. (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
1182
1182
            if trans_id not in self._new_contents:
1183
1183
                continue
1184
1184
            new_path = self._limbo_name(trans_id)
1185
 
            os.rename(old_path, new_path)
 
1185
            osutils.rename(old_path, new_path)
1186
1186
            for descendant in self._limbo_descendants(trans_id):
1187
1187
                desc_path = self._limbo_files[descendant]
1188
1188
                desc_path = new_path + desc_path[len(old_path):]
1792
1792
        parent_keys = [(file_id, self._file_revision(t, file_id)) for t in
1793
1793
                       self._iter_parent_trees()]
1794
1794
        vf.add_lines((file_id, tree_revision), parent_keys,
1795
 
                     self.get_file_lines(file_id))
 
1795
                     self.get_file(file_id).readlines())
1796
1796
        repo = self._get_repository()
1797
1797
        base_vf = repo.texts
1798
1798
        if base_vf not in vf.fallback_versionedfiles:
2291
2291
    for num, _unused in enumerate(wt.all_file_ids()):
2292
2292
        if num > 0:  # more than just a root
2293
2293
            raise errors.WorkingTreeAlreadyPopulated(base=wt.basedir)
 
2294
    existing_files = set()
 
2295
    for dir, files in wt.walkdirs():
 
2296
        existing_files.update(f[0] for f in files)
2294
2297
    file_trans_id = {}
2295
2298
    top_pb = bzrlib.ui.ui_factory.nested_progress_bar()
2296
2299
    pp = ProgressPhase("Build phase", 2, top_pb)
2320
2323
                precomputed_delta = []
2321
2324
            else:
2322
2325
                precomputed_delta = None
2323
 
            # Check if tree inventory has content. If so, we populate
2324
 
            # existing_files with the directory content. If there are no
2325
 
            # entries we skip populating existing_files as its not used.
2326
 
            # This improves performance and unncessary work on large
2327
 
            # directory trees. (#501307)
2328
 
            if total > 0:
2329
 
                existing_files = set()
2330
 
                for dir, files in wt.walkdirs():
2331
 
                    existing_files.update(f[0] for f in files)
2332
2326
            for num, (tree_path, entry) in \
2333
2327
                enumerate(tree.inventory.iter_entries_by_dir()):
2334
2328
                pb.update("Building tree", num - len(deferred_contents), total)
2466
2460
    if entry.kind == "directory":
2467
2461
        return True
2468
2462
    if entry.kind == "file":
2469
 
        f = file(target_path, 'rb')
2470
 
        try:
2471
 
            if tree.get_file_text(file_id) == f.read():
2472
 
                return True
2473
 
        finally:
2474
 
            f.close()
 
2463
        if tree.get_file(file_id).read() == file(target_path, 'rb').read():
 
2464
            return True
2475
2465
    elif entry.kind == "symlink":
2476
2466
        if tree.get_symlink_target(file_id) == os.readlink(target_path):
2477
2467
            return True
2529
2519
        raise errors.BadFileKindError(name, kind)
2530
2520
 
2531
2521
 
 
2522
@deprecated_function(deprecated_in((1, 9, 0)))
 
2523
def create_by_entry(tt, entry, tree, trans_id, lines=None, mode_id=None):
 
2524
    """Create new file contents according to an inventory entry.
 
2525
 
 
2526
    DEPRECATED.  Use create_from_tree instead.
 
2527
    """
 
2528
    if entry.kind == "file":
 
2529
        if lines is None:
 
2530
            lines = tree.get_file(entry.file_id).readlines()
 
2531
        tt.create_file(lines, trans_id, mode_id=mode_id)
 
2532
    elif entry.kind == "symlink":
 
2533
        tt.create_symlink(tree.get_symlink_target(entry.file_id), trans_id)
 
2534
    elif entry.kind == "directory":
 
2535
        tt.create_directory(trans_id)
 
2536
 
 
2537
 
2532
2538
def create_from_tree(tt, trans_id, tree, file_id, bytes=None,
2533
2539
    filter_tree_path=None):
2534
2540
    """Create new file contents according to tree contents.
2919
2925
    def rename(self, from_, to):
2920
2926
        """Rename a file from one path to another."""
2921
2927
        try:
2922
 
            os.rename(from_, to)
2923
 
        except OSError, e:
 
2928
            osutils.rename(from_, to)
 
2929
        except (IOError, OSError), e:
2924
2930
            if e.errno in (errno.EEXIST, errno.ENOTEMPTY):
2925
2931
                raise errors.FileExists(to, str(e))
2926
2932
            # normal OSError doesn't include filenames so it's hard to see where
2942
2948
        """Reverse all renames that have been performed"""
2943
2949
        for from_, to in reversed(self.past_renames):
2944
2950
            try:
2945
 
                os.rename(to, from_)
2946
 
            except OSError, e:
 
2951
                osutils.rename(to, from_)
 
2952
            except (OSError, IOError), e:
2947
2953
                raise errors.TransformRenameFailed(to, from_, str(e), e.errno)                
2948
2954
        # after rollback, don't reuse _FileMover
2949
2955
        past_renames = None