~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Vincent Ladeuil
  • Date: 2011-12-08 08:32:36 UTC
  • mto: This revision was merged to the branch mainline in revision 6350.
  • Revision ID: v.ladeuil+lp@free.fr-20111208083236-3cedhs5m0ph6hamk
Tags: bzr-2.5b4
ReleaseĀ 2.5b4

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    commit,
35
35
    conflicts,
36
36
    delta,
37
 
    errors,
38
37
    inventory,
39
38
    multiparent,
40
39
    osutils,
44
43
    )
45
44
from bzrlib.i18n import gettext
46
45
""")
47
 
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
 
46
from bzrlib.errors import (DuplicateKey, MalformedTransform,
48
47
                           ReusingTransform, CantMoveRoot,
49
48
                           ExistingLimbo, ImmortalLimbo, NoFinalPath,
50
49
                           UnableCreateSymlink)
562
561
        for trans_id in self._removed_id:
563
562
            file_id = self.tree_file_id(trans_id)
564
563
            if file_id is not None:
565
 
                # XXX: This seems like something that should go via a different
566
 
                #      indirection.
567
 
                if self._tree.inventory[file_id].kind == 'directory':
 
564
                if self._tree.stored_kind(file_id) == 'directory':
568
565
                    parents.append(trans_id)
569
566
            elif self.tree_kind(trans_id) == 'directory':
570
567
                parents.append(trans_id)
779
776
                    to_mode |= 0010 & ~umask
780
777
            else:
781
778
                to_mode = current_mode & ~0111
782
 
            os.chmod(abspath, to_mode)
 
779
            osutils.chmod_if_possible(abspath, to_mode)
783
780
 
784
781
    def _new_entry(self, name, parent_id, file_id):
785
782
        """Helper function to create a new filesystem entry."""
1558
1555
        try:
1559
1556
            limbodir = urlutils.local_path_from_url(
1560
1557
                tree._transport.abspath('limbo'))
1561
 
            try:
1562
 
                os.mkdir(limbodir)
1563
 
            except OSError, e:
1564
 
                if e.errno == errno.EEXIST:
1565
 
                    raise ExistingLimbo(limbodir)
 
1558
            osutils.ensure_empty_directory_exists(
 
1559
                limbodir,
 
1560
                errors.ExistingLimbo)
1566
1561
            deletiondir = urlutils.local_path_from_url(
1567
1562
                tree._transport.abspath('pending-deletion'))
1568
 
            try:
1569
 
                os.mkdir(deletiondir)
1570
 
            except OSError, e:
1571
 
                if e.errno == errno.EEXIST:
1572
 
                    raise errors.ExistingPendingDeletion(deletiondir)
 
1563
            osutils.ensure_empty_directory_exists(
 
1564
                deletiondir,
 
1565
                errors.ExistingPendingDeletion)
1573
1566
        except:
1574
1567
            tree.unlock()
1575
1568
            raise
1638
1631
            else:
1639
1632
                raise
1640
1633
        if typefunc(mode):
1641
 
            os.chmod(self._limbo_name(trans_id), mode)
 
1634
            osutils.chmod_if_possible(self._limbo_name(trans_id), mode)
1642
1635
 
1643
1636
    def iter_tree_children(self, parent_id):
1644
1637
        """Iterate through the entry's tree children, if any"""
2547
2540
    file_trans_id = {}
2548
2541
    top_pb = ui.ui_factory.nested_progress_bar()
2549
2542
    pp = ProgressPhase("Build phase", 2, top_pb)
2550
 
    if tree.inventory.root is not None:
 
2543
    if tree.get_root_id() is not None:
2551
2544
        # This is kind of a hack: we should be altering the root
2552
2545
        # as part of the regular tree shape diff logic.
2553
2546
        # The conditional test here is to avoid doing an
2568
2561
        try:
2569
2562
            deferred_contents = []
2570
2563
            num = 0
2571
 
            total = len(tree.inventory)
 
2564
            total = len(tree.all_file_ids())
2572
2565
            if delta_from_tree:
2573
2566
                precomputed_delta = []
2574
2567
            else:
2583
2576
                for dir, files in wt.walkdirs():
2584
2577
                    existing_files.update(f[0] for f in files)
2585
2578
            for num, (tree_path, entry) in \
2586
 
                enumerate(tree.inventory.iter_entries_by_dir()):
 
2579
                enumerate(tree.iter_entries_by_dir()):
2587
2580
                pb.update(gettext("Building tree"), num - len(deferred_contents), total)
2588
2581
                if entry.parent_id is None:
2589
2582
                    continue
2839
2832
            return new_name
2840
2833
 
2841
2834
 
2842
 
def _entry_changes(file_id, entry, working_tree):
2843
 
    """Determine in which ways the inventory entry has changed.
2844
 
 
2845
 
    Returns booleans: has_contents, content_mod, meta_mod
2846
 
    has_contents means there are currently contents, but they differ
2847
 
    contents_mod means contents need to be modified
2848
 
    meta_mod means the metadata needs to be modified
2849
 
    """
2850
 
    cur_entry = working_tree.inventory[file_id]
2851
 
    try:
2852
 
        working_kind = working_tree.kind(file_id)
2853
 
        has_contents = True
2854
 
    except NoSuchFile:
2855
 
        has_contents = False
2856
 
        contents_mod = True
2857
 
        meta_mod = False
2858
 
    if has_contents is True:
2859
 
        if entry.kind != working_kind:
2860
 
            contents_mod, meta_mod = True, False
2861
 
        else:
2862
 
            cur_entry._read_tree_state(working_tree.id2path(file_id),
2863
 
                                       working_tree)
2864
 
            contents_mod, meta_mod = entry.detect_changes(cur_entry)
2865
 
            cur_entry._forget_tree_state()
2866
 
    return has_contents, contents_mod, meta_mod
2867
 
 
2868
 
 
2869
2835
def revert(working_tree, target_tree, filenames, backups=False,
2870
2836
           pb=None, change_reporter=None):
2871
2837
    """Revert a working tree's contents to those of a target tree."""
3078
3044
                existing_file, new_file = conflict[2], conflict[1]
3079
3045
            else:
3080
3046
                existing_file, new_file = conflict[1], conflict[2]
3081
 
            new_name = tt.final_name(existing_file)+'.moved'
 
3047
            new_name = tt.final_name(existing_file) + '.moved'
3082
3048
            tt.adjust_path(new_name, final_parent, existing_file)
3083
3049
            new_conflicts.add((c_type, 'Moved existing file to',
3084
3050
                               existing_file, new_file))