~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Vincent Ladeuil
  • Date: 2008-09-11 19:36:38 UTC
  • mfrom: (3703 +trunk)
  • mto: (3705.1.1 trunk2)
  • mto: This revision was merged to the branch mainline in revision 3708.
  • Revision ID: v.ladeuil+lp@free.fr-20080911193638-wtjyc1kcmacc6t1f
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
379
379
        """Return RevisionTree for the current last revision.
380
380
        
381
381
        If the left most parent is a ghost then the returned tree will be an
382
 
        empty tree - one obtained by calling repository.revision_tree(None).
 
382
        empty tree - one obtained by calling 
 
383
        repository.revision_tree(NULL_REVISION).
383
384
        """
384
385
        try:
385
386
            revision_id = self.get_parent_ids()[0]
387
388
            # no parents, return an empty revision tree.
388
389
            # in the future this should return the tree for
389
390
            # 'empty:' - the implicit root empty tree.
390
 
            return self.branch.repository.revision_tree(None)
 
391
            return self.branch.repository.revision_tree(
 
392
                       _mod_revision.NULL_REVISION)
391
393
        try:
392
394
            return self.revision_tree(revision_id)
393
395
        except errors.NoSuchRevision:
404
406
            if self.branch.repository.has_revision(revision_id):
405
407
                raise
406
408
            # the basis tree is a ghost so return an empty tree.
407
 
            return self.branch.repository.revision_tree(None)
 
409
            return self.branch.repository.revision_tree(
 
410
                       _mod_revision.NULL_REVISION)
408
411
 
409
412
    def _cleanup(self):
410
413
        self._flush_ignore_list_cache()
520
523
            and this one merged in.
521
524
        """
522
525
        # assumes the target bzr dir format is compatible.
523
 
        result = self._format.initialize(to_bzrdir)
 
526
        result = to_bzrdir.create_workingtree()
524
527
        self.copy_content_into(result, revision_id)
525
528
        return result
526
529
 
897
900
            hashfile = self._transport.get('merge-hashes')
898
901
        except errors.NoSuchFile:
899
902
            return {}
900
 
        merge_hashes = {}
901
903
        try:
902
 
            if hashfile.next() != MERGE_MODIFIED_HEADER_1 + '\n':
 
904
            merge_hashes = {}
 
905
            try:
 
906
                if hashfile.next() != MERGE_MODIFIED_HEADER_1 + '\n':
 
907
                    raise errors.MergeModifiedFormatError()
 
908
            except StopIteration:
903
909
                raise errors.MergeModifiedFormatError()
904
 
        except StopIteration:
905
 
            raise errors.MergeModifiedFormatError()
906
 
        for s in RioReader(hashfile):
907
 
            # RioReader reads in Unicode, so convert file_ids back to utf8
908
 
            file_id = osutils.safe_file_id(s.get("file_id"), warn=False)
909
 
            if file_id not in self.inventory:
910
 
                continue
911
 
            text_hash = s.get("hash")
912
 
            if text_hash == self.get_file_sha1(file_id):
913
 
                merge_hashes[file_id] = text_hash
914
 
        return merge_hashes
 
910
            for s in RioReader(hashfile):
 
911
                # RioReader reads in Unicode, so convert file_ids back to utf8
 
912
                file_id = osutils.safe_file_id(s.get("file_id"), warn=False)
 
913
                if file_id not in self.inventory:
 
914
                    continue
 
915
                text_hash = s.get("hash")
 
916
                if text_hash == self.get_file_sha1(file_id):
 
917
                    merge_hashes[file_id] = text_hash
 
918
            return merge_hashes
 
919
        finally:
 
920
            hashfile.close()
915
921
 
916
922
    @needs_write_lock
917
923
    def mkdir(self, path, file_id=None):
2593
2599
        except errors.NoSuchFile:
2594
2600
            return _mod_conflicts.ConflictList()
2595
2601
        try:
2596
 
            if confile.next() != CONFLICT_HEADER_1 + '\n':
 
2602
            try:
 
2603
                if confile.next() != CONFLICT_HEADER_1 + '\n':
 
2604
                    raise errors.ConflictFormatError()
 
2605
            except StopIteration:
2597
2606
                raise errors.ConflictFormatError()
2598
 
        except StopIteration:
2599
 
            raise errors.ConflictFormatError()
2600
 
        return _mod_conflicts.ConflictList.from_stanzas(RioReader(confile))
 
2607
            return _mod_conflicts.ConflictList.from_stanzas(RioReader(confile))
 
2608
        finally:
 
2609
            confile.close()
2601
2610
 
2602
2611
    def unlock(self):
2603
2612
        # do non-implementation specific cleanup
2714
2723
        """See WorkingTreeFormat.get_format_description()."""
2715
2724
        return "Working tree format 2"
2716
2725
 
2717
 
    def _stub_initialize_remote(self, branch):
2718
 
        """As a special workaround create critical control files for a remote working tree.
2719
 
        
 
2726
    def _stub_initialize_on_transport(self, transport, file_mode):
 
2727
        """Workaround: create control files for a remote working tree.
 
2728
 
2720
2729
        This ensures that it can later be updated and dealt with locally,
2721
 
        since BzrDirFormat6 and BzrDirFormat5 cannot represent dirs with 
 
2730
        since BzrDirFormat6 and BzrDirFormat5 cannot represent dirs with
2722
2731
        no working tree.  (See bug #43064).
2723
2732
        """
2724
2733
        sio = StringIO()
2725
2734
        inv = Inventory()
2726
2735
        xml5.serializer_v5.write_inventory(inv, sio, working=True)
2727
2736
        sio.seek(0)
2728
 
        branch._transport.put_file('inventory', sio,
2729
 
            mode=branch.control_files._file_mode)
2730
 
        branch._transport.put_bytes('pending-merges', '',
2731
 
            mode=branch.control_files._file_mode)
2732
 
        
 
2737
        transport.put_file('inventory', sio, file_mode)
 
2738
        transport.put_bytes('pending-merges', '', file_mode)
2733
2739
 
2734
2740
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
2735
2741
                   accelerator_tree=None, hardlink=False):