~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Vincent Ladeuil
  • Date: 2016-01-21 17:48:07 UTC
  • mto: This revision was merged to the branch mainline in revision 6613.
  • Revision ID: v.ladeuil+lp@free.fr-20160121174807-g4ybpaij9ln5wj6a
Make all transport put_bytes() raises TypeError when given unicode strings rather than bytes.

There was a mix of AssertionError or UnicodeEncodeError.

Also deleted test_put_file_unicode() which was bogus, files contain bytes not unicode strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
import re
18
20
import sys
19
21
 
25
27
from bzrlib import (
26
28
    chk_map,
27
29
    cleanup,
 
30
    config,
28
31
    debug,
29
32
    graph,
30
33
    osutils,
54
57
from bzrlib.repository import (
55
58
    _LazyListJoin,
56
59
    MetaDirRepository,
57
 
    RepositoryFormat,
 
60
    RepositoryFormatMetaDir,
58
61
    RepositoryWriteLockResult,
59
62
    )
60
63
from bzrlib.vf_repository import (
478
481
        # visible is smaller.  On the other hand none will be seen until
479
482
        # they're in the names list.
480
483
        self.index_sizes = [None, None, None, None]
481
 
        self._write_index('revision', self.revision_index, 'revision', suspend)
 
484
        self._write_index('revision', self.revision_index, 'revision',
 
485
            suspend)
482
486
        self._write_index('inventory', self.inventory_index, 'inventory',
483
487
            suspend)
484
488
        self._write_index('text', self.text_index, 'file texts', suspend)
488
492
            self.index_sizes.append(None)
489
493
            self._write_index('chk', self.chk_index,
490
494
                'content hash bytes', suspend)
491
 
        self.write_stream.close()
 
495
        self.write_stream.close(
 
496
            want_fdatasync=self._pack_collection.config_stack.get('repository.fdatasync'))
492
497
        # Note that this will clobber an existing pack with the same name,
493
498
        # without checking for hash collisions. While this is undesirable this
494
499
        # is something that can be rectified in a subsequent release. One way
537
542
            transport = self.upload_transport
538
543
        else:
539
544
            transport = self.index_transport
540
 
        self.index_sizes[self.index_offset(index_type)] = transport.put_file(
541
 
            index_name, index.finish(), mode=self._file_mode)
 
545
        index_tempfile = index.finish()
 
546
        index_bytes = index_tempfile.read()
 
547
        write_stream = transport.open_write_stream(index_name,
 
548
            mode=self._file_mode)
 
549
        write_stream.write(index_bytes)
 
550
        write_stream.close(
 
551
            want_fdatasync=self._pack_collection.config_stack.get('repository.fdatasync'))
 
552
        self.index_sizes[self.index_offset(index_type)] = len(index_bytes)
542
553
        if 'pack' in debug.debug_flags:
543
554
            # XXX: size might be interesting?
544
555
            mutter('%s: create_pack: wrote %s index: %s%s t+%6.3fs',
822
833
                set(all_combined).difference([combined_idx]))
823
834
        # resumed packs
824
835
        self._resumed_packs = []
 
836
        self.config_stack = config.LocationStack(self.transport.base)
825
837
 
826
838
    def __repr__(self):
827
839
        return '%s(%r)' % (self.__class__.__name__, self.repo)
1211
1223
        """
1212
1224
        for pack in packs:
1213
1225
            try:
1214
 
                pack.pack_transport.move(pack.file_name(),
1215
 
                    '../obsolete_packs/' + pack.file_name())
 
1226
                try:
 
1227
                    pack.pack_transport.move(pack.file_name(),
 
1228
                        '../obsolete_packs/' + pack.file_name())
 
1229
                except errors.NoSuchFile:
 
1230
                    # perhaps obsolete_packs was removed? Let's create it and
 
1231
                    # try again
 
1232
                    try:
 
1233
                        pack.pack_transport.mkdir('../obsolete_packs/')
 
1234
                    except errors.FileExists:
 
1235
                        pass
 
1236
                    pack.pack_transport.move(pack.file_name(),
 
1237
                        '../obsolete_packs/' + pack.file_name())
1216
1238
            except (errors.PathError, errors.TransportError), e:
1217
1239
                # TODO: Should these be warnings or mutters?
1218
1240
                mutter("couldn't rename obsolete pack, skipping it:\n%s"
1484
1506
        obsolete_pack_transport = self.transport.clone('obsolete_packs')
1485
1507
        if preserve is None:
1486
1508
            preserve = set()
1487
 
        for filename in obsolete_pack_transport.list_dir('.'):
 
1509
        try:
 
1510
            obsolete_pack_files = obsolete_pack_transport.list_dir('.')
 
1511
        except errors.NoSuchFile:
 
1512
            return found
 
1513
        for filename in obsolete_pack_files:
1488
1514
            name, ext = osutils.splitext(filename)
1489
1515
            if ext == '.pack':
1490
1516
                found.append(name)
1896
1922
                                    than normal. I.e. during 'upgrade'.
1897
1923
        """
1898
1924
        if not _found:
1899
 
            format = RepositoryFormat.find_format(a_bzrdir)
 
1925
            format = RepositoryFormatMetaDir.find_format(a_bzrdir)
1900
1926
        if _override_transport is not None:
1901
1927
            repo_transport = _override_transport
1902
1928
        else: