/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/branch.py

Merge from integration, mode-changes are broken.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import bzrlib
27
27
from bzrlib.trace import mutter, note
28
28
from bzrlib.osutils import (isdir, quotefn,
29
 
                            rename, splitpath, sha_file, appendpath, 
30
 
                            file_kind, abspath)
 
29
                            rename, splitpath, sha_file,
 
30
                            file_kind, abspath, normpath, pathjoin)
31
31
import bzrlib.errors as errors
32
32
from bzrlib.errors import (BzrError, InvalidRevisionNumber, InvalidRevisionId,
33
33
                           NoSuchRevision, HistoryMissing, NotBranchError,
130
130
        while True:
131
131
            try:
132
132
                return BzrBranch(t), t.relpath(url)
133
 
            except NotBranchError:
134
 
                pass
 
133
            except NotBranchError, e:
 
134
                mutter('not a branch in: %r %s', t.base, e)
135
135
            new_t = t.clone('..')
136
136
            if new_t.base == t.base:
137
137
                # reached the root, whatever that may be
422
422
    # filesystem access, so that in a later step, we can extricate them to
423
423
    # a separarte ("storage") class.
424
424
    _inventory_weave = None
 
425
    # If set to False (by a plugin, etc) BzrBranch will not set the
 
426
    # mode on created files or directories
 
427
    _set_file_mode = True
 
428
    _set_dir_mode = True
425
429
    
426
430
    # Map some sort of prefix into a namespace
427
431
    # stuff like "revno:10", "revid:", etc.
472
476
        if init:
473
477
            self._make_control()
474
478
        self._check_format(relax_version_check)
475
 
        self.repository = Repository(transport, self._branch_format)
 
479
        self._find_modes()
 
480
        self.repository = Repository(transport, self._branch_format,
 
481
                                     dir_mode=self._dir_mode,
 
482
                                     file_mode=self._file_mode)
476
483
 
477
484
    def __str__(self):
478
485
        return '%s(%r)' % (self.__class__.__name__, self.base)
527
534
        """See Branch.abspath."""
528
535
        return self.control_files._transport.abspath(name)
529
536
 
 
537
    def _find_modes(self, path=None):
 
538
        """Determine the appropriate modes for files and directories."""
 
539
        # RBC 20060103 FIXME where does this belong ?
 
540
        try:
 
541
            if path is None:
 
542
                path = ''
 
543
                #self.control_files._rel_controlfilename('')
 
544
            st = self.control_files._transport.stat(path)
 
545
        except errors.TransportNotPossible:
 
546
            self._dir_mode = 0755
 
547
            self._file_mode = 0644
 
548
        else:
 
549
            self._dir_mode = st.st_mode & 07777
 
550
            # Remove the sticky and execute bits for files
 
551
            self._file_mode = self._dir_mode & ~07111
 
552
        if not self._set_dir_mode:
 
553
            self._dir_mode = None
 
554
        if not self._set_file_mode:
 
555
            self._file_mode = None
 
556
 
530
557
    def _make_control(self):
531
558
        from bzrlib.inventory import Inventory
532
559
        from bzrlib.weavefile import write_weave_v5
543
570
        bzrlib.weavefile.write_weave_v5(Weave(), sio)
544
571
        empty_weave = sio.getvalue()
545
572
 
546
 
        dirs = [[], 'revision-store', 'weaves']
 
573
        # Since we don't have a .bzr directory, inherit the
 
574
        # mode from the root directory
 
575
        self._find_modes('.')
 
576
 
 
577
        dirs = ['', 'revision-store', 'weaves']
547
578
        files = [('README', 
548
579
            "This is a Bazaar-NG control directory.\n"
549
580
            "Do not change any files in this directory.\n"),
557
588
            ('ancestry.weave', empty_weave)
558
589
        ]
559
590
        cfn = self.control_files._rel_controlfilename
560
 
        self.control_files._transport.mkdir_multi([cfn(d) for d in dirs])
 
591
        self.control_files._transport.mkdir_multi([cfn(d) for d in dirs],
 
592
                                                  mode=self._dir_mode)
561
593
        self.control_files.lock_write()
562
594
        try:
563
595
            for file, content in files:
645
677
        except NoWorkingTree:
646
678
            mutter('Unable to set_last_revision without a working tree.')
647
679
 
648
 
 
649
680
    def get_revision_delta(self, revno):
650
681
        """Return the delta for one revision.
651
682
 
726
757
            # that for a working tree. RBC 20051207
727
758
            xml = self.working_tree().read_basis_inventory(revision_id)
728
759
            inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
729
 
            return RevisionTree(self.repository.weave_store, inv, revision_id)
 
760
            return RevisionTree(self.repository, inv, revision_id)
730
761
        except (IndexError, NoSuchFile, NoWorkingTree), e:
731
762
            return self.repository.revision_tree(self.last_revision())
732
763
 
880
911
        ...   orig.base == clone.base
881
912
        ...
882
913
        False
883
 
        >>> os.path.isfile(os.path.join(clone.base, "file1"))
 
914
        >>> os.path.isfile(pathjoin(clone.base, "file1"))
884
915
        True
885
916
        """
886
917
        from shutil import copytree
887
 
        from tempfile import mkdtemp
 
918
        from bzrlib.osutils import mkdtemp
888
919
        base = mkdtemp()
889
920
        os.rmdir(base)
890
921
        copytree(self.base, base, symlinks=True)
898
929
 
899
930
def is_control_file(filename):
900
931
    ## FIXME: better check
901
 
    filename = os.path.normpath(filename)
 
932
    filename = normpath(filename)
902
933
    while filename != '':
903
934
        head, tail = os.path.split(filename)
904
935
        ## mutter('check %r for control file' % ((head, tail), ))