~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

merge permissions branch, also fixup tests so they are lined up with bzr.dev to help prevent conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
355
355
        >>> commit(br1, "lala!", rev_id="REVISION-ID-2B")
356
356
        >>> br1.missing_revisions(br2)
357
357
        Traceback (most recent call last):
358
 
        DivergedBranches: These branches have diverged.
 
358
        DivergedBranches: These branches have diverged.  Try merge.
359
359
        """
360
360
        self_history = self.revision_history()
361
361
        self_len = len(self_history)
512
512
    _lock_count = None
513
513
    _lock = None
514
514
    _inventory_weave = None
 
515
    # If set to False (by a plugin, etc) BzrBranch will not set the
 
516
    # mode on created files or directories
 
517
    _set_file_mode = True
 
518
    _set_dir_mode = True
515
519
    
516
520
    # Map some sort of prefix into a namespace
517
521
    # stuff like "revno:10", "revid:", etc.
562
566
        if init:
563
567
            self._make_control()
564
568
        self._check_format(relax_version_check)
 
569
        self._find_modes()
565
570
 
566
571
        def get_store(name, compressed=True, prefixed=False):
567
 
            # FIXME: This approach of assuming stores are all entirely compressed
568
 
            # or entirely uncompressed is tidy, but breaks upgrade from 
569
 
            # some existing branches where there's a mixture; we probably 
570
 
            # still want the option to look for both.
571
572
            relpath = self._rel_controlfilename(unicode(name))
572
573
            store = TextStore(self._transport.clone(relpath),
 
574
                              dir_mode=self._dir_mode,
 
575
                              file_mode=self._file_mode,
573
576
                              prefixed=prefixed,
574
577
                              compressed=compressed)
575
 
            #if self._transport.should_cache():
576
 
            #    cache_path = pathjoin(self.cache_root, name)
577
 
            #    os.mkdir(cache_path)
578
 
            #    store = bzrlib.store.CachedStore(store, cache_path)
579
578
            return store
580
579
 
581
580
        def get_weave(name, prefixed=False):
582
581
            relpath = self._rel_controlfilename(unicode(name))
583
 
            ws = WeaveStore(self._transport.clone(relpath), prefixed=prefixed)
 
582
            ws = WeaveStore(self._transport.clone(relpath),
 
583
                            prefixed=prefixed,
 
584
                            dir_mode=self._dir_mode,
 
585
                            file_mode=self._file_mode)
584
586
            if self._transport.should_cache():
585
587
                ws.enable_cache = True
586
588
            return ws
753
755
                    f = codecs.getwriter('utf-8')(f, errors='replace')
754
756
            path = self._rel_controlfilename(path)
755
757
            ctrl_files.append((path, f))
756
 
        self._transport.put_multi(ctrl_files)
 
758
        self._transport.put_multi(ctrl_files, mode=self._file_mode)
 
759
 
 
760
    def _find_modes(self, path=None):
 
761
        """Determine the appropriate modes for files and directories."""
 
762
        try:
 
763
            if path is None:
 
764
                path = self._rel_controlfilename('')
 
765
            st = self._transport.stat(path)
 
766
        except errors.TransportNotPossible:
 
767
            self._dir_mode = 0755
 
768
            self._file_mode = 0644
 
769
        else:
 
770
            self._dir_mode = st.st_mode & 07777
 
771
            # Remove the sticky and execute bits for files
 
772
            self._file_mode = self._dir_mode & ~07111
 
773
        if not self._set_dir_mode:
 
774
            self._dir_mode = None
 
775
        if not self._set_file_mode:
 
776
            self._file_mode = None
757
777
 
758
778
    def _make_control(self):
759
779
        from bzrlib.inventory import Inventory
771
791
        bzrlib.weavefile.write_weave_v5(Weave(), sio)
772
792
        empty_weave = sio.getvalue()
773
793
 
774
 
        dirs = [[], 'revision-store', 'weaves']
 
794
        cfn = self._rel_controlfilename
 
795
        # Since we don't have a .bzr directory, inherit the
 
796
        # mode from the root directory
 
797
        self._find_modes(u'.')
 
798
 
 
799
        dirs = ['', 'revision-store', 'weaves']
775
800
        files = [('README', 
776
801
            "This is a Bazaar-NG control directory.\n"
777
802
            "Do not change any files in this directory.\n"),
784
809
            ('inventory.weave', empty_weave),
785
810
            ('ancestry.weave', empty_weave)
786
811
        ]
787
 
        cfn = self._rel_controlfilename
788
 
        self._transport.mkdir_multi([cfn(d) for d in dirs])
 
812
        self._transport.mkdir_multi([cfn(d) for d in dirs], mode=self._dir_mode)
789
813
        self.put_controlfiles(files)
790
814
        mutter('created control directory in ' + self._transport.base)
791
815