~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Martin Pool
  • Date: 2010-01-12 01:44:13 UTC
  • mto: (4634.119.3 2.0)
  • mto: This revision was merged to the branch mainline in revision 4951.
  • Revision ID: mbp@sourcefrog.net-20100112014413-uw90vrssc3trlzmt
Refuse to build with pyrex 0.9.4*

Show diffs side-by-side

added added

removed removed

Lines of Context:
281
281
        self._control_files.break_lock()
282
282
        self.branch.break_lock()
283
283
 
 
284
    def _get_check_refs(self):
 
285
        """Return the references needed to perform a check of this tree.
 
286
        
 
287
        The default implementation returns no refs, and is only suitable for
 
288
        trees that have no local caching and can commit on ghosts at any time.
 
289
 
 
290
        :seealso: bzrlib.check for details about check_refs.
 
291
        """
 
292
        return []
 
293
 
284
294
    def requires_rich_root(self):
285
295
        return self._format.requires_rich_root
286
296
 
603
613
 
604
614
    def get_file_size(self, file_id):
605
615
        """See Tree.get_file_size"""
 
616
        # XXX: this returns the on-disk size; it should probably return the
 
617
        # canonical size
606
618
        try:
607
619
            return os.path.getsize(self.id2abspath(file_id))
608
620
        except OSError, e:
739
751
            raise
740
752
        kind = _mapper(stat_result.st_mode)
741
753
        if kind == 'file':
742
 
            size = stat_result.st_size
743
 
            # try for a stat cache lookup
744
 
            executable = self._is_executable_from_path_and_stat(path, stat_result)
745
 
            return (kind, size, executable, self._sha_from_stat(
746
 
                path, stat_result))
 
754
            return self._file_content_summary(path, stat_result)
747
755
        elif kind == 'directory':
748
756
            # perhaps it looks like a plain directory, but it's really a
749
757
            # reference.
756
764
        else:
757
765
            return (kind, None, None, None)
758
766
 
 
767
    def _file_content_summary(self, path, stat_result):
 
768
        size = stat_result.st_size
 
769
        executable = self._is_executable_from_path_and_stat(path, stat_result)
 
770
        # try for a stat cache lookup
 
771
        return ('file', size, executable, self._sha_from_stat(
 
772
            path, stat_result))
 
773
 
759
774
    def _check_parents_for_ghosts(self, revision_ids, allow_leftmost_as_ghost):
760
775
        """Common ghost checking functionality from set_parent_*.
761
776
 
1476
1491
        from_tail = splitpath(from_rel)[-1]
1477
1492
        from_id = inv.path2id(from_rel)
1478
1493
        if from_id is None:
1479
 
            raise errors.BzrRenameFailedError(from_rel,to_rel,
1480
 
                errors.NotVersionedError(path=str(from_rel)))
1481
 
        from_entry = inv[from_id]
 
1494
            # if file is missing in the inventory maybe it's in the basis_tree
 
1495
            basis_tree = self.branch.basis_tree()
 
1496
            from_id = basis_tree.path2id(from_rel)
 
1497
            if from_id is None:
 
1498
                raise errors.BzrRenameFailedError(from_rel,to_rel,
 
1499
                    errors.NotVersionedError(path=str(from_rel)))
 
1500
            # put entry back in the inventory so we can rename it
 
1501
            from_entry = basis_tree.inventory[from_id].copy()
 
1502
            inv.add(from_entry)
 
1503
        else:
 
1504
            from_entry = inv[from_id]
1482
1505
        from_parent_id = from_entry.parent_id
1483
1506
        to_dir, to_tail = os.path.split(to_rel)
1484
1507
        to_dir_id = inv.path2id(to_dir)
1875
1898
            firstline = xml.split('\n', 1)[0]
1876
1899
            if (not 'revision_id="' in firstline or
1877
1900
                'format="7"' not in firstline):
1878
 
                inv = self.branch.repository.deserialise_inventory(
1879
 
                    new_revision, xml)
 
1901
                inv = self.branch.repository._serializer.read_inventory_from_string(
 
1902
                    xml, new_revision)
1880
1903
                xml = self._create_basis_xml_from_inventory(new_revision, inv)
1881
1904
            self._write_basis_inventory(xml)
1882
1905
        except (errors.NoSuchRevision, errors.RevisionNotPresent):
2528
2551
        return un_resolved, resolved
2529
2552
 
2530
2553
    @needs_read_lock
2531
 
    def _check(self):
 
2554
    def _check(self, references):
 
2555
        """Check the tree for consistency.
 
2556
 
 
2557
        :param references: A dict with keys matching the items returned by
 
2558
            self._get_check_refs(), and values from looking those keys up in
 
2559
            the repository.
 
2560
        """
2532
2561
        tree_basis = self.basis_tree()
2533
2562
        tree_basis.lock_read()
2534
2563
        try:
2535
 
            repo_basis = self.branch.repository.revision_tree(
2536
 
                self.last_revision())
 
2564
            repo_basis = references[('trees', self.last_revision())]
2537
2565
            if len(list(repo_basis.iter_changes(tree_basis))) > 0:
2538
2566
                raise errors.BzrCheckError(
2539
2567
                    "Mismatched basis inventory content.")
2585
2613
        if self._inventory is None:
2586
2614
            self.read_working_inventory()
2587
2615
 
 
2616
    def _get_check_refs(self):
 
2617
        """Return the references needed to perform a check of this tree."""
 
2618
        return [('trees', self.last_revision())]
 
2619
 
2588
2620
    def lock_tree_write(self):
2589
2621
        """See WorkingTree.lock_tree_write().
2590
2622
 
2647
2679
                mode=self.bzrdir._get_file_mode())
2648
2680
            return True
2649
2681
 
 
2682
    def _get_check_refs(self):
 
2683
        """Return the references needed to perform a check of this tree."""
 
2684
        return [('trees', self.last_revision())]
 
2685
 
2650
2686
    @needs_tree_write_lock
2651
2687
    def set_conflicts(self, conflicts):
2652
2688
        self._put_rio('conflicts', conflicts.to_stanzas(),
2999
3035
        return self.get_format_string()
3000
3036
 
3001
3037
 
3002
 
__default_format = WorkingTreeFormat4()
 
3038
__default_format = WorkingTreeFormat6()
3003
3039
WorkingTreeFormat.register_format(__default_format)
3004
 
WorkingTreeFormat.register_format(WorkingTreeFormat6())
3005
3040
WorkingTreeFormat.register_format(WorkingTreeFormat5())
 
3041
WorkingTreeFormat.register_format(WorkingTreeFormat4())
3006
3042
WorkingTreeFormat.register_format(WorkingTreeFormat3())
3007
3043
WorkingTreeFormat.set_default_format(__default_format)
3008
3044
# formats which have no format string are not discoverable