~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-11-17 03:20:35 UTC
  • mfrom: (4792.4.3 456036)
  • Revision ID: pqm@pqm.ubuntu.com-20091117032035-s3sgtlixj1lrminn
(Gordon Tyler) Fix IndexError during 'bzr ignore /' (#456036)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
24
24
    bzrdir,
25
25
    check,
26
26
    chk_map,
27
 
    config,
28
27
    debug,
29
28
    errors,
30
 
    fetch as _mod_fetch,
31
29
    fifo_cache,
32
30
    generate_ids,
33
31
    gpg,
41
39
    osutils,
42
40
    revision as _mod_revision,
43
41
    symbol_versioning,
44
 
    trace,
45
42
    tsort,
46
43
    ui,
47
44
    versionedfile,
209
206
            # an inventory delta was accumulated without creating a new
210
207
            # inventory.
211
208
            basis_id = self.basis_delta_revision
212
 
            # We ignore the 'inventory' returned by add_inventory_by_delta
213
 
            # because self.new_inventory is used to hint to the rest of the
214
 
            # system what code path was taken
215
 
            self.inv_sha1, _ = self.repository.add_inventory_by_delta(
 
209
            self.inv_sha1 = self.repository.add_inventory_by_delta(
216
210
                basis_id, self._basis_delta, self._new_revision_id,
217
211
                self.parents)
218
212
        else:
1306
1300
        self._reconcile_does_inventory_gc = True
1307
1301
        self._reconcile_fixes_text_parents = False
1308
1302
        self._reconcile_backsup_inventory = True
 
1303
        # not right yet - should be more semantically clear ?
 
1304
        #
 
1305
        # TODO: make sure to construct the right store classes, etc, depending
 
1306
        # on whether escaping is required.
 
1307
        self._warn_if_deprecated()
1309
1308
        self._write_group = None
1310
1309
        # Additional places to query for data.
1311
1310
        self._fallback_repositories = []
1312
1311
        # An InventoryEntry cache, used during deserialization
1313
1312
        self._inventory_entry_cache = fifo_cache.FIFOCache(10*1024)
1314
 
        # Is it safe to return inventory entries directly from the entry cache,
1315
 
        # rather copying them?
1316
 
        self._safe_to_return_from_cache = False
1317
1313
 
1318
1314
    def __repr__(self):
1319
1315
        if self._fallback_repositories:
1386
1382
        locked = self.is_locked()
1387
1383
        result = self.control_files.lock_write(token=token)
1388
1384
        if not locked:
1389
 
            self._warn_if_deprecated()
1390
1385
            self._note_lock('w')
1391
1386
            for repo in self._fallback_repositories:
1392
1387
                # Writes don't affect fallback repos
1398
1393
        locked = self.is_locked()
1399
1394
        self.control_files.lock_read()
1400
1395
        if not locked:
1401
 
            self._warn_if_deprecated()
1402
1396
            self._note_lock('r')
1403
1397
            for repo in self._fallback_repositories:
1404
1398
                repo.lock_read()
2433
2427
        :param xml: A serialised inventory.
2434
2428
        """
2435
2429
        result = self._serializer.read_inventory_from_string(xml, revision_id,
2436
 
                    entry_cache=self._inventory_entry_cache,
2437
 
                    return_from_cache=self._safe_to_return_from_cache)
 
2430
                    entry_cache=self._inventory_entry_cache)
2438
2431
        if result.revision_id != revision_id:
2439
2432
            raise AssertionError('revision id mismatch %s != %s' % (
2440
2433
                result.revision_id, revision_id))
2672
2665
        for ((revision_id,), parent_keys) in \
2673
2666
                self.revisions.get_parent_map(query_keys).iteritems():
2674
2667
            if parent_keys:
2675
 
                result[revision_id] = tuple([parent_revid
2676
 
                    for (parent_revid,) in parent_keys])
 
2668
                result[revision_id] = tuple(parent_revid
 
2669
                    for (parent_revid,) in parent_keys)
2677
2670
            else:
2678
2671
                result[revision_id] = (_mod_revision.NULL_REVISION,)
2679
2672
        return result
2781
2774
        result.check(callback_refs)
2782
2775
        return result
2783
2776
 
2784
 
    def _warn_if_deprecated(self, branch=None):
 
2777
    def _warn_if_deprecated(self):
2785
2778
        global _deprecation_warning_done
2786
2779
        if _deprecation_warning_done:
2787
2780
            return
2788
 
        try:
2789
 
            if branch is None:
2790
 
                conf = config.GlobalConfig()
2791
 
            else:
2792
 
                conf = branch.get_config()
2793
 
            if conf.suppress_warning('format_deprecation'):
2794
 
                return
2795
 
            warning("Format %s for %s is deprecated -"
2796
 
                    " please use 'bzr upgrade' to get better performance"
2797
 
                    % (self._format, self.bzrdir.transport.base))
2798
 
        finally:
2799
 
            _deprecation_warning_done = True
 
2781
        _deprecation_warning_done = True
 
2782
        warning("Format %s for %s is deprecated - please use 'bzr upgrade' to get better performance"
 
2783
                % (self._format, self.bzrdir.transport.base))
2800
2784
 
2801
2785
    def supports_rich_root(self):
2802
2786
        return self._format.rich_root_data
3106
3090
        """
3107
3091
        try:
3108
3092
            transport = a_bzrdir.get_repository_transport(None)
3109
 
            format_string = transport.get_bytes("format")
 
3093
            format_string = transport.get("format").read()
3110
3094
            return format_registry.get(format_string)
3111
3095
        except errors.NoSuchFile:
3112
3096
            raise errors.NoRepositoryPresent(a_bzrdir)
3425
3409
                   provided a default one will be created.
3426
3410
        :return: None.
3427
3411
        """
3428
 
        f = _mod_fetch.RepoFetcher(to_repository=self.target,
 
3412
        from bzrlib.fetch import RepoFetcher
 
3413
        f = RepoFetcher(to_repository=self.target,
3429
3414
                               from_repository=self.source,
3430
3415
                               last_revision=revision_id,
3431
3416
                               fetch_spec=fetch_spec,
3831
3816
                basis_id, delta, current_revision_id, parents_parents)
3832
3817
            cache[current_revision_id] = parent_tree
3833
3818
 
3834
 
    def _fetch_batch(self, revision_ids, basis_id, cache, a_graph=None):
 
3819
    def _fetch_batch(self, revision_ids, basis_id, cache):
3835
3820
        """Fetch across a few revisions.
3836
3821
 
3837
3822
        :param revision_ids: The revisions to copy
3838
3823
        :param basis_id: The revision_id of a tree that must be in cache, used
3839
3824
            as a basis for delta when no other base is available
3840
3825
        :param cache: A cache of RevisionTrees that we can use.
3841
 
        :param a_graph: A Graph object to determine the heads() of the
3842
 
            rich-root data stream.
3843
3826
        :return: The revision_id of the last converted tree. The RevisionTree
3844
3827
            for it will be in cache
3845
3828
        """
3852
3835
        pending_revisions = []
3853
3836
        parent_map = self.source.get_parent_map(revision_ids)
3854
3837
        self._fetch_parent_invs_for_stacking(parent_map, cache)
3855
 
        self.source._safe_to_return_from_cache = True
3856
3838
        for tree in self.source.revision_trees(revision_ids):
3857
3839
            # Find a inventory delta for this revision.
3858
3840
            # Find text entries that need to be copied, too.
3906
3888
            pending_revisions.append(revision)
3907
3889
            cache[current_revision_id] = tree
3908
3890
            basis_id = current_revision_id
3909
 
        self.source._safe_to_return_from_cache = False
3910
3891
        # Copy file texts
3911
3892
        from_texts = self.source.texts
3912
3893
        to_texts = self.target.texts
3913
3894
        if root_keys_to_create:
3914
 
            root_stream = _mod_fetch._new_root_data_stream(
 
3895
            from bzrlib.fetch import _new_root_data_stream
 
3896
            root_stream = _new_root_data_stream(
3915
3897
                root_keys_to_create, self._revision_id_to_root_id, parent_map,
3916
 
                self.source, graph=a_graph)
 
3898
                self.source)
3917
3899
            to_texts.insert_record_stream(root_stream)
3918
3900
        to_texts.insert_record_stream(from_texts.get_record_stream(
3919
3901
            text_keys, self.target._format._fetch_order,
3976
3958
        cache[basis_id] = basis_tree
3977
3959
        del basis_tree # We don't want to hang on to it here
3978
3960
        hints = []
3979
 
        if self._converting_to_rich_root and len(revision_ids) > 100:
3980
 
            a_graph = _mod_fetch._get_rich_root_heads_graph(self.source,
3981
 
                                                            revision_ids)
3982
 
        else:
3983
 
            a_graph = None
3984
 
 
3985
3961
        for offset in range(0, len(revision_ids), batch_size):
3986
3962
            self.target.start_write_group()
3987
3963
            try:
3988
3964
                pb.update('Transferring revisions', offset,
3989
3965
                          len(revision_ids))
3990
3966
                batch = revision_ids[offset:offset+batch_size]
3991
 
                basis_id = self._fetch_batch(batch, basis_id, cache,
3992
 
                                             a_graph=a_graph)
 
3967
                basis_id = self._fetch_batch(batch, basis_id, cache)
3993
3968
            except:
3994
 
                self.source._safe_to_return_from_cache = False
3995
3969
                self.target.abort_write_group()
3996
3970
                raise
3997
3971
            else:
4009
3983
        """See InterRepository.fetch()."""
4010
3984
        if fetch_spec is not None:
4011
3985
            raise AssertionError("Not implemented yet...")
4012
 
        # See <https://launchpad.net/bugs/456077> asking for a warning here
4013
 
        #
4014
 
        # nb this is only active for local-local fetches; other things using
4015
 
        # streaming.
4016
 
        trace.warning("Fetching between repositories with different formats\n"
4017
 
            "from %s to %s.\n"
4018
 
            "This may take some time. Upgrade the branches to the same format \n"
4019
 
            "for better results.\n"
4020
 
            % (self.source._format, self.target._format))
4021
3986
        if (not self.source.supports_rich_root()
4022
3987
            and self.target.supports_rich_root()):
4023
3988
            self._converting_to_rich_root = True
4478
4443
        fetching the inventory weave.
4479
4444
        """
4480
4445
        if self._rich_root_upgrade():
4481
 
            return _mod_fetch.Inter1and2Helper(
 
4446
            import bzrlib.fetch
 
4447
            return bzrlib.fetch.Inter1and2Helper(
4482
4448
                self.from_repository).generate_root_texts(revs)
4483
4449
        else:
4484
4450
            return []