/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: John Arbash Meinel
  • Date: 2009-07-08 14:37:25 UTC
  • mfrom: (4516 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4517.
  • Revision ID: john@arbash-meinel.com-20090708143725-sc9sjy3mz4cxwxzz
Merge bzr.dev 4516

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
import itertools
49
49
import operator
50
50
import stat
51
 
from time import time
52
 
import warnings
53
51
import re
54
52
 
55
53
import bzrlib
57
55
    branch,
58
56
    bzrdir,
59
57
    conflicts as _mod_conflicts,
60
 
    dirstate,
61
58
    errors,
62
59
    generate_ids,
63
60
    globbing,
64
61
    hashcache,
65
62
    ignores,
 
63
    inventory,
66
64
    merge,
67
65
    revision as _mod_revision,
68
66
    revisiontree,
69
 
    repository,
70
67
    textui,
71
68
    trace,
72
69
    transform,
73
70
    ui,
74
 
    urlutils,
75
71
    views,
76
72
    xml5,
77
 
    xml6,
78
73
    xml7,
79
74
    )
80
75
import bzrlib.branch
81
76
from bzrlib.transport import get_transport
82
 
import bzrlib.ui
83
77
from bzrlib.workingtree_4 import (
84
78
    WorkingTreeFormat4,
85
79
    WorkingTreeFormat5,
89
83
 
90
84
from bzrlib import symbol_versioning
91
85
from bzrlib.decorators import needs_read_lock, needs_write_lock
92
 
from bzrlib.inventory import InventoryEntry, Inventory, ROOT_ID, TreeReference
93
86
from bzrlib.lockable_files import LockableFiles
94
87
from bzrlib.lockdir import LockDir
95
88
import bzrlib.mutabletree
96
89
from bzrlib.mutabletree import needs_tree_write_lock
97
90
from bzrlib import osutils
98
91
from bzrlib.osutils import (
99
 
    compact_date,
100
92
    file_kind,
101
93
    isdir,
102
94
    normpath,
103
95
    pathjoin,
104
 
    rand_chars,
105
96
    realpath,
106
97
    safe_unicode,
107
98
    splitpath,
111
102
from bzrlib.trace import mutter, note
112
103
from bzrlib.transport.local import LocalTransport
113
104
from bzrlib.progress import DummyProgress, ProgressPhase
114
 
from bzrlib.revision import NULL_REVISION, CURRENT_REVISION
 
105
from bzrlib.revision import CURRENT_REVISION
115
106
from bzrlib.rio import RioReader, rio_file, Stanza
116
 
from bzrlib.symbol_versioning import (deprecated_passed,
117
 
        deprecated_method,
118
 
        deprecated_function,
119
 
        DEPRECATED_PARAMETER,
120
 
        )
 
107
from bzrlib.symbol_versioning import (
 
108
    deprecated_passed,
 
109
    DEPRECATED_PARAMETER,
 
110
    )
121
111
 
122
112
 
123
113
MERGE_MODIFIED_HEADER_1 = "BZR merge-modified list format 1"
446
436
 
447
437
    def get_file_with_stat(self, file_id, path=None, filtered=True,
448
438
        _fstat=os.fstat):
449
 
        """See MutableTree.get_file_with_stat."""
 
439
        """See Tree.get_file_with_stat."""
450
440
        if path is None:
451
441
            path = self.id2path(file_id)
452
442
        file_obj = self.get_file_byname(path, filtered=False)
453
443
        stat_value = _fstat(file_obj.fileno())
454
 
        if self.supports_content_filtering() and filtered:
 
444
        if filtered and self.supports_content_filtering():
455
445
            filters = self._content_filter_stack(path)
456
446
            file_obj = filtered_input_file(file_obj, filters)
457
447
        return (file_obj, stat_value)
462
452
    def get_file_byname(self, filename, filtered=True):
463
453
        path = self.abspath(filename)
464
454
        f = file(path, 'rb')
465
 
        if self.supports_content_filtering() and filtered:
 
455
        if filtered and self.supports_content_filtering():
466
456
            filters = self._content_filter_stack(filename)
467
457
            return filtered_input_file(f, filters)
468
458
        else:
889
879
            branch.last_revision().
890
880
        """
891
881
        from bzrlib.merge import Merger, Merge3Merger
892
 
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
882
        pb = ui.ui_factory.nested_progress_bar()
893
883
        try:
894
884
            merger = Merger(self.branch, this_tree=self, pb=pb)
895
885
            merger.pp = ProgressPhase("Merge phase", 5, pb)
1081
1071
            branch.BranchReferenceFormat().initialize(tree_bzrdir, new_branch)
1082
1072
        else:
1083
1073
            tree_bzrdir = branch_bzrdir
1084
 
        wt = tree_bzrdir.create_workingtree(NULL_REVISION)
 
1074
        wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION)
1085
1075
        wt.set_parent_ids(self.get_parent_ids())
1086
1076
        my_inv = self.inventory
1087
 
        child_inv = Inventory(root_id=None)
 
1077
        child_inv = inventory.Inventory(root_id=None)
1088
1078
        new_root = my_inv[file_id]
1089
1079
        my_inv.remove_recursive_id(file_id)
1090
1080
        new_root.parent_id = None
1115
1105
    def _kind(self, relpath):
1116
1106
        return osutils.file_kind(self.abspath(relpath))
1117
1107
 
1118
 
    def list_files(self, include_root=False):
1119
 
        """Recursively list all files as (path, class, kind, id, entry).
 
1108
    def list_files(self, include_root=False, from_dir=None, recursive=True):
 
1109
        """List all files as (path, class, kind, id, entry).
1120
1110
 
1121
1111
        Lists, but does not descend into unversioned directories.
1122
 
 
1123
1112
        This does not include files that have been deleted in this
1124
 
        tree.
 
1113
        tree. Skips the control directory.
1125
1114
 
1126
 
        Skips the control directory.
 
1115
        :param include_root: if True, do not return an entry for the root
 
1116
        :param from_dir: start from this directory or None for the root
 
1117
        :param recursive: whether to recurse into subdirectories or not
1127
1118
        """
1128
1119
        # list_files is an iterator, so @needs_read_lock doesn't work properly
1129
1120
        # with it. So callers should be careful to always read_lock the tree.
1131
1122
            raise errors.ObjectNotLocked(self)
1132
1123
 
1133
1124
        inv = self.inventory
1134
 
        if include_root is True:
 
1125
        if from_dir is None and include_root is True:
1135
1126
            yield ('', 'V', 'directory', inv.root.file_id, inv.root)
1136
1127
        # Convert these into local objects to save lookup times
1137
1128
        pathjoin = osutils.pathjoin
1144
1135
        fk_entries = {'directory':TreeDirectory, 'file':TreeFile, 'symlink':TreeLink}
1145
1136
 
1146
1137
        # directory file_id, relative path, absolute path, reverse sorted children
1147
 
        children = os.listdir(self.basedir)
 
1138
        if from_dir is not None:
 
1139
            from_dir_id = inv.path2id(from_dir)
 
1140
            if from_dir_id is None:
 
1141
                # Directory not versioned
 
1142
                return
 
1143
            from_dir_abspath = pathjoin(self.basedir, from_dir)
 
1144
        else:
 
1145
            from_dir_id = inv.root.file_id
 
1146
            from_dir_abspath = self.basedir
 
1147
        children = os.listdir(from_dir_abspath)
1148
1148
        children.sort()
1149
1149
        # jam 20060527 The kernel sized tree seems equivalent whether we
1150
1150
        # use a deque and popleft to keep them sorted, or if we use a plain
1151
1151
        # list and just reverse() them.
1152
1152
        children = collections.deque(children)
1153
 
        stack = [(inv.root.file_id, u'', self.basedir, children)]
 
1153
        stack = [(from_dir_id, u'', from_dir_abspath, children)]
1154
1154
        while stack:
1155
1155
            from_dir_id, from_dir_relpath, from_dir_abspath, children = stack[-1]
1156
1156
 
1214
1214
                if fk != 'directory':
1215
1215
                    continue
1216
1216
 
1217
 
                # But do this child first
1218
 
                new_children = os.listdir(fap)
1219
 
                new_children.sort()
1220
 
                new_children = collections.deque(new_children)
1221
 
                stack.append((f_ie.file_id, fp, fap, new_children))
1222
 
                # Break out of inner loop,
1223
 
                # so that we start outer loop with child
1224
 
                break
 
1217
                # But do this child first if recursing down
 
1218
                if recursive:
 
1219
                    new_children = os.listdir(fap)
 
1220
                    new_children.sort()
 
1221
                    new_children = collections.deque(new_children)
 
1222
                    stack.append((f_ie.file_id, fp, fap, new_children))
 
1223
                    # Break out of inner loop,
 
1224
                    # so that we start outer loop with child
 
1225
                    break
1225
1226
            else:
1226
1227
                # if we finished all children, pop it off the stack
1227
1228
                stack.pop()
1405
1406
        inv = self.inventory
1406
1407
        for entry in moved:
1407
1408
            try:
1408
 
                self._move_entry(_RenameEntry(entry.to_rel, entry.from_id,
 
1409
                self._move_entry(WorkingTree._RenameEntry(
 
1410
                    entry.to_rel, entry.from_id,
1409
1411
                    entry.to_tail, entry.to_parent_id, entry.from_rel,
1410
1412
                    entry.from_tail, entry.from_parent_id,
1411
1413
                    entry.only_change_inv))
1562
1564
    @needs_write_lock
1563
1565
    def pull(self, source, overwrite=False, stop_revision=None,
1564
1566
             change_reporter=None, possible_transports=None, local=False):
1565
 
        top_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
1567
        top_pb = ui.ui_factory.nested_progress_bar()
1566
1568
        source.lock_read()
1567
1569
        try:
1568
1570
            pp = ProgressPhase("Pull phase", 2, top_pb)
1576
1578
            if new_revision_info != old_revision_info:
1577
1579
                pp.next_phase()
1578
1580
                repository = self.branch.repository
1579
 
                pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
1581
                pb = ui.ui_factory.nested_progress_bar()
1580
1582
                basis_tree.lock_read()
1581
1583
                try:
1582
1584
                    new_basis_tree = self.branch.basis_tree()
2031
2033
            if filenames is None and len(self.get_parent_ids()) > 1:
2032
2034
                parent_trees = []
2033
2035
                last_revision = self.last_revision()
2034
 
                if last_revision != NULL_REVISION:
 
2036
                if last_revision != _mod_revision.NULL_REVISION:
2035
2037
                    if basis_tree is None:
2036
2038
                        basis_tree = self.basis_tree()
2037
2039
                        basis_tree.lock_read()
2075
2077
    def set_inventory(self, new_inventory_list):
2076
2078
        from bzrlib.inventory import (Inventory,
2077
2079
                                      InventoryDirectory,
2078
 
                                      InventoryEntry,
2079
2080
                                      InventoryFile,
2080
2081
                                      InventoryLink)
2081
2082
        inv = Inventory(self.get_root_id())
2623
2624
 
2624
2625
    def _change_last_revision(self, revision_id):
2625
2626
        """See WorkingTree._change_last_revision."""
2626
 
        if revision_id is None or revision_id == NULL_REVISION:
 
2627
        if revision_id is None or revision_id == _mod_revision.NULL_REVISION:
2627
2628
            try:
2628
2629
                self._transport.delete('last-revision')
2629
2630
            except errors.NoSuchFile:
2793
2794
        no working tree.  (See bug #43064).
2794
2795
        """
2795
2796
        sio = StringIO()
2796
 
        inv = Inventory()
 
2797
        inv = inventory.Inventory()
2797
2798
        xml5.serializer_v5.write_inventory(inv, sio, working=True)
2798
2799
        sio.seek(0)
2799
2800
        transport.put_file('inventory', sio, file_mode)
2815
2816
            branch.generate_revision_history(revision_id)
2816
2817
        finally:
2817
2818
            branch.unlock()
2818
 
        inv = Inventory()
 
2819
        inv = inventory.Inventory()
2819
2820
        wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
2820
2821
                         branch,
2821
2822
                         inv,
2938
2939
            # only set an explicit root id if there is one to set.
2939
2940
            if basis_tree.inventory.root is not None:
2940
2941
                wt.set_root_id(basis_tree.get_root_id())
2941
 
            if revision_id == NULL_REVISION:
 
2942
            if revision_id == _mod_revision.NULL_REVISION:
2942
2943
                wt.set_parent_trees([])
2943
2944
            else:
2944
2945
                wt.set_parent_trees([(revision_id, basis_tree)])
2951
2952
        return wt
2952
2953
 
2953
2954
    def _initial_inventory(self):
2954
 
        return Inventory()
 
2955
        return inventory.Inventory()
2955
2956
 
2956
2957
    def __init__(self):
2957
2958
        super(WorkingTreeFormat3, self).__init__()