~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Shannon Weyrick
  • Date: 2011-11-04 13:40:04 UTC
  • mfrom: (6238 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6256.
  • Revision ID: weyrick@mozek.us-20111104134004-033t2wqhc3ydzm0a
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from bzrlib import (
31
31
    annotate,
32
32
    bencode,
33
 
    bzrdir,
 
33
    controldir,
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)
2547
2544
    file_trans_id = {}
2548
2545
    top_pb = ui.ui_factory.nested_progress_bar()
2549
2546
    pp = ProgressPhase("Build phase", 2, top_pb)
2550
 
    if tree.inventory.root is not None:
 
2547
    if tree.get_root_id() is not None:
2551
2548
        # This is kind of a hack: we should be altering the root
2552
2549
        # as part of the regular tree shape diff logic.
2553
2550
        # The conditional test here is to avoid doing an
2568
2565
        try:
2569
2566
            deferred_contents = []
2570
2567
            num = 0
2571
 
            total = len(tree.inventory)
 
2568
            total = len(tree.all_file_ids())
2572
2569
            if delta_from_tree:
2573
2570
                precomputed_delta = []
2574
2571
            else:
2583
2580
                for dir, files in wt.walkdirs():
2584
2581
                    existing_files.update(f[0] for f in files)
2585
2582
            for num, (tree_path, entry) in \
2586
 
                enumerate(tree.inventory.iter_entries_by_dir()):
 
2583
                enumerate(tree.iter_entries_by_dir()):
2587
2584
                pb.update(gettext("Building tree"), num - len(deferred_contents), total)
2588
2585
                if entry.parent_id is None:
2589
2586
                    continue
2596
2593
                    kind = file_kind(target_path)
2597
2594
                    if kind == "directory":
2598
2595
                        try:
2599
 
                            bzrdir.BzrDir.open(target_path)
 
2596
                            controldir.ControlDir.open(target_path)
2600
2597
                        except errors.NotBranchError:
2601
2598
                            pass
2602
2599
                        else:
2839
2836
            return new_name
2840
2837
 
2841
2838
 
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
2839
def revert(working_tree, target_tree, filenames, backups=False,
2870
2840
           pb=None, change_reporter=None):
2871
2841
    """Revert a working tree's contents to those of a target tree."""
3078
3048
                existing_file, new_file = conflict[2], conflict[1]
3079
3049
            else:
3080
3050
                existing_file, new_file = conflict[1], conflict[2]
3081
 
            new_name = tt.final_name(existing_file)+'.moved'
 
3051
            new_name = tt.final_name(existing_file) + '.moved'
3082
3052
            tt.adjust_path(new_name, final_parent, existing_file)
3083
3053
            new_conflicts.add((c_type, 'Moved existing file to',
3084
3054
                               existing_file, new_file))