~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Patch Queue Manager
  • Date: 2012-01-27 14:28:32 UTC
  • mfrom: (6445.2.6 avoid-inventory)
  • Revision ID: pqm@pqm.ubuntu.com-20120127142832-qcv2y1c3i0mbt9bl
(jelmer) Avoid the use of inventories in a few more places. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
379
379
                                              list_current=list_current)
380
380
        return [tr for tr in iterator if tr is not None]
381
381
 
382
 
    def all_file_ids(self):
383
 
        """See Tree.iter_all_file_ids"""
384
 
        raise NotImplementedError(self.all_file_ids)
385
 
 
386
382
    def __repr__(self):
387
383
        return "<%s of %s>" % (self.__class__.__name__,
388
384
                               getattr(self, 'basedir', None))
1946
1942
            if entry.parent_id == orig_root_id:
1947
1943
                entry.parent_id = inv.root.file_id
1948
1944
 
1949
 
    def all_file_ids(self):
1950
 
        """See Tree.iter_all_file_ids"""
1951
 
        return set(self.inventory)
1952
 
 
1953
1945
    @needs_tree_write_lock
1954
1946
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
1955
1947
        """See MutableTree.set_parent_trees."""
2077
2069
 
2078
2070
    def has_id(self, file_id):
2079
2071
        # files that have been deleted are excluded
2080
 
        inv = self.inventory
2081
 
        if not inv.has_id(file_id):
 
2072
        if not self.inventory.has_id(file_id):
2082
2073
            return False
2083
 
        path = inv.id2path(file_id)
 
2074
        path = self.inventory.id2path(file_id)
2084
2075
        return osutils.lexists(self.abspath(path))
2085
2076
 
2086
2077
    def has_or_had_id(self, file_id):
2088
2079
            return True
2089
2080
        return self.inventory.has_id(file_id)
2090
2081
 
2091
 
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
2092
 
    def __iter__(self):
 
2082
    def all_file_ids(self):
2093
2083
        """Iterate through file_ids for this tree.
2094
2084
 
2095
2085
        file_ids are in a WorkingTree if they are in the working inventory
2096
2086
        and the working file exists.
2097
2087
        """
2098
 
        inv = self._inventory
2099
 
        for path, ie in inv.iter_entries():
2100
 
            if osutils.lexists(self.abspath(path)):
2101
 
                yield ie.file_id
 
2088
        ret = set()
 
2089
        for path, ie in self.iter_entries_by_dir():
 
2090
            ret.add(ie.file_id)
 
2091
        return ret
2102
2092
 
2103
2093
    @needs_tree_write_lock
2104
2094
    def set_last_revision(self, new_revision):
2178
2168
    def get_file_mtime(self, file_id, path=None):
2179
2169
        """See Tree.get_file_mtime."""
2180
2170
        if not path:
2181
 
            path = self.inventory.id2path(file_id)
 
2171
            path = self.id2path(file_id)
2182
2172
        try:
2183
2173
            return os.lstat(self.abspath(path)).st_mtime
2184
2174
        except OSError, e:
2192
2182
            # For unversioned files on win32, we just assume they are not
2193
2183
            # executable
2194
2184
            return False
2195
 
        return self._inventory[file_id].executable
 
2185
        return self.inventory[file_id].executable
2196
2186
 
2197
2187
    def _is_executable_from_path_and_stat_from_stat(self, path, stat_result):
2198
2188
        mode = stat_result.st_mode
2200
2190
 
2201
2191
    def is_executable(self, file_id, path=None):
2202
2192
        if not self._supports_executable():
2203
 
            return self._inventory[file_id].executable
 
2193
            return self.inventory[file_id].executable
2204
2194
        else:
2205
2195
            if not path:
2206
2196
                path = self.id2path(file_id)
2267
2257
                parent_tree = self.branch.repository.revision_tree(parent_id)
2268
2258
            parent_tree.lock_read()
2269
2259
            try:
2270
 
                if not parent_tree.has_id(file_id):
 
2260
                try:
 
2261
                    kind = parent_tree.kind(file_id)
 
2262
                except errors.NoSuchId:
2271
2263
                    continue
2272
 
                ie = parent_tree.inventory[file_id]
2273
 
                if ie.kind != 'file':
 
2264
                if kind != 'file':
2274
2265
                    # Note: this is slightly unnecessary, because symlinks and
2275
2266
                    # directories have a "text" which is the empty text, and we
2276
2267
                    # know that won't mess up annotations. But it seems cleaner
2277
2268
                    continue
2278
 
                parent_text_key = (file_id, ie.revision)
 
2269
                parent_text_key = (
 
2270
                    file_id, parent_tree.get_file_revision(file_id))
2279
2271
                if parent_text_key not in maybe_file_parent_keys:
2280
2272
                    maybe_file_parent_keys.append(parent_text_key)
2281
2273
            finally:
2335
2327
            for s in _mod_rio.RioReader(hashfile):
2336
2328
                # RioReader reads in Unicode, so convert file_ids back to utf8
2337
2329
                file_id = osutils.safe_file_id(s.get("file_id"), warn=False)
2338
 
                if not self.inventory.has_id(file_id):
 
2330
                if not self.has_id(file_id):
2339
2331
                    continue
2340
2332
                text_hash = s.get("hash")
2341
2333
                if text_hash == self.get_file_sha1(file_id):
2451
2443
        if not self.is_locked():
2452
2444
            raise errors.ObjectNotLocked(self)
2453
2445
 
2454
 
        inv = self.inventory
2455
2446
        if from_dir is None and include_root is True:
2456
 
            yield ('', 'V', 'directory', inv.root.file_id, inv.root)
 
2447
            yield ('', 'V', 'directory', self.get_root_id(), self.inventory.root)
2457
2448
        # Convert these into local objects to save lookup times
2458
2449
        pathjoin = osutils.pathjoin
2459
2450
        file_kind = self._kind
2466
2457
 
2467
2458
        # directory file_id, relative path, absolute path, reverse sorted children
2468
2459
        if from_dir is not None:
2469
 
            from_dir_id = inv.path2id(from_dir)
 
2460
            inv = self.inventory
 
2461
            from_dir_id = self.path2id(from_dir)
2470
2462
            if from_dir_id is None:
2471
2463
                # Directory not versioned
2472
2464
                return
2473
2465
            from_dir_abspath = pathjoin(self.basedir, from_dir)
2474
2466
        else:
 
2467
            inv = self.inventory
2475
2468
            from_dir_id = inv.root.file_id
2476
2469
            from_dir_abspath = self.basedir
2477
2470
        children = os.listdir(from_dir_abspath)
2606
2599
        # check destination directory
2607
2600
        if isinstance(from_paths, basestring):
2608
2601
            raise ValueError()
2609
 
        inv = self.inventory
2610
2602
        to_abs = self.abspath(to_dir)
2611
2603
        if not isdir(to_abs):
2612
2604
            raise errors.BzrMoveFailedError('',to_dir,
2614
2606
        if not self.has_filename(to_dir):
2615
2607
            raise errors.BzrMoveFailedError('',to_dir,
2616
2608
                errors.NotInWorkingDirectory(to_dir))
2617
 
        to_dir_id = inv.path2id(to_dir)
 
2609
        to_dir_id = self.path2id(to_dir)
2618
2610
        if to_dir_id is None:
2619
2611
            raise errors.BzrMoveFailedError('',to_dir,
2620
2612
                errors.NotVersionedError(path=to_dir))
2621
2613
 
2622
 
        to_dir_ie = inv[to_dir_id]
 
2614
        to_dir_ie = self.inventory[to_dir_id]
2623
2615
        if to_dir_ie.kind != 'directory':
2624
2616
            raise errors.BzrMoveFailedError('',to_dir,
2625
2617
                errors.NotADirectory(to_abs))
2627
2619
        # create rename entries and tuples
2628
2620
        for from_rel in from_paths:
2629
2621
            from_tail = splitpath(from_rel)[-1]
2630
 
            from_id = inv.path2id(from_rel)
 
2622
            from_id = self.path2id(from_rel)
2631
2623
            if from_id is None:
2632
2624
                raise errors.BzrMoveFailedError(from_rel,to_dir,
2633
2625
                    errors.NotVersionedError(path=from_rel))
2634
2626
 
2635
 
            from_entry = inv[from_id]
 
2627
            from_entry = self.inventory[from_id]
2636
2628
            from_parent_id = from_entry.parent_id
2637
2629
            to_rel = pathjoin(to_dir, from_tail)
2638
2630
            rename_entry = InventoryWorkingTree._RenameEntry(
2657
2649
            # restore the inventory on error
2658
2650
            self._inventory_is_modified = original_modified
2659
2651
            raise
2660
 
        self._write_inventory(inv)
 
2652
        self._write_inventory(self.inventory)
2661
2653
        return rename_tuples
2662
2654
 
2663
2655
    @needs_tree_write_lock
2683
2675
 
2684
2676
        Everything else results in an error.
2685
2677
        """
2686
 
        inv = self.inventory
2687
2678
        rename_entries = []
2688
2679
 
2689
2680
        # create rename entries and tuples
2690
2681
        from_tail = splitpath(from_rel)[-1]
2691
 
        from_id = inv.path2id(from_rel)
 
2682
        from_id = self.path2id(from_rel)
2692
2683
        if from_id is None:
2693
2684
            # if file is missing in the inventory maybe it's in the basis_tree
2694
2685
            basis_tree = self.branch.basis_tree()
2698
2689
                    errors.NotVersionedError(path=from_rel))
2699
2690
            # put entry back in the inventory so we can rename it
2700
2691
            from_entry = basis_tree.inventory[from_id].copy()
2701
 
            inv.add(from_entry)
 
2692
            self.inventory.add(from_entry)
2702
2693
        else:
2703
 
            from_entry = inv[from_id]
 
2694
            from_entry = self.inventory[from_id]
2704
2695
        from_parent_id = from_entry.parent_id
2705
2696
        to_dir, to_tail = os.path.split(to_rel)
2706
 
        to_dir_id = inv.path2id(to_dir)
 
2697
        to_dir_id = self.path2id(to_dir)
2707
2698
        rename_entry = InventoryWorkingTree._RenameEntry(from_rel=from_rel,
2708
2699
                                     from_id=from_id,
2709
2700
                                     from_tail=from_tail,
2731
2722
               from_id, from_rel, to_rel, to_dir, to_dir_id)
2732
2723
 
2733
2724
        self._move(rename_entries)
2734
 
        self._write_inventory(inv)
 
2725
        self._write_inventory(self.inventory)
2735
2726
 
2736
2727
    class _RenameEntry(object):
2737
2728
        def __init__(self, from_rel, from_id, from_tail, from_parent_id,
2817
2808
        Depending on the value of the flag 'only_change_inv', the
2818
2809
        file will be moved on the file system or not.
2819
2810
        """
2820
 
        inv = self.inventory
2821
2811
        moved = []
2822
2812
 
2823
2813
        for entry in rename_entries:
2830
2820
 
2831
2821
    def _rollback_move(self, moved):
2832
2822
        """Try to rollback a previous move in case of an filesystem error."""
2833
 
        inv = self.inventory
2834
2823
        for entry in moved:
2835
2824
            try:
2836
2825
                self._move_entry(WorkingTree._RenameEntry(